From a19e8f6b7ee753dcea58bb2b934553e5530b2161 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 16 Sep 2021 22:50:34 +0200 Subject: Exposed session id in ZenServerState --- zen/cmds/top.cpp | 20 +++++++++++++++++++- zenutil/include/zenserverprocess.h | 12 +++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/zen/cmds/top.cpp b/zen/cmds/top.cpp index b0d684705..f519c6c03 100644 --- a/zen/cmds/top.cpp +++ b/zen/cmds/top.cpp @@ -3,6 +3,8 @@ #include "top.h" #include +#include +#include #include #include @@ -28,7 +30,23 @@ TopCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 0; } - State.Snapshot([&](const ZenServerState::ZenServerEntry& Entry) { ZEN_INFO("Port {} : pid {}", Entry.ListenPort, Entry.Pid); }); + int n = 0; + const int HeaderPeriod = 20; + + for (;;) + { + if ((n++ % HeaderPeriod) == 0) + { + ZEN_CONSOLE("{:>5} {:>6} {:>24}", "port", "pid", "session"); + } + + State.Snapshot([&](const ZenServerState::ZenServerEntry& Entry) { ZEN_CONSOLE("{:5} {:6} {:24}", Entry.ListenPort, Entry.Pid, Entry.GetSessionId()); }); + + zen::Sleep(1000); + + State.Sweep(); + } + return 0; } diff --git a/zenutil/include/zenserverprocess.h b/zenutil/include/zenserverprocess.h index b659f6e58..d1897d5e2 100644 --- a/zenutil/include/zenserverprocess.h +++ b/zenutil/include/zenserverprocess.h @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -106,9 +107,10 @@ public: FRIEND_ENUM_CLASS_FLAGS(FlagsEnum); - void Reset(); - void SignalShutdownRequest(); - bool AddSponsorProcess(uint32_t Pid); + zen::Oid GetSessionId() const { return zen::Oid::FromMemory(SessionId); } + void Reset(); + void SignalShutdownRequest(); + bool AddSponsorProcess(uint32_t Pid); }; static_assert(sizeof(ZenServerEntry) == 256); @@ -121,8 +123,8 @@ public: void Snapshot(std::function&& Callback); private: - void* m_hMapFile = nullptr; - ZenServerEntry* m_Data; + void* m_hMapFile = nullptr; + ZenServerEntry* m_Data = nullptr; int m_MaxEntryCount = 131072 / sizeof(ZenServerEntry); ZenServerEntry* m_OurEntry = nullptr; }; -- cgit v1.2.3