From c7fc01da732f473ef5ce980e7d3ab20d5b8c761e Mon Sep 17 00:00:00 2001 From: Dan Notestein Date: Wed, 7 Jan 2026 14:36:07 -0500 Subject: [PATCH] Add iso_8601_realtime_microseconds time format for logging Adds a new time_format option that uses syscall(SYS_clock_gettime) directly to bypass libfaketime interception. This allows accurate wall-clock timing of hived initialization steps during tests that use fake time. --- include/fc/log/appender.hpp | 8 +++++--- src/log/appender.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/fc/log/appender.hpp b/include/fc/log/appender.hpp index 25fd222..1b0fb43 100644 --- a/include/fc/log/appender.hpp +++ b/include/fc/log/appender.hpp @@ -33,7 +33,8 @@ namespace fc { milliseconds_since_epoch, /// 1685696704999ms iso_8601_seconds, /// 2023-06-02T09:05:41 iso_8601_milliseconds, /// 2023-06-02T09:05:10.580 - iso_8601_microseconds /// 2023-06-02T09:05:06.894046 + iso_8601_microseconds, /// 2023-06-02T09:05:06.894046 + iso_8601_realtime_microseconds /// Real wall-clock time (bypasses libfaketime) }; typedef fc::shared_ptr ptr; @@ -51,9 +52,10 @@ namespace fc { virtual void log( const log_message& m ) = 0; }; } -FC_REFLECT_ENUM( fc::appender::time_format, +FC_REFLECT_ENUM( fc::appender::time_format, (milliseconds_since_hour) (milliseconds_since_epoch) (iso_8601_seconds) (iso_8601_milliseconds) - (iso_8601_microseconds) ) + (iso_8601_microseconds) + (iso_8601_realtime_microseconds) ) diff --git a/src/log/appender.cpp b/src/log/appender.cpp index 588e656..7494fe0 100644 --- a/src/log/appender.cpp +++ b/src/log/appender.cpp @@ -9,6 +9,12 @@ #include #include #include "console_defines.h" +#include + +#ifndef _WIN32 +#include +#include +#endif namespace fc { @@ -59,6 +65,23 @@ namespace fc { case appender::time_format::iso_8601_microseconds: result << time.to_iso_string_in_microseconds(); break; + case appender::time_format::iso_8601_realtime_microseconds: + { +#ifndef _WIN32 + // Use syscall directly to bypass libfaketime interception + struct timespec ts; + syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); + std::time_t seconds = ts.tv_sec; + std::tm utc_tm; + gmtime_r(&seconds, &utc_tm); + result << std::put_time(&utc_tm, "%Y-%m-%dT%H:%M:%S") + << '.' << std::setfill('0') << std::setw(6) << (ts.tv_nsec / 1000); +#else + // On Windows, just use regular time (libfaketime is Linux-only anyway) + result << time.to_iso_string_in_microseconds(); +#endif + } + break; case appender::time_format::milliseconds_since_hour: default: result << (time.time_since_epoch().count() % (1000ll * 1000ll * 60ll * 60)) / 1000 << "ms"; -- GitLab