From 507ce9a26a2eddfb32424c794c8e7de4fb65a6ad Mon Sep 17 00:00:00 2001 From: Ernst Hellbar Date: Wed, 2 Apr 2025 14:52:07 +0200 Subject: [PATCH] DPL: avoid expensive find_if for check of AVAILABLE_MANAGED_SHM metric when sending metrics --- .../Core/include/Framework/DataProcessingStats.h | 2 ++ Framework/Core/src/CommonServices.cxx | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Framework/Core/include/Framework/DataProcessingStats.h b/Framework/Core/include/Framework/DataProcessingStats.h index ec96bf8e9973c..d42f9a9d26610 100644 --- a/Framework/Core/include/Framework/DataProcessingStats.h +++ b/Framework/Core/include/Framework/DataProcessingStats.h @@ -189,6 +189,8 @@ struct DataProcessingStats { std::array metricSpecs = {}; std::array lastPublishedMetrics = {}; std::vector availableMetrics; + // for fast check for AVAILABLE_MANAGED_SHM metric which is only provided for readout-proxy + bool hasAvailSHMMetric = false; // How many commands have been committed to the queue. std::atomic insertedCmds = 0; // The insertion point for the next command. diff --git a/Framework/Core/src/CommonServices.cxx b/Framework/Core/src/CommonServices.cxx index cc3c920bc7be1..e13f1cb2094b7 100644 --- a/Framework/Core/src/CommonServices.cxx +++ b/Framework/Core/src/CommonServices.cxx @@ -764,11 +764,8 @@ auto sendRelayerMetrics(ServiceRegistryRef registry, DataProcessingStats& stats) using namespace fair::mq::shmem; auto& spec = registry.get(); - auto hasMetric = [&runningWorkflow](const DataProcessingStats::MetricSpec& metric) -> bool { - return metric.metricId == static_cast(ProcessingStatsId::AVAILABLE_MANAGED_SHM_BASE) + (runningWorkflow.shmSegmentId % 512); - }; // FIXME: Ugly, but we do it only every 5 seconds... - if (std::find_if(stats.metricSpecs.begin(), stats.metricSpecs.end(), hasMetric) != stats.metricSpecs.end()) { + if (stats.hasAvailSHMMetric) { auto device = registry.get().device(); long freeMemory = -1; try { @@ -1104,8 +1101,12 @@ o2::framework::ServiceSpec CommonServices::dataProcessingStats() .sendInitialValue = true}}; for (auto& metric : metrics) { - if (metric.metricId == (int)ProcessingStatsId::AVAILABLE_MANAGED_SHM_BASE + (runningWorkflow.shmSegmentId % 512) && spec.name.compare("readout-proxy") != 0) { - continue; + if (metric.metricId == (int)ProcessingStatsId::AVAILABLE_MANAGED_SHM_BASE + (runningWorkflow.shmSegmentId % 512)) { + if (spec.name.compare("readout-proxy") == 0) { + stats->hasAvailSHMMetric = true; + } else { + continue; + } } stats->registerMetric(metric); }