Project
Loading...
Searching...
No Matches
DataProcessingStats.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef O2_FRAMEWORK_DATAPROCESSINGSTATS_H_
12#define O2_FRAMEWORK_DATAPROCESSINGSTATS_H_
13
14#include "DeviceState.h"
16#include <atomic>
17#include <cstdint>
18#include <array>
19#include <memory>
20#include <numeric>
21#include <mutex>
22#include <utility>
23
24namespace o2::framework
25{
26
81
84 // Parameters for the default behaviour
88
90
91 DataProcessingStats(std::function<void(int64_t& base, int64_t& offset)> getRealtimeBase,
92 std::function<int64_t(int64_t base, int64_t offset)> getTimestamp,
93 DefaultConfig config);
94
96 constexpr static unsigned short MAX_METRICS = 1 << 15;
97 constexpr static short MAX_CMDS = 64;
98
99 enum struct Op : char {
100 Nop,
101 Set,
105 Add,
106 Sub,
107 Max,
108 Min
109 };
110
111 // Kind of the metric. This is used to know how to interpret the value
112 enum struct Kind : char {
113 Int,
114 UInt64,
115 Double,
116 Rate,
119 Unknown,
120 };
121
122 // The scope for a given metric. DPL is used for the DPL Monitoring GUI,
123 // Online is used for the online monitoring.
124 enum struct Scope : char {
125 DPL,
126 Online
127 };
128
129 // This is what the user passes. Notice that there is no
130 // need to specify the timestamp, because we calculate it for them
131 // using the delta between the last update and the current time.
132 struct CommandSpec {
133 unsigned short id = 0;
136 };
137
138 // This is the structure to keep track of local updates to the stats.
139 // Each command will be queued in a buffer and then flushed to the
140 // global stats either when the buffer is full (after MAX_CMDS commands)
141 // or when the queue is flushed explicitly via the processQueue() method.
142 struct Command {
143 unsigned short id = 0; // StatsId of the metric to update
144 int64_t value = 0; // Value to update the metric with
145 int64_t timestamp = 0; // Timestamp of the update
146 Op op = Op::Nop; // Operation to perform to do the update
147 };
148
149 // This structure is used to keep track of the last updates
150 // for each of the metrics. This can be used to defer the need
151 // to flush the buffers to the remote end, so that we do not need to
152 // send metrics synchronously but we can do e.g. as a batch update.
153 // It also prevents that we send the same metric multiple times, because
154 // we keep track of the time of the last update.
155 struct UpdateInfo {
156 int64_t timestamp = 0; // When the update actually took place
157 int64_t lastPublished = 0; // When the update was last published
158 };
159
160 struct MetricSpec {
161 // Id of the metric. It must match the index in the metrics array.
162 // Name of the metric
163 std::string name = "";
164 // Wether or not the metric is enabled
165 bool enabled = true;
166 int metricId = -1;
180 bool sendInitialValue = false;
181 };
182
183 void registerMetric(MetricSpec const& spec);
184
185 // Update some stats as specified by the @cmd cmd
186 void updateStats(CommandSpec cmd);
187
188 char const* findMetricNameById(ProcessingStatsId id) const;
191 void processCommandQueue();
192
193 void flushChangedMetrics(std::function<void(MetricSpec const&, int64_t, int64_t)> const& callback);
194
195 std::atomic<size_t> statesSize = 0;
196
197 std::array<Command, MAX_CMDS> cmds = {};
198 std::array<int64_t, MAX_METRICS> metrics = {};
199 std::array<bool, MAX_METRICS> updated = {};
200 std::array<std::string, MAX_METRICS> metricsNames = {};
201 std::array<UpdateInfo, MAX_METRICS> updateInfos = {};
202 std::array<MetricSpec, MAX_METRICS> metricSpecs = {};
203 std::array<int64_t, MAX_METRICS> lastPublishedMetrics = {};
204 std::vector<int> availableMetrics;
205 // for fast check for AVAILABLE_MANAGED_SHM metric which is only provided for readout-proxy
206 bool hasAvailSHMMetric = false;
207 // How many commands have been committed to the queue.
208 std::atomic<int> insertedCmds = 0;
209 // The insertion point for the next command.
210 std::atomic<int> nextCmd = 0;
211 // How many commands are currently in flight.
212 std::atomic<int> pendingCmds = 0;
215 // This is the mutex to protect the queue of commands.
216 std::mutex mMutex;
217
218 // Function to retrieve an aritrary base for the realtime clock.
219 std::function<void(int64_t& base, int64_t& offset)> getRealtimeBase;
220 // Function to retrieve the timestamp from the value returned by getRealtimeBase.
222 // The value of the uv_hrtime() at the last update.
224 // The value of the uv_now() at the last update.
226
227 // Invoke to make sure that the updatedMetricsTotal is updated.
237
238 // Telemetry for the metric updates and pushes
239 std::atomic<int64_t> updatedMetricsLapse = 0;
247};
248
249} // namespace o2::framework
250
251#endif // O2_FRAMEWORK_DATAPROCESSINGSTATS_H_
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
GLuint const GLchar * name
Definition glcorearb.h:781
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition glcorearb.h:2513
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
Definition glcorearb.h:5500
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLintptr offset
Definition glcorearb.h:660
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
ServiceKind
The kind of service we are asking for.
int64_t minPublishInterval
How many milliseconds must have passed since the last publishing.
int64_t defaultValue
The default value for the metric.
Helper struct to hold statistics about the data processing happening.
std::array< bool, MAX_METRICS > updated
char const * findMetricNameById(ProcessingStatsId id) const
void registerMetric(MetricSpec const &spec)
std::array< MetricSpec, MAX_METRICS > metricSpecs
std::function< int64_t(int64_t base, int64_t offset)> getTimestamp
@ SetIfPositive
Set the value to the specified value.
@ InstantaneousRate
Update the rate of the metric given the cumulative value since last time it got published.
@ Max
Subtract the value from the current value.
@ Min
Set the value to the maximum of the current value and the specified value.
@ CumulativeRate
Set the value to the specified value if it is positive.
@ Sub
Add the value to the current value.
@ Add
Update the rate of the metric given the amount since the last time.
std::array< std::string, MAX_METRICS > metricsNames
std::array< Command, MAX_CMDS > cmds
void flushChangedMetrics(std::function< void(MetricSpec const &, int64_t, int64_t)> const &callback)
std::array< int64_t, MAX_METRICS > lastPublishedMetrics
std::function< void(int64_t &base, int64_t &offset)> getRealtimeBase
static constexpr unsigned short MAX_METRICS
std::array< UpdateInfo, MAX_METRICS > updateInfos
static constexpr ServiceKind service_kind