mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
shm: Improve debug output a bit
This commit is contained in:
parent
b7a4f22a13
commit
19e40bd32e
|
@ -207,22 +207,22 @@ class Manager
|
||||||
|
|
||||||
fEventCounter = fManagementSegment.find<EventCounter>(unique_instance).first;
|
fEventCounter = fManagementSegment.find<EventCounter>(unique_instance).first;
|
||||||
if (fEventCounter) {
|
if (fEventCounter) {
|
||||||
LOG(debug) << "event counter found: " << fEventCounter->fCount;
|
LOG(trace) << "event counter found: " << fEventCounter->fCount;
|
||||||
} else {
|
} else {
|
||||||
LOG(debug) << "no event counter found, creating one and initializing with 0";
|
LOG(trace) << "no event counter found, creating one and initializing with 0";
|
||||||
fEventCounter = fManagementSegment.construct<EventCounter>(unique_instance)(0);
|
fEventCounter = fManagementSegment.construct<EventCounter>(unique_instance)(0);
|
||||||
LOG(debug) << "initialized event counter with: " << fEventCounter->fCount;
|
LOG(trace) << "initialized event counter with: " << fEventCounter->fCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(trace) << "device counter found, with value of " << fDeviceCounter->fCount << ". incrementing.";
|
||||||
(fDeviceCounter->fCount)++;
|
(fDeviceCounter->fCount)++;
|
||||||
LOG(debug) << "incremented device counter, now: " << fDeviceCounter->fCount;
|
LOG(trace) << "incremented device counter, now: " << fDeviceCounter->fCount;
|
||||||
} else {
|
} else {
|
||||||
LOG(debug) << "no device counter found, creating one and initializing with 1";
|
LOG(trace) << "no device counter found, creating one and initializing with 1";
|
||||||
fDeviceCounter = fManagementSegment.construct<DeviceCounter>(unique_instance)(1);
|
fDeviceCounter = fManagementSegment.construct<DeviceCounter>(unique_instance)(1);
|
||||||
LOG(debug) << "initialized device counter with: " << fDeviceCounter->fCount;
|
LOG(trace) << "initialized device counter with: " << fDeviceCounter->fCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
fShmSegments = fManagementSegment.find_or_construct<Uint16SegmentInfoHashMap>(unique_instance)(fShmVoidAlloc);
|
fShmSegments = fManagementSegment.find_or_construct<Uint16SegmentInfoHashMap>(unique_instance)(fShmVoidAlloc);
|
||||||
|
@ -265,10 +265,10 @@ class Manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG(debug) << "Created/opened shared memory segment '" << "fmq_" << fShmId << "_m_" << fSegmentId << "'."
|
LOG(debug) << (createdSegment ? "Created" : "Opened") << " managed shared memory segment " << "fmq_" << fShmId << "_m_" << fSegmentId
|
||||||
<< " Size: " << boost::apply_visitor(SegmentSize(), fSegments.at(fSegmentId)) << " bytes."
|
<< ". Size: " << boost::apply_visitor(SegmentSize(), fSegments.at(fSegmentId)) << " bytes."
|
||||||
<< " Available: " << boost::apply_visitor(SegmentFreeMemory(), fSegments.at(fSegmentId)) << " bytes."
|
<< " Available: " << boost::apply_visitor(SegmentFreeMemory(), fSegments.at(fSegmentId)) << " bytes."
|
||||||
<< " Allocation algorithm: " << allocationAlgorithm;
|
<< " Allocation algorithm: " << allocationAlgorithm;
|
||||||
} catch (interprocess_exception& bie) {
|
} catch (interprocess_exception& bie) {
|
||||||
LOG(error) << "Failed to create/open shared memory segment '" << "fmq_" << fShmId << "_m_" << fSegmentId << "': " << bie.what();
|
LOG(error) << "Failed to create/open shared memory segment '" << "fmq_" << fShmId << "_m_" << fSegmentId << "': " << bie.what();
|
||||||
throw TransportError(tools::ToString("Failed to create/open shared memory segment '", "fmq_", fShmId, "_m_", fSegmentId, "': ", bie.what()));
|
throw TransportError(tools::ToString("Failed to create/open shared memory segment '", "fmq_", fShmId, "_m_", fSegmentId, "': ", bie.what()));
|
||||||
|
@ -447,7 +447,6 @@ class Manager
|
||||||
UnmanagedRegion* GetRegion(uint16_t id)
|
UnmanagedRegion* GetRegion(uint16_t id)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(fLocalRegionsMtx);
|
std::lock_guard<std::mutex> lock(fLocalRegionsMtx);
|
||||||
// remote region could actually be a local one if a message originates from this device (has been sent out and returned)
|
|
||||||
auto it = fRegions.find(id);
|
auto it = fRegions.find(id);
|
||||||
if (it != fRegions.end()) {
|
if (it != fRegions.end()) {
|
||||||
return it->second.get();
|
return it->second.get();
|
||||||
|
|
|
@ -73,6 +73,8 @@ struct UnmanagedRegion
|
||||||
|
|
||||||
// TODO: refactor this
|
// TODO: refactor this
|
||||||
cfg.size = size;
|
cfg.size = size;
|
||||||
|
const uint16_t id = cfg.id.value();
|
||||||
|
bool created = false;
|
||||||
|
|
||||||
LOG(debug) << "UnmanagedRegion(): " << fName << " | remote: " << remote << ".";
|
LOG(debug) << "UnmanagedRegion(): " << fName << " | remote: " << remote << ".";
|
||||||
|
|
||||||
|
@ -94,23 +96,25 @@ struct UnmanagedRegion
|
||||||
if (!fFile) {
|
if (!fFile) {
|
||||||
LOG(error) << "Failed to initialize file: " << fName;
|
LOG(error) << "Failed to initialize file: " << fName;
|
||||||
LOG(error) << "errno: " << errno << ": " << strerror(errno);
|
LOG(error) << "errno: " << errno << ": " << strerror(errno);
|
||||||
throw std::runtime_error(tools::ToString("Failed to initialize file for shared memory region: ", strerror(errno)));
|
throw TransportError(tools::ToString("Failed to initialize file for shared memory region: ", strerror(errno)));
|
||||||
}
|
}
|
||||||
fFileMapping = file_mapping(fName.c_str(), read_write);
|
fFileMapping = file_mapping(fName.c_str(), read_write);
|
||||||
LOG(debug) << "shmem: initialized file: " << fName;
|
LOG(debug) << "UnmanagedRegion(): initialized file: " << fName;
|
||||||
fRegion = mapped_region(fFileMapping, read_write, 0, size, 0, cfg.creationFlags);
|
fRegion = mapped_region(fFileMapping, read_write, 0, size, 0, cfg.creationFlags);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
// if opening fails, create
|
// if opening fails, create
|
||||||
try {
|
try {
|
||||||
fShmemObject = shared_memory_object(open_only, fName.c_str(), read_write);
|
fShmemObject = shared_memory_object(open_only, fName.c_str(), read_write);
|
||||||
|
created = false;
|
||||||
} catch (interprocess_exception& e) {
|
} catch (interprocess_exception& e) {
|
||||||
LOG(debug) << "Could not open " << (remote ? "remote" : "local") << " shared_memory_object for region id '" << cfg.id.value() << "': " << e.what() << ", creating...";
|
LOG(debug) << "Could not open " << (remote ? "remote" : "local") << " shared_memory_object for region id '" << id << "': " << e.what() << ", creating...";
|
||||||
fShmemObject = shared_memory_object(create_only, fName.c_str(), read_write);
|
fShmemObject = shared_memory_object(create_only, fName.c_str(), read_write);
|
||||||
fShmemObject.truncate(size);
|
fShmemObject.truncate(size);
|
||||||
|
created = true;
|
||||||
}
|
}
|
||||||
} catch (interprocess_exception& e) {
|
} catch (interprocess_exception& e) {
|
||||||
LOG(error) << "Failed " << (remote ? "opening" : "creating") << " shared_memory_object for region id '" << cfg.id.value() << "': " << e.what();
|
LOG(error) << "Failed initializing shared_memory_object for region id " << id << ": " << e.what();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,27 +125,27 @@ struct UnmanagedRegion
|
||||||
throw TransportError(tools::ToString("Created/opened region size (", fRegion.get_size(), ") does not match configured size (", size, ")"));
|
throw TransportError(tools::ToString("Created/opened region size (", fRegion.get_size(), ") does not match configured size (", size, ")"));
|
||||||
}
|
}
|
||||||
} catch (interprocess_exception& e) {
|
} catch (interprocess_exception& e) {
|
||||||
LOG(error) << "Failed mapping shared_memory_object for region id '" << cfg.id.value() << "': " << e.what();
|
LOG(error) << "Failed mapping shared_memory_object for region id " << id << ": " << e.what();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.lock) {
|
if (cfg.lock) {
|
||||||
LOG(debug) << "Locking region " << cfg.id.value() << "...";
|
LOG(debug) << "Locking region " << id << "...";
|
||||||
Lock();
|
Lock();
|
||||||
LOG(debug) << "Successfully locked region " << cfg.id.value() << ".";
|
LOG(debug) << "Successfully locked region " << id << ".";
|
||||||
}
|
}
|
||||||
if (cfg.zero) {
|
if (cfg.zero) {
|
||||||
LOG(debug) << "Zeroing free memory of region " << cfg.id.value() << "...";
|
LOG(debug) << "Zeroing free memory of region " << id << "...";
|
||||||
Zero();
|
Zero();
|
||||||
LOG(debug) << "Successfully zeroed free memory of region " << cfg.id.value() << ".";
|
LOG(debug) << "Successfully zeroed free memory of region " << id << ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
Register(shmId, cfg);
|
Register(shmId, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(trace) << "shmem: initialized region: " << fName << " (" << (remote ? "remote" : "local") << ")";
|
LOG(debug) << (created ? "Created" : "Opened") << " unmanaged shared memory region: " << fName << " (" << (remote ? "remote" : "local") << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
UnmanagedRegion() = delete;
|
UnmanagedRegion() = delete;
|
||||||
|
@ -246,6 +250,7 @@ struct UnmanagedRegion
|
||||||
static void Register(const std::string& shmId, const RegionConfig& cfg)
|
static void Register(const std::string& shmId, const RegionConfig& cfg)
|
||||||
{
|
{
|
||||||
using namespace boost::interprocess;
|
using namespace boost::interprocess;
|
||||||
|
LOG(debug) << "Registering unmanaged shared memory region with id " << cfg.id.value();
|
||||||
managed_shared_memory mngSegment(open_or_create, std::string("fmq_" + shmId + "_mng").c_str(), kManagementSegmentSize);
|
managed_shared_memory mngSegment(open_or_create, std::string("fmq_" + shmId + "_mng").c_str(), kManagementSegmentSize);
|
||||||
VoidAlloc alloc(mngSegment.get_segment_manager());
|
VoidAlloc alloc(mngSegment.get_segment_manager());
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ class UnmanagedRegionImpl final : public fair::mq::UnmanagedRegion
|
||||||
, fRegion(nullptr)
|
, fRegion(nullptr)
|
||||||
, fRegionId(0)
|
, fRegionId(0)
|
||||||
{
|
{
|
||||||
auto result = fManager.CreateRegion(size, callback, bulkCallback, std::move(cfg));
|
auto [regionPtr, regionId] = fManager.CreateRegion(size, callback, bulkCallback, std::move(cfg));
|
||||||
fRegion = result.first;
|
fRegion = regionPtr;
|
||||||
fRegionId = result.second;
|
fRegionId = regionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnmanagedRegionImpl(const UnmanagedRegionImpl&) = delete;
|
UnmanagedRegionImpl(const UnmanagedRegionImpl&) = delete;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user