From 755364e2df22eb088c646bac640ab3eb9c720987 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 13 Jun 2025 14:33:10 +0200 Subject: [PATCH] FEXServer: Clean up time display for logging This is now relative to the time of the first message. Furthermore, display precision is limited to milliseconds (which are actually zero-padded now!). --- Source/Tools/FEXServer/Main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Tools/FEXServer/Main.cpp b/Source/Tools/FEXServer/Main.cpp index 80db51be3..4ea5a7f1e 100644 --- a/Source/Tools/FEXServer/Main.cpp +++ b/Source/Tools/FEXServer/Main.cpp @@ -26,6 +26,8 @@ #include #include +static timespec StartTime {}; + namespace Logging { void MsgHandler(LogMan::DebugLevels Level, const char* Message) { const auto Output = fmt::format("[{}] {}\n", LogMan::DebugLevelStr(Level), Message); @@ -38,7 +40,12 @@ void AssertHandler(const char* Message) { } void ClientMsgHandler(int FD, FEXServerClient::Logging::PacketMsg* const Msg, const char* MsgStr) { - const auto Output = fmt::format("[{}][{}.{}][{}.{}] {}\n", LogMan::DebugLevelStr(Msg->Level), Msg->Header.Timestamp.tv_sec, + if (!StartTime.tv_sec && !StartTime.tv_nsec) { + StartTime = Msg->Header.Timestamp; + } + auto seconds = Msg->Header.Timestamp.tv_sec - StartTime.tv_sec - (Msg->Header.Timestamp.tv_nsec < StartTime.tv_nsec); + auto nanos = (1'000'000'000 + Msg->Header.Timestamp.tv_nsec - StartTime.tv_nsec) % 1'000'000'000; + const auto Output = fmt::format("[{}][{}.{:03}][{}.{}] {}\n", LogMan::DebugLevelStr(Msg->Level), Msg->Header.Timestamp.tv_sec, Msg->Header.Timestamp.tv_nsec, Msg->Header.PID, Msg->Header.TID, MsgStr); write(STDERR_FILENO, Output.c_str(), Output.size()); }