diff options
| author | Stefan Boberg <[email protected]> | 2021-09-16 22:50:34 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-16 22:50:34 +0200 |
| commit | a19e8f6b7ee753dcea58bb2b934553e5530b2161 (patch) | |
| tree | 4acf7192a8ffeb5eaa4ee1d875fd415cf0f7c571 | |
| parent | clang-format (diff) | |
| download | zen-a19e8f6b7ee753dcea58bb2b934553e5530b2161.tar.xz zen-a19e8f6b7ee753dcea58bb2b934553e5530b2161.zip | |
Exposed session id in ZenServerState
| -rw-r--r-- | zen/cmds/top.cpp | 20 | ||||
| -rw-r--r-- | 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 <zencore/logging.h> +#include <zencore/uid.h> +#include <zencore/fmtutils.h> #include <zenserverprocess.h> #include <memory> @@ -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 <zencore/enumflags.h> #include <zencore/logging.h> #include <zencore/thread.h> +#include <zencore/uid.h> #include <gsl/gsl-lite.hpp> @@ -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<void(const ZenServerEntry&)>&& 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; }; |