mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
shmmonitor: add --list-all
This commit is contained in:
parent
2602f53585
commit
5facc441b8
|
@ -20,6 +20,7 @@
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -271,6 +272,35 @@ bool Monitor::PrintShm(const ShmId& shmId)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Monitor::ListAll(const std::string& path)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (std::filesystem::is_empty(path)) {
|
||||||
|
LOG(info) << "directory " << filesystem::path(path) << " is empty.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& entry : filesystem::directory_iterator(path)) {
|
||||||
|
string filename = entry.path().filename().string();
|
||||||
|
// LOG(info) << filename << ", size: " << entry.file_size() << " bytes";
|
||||||
|
if (tools::StrStartsWith(filename, "fmq_") || tools::StrStartsWith(filename, "sem.fmq_")) {
|
||||||
|
// LOG(info) << "The file '" << filename << "' belongs to FairMQ.";
|
||||||
|
if (tools::StrEndsWith(filename, "_mng")) {
|
||||||
|
string shmId = filename.substr(4, 8);
|
||||||
|
LOG(info) << "\nFound shmid '" << shmId << "':\n";
|
||||||
|
if (!PrintShm(ShmId{shmId})) {
|
||||||
|
LOG(info) << "could not open file for shmid '" << shmId << "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG(info) << "The file '" << filename << "' does not belong to FairMQ, skipping...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (filesystem::filesystem_error& fse) {
|
||||||
|
LOG(error) << "error: " << fse.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Monitor::ReceiveHeartbeats()
|
void Monitor::ReceiveHeartbeats()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -85,6 +85,7 @@ class Monitor
|
||||||
static std::unordered_map<uint16_t, std::vector<BufferDebugInfo>> GetDebugInfo(const SessionId& shmId);
|
static std::unordered_map<uint16_t, std::vector<BufferDebugInfo>> GetDebugInfo(const SessionId& shmId);
|
||||||
|
|
||||||
static bool PrintShm(const ShmId& shmId);
|
static bool PrintShm(const ShmId& shmId);
|
||||||
|
static void ListAll(const std::string& path);
|
||||||
|
|
||||||
static bool RemoveObject(const std::string& name);
|
static bool RemoveObject(const std::string& name);
|
||||||
static bool RemoveFileMapping(const std::string& name);
|
static bool RemoveFileMapping(const std::string& name);
|
||||||
|
|
|
@ -86,6 +86,8 @@ int main(int argc, char** argv)
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
bool cleanOnExit = false;
|
bool cleanOnExit = false;
|
||||||
bool getShmId = false;
|
bool getShmId = false;
|
||||||
|
bool listAll = false;
|
||||||
|
string listAllPath;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
int userId = -1;
|
int userId = -1;
|
||||||
|
|
||||||
|
@ -104,6 +106,8 @@ int main(int argc, char** argv)
|
||||||
("clean-on-exit,e", value<bool>(&cleanOnExit)->implicit_value(true), "Perform cleanup on exit")
|
("clean-on-exit,e", value<bool>(&cleanOnExit)->implicit_value(true), "Perform cleanup on exit")
|
||||||
("interval" , value<unsigned int>(&intervalInMS)->default_value(100), "Output interval for interactive mode")
|
("interval" , value<unsigned int>(&intervalInMS)->default_value(100), "Output interval for interactive mode")
|
||||||
("get-shmid" , value<bool>(&getShmId)->implicit_value(true), "Translate given session id and user id to a shmem id (uses current user id if none provided)")
|
("get-shmid" , value<bool>(&getShmId)->implicit_value(true), "Translate given session id and user id to a shmem id (uses current user id if none provided)")
|
||||||
|
("list-all" , value<bool>(&listAll)->implicit_value(true), "List all sessions & segments")
|
||||||
|
("list-all-path" , value<string>(&listAllPath)->default_value("/dev/shm/"),"Path for the --list-all command to search segments in")
|
||||||
("verbose" , value<bool>(&verbose)->implicit_value(true), "Verbose mode (daemon will output to a file 'fairmq-shmmonitor_log_<timestamp>')")
|
("verbose" , value<bool>(&verbose)->implicit_value(true), "Verbose mode (daemon will output to a file 'fairmq-shmmonitor_log_<timestamp>')")
|
||||||
("user-id" , value<int>(&userId)->default_value(-1), "User id (used with --get-shmid)")
|
("user-id" , value<int>(&userId)->default_value(-1), "User id (used with --get-shmid)")
|
||||||
("help,h", "Print help");
|
("help,h", "Print help");
|
||||||
|
@ -150,6 +154,11 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (listAll) {
|
||||||
|
Monitor::ListAll(listAllPath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!viewOnly && !interactive && !monitor) {
|
if (!viewOnly && !interactive && !monitor) {
|
||||||
// if neither of the run modes are selected, use view only mode.
|
// if neither of the run modes are selected, use view only mode.
|
||||||
viewOnly = true;
|
viewOnly = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user