From effba534f087fc129d10ff45211acf0f937807ef Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Sat, 27 Mar 2021 23:26:23 +0100 Subject: [PATCH] shmmonitor: add session name and creator id to the output --- fairmq/shmem/Common.h | 11 +++++++++++ fairmq/shmem/Manager.h | 20 ++++++++++++++++---- fairmq/shmem/Monitor.cxx | 15 ++++++++++++++- fairmq/shmem/TransportFactory.h | 5 +---- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/fairmq/shmem/Common.h b/fairmq/shmem/Common.h index a8a49b58..2b134ff5 100644 --- a/fairmq/shmem/Common.h +++ b/fairmq/shmem/Common.h @@ -91,6 +91,17 @@ struct SegmentInfo AllocationAlgorithm fAllocationAlgorithm; }; +struct SessionInfo +{ + SessionInfo(const char* sessionName, int creatorId, const VoidAlloc& alloc) + : fSessionName(sessionName, alloc) + , fCreatorId(creatorId) + {} + + Str fSessionName; + int fCreatorId; +}; + using Uint16SegmentInfoPairAlloc = boost::interprocess::allocator, SegmentManager>; using Uint16SegmentInfoHashMap = boost::unordered_map, std::equal_to, Uint16SegmentInfoPairAlloc>; // using Uint16SegmentInfoMap = boost::interprocess::map, Uint16SegmentInfoPairAlloc>; diff --git a/fairmq/shmem/Manager.h b/fairmq/shmem/Manager.h index e7b433ce..24728d52 100644 --- a/fairmq/shmem/Manager.h +++ b/fairmq/shmem/Manager.h @@ -46,6 +46,9 @@ #include // pair #include +#include // getuid +#include // getuid + #include // mlock namespace fair::mq::shmem @@ -54,8 +57,8 @@ namespace fair::mq::shmem class Manager { public: - Manager(std::string shmId, std::string deviceId, size_t size, const ProgOptions* config) - : fShmId(std::move(shmId)) + Manager(const std::string& sessionName, std::string deviceId, size_t size, const ProgOptions* config) + : fShmId(makeShmIdStr(sessionName)) , fSegmentId(config ? config->GetProperty("shm-segment-id", 0) : 0) , fDeviceId(std::move(deviceId)) , fSegments() @@ -82,6 +85,8 @@ class Manager { using namespace boost::interprocess; + LOG(debug) << "Generated shmid '" << fShmId << "' out of session id '" << sessionName << "'."; + bool mlockSegment = false; bool zeroSegment = false; bool autolaunchMonitor = false; @@ -105,8 +110,16 @@ class Manager fShmSegments = fManagementSegment.find_or_construct(unique_instance)(fShmVoidAlloc); - fEventCounter = fManagementSegment.find(unique_instance).first; + SessionInfo* sessionInfo = fManagementSegment.find(unique_instance).first; + if (sessionInfo) { + LOG(debug) << "session info found, name: " << sessionInfo->fSessionName << ", creator id: " << sessionInfo->fCreatorId; + } else { + LOG(debug) << "no session info found, creating and initializing"; + sessionInfo = fManagementSegment.construct(unique_instance)(sessionName.c_str(), geteuid(), fShmVoidAlloc); + LOG(debug) << "initialized session info, name: " << sessionInfo->fSessionName << ", creator id: " << sessionInfo->fCreatorId; + } + fEventCounter = fManagementSegment.find(unique_instance).first; if (fEventCounter) { LOG(debug) << "event counter found: " << fEventCounter->fCount; } else { @@ -171,7 +184,6 @@ class Manager fShmRegions = fManagementSegment.find_or_construct(unique_instance)(fShmVoidAlloc); fDeviceCounter = fManagementSegment.find(unique_instance).first; - if (fDeviceCounter) { LOG(debug) << "device counter found, with value of " << fDeviceCounter->fCount << ". incrementing."; (fDeviceCounter->fCount)++; diff --git a/fairmq/shmem/Monitor.cxx b/fairmq/shmem/Monitor.cxx index 46a2610c..b2ceff4b 100644 --- a/fairmq/shmem/Monitor.cxx +++ b/fairmq/shmem/Monitor.cxx @@ -270,6 +270,8 @@ void Monitor::CheckSegment() fSeenOnce = true; unsigned int numDevices = 0; + int creatorId = -1; + std::string sessionName; #ifdef FAIRMQ_DEBUG_MODE Uint16MsgCounterHashMap* msgCounters = nullptr; #endif @@ -279,6 +281,11 @@ void Monitor::CheckSegment() if (dc) { numDevices = dc->fCount; } + SessionInfo* si = managementSegment.find(unique_instance).first; + if (si) { + creatorId = si->fCreatorId; + sessionName = si->fSessionName; + } #ifdef FAIRMQ_DEBUG_MODE msgCounters = managementSegment.find(unique_instance).first; #endif @@ -305,7 +312,10 @@ void Monitor::CheckSegment() size_t mused = mtotal - mfree; ss << "shm id: " << fShmId - << ", devices: " << numDevices << ", segments:\n"; + << ", session: " << sessionName + << ", creator id: " << creatorId + << ", devices: " << numDevices + << ", segments:\n"; for (const auto& s : segments) { size_t free = boost::apply_visitor(SegmentFreeMemory(), s.second); size_t total = boost::apply_visitor(SegmentSize(), s.second); @@ -328,6 +338,9 @@ void Monitor::CheckSegment() LOGV(info, user1) << ss.str(); } } catch (bie&) { + if (!fMonitor && !fInteractive) { + cout << "No segments found." << endl; + } fHeartbeatTriggered = false; if (fSelfDestruct) { diff --git a/fairmq/shmem/TransportFactory.h b/fairmq/shmem/TransportFactory.h index 60f5e055..0081f2d5 100644 --- a/fairmq/shmem/TransportFactory.h +++ b/fairmq/shmem/TransportFactory.h @@ -68,9 +68,6 @@ class TransportFactory final : public fair::mq::TransportFactory throw SharedMemoryError(tools::ToString("Provided shared memory allocation algorithm '", allocationAlgorithm, "' is not supported. Supported are 'rbtree_best_fit'/'simple_seq_fit'")); } - std::string shmId = makeShmIdStr(sessionName); - LOG(debug) << "Generated shmid '" << shmId << "' out of session id '" << sessionName << "'."; - try { if (zmq_ctx_set(fZmqCtx, ZMQ_IO_THREADS, numIoThreads) != 0) { LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno); @@ -81,7 +78,7 @@ class TransportFactory final : public fair::mq::TransportFactory LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno); } - fManager = std::make_unique(shmId, deviceId, segmentSize, config); + fManager = std::make_unique(sessionName, deviceId, segmentSize, config); } catch (boost::interprocess::interprocess_exception& e) { LOG(error) << "Could not initialize shared memory transport: " << e.what(); throw std::runtime_error(tools::ToString("Could not initialize shared memory transport: ", e.what()));