Merge pull request #3664 from Sonicadvance1/change_timestamp

FEXLogging: Changes representation of timestamp
This commit is contained in:
Alyssa Rosenzweig 2024-05-29 16:44:42 -04:00 committed by GitHub
commit 9b1b9c26cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 11 deletions

View File

@ -116,7 +116,7 @@ namespace Logging {
};
struct PacketHeader {
uint64_t Timestamp {};
struct timespec Timestamp {};
PacketTypes PacketType {};
int32_t PID {};
int32_t TID {};
@ -131,21 +131,17 @@ namespace Logging {
uint32_t Pad {};
};
static_assert(sizeof(PacketHeader) == 24, "Wrong size");
static_assert(sizeof(PacketHeader) == 32, "Wrong size");
[[maybe_unused]]
static PacketHeader FillHeader(Logging::PacketTypes Type) {
struct timespec Time {};
uint64_t Timestamp {};
clock_gettime(CLOCK_MONOTONIC, &Time);
Timestamp = Time.tv_sec * 1e9 + Time.tv_nsec;
Logging::PacketHeader Msg {
.Timestamp = Timestamp,
.PacketType = Type,
.PID = ::getpid(),
.TID = FHU::Syscalls::gettid(),
};
clock_gettime(CLOCK_MONOTONIC, &Msg.Timestamp);
return Msg;
}

View File

@ -8,7 +8,7 @@
#include <vector>
namespace Logging {
void ClientMsgHandler(int FD, uint64_t Timestamp, uint32_t PID, uint32_t TID, uint32_t Level, const char* Msg);
void ClientMsgHandler(int FD, FEXServerClient::Logging::PacketMsg* const Msg, const char* MsgStr);
}
namespace Logger {
@ -48,7 +48,7 @@ void HandleLogData(int Socket) {
if (Header->PacketType == FEXServerClient::Logging::PacketTypes::TYPE_MSG) {
FEXServerClient::Logging::PacketMsg* Msg = reinterpret_cast<FEXServerClient::Logging::PacketMsg*>(&Data[CurrentOffset]);
const char* MsgText = reinterpret_cast<const char*>(&Data[CurrentOffset + sizeof(FEXServerClient::Logging::PacketMsg)]);
Logging::ClientMsgHandler(Socket, Msg->Header.Timestamp, Msg->Header.PID, Msg->Header.TID, Msg->Level, MsgText);
Logging::ClientMsgHandler(Socket, Msg, MsgText);
CurrentOffset += sizeof(FEXServerClient::Logging::PacketMsg) + Msg->MessageLength;
} else {

View File

@ -35,8 +35,9 @@ void AssertHandler(const char* Message) {
write(STDOUT_FILENO, Output.c_str(), Output.size());
}
void ClientMsgHandler(int FD, uint64_t Timestamp, uint32_t PID, uint32_t TID, uint32_t Level, const char* Msg) {
const auto Output = fmt::format("[{}][{}][{}.{}] {}\n", LogMan::DebugLevelStr(Level), Timestamp, PID, TID, Msg);
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,
Msg->Header.Timestamp.tv_nsec, Msg->Header.PID, Msg->Header.TID, MsgStr);
write(STDERR_FILENO, Output.c_str(), Output.size());
}
} // namespace Logging