|
10 | 10 | // or submit itself to any jurisdiction. |
11 | 11 |
|
12 | 12 | #include "Framework/DataProcessingContext.h" |
| 13 | +#include "Framework/DataProcessorSpec.h" |
| 14 | +#include "Framework/Signpost.h" |
13 | 15 |
|
| 16 | +O2_DECLARE_DYNAMIC_LOG(data_processor_context); |
14 | 17 | namespace o2::framework |
15 | 18 | { |
| 19 | + |
| 20 | +namespace |
| 21 | +{ |
| 22 | +template <typename T, typename... ARGS> |
| 23 | +void invokeAll(T& handles, char const* callbackName, o2::framework::DataProcessorSpec* spec, ARGS&... args) |
| 24 | +{ |
| 25 | + assert(callbackName); |
| 26 | + O2_SIGNPOST_ID_FROM_POINTER(dpid, data_processor_context, spec); |
| 27 | + // FIXME: for now spec is nullptr because we don't have a list of possible DataProcessorSpecs |
| 28 | + // per device. |
| 29 | + char const* dataProcessorName = spec ? spec->name.c_str() : "DataProcessorContext"; |
| 30 | + O2_SIGNPOST_START(data_processor_context, dpid, "callbacks", "Starting %{public}s::%{public}s", dataProcessorName, callbackName); |
| 31 | + for (auto& handle : handles) { |
| 32 | + O2_SIGNPOST_ID_FROM_POINTER(cid, data_processor_context, handle.service); |
| 33 | + O2_SIGNPOST_START(data_processor_context, cid, "callbacks", "Starting %{public}s::%{public}s::%{public}s", dataProcessorName, handle.spec.name.c_str(), callbackName); |
| 34 | + handle.callback(args..., handle.service); |
| 35 | + O2_SIGNPOST_END(data_processor_context, cid, "callbacks", "Ending %{public}s::%{public}s::%{public}s", dataProcessorName, handle.spec.name.c_str(), callbackName); |
| 36 | + } |
| 37 | + O2_SIGNPOST_END(data_processor_context, dpid, "callbacks", "Ending %{public}s::%{public}s", dataProcessorName, callbackName); |
| 38 | +} |
| 39 | +} // namespace |
| 40 | + |
16 | 41 | /// Invoke callbacks to be executed before every dangling check |
17 | 42 | void DataProcessorContext::preProcessingCallbacks(ProcessingContext& ctx) |
18 | 43 | { |
19 | | - for (auto& handle : preProcessingHandlers) { |
20 | | - LOGP(debug, "Invoking preDanglingCallback for service {}", handle.spec.name); |
21 | | - handle.callback(ctx, handle.service); |
22 | | - } |
| 44 | + invokeAll(preProcessingHandlers, "preProcessingCallbacks", spec, ctx); |
23 | 45 | } |
24 | 46 |
|
25 | 47 | void DataProcessorContext::finaliseOutputsCallbacks(ProcessingContext& ctx) |
26 | 48 | { |
27 | | - for (auto& handle : finaliseOutputsHandles) { |
28 | | - LOGP(debug, "Invoking postProcessingCallback for service {}", handle.spec.name); |
29 | | - handle.callback(ctx, handle.service); |
30 | | - } |
| 49 | + invokeAll(finaliseOutputsHandles, "finaliseOutputsCallbacks", spec, ctx); |
31 | 50 | } |
32 | 51 |
|
33 | 52 | /// Invoke callbacks to be executed before every dangling check |
34 | 53 | void DataProcessorContext::postProcessingCallbacks(ProcessingContext& ctx) |
35 | 54 | { |
36 | | - for (auto& handle : postProcessingHandlers) { |
37 | | - LOGP(debug, "Invoking postProcessingCallback for service {}", handle.spec.name); |
38 | | - handle.callback(ctx, handle.service); |
39 | | - } |
| 55 | + invokeAll(postProcessingHandlers, "postProcessingCallbacks", spec, ctx); |
40 | 56 | } |
41 | 57 |
|
42 | 58 | /// Invoke callbacks to be executed before every dangling check |
43 | | -void DataProcessorContext::preDanglingCallbacks(DanglingContext& danglingContext) |
| 59 | +void DataProcessorContext::preDanglingCallbacks(DanglingContext& ctx) |
44 | 60 | { |
45 | | - for (auto& handle : preDanglingHandles) { |
46 | | - LOGP(debug, "Invoking preDanglingCallback for service {}", handle.spec.name); |
47 | | - handle.callback(danglingContext, handle.service); |
48 | | - } |
| 61 | + invokeAll(preDanglingHandles, "preDanglingCallbacks", spec, ctx); |
49 | 62 | } |
50 | 63 |
|
51 | 64 | /// Invoke callbacks to be executed after every dangling check |
52 | | -void DataProcessorContext::postDanglingCallbacks(DanglingContext& danglingContext) |
| 65 | +void DataProcessorContext::postDanglingCallbacks(DanglingContext& ctx) |
53 | 66 | { |
54 | | - for (auto& handle : postDanglingHandles) { |
55 | | - LOGP(debug, "Invoking postDanglingCallback for service {}", handle.spec.name); |
56 | | - handle.callback(danglingContext, handle.service); |
57 | | - } |
| 67 | + invokeAll(postDanglingHandles, "postDanglingCallbacks", spec, ctx); |
58 | 68 | } |
59 | 69 |
|
60 | 70 | /// Invoke callbacks to be executed before every EOS user callback invokation |
61 | | -void DataProcessorContext::preEOSCallbacks(EndOfStreamContext& eosContext) |
| 71 | +void DataProcessorContext::preEOSCallbacks(EndOfStreamContext& ctx) |
62 | 72 | { |
63 | | - for (auto& handle : preEOSHandles) { |
64 | | - LOGP(detail, "Invoking preEosCallback for service {}", handle.spec.name); |
65 | | - handle.callback(eosContext, handle.service); |
66 | | - } |
| 73 | + invokeAll(preEOSHandles, "preEOSCallbacks", spec, ctx); |
67 | 74 | } |
68 | 75 |
|
69 | 76 | /// Invoke callbacks to be executed after every EOS user callback invokation |
70 | | -void DataProcessorContext::postEOSCallbacks(EndOfStreamContext& eosContext) |
| 77 | +void DataProcessorContext::postEOSCallbacks(EndOfStreamContext& ctx) |
71 | 78 | { |
72 | | - for (auto& handle : postEOSHandles) { |
73 | | - LOGP(detail, "Invoking postEoSCallback for service {}", handle.spec.name); |
74 | | - handle.callback(eosContext, handle.service); |
75 | | - } |
| 79 | + invokeAll(postEOSHandles, "postEOSCallbacks", spec, ctx); |
76 | 80 | } |
77 | 81 |
|
78 | 82 | /// Invoke callbacks to be executed after every data Dispatching |
79 | | -void DataProcessorContext::postDispatchingCallbacks(ProcessingContext& processContext) |
| 83 | +void DataProcessorContext::postDispatchingCallbacks(ProcessingContext& ctx) |
80 | 84 | { |
81 | | - for (auto& handle : postDispatchingHandles) { |
82 | | - LOGP(debug, "Invoking postDispatchingCallback for service {}", handle.spec.name); |
83 | | - handle.callback(processContext, handle.service); |
84 | | - } |
| 85 | + invokeAll(postDispatchingHandles, "postDispatchingCallbacks", spec, ctx); |
85 | 86 | } |
86 | 87 |
|
87 | 88 | /// Invoke callbacks to be executed after every data Dispatching |
88 | | -void DataProcessorContext::postForwardingCallbacks(ProcessingContext& processContext) |
| 89 | +void DataProcessorContext::postForwardingCallbacks(ProcessingContext& ctx) |
89 | 90 | { |
90 | | - for (auto& handle : postForwardingHandles) { |
91 | | - LOGP(debug, "Invoking postForwardingCallback for service {}", handle.spec.name); |
92 | | - handle.callback(processContext, handle.service); |
93 | | - } |
| 91 | + invokeAll(postForwardingHandles, "postForwardingCallbacks", spec, ctx); |
94 | 92 | } |
95 | 93 |
|
96 | 94 | /// Callbacks to be called in fair::mq::Device::PreRun() |
97 | 95 | void DataProcessorContext::preStartCallbacks(ServiceRegistryRef ref) |
98 | 96 | { |
99 | | - for (auto& handle : preStartHandles) { |
100 | | - LOGP(detail, "Invoking preStartCallback for service {}", handle.spec.name); |
101 | | - handle.callback(ref, handle.service); |
102 | | - } |
| 97 | + invokeAll(preStartHandles, "preStartCallbacks", spec, ref); |
103 | 98 | } |
104 | 99 |
|
105 | 100 | void DataProcessorContext::postStopCallbacks(ServiceRegistryRef ref) |
106 | 101 | { |
107 | | - // FIXME: we need to call the callback only once for the global services |
108 | | - /// I guess... |
109 | | - for (auto& handle : postStopHandles) { |
110 | | - LOGP(detail, "Invoking postStopCallback for service {}", handle.spec.name); |
111 | | - handle.callback(ref, handle.service); |
112 | | - } |
| 102 | + invokeAll(postStopHandles, "postStopCallbacks", spec, ref); |
113 | 103 | } |
114 | 104 |
|
115 | 105 | /// Invoke callback to be executed on exit, in reverse order. |
116 | 106 | void DataProcessorContext::preExitCallbacks(std::vector<ServiceExitHandle> handles, ServiceRegistryRef ref) |
117 | 107 | { |
| 108 | + O2_SIGNPOST_ID_FROM_POINTER(dpid, data_processor_context, &ref); |
| 109 | + O2_SIGNPOST_START(data_processor_context, dpid, "callbacks", "Starting DataProcessorContext preExitCallbacks"); |
118 | 110 | // FIXME: we need to call the callback only once for the global services |
119 | 111 | /// I guess... |
120 | 112 | for (auto handle = handles.rbegin(); handle != handles.rend(); ++handle) { |
121 | | - LOGP(detail, "Invoking preExitCallback for service {}", handle->spec.name); |
| 113 | + O2_SIGNPOST_ID_FROM_POINTER(cid, data_processor_context, handle->service); |
| 114 | + O2_SIGNPOST_START(data_processor_context, cid, "callbacks", "Starting DataProcessorContext::preExitCallbacks for service %{public}s", handle->spec.name.c_str()); |
122 | 115 | handle->callback(ref, handle->service); |
| 116 | + O2_SIGNPOST_END(data_processor_context, cid, "callbacks", "Ending DataProcessorContext::preExitCallbacks for service %{public}s", handle->spec.name.c_str()); |
123 | 117 | } |
| 118 | + O2_SIGNPOST_END(data_processor_context, dpid, "callbacks", "Ending DataProcessorContext preExitCallbacks"); |
124 | 119 | } |
125 | 120 |
|
126 | 121 | /// Invoke callback to be executed on exit, in reverse order. |
127 | 122 | void DataProcessorContext::preLoopCallbacks(ServiceRegistryRef ref) |
128 | 123 | { |
129 | | - // FIXME: we need to call the callback only once for the global services |
130 | | - /// I guess... |
131 | | - LOGP(debug, "Invoking preLoopCallbacks"); |
132 | | - for (auto& handle : preLoopHandles) { |
133 | | - LOGP(debug, "Invoking preLoopCallback for service {}", handle.spec.name); |
134 | | - handle.callback(ref, handle.service); |
135 | | - } |
| 124 | + invokeAll(preLoopHandles, "preLoopCallbacks", spec, ref); |
136 | 125 | } |
137 | 126 |
|
138 | 127 | void DataProcessorContext::domainInfoUpdatedCallback(ServiceRegistryRef ref, size_t oldestPossibleTimeslice, ChannelIndex channelIndex) |
139 | 128 | { |
| 129 | + O2_SIGNPOST_ID_FROM_POINTER(dpid, data_processor_context, this); |
| 130 | + O2_SIGNPOST_START(data_processor_context, dpid, "callbacks", "Starting DataProcessorContext domainInfoUpdatedCallback"); |
140 | 131 | for (auto& handle : domainInfoHandles) { |
141 | | - LOGP(debug, "Invoking domainInfoHandles for service {}", handle.spec.name); |
| 132 | + O2_SIGNPOST_ID_FROM_POINTER(cid, data_processor_context, handle.service); |
| 133 | + O2_SIGNPOST_START(data_processor_context, cid, "callbacks", "Starting DataProcessorContext::domainInfoUpdatedCallback for service %{public}s", handle.spec.name.c_str()); |
142 | 134 | handle.callback(ref, oldestPossibleTimeslice, channelIndex); |
| 135 | + O2_SIGNPOST_END(data_processor_context, cid, "callbacks", "Ending DataProcessorContext::domainInfoUpdatedCallback for service %{public}s", handle.spec.name.c_str()); |
143 | 136 | } |
| 137 | + O2_SIGNPOST_END(data_processor_context, dpid, "callbacks", "Ending DataProcessorContext domainInfoUpdatedCallback"); |
144 | 138 | } |
145 | 139 |
|
146 | 140 | void DataProcessorContext::preSendingMessagesCallbacks(ServiceRegistryRef ref, fair::mq::Parts& parts, ChannelIndex channelIndex) |
147 | 141 | { |
| 142 | + O2_SIGNPOST_ID_FROM_POINTER(dpid, data_processor_context, this); |
| 143 | + O2_SIGNPOST_START(data_processor_context, dpid, "callbacks", "Starting DataProcessorContext preSendingMessagesCallbacks"); |
148 | 144 | for (auto& handle : preSendingMessagesHandles) { |
149 | | - LOGP(debug, "Invoking preSending for service {}", handle.spec.name); |
| 145 | + O2_SIGNPOST_ID_FROM_POINTER(cid, data_processor_context, handle.service); |
| 146 | + O2_SIGNPOST_START(data_processor_context, cid, "callbacks", "Starting DataProcessorContext::preSendingMessagesCallbacks for service %{public}s", handle.spec.name.c_str()); |
150 | 147 | handle.callback(ref, parts, channelIndex); |
| 148 | + O2_SIGNPOST_END(data_processor_context, cid, "callbacks", "Ending DataProcessorContext::preSendingMessagesCallbacks for service %{public}s", handle.spec.name.c_str()); |
151 | 149 | } |
| 150 | + O2_SIGNPOST_END(data_processor_context, dpid, "callbacks", "Ending DataProcessorContext preSendingMessagesCallbacks"); |
152 | 151 | } |
153 | 152 |
|
154 | 153 | } // namespace o2::framework |
0 commit comments