mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
shmmonitor: add session name and creator id to the output
This commit is contained in:
parent
efd42075a9
commit
effba534f0
|
@ -91,6 +91,17 @@ struct SegmentInfo
|
||||||
AllocationAlgorithm fAllocationAlgorithm;
|
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<std::pair<const uint16_t, SegmentInfo>, SegmentManager>;
|
using Uint16SegmentInfoPairAlloc = boost::interprocess::allocator<std::pair<const uint16_t, SegmentInfo>, SegmentManager>;
|
||||||
using Uint16SegmentInfoHashMap = boost::unordered_map<uint16_t, SegmentInfo, boost::hash<uint16_t>, std::equal_to<uint16_t>, Uint16SegmentInfoPairAlloc>;
|
using Uint16SegmentInfoHashMap = boost::unordered_map<uint16_t, SegmentInfo, boost::hash<uint16_t>, std::equal_to<uint16_t>, Uint16SegmentInfoPairAlloc>;
|
||||||
// using Uint16SegmentInfoMap = boost::interprocess::map<uint16_t, SegmentInfo, std::less<uint16_t>, Uint16SegmentInfoPairAlloc>;
|
// using Uint16SegmentInfoMap = boost::interprocess::map<uint16_t, SegmentInfo, std::less<uint16_t>, Uint16SegmentInfoPairAlloc>;
|
||||||
|
|
|
@ -46,6 +46,9 @@
|
||||||
#include <utility> // pair
|
#include <utility> // pair
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <unistd.h> // getuid
|
||||||
|
#include <sys/types.h> // getuid
|
||||||
|
|
||||||
#include <sys/mman.h> // mlock
|
#include <sys/mman.h> // mlock
|
||||||
|
|
||||||
namespace fair::mq::shmem
|
namespace fair::mq::shmem
|
||||||
|
@ -54,8 +57,8 @@ namespace fair::mq::shmem
|
||||||
class Manager
|
class Manager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Manager(std::string shmId, std::string deviceId, size_t size, const ProgOptions* config)
|
Manager(const std::string& sessionName, std::string deviceId, size_t size, const ProgOptions* config)
|
||||||
: fShmId(std::move(shmId))
|
: fShmId(makeShmIdStr(sessionName))
|
||||||
, fSegmentId(config ? config->GetProperty<uint16_t>("shm-segment-id", 0) : 0)
|
, fSegmentId(config ? config->GetProperty<uint16_t>("shm-segment-id", 0) : 0)
|
||||||
, fDeviceId(std::move(deviceId))
|
, fDeviceId(std::move(deviceId))
|
||||||
, fSegments()
|
, fSegments()
|
||||||
|
@ -82,6 +85,8 @@ class Manager
|
||||||
{
|
{
|
||||||
using namespace boost::interprocess;
|
using namespace boost::interprocess;
|
||||||
|
|
||||||
|
LOG(debug) << "Generated shmid '" << fShmId << "' out of session id '" << sessionName << "'.";
|
||||||
|
|
||||||
bool mlockSegment = false;
|
bool mlockSegment = false;
|
||||||
bool zeroSegment = false;
|
bool zeroSegment = false;
|
||||||
bool autolaunchMonitor = false;
|
bool autolaunchMonitor = false;
|
||||||
|
@ -105,8 +110,16 @@ class Manager
|
||||||
|
|
||||||
fShmSegments = fManagementSegment.find_or_construct<Uint16SegmentInfoHashMap>(unique_instance)(fShmVoidAlloc);
|
fShmSegments = fManagementSegment.find_or_construct<Uint16SegmentInfoHashMap>(unique_instance)(fShmVoidAlloc);
|
||||||
|
|
||||||
fEventCounter = fManagementSegment.find<EventCounter>(unique_instance).first;
|
SessionInfo* sessionInfo = fManagementSegment.find<SessionInfo>(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<SessionInfo>(unique_instance)(sessionName.c_str(), geteuid(), fShmVoidAlloc);
|
||||||
|
LOG(debug) << "initialized session info, name: " << sessionInfo->fSessionName << ", creator id: " << sessionInfo->fCreatorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
fEventCounter = fManagementSegment.find<EventCounter>(unique_instance).first;
|
||||||
if (fEventCounter) {
|
if (fEventCounter) {
|
||||||
LOG(debug) << "event counter found: " << fEventCounter->fCount;
|
LOG(debug) << "event counter found: " << fEventCounter->fCount;
|
||||||
} else {
|
} else {
|
||||||
|
@ -171,7 +184,6 @@ class Manager
|
||||||
fShmRegions = fManagementSegment.find_or_construct<Uint16RegionInfoHashMap>(unique_instance)(fShmVoidAlloc);
|
fShmRegions = fManagementSegment.find_or_construct<Uint16RegionInfoHashMap>(unique_instance)(fShmVoidAlloc);
|
||||||
|
|
||||||
fDeviceCounter = fManagementSegment.find<DeviceCounter>(unique_instance).first;
|
fDeviceCounter = fManagementSegment.find<DeviceCounter>(unique_instance).first;
|
||||||
|
|
||||||
if (fDeviceCounter) {
|
if (fDeviceCounter) {
|
||||||
LOG(debug) << "device counter found, with value of " << fDeviceCounter->fCount << ". incrementing.";
|
LOG(debug) << "device counter found, with value of " << fDeviceCounter->fCount << ". incrementing.";
|
||||||
(fDeviceCounter->fCount)++;
|
(fDeviceCounter->fCount)++;
|
||||||
|
|
|
@ -270,6 +270,8 @@ void Monitor::CheckSegment()
|
||||||
fSeenOnce = true;
|
fSeenOnce = true;
|
||||||
|
|
||||||
unsigned int numDevices = 0;
|
unsigned int numDevices = 0;
|
||||||
|
int creatorId = -1;
|
||||||
|
std::string sessionName;
|
||||||
#ifdef FAIRMQ_DEBUG_MODE
|
#ifdef FAIRMQ_DEBUG_MODE
|
||||||
Uint16MsgCounterHashMap* msgCounters = nullptr;
|
Uint16MsgCounterHashMap* msgCounters = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
@ -279,6 +281,11 @@ void Monitor::CheckSegment()
|
||||||
if (dc) {
|
if (dc) {
|
||||||
numDevices = dc->fCount;
|
numDevices = dc->fCount;
|
||||||
}
|
}
|
||||||
|
SessionInfo* si = managementSegment.find<SessionInfo>(unique_instance).first;
|
||||||
|
if (si) {
|
||||||
|
creatorId = si->fCreatorId;
|
||||||
|
sessionName = si->fSessionName;
|
||||||
|
}
|
||||||
#ifdef FAIRMQ_DEBUG_MODE
|
#ifdef FAIRMQ_DEBUG_MODE
|
||||||
msgCounters = managementSegment.find<Uint16MsgCounterHashMap>(unique_instance).first;
|
msgCounters = managementSegment.find<Uint16MsgCounterHashMap>(unique_instance).first;
|
||||||
#endif
|
#endif
|
||||||
|
@ -305,7 +312,10 @@ void Monitor::CheckSegment()
|
||||||
size_t mused = mtotal - mfree;
|
size_t mused = mtotal - mfree;
|
||||||
|
|
||||||
ss << "shm id: " << fShmId
|
ss << "shm id: " << fShmId
|
||||||
<< ", devices: " << numDevices << ", segments:\n";
|
<< ", session: " << sessionName
|
||||||
|
<< ", creator id: " << creatorId
|
||||||
|
<< ", devices: " << numDevices
|
||||||
|
<< ", segments:\n";
|
||||||
for (const auto& s : segments) {
|
for (const auto& s : segments) {
|
||||||
size_t free = boost::apply_visitor(SegmentFreeMemory(), s.second);
|
size_t free = boost::apply_visitor(SegmentFreeMemory(), s.second);
|
||||||
size_t total = boost::apply_visitor(SegmentSize(), s.second);
|
size_t total = boost::apply_visitor(SegmentSize(), s.second);
|
||||||
|
@ -328,6 +338,9 @@ void Monitor::CheckSegment()
|
||||||
LOGV(info, user1) << ss.str();
|
LOGV(info, user1) << ss.str();
|
||||||
}
|
}
|
||||||
} catch (bie&) {
|
} catch (bie&) {
|
||||||
|
if (!fMonitor && !fInteractive) {
|
||||||
|
cout << "No segments found." << endl;
|
||||||
|
}
|
||||||
fHeartbeatTriggered = false;
|
fHeartbeatTriggered = false;
|
||||||
|
|
||||||
if (fSelfDestruct) {
|
if (fSelfDestruct) {
|
||||||
|
|
|
@ -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'"));
|
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 {
|
try {
|
||||||
if (zmq_ctx_set(fZmqCtx, ZMQ_IO_THREADS, numIoThreads) != 0) {
|
if (zmq_ctx_set(fZmqCtx, ZMQ_IO_THREADS, numIoThreads) != 0) {
|
||||||
LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno);
|
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);
|
LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
fManager = std::make_unique<Manager>(shmId, deviceId, segmentSize, config);
|
fManager = std::make_unique<Manager>(sessionName, deviceId, segmentSize, config);
|
||||||
} catch (boost::interprocess::interprocess_exception& e) {
|
} catch (boost::interprocess::interprocess_exception& e) {
|
||||||
LOG(error) << "Could not initialize shared memory transport: " << e.what();
|
LOG(error) << "Could not initialize shared memory transport: " << e.what();
|
||||||
throw std::runtime_error(tools::ToString("Could not initialize shared memory transport: ", e.what()));
|
throw std::runtime_error(tools::ToString("Could not initialize shared memory transport: ", e.what()));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user