diff options
| author | Stefan Boberg <[email protected]> | 2021-08-09 14:15:38 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-08-09 14:15:38 +0200 |
| commit | 86eeae501830be5c5e120c11b307f87c6a12ebf1 (patch) | |
| tree | bc447adce097605eb7d9a97ae1d1f849610429b6 | |
| parent | Added self-registration of Zen server instance in shared state map (diff) | |
| download | zen-86eeae501830be5c5e120c11b307f87c6a12ebf1.tar.xz zen-86eeae501830be5c5e120c11b307f87c6a12ebf1.zip | |
Basic implementation of zen top/ps (currently identical but won't be) functionality
| -rw-r--r-- | zen/cmds/top.cpp | 36 | ||||
| -rw-r--r-- | zen/cmds/top.h | 13 | ||||
| -rw-r--r-- | zen/zen.cpp | 2 |
3 files changed, 51 insertions, 0 deletions
diff --git a/zen/cmds/top.cpp b/zen/cmds/top.cpp index e69f5e94c..cd20e0d1c 100644 --- a/zen/cmds/top.cpp +++ b/zen/cmds/top.cpp @@ -4,9 +4,13 @@ #include "top.h" +#include <zenserverprocess.h> + #include <spdlog/spdlog.h> #include <memory> +////////////////////////////////////////////////////////////////////////// + TopCommand::TopCommand() { } @@ -18,5 +22,37 @@ TopCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { ZEN_UNUSED(GlobalOptions, argc, argv); + ZenServerState State; + if (!State.InitializeReadOnly()) + { + spdlog::info("no Zen state found"); + } + + State.Snapshot([&](const ZenServerState::ZenServerEntry& Entry) { spdlog::info("Port {} : pid {}", Entry.ListenPort, Entry.Pid); }); + + return 0; +} + +////////////////////////////////////////////////////////////////////////// + +PsCommand::PsCommand() +{ +} + +PsCommand::~PsCommand() = default; + +int +PsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions, argc, argv); + + ZenServerState State; + if (!State.InitializeReadOnly()) + { + spdlog::info("no Zen state found"); + } + + State.Snapshot([&](const ZenServerState::ZenServerEntry& Entry) { spdlog::info("Port {} : pid {}", Entry.ListenPort, Entry.Pid); }); + return 0; } diff --git a/zen/cmds/top.h b/zen/cmds/top.h index 4e886e9fc..32ba6c57b 100644 --- a/zen/cmds/top.h +++ b/zen/cmds/top.h @@ -16,3 +16,16 @@ public: private: cxxopts::Options m_Options{"top", "Show dev UI"}; }; + +class PsCommand : public ZenCmdBase +{ +public: + PsCommand(); + ~PsCommand(); + + virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override; + virtual cxxopts::Options* Options() override { return &m_Options; } + +private: + cxxopts::Options m_Options{"ps", "Enumerate running Zen server instances"}; +}; diff --git a/zen/zen.cpp b/zen/zen.cpp index 03abff6d0..9e3095367 100644 --- a/zen/zen.cpp +++ b/zen/zen.cpp @@ -127,6 +127,7 @@ main(int argc, char** argv) RunCommand RunCmd; StatusCommand StatusCmd; TopCommand TopCmd; + PsCommand PsCmd; UpCommand UpCmd; DownCommand DownCmd; @@ -144,6 +145,7 @@ main(int argc, char** argv) {"runtests", &RunTestsCmd, "Run zen tests"}, {"run", &RunCmd, "Remote execution"}, {"status", &StatusCmd, "Show zen status"}, + {"ps", &PsCmd, "Enumerate running zen server instances"}, {"top", &TopCmd, "Monitor zen server activity"}, {"up", &UpCmd, "Bring zen server up"}, {"down", &DownCmd, "Bring zen server down"}, |