Skip to content

Commit 3269ab5

Browse files
committed
DPL: do not flush metrics from threads
This avoids having to have a mutex for the flushing.
1 parent 0abf8fb commit 3269ab5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Framework/Core/src/CommonServices.cxx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,13 @@ O2_DECLARE_DYNAMIC_LOG(monitoring_service);
783783
/// This will flush metrics only once every second.
784784
auto flushMetrics(ServiceRegistryRef registry, DataProcessingStats& stats) -> void
785785
{
786+
// Flushing metrics should only happen on main thread to avoid
787+
// having to have a mutex for the communication with the driver.
786788
O2_SIGNPOST_ID_GENERATE(sid, monitoring_service);
787789
O2_SIGNPOST_START(monitoring_service, sid, "flush", "flushing metrics");
790+
if (registry.isMainThread() == false) {
791+
LOGP(fatal, "Flushing metrics should only happen on the main thread.");
792+
}
788793
auto& monitoring = registry.get<Monitoring>();
789794
auto& relayer = registry.get<DataRelayer>();
790795

@@ -1071,13 +1076,9 @@ o2::framework::ServiceSpec CommonServices::dataProcessingStats()
10711076
return ServiceHandle{TypeIdHelpers::uniqueId<DataProcessingStats>(), stats};
10721077
},
10731078
.configure = noConfiguration(),
1074-
.preProcessing = [](ProcessingContext& context, void* service) {
1075-
auto* stats = (DataProcessingStats*)service;
1076-
flushMetrics(context.services(), *stats); },
10771079
.postProcessing = [](ProcessingContext& context, void* service) {
10781080
auto* stats = (DataProcessingStats*)service;
1079-
stats->updateStats({(short)ProcessingStatsId::PERFORMED_COMPUTATIONS, DataProcessingStats::Op::Add, 1});
1080-
flushMetrics(context.services(), *stats); },
1081+
stats->updateStats({(short)ProcessingStatsId::PERFORMED_COMPUTATIONS, DataProcessingStats::Op::Add, 1}); },
10811082
.preDangling = [](DanglingContext& context, void* service) {
10821083
auto* stats = (DataProcessingStats*)service;
10831084
sendRelayerMetrics(context.services(), *stats);
@@ -1090,9 +1091,6 @@ o2::framework::ServiceSpec CommonServices::dataProcessingStats()
10901091
auto* stats = (DataProcessingStats*)service;
10911092
sendRelayerMetrics(context.services(), *stats);
10921093
flushMetrics(context.services(), *stats); },
1093-
.postDispatching = [](ProcessingContext& context, void* service) {
1094-
auto* stats = (DataProcessingStats*)service;
1095-
flushMetrics(context.services(), *stats); },
10961094
.preLoop = [](ServiceRegistryRef ref, void* service) {
10971095
auto* stats = (DataProcessingStats*)service;
10981096
flushMetrics(ref, *stats); },

0 commit comments

Comments
 (0)