Skip to content

Commit c3f439d

Browse files
authored
DPL: avoid expensive find_if for check of AVAILABLE_MANAGED_SHM metric when sending metrics (#14138)
1 parent e562336 commit c3f439d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Framework/Core/include/Framework/DataProcessingStats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ struct DataProcessingStats {
189189
std::array<MetricSpec, MAX_METRICS> metricSpecs = {};
190190
std::array<int64_t, MAX_METRICS> lastPublishedMetrics = {};
191191
std::vector<int> availableMetrics;
192+
// for fast check for AVAILABLE_MANAGED_SHM metric which is only provided for readout-proxy
193+
bool hasAvailSHMMetric = false;
192194
// How many commands have been committed to the queue.
193195
std::atomic<int> insertedCmds = 0;
194196
// The insertion point for the next command.

Framework/Core/src/CommonServices.cxx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,8 @@ auto sendRelayerMetrics(ServiceRegistryRef registry, DataProcessingStats& stats)
764764
using namespace fair::mq::shmem;
765765
auto& spec = registry.get<DeviceSpec const>();
766766

767-
auto hasMetric = [&runningWorkflow](const DataProcessingStats::MetricSpec& metric) -> bool {
768-
return metric.metricId == static_cast<int>(ProcessingStatsId::AVAILABLE_MANAGED_SHM_BASE) + (runningWorkflow.shmSegmentId % 512);
769-
};
770767
// FIXME: Ugly, but we do it only every 5 seconds...
771-
if (std::find_if(stats.metricSpecs.begin(), stats.metricSpecs.end(), hasMetric) != stats.metricSpecs.end()) {
768+
if (stats.hasAvailSHMMetric) {
772769
auto device = registry.get<RawDeviceService>().device();
773770
long freeMemory = -1;
774771
try {
@@ -1104,8 +1101,12 @@ o2::framework::ServiceSpec CommonServices::dataProcessingStats()
11041101
.sendInitialValue = true}};
11051102

11061103
for (auto& metric : metrics) {
1107-
if (metric.metricId == (int)ProcessingStatsId::AVAILABLE_MANAGED_SHM_BASE + (runningWorkflow.shmSegmentId % 512) && spec.name.compare("readout-proxy") != 0) {
1108-
continue;
1104+
if (metric.metricId == (int)ProcessingStatsId::AVAILABLE_MANAGED_SHM_BASE + (runningWorkflow.shmSegmentId % 512)) {
1105+
if (spec.name.compare("readout-proxy") == 0) {
1106+
stats->hasAvailSHMMetric = true;
1107+
} else {
1108+
continue;
1109+
}
11091110
}
11101111
stats->registerMetric(metric);
11111112
}

0 commit comments

Comments
 (0)