Project
Loading...
Searching...
No Matches
DeviceMetricsHelper.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//
12#ifndef O2_FRAMEWORK_DEVICEMETRICSHELPERS_H_
13#define O2_FRAMEWORK_DEVICEMETRICSHELPERS_H_
14
16#include <concepts>
17#include <cstddef>
18#include <cstdint>
19#include <cstring>
20#include <functional>
21#include <string_view>
22#include <vector>
23
24namespace o2::framework
25{
26struct DriverInfo;
27
28// General definition of what can of values can be put in a metric.
29// Notice that int8_t is used for enums.
30template <typename T>
31concept DeviceMetricValue = std::same_as<int, T> || std::same_as<float, T> || std::same_as<uint64_t, T> || std::same_as<int8_t, T>;
32
33// Numeric like metrics values.
34template <typename T>
35concept DeviceMetricNumericValue = std::same_as<int, T> || std::same_as<float, T> || std::same_as<uint64_t, T>;
36
37// Enum like values
38template <typename T>
39concept DeviceMetricEnumValue = std::same_as<int8_t, T>;
40
44 using NewMetricCallback = std::function<void(std::string const&, MetricInfo const&, int value, size_t metricIndex)>;
45
47 static bool parseMetric(std::string_view const s, ParsedMetricMatch& results);
48
54 static bool processMetric(ParsedMetricMatch& results,
56 NewMetricCallback newMetricCallback = nullptr);
58 static size_t metricIdxByName(std::string_view const name,
59 const DeviceMetricsInfo& info);
60
61 template <std::same_as<int> T>
63 {
64 return metrics.intMetrics;
65 }
66
67 template <std::same_as<float> T>
69 {
70 return metrics.floatMetrics;
71 }
72
73 template <std::same_as<uint64_t> T>
75 {
76 return metrics.uint64Metrics;
77 }
78
79 template <std::same_as<int8_t> T>
81 {
82 return metrics.enumMetrics;
83 }
84
85 template <std::same_as<int> T>
87 {
88 return metrics.intTimestamps;
89 }
90
91 template <std::same_as<float> T>
93 {
94 return metrics.floatTimestamps;
95 }
96
97 template <std::same_as<uint64_t> T>
99 {
100 return metrics.uint64Timestamps;
101 }
102
103 template <std::same_as<int8_t> T>
105 {
106 return metrics.enumTimestamps;
107 }
108
109 template <std::same_as<int> T>
110 static auto getMetricType() -> MetricType
111 {
112 return MetricType::Int;
113 }
114
115 template <std::same_as<float> T>
116 static auto getMetricType() -> MetricType
117 {
118 return MetricType::Float;
119 }
120
121 template <std::same_as<uint64_t> T>
122 static auto getMetricType() -> MetricType
123 {
124 return MetricType::Uint64;
125 }
126
127 template <std::same_as<int8_t> T>
128 static auto getMetricType() -> MetricType
129 {
130 return MetricType::Enum;
131 }
132
133 static auto updateNumericInfo(DeviceMetricsInfo& metrics, size_t metricIndex, float value, size_t timestamp)
134 {
135 metrics.minDomain[metricIndex] = std::min(metrics.minDomain[metricIndex], timestamp);
136 metrics.maxDomain[metricIndex] = std::max(metrics.maxDomain[metricIndex], timestamp);
137 metrics.max[metricIndex] = std::max(metrics.max[metricIndex], (float)value);
138 metrics.min[metricIndex] = std::min(metrics.min[metricIndex], (float)value);
139 metrics.changed.at(metricIndex) = true;
140 }
141
142 template <DeviceMetricNumericValue T>
143 static auto getNumericMetricCursor(size_t metricIndex)
144 {
145 return [metricIndex](DeviceMetricsInfo& metrics, T value, size_t timestamp) {
146 MetricInfo& metric = metrics.metrics[metricIndex];
147 updateNumericInfo(metrics, metricIndex, (float)value, timestamp);
148
149 auto& store = getMetricsStore<T>(metrics);
150 auto& timestamps = getTimestampsStore<T>(metrics);
151 size_t pos = metric.pos++ % store[metric.storeIdx].size();
152 timestamps[metric.storeIdx][pos] = timestamp;
153 store[metric.storeIdx][pos] = value;
154 metric.filledMetrics++;
155 };
156 }
157
158 static size_t bookMetricInfo(DeviceMetricsInfo& metrics, char const* name, MetricType type);
159
161 template <DeviceMetricNumericValue T>
162 static size_t
164 char const* name,
165 NewMetricCallback newMetricsCallback = nullptr)
166 {
167 size_t metricIndex = bookMetricInfo(metrics, name, getMetricType<T>());
168 auto& metricInfo = metrics.metrics[metricIndex];
169 if (newMetricsCallback != nullptr) {
170 newMetricsCallback(name, metricInfo, 0, metricIndex);
171 }
172 return metricIndex;
173 }
174
176 template <DeviceMetricNumericValue T>
177 static std::function<void(DeviceMetricsInfo&, T value, size_t timestamp)>
179 char const* name,
180 NewMetricCallback newMetricsCallback = nullptr)
181 {
182 size_t metricIndex = bookNumericMetric<T>(metrics, name, newMetricsCallback);
183 return getNumericMetricCursor<T>(metricIndex);
184 }
185};
186
187} // namespace o2::framework
188
189#endif // O2_FRAMEWORK_DEVICEMETRICSINFO_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 s
uint16_t pos
Definition RawData.h:3
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
Definition glcorearb.h:5500
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
static auto & getMetricsStore(DeviceMetricsInfo &metrics)
static bool parseMetric(std::string_view const s, ParsedMetricMatch &results)
Helper function to parse a metric string.
static auto updateNumericInfo(DeviceMetricsInfo &metrics, size_t metricIndex, float value, size_t timestamp)
static auto & getTimestampsStore(DeviceMetricsInfo &metrics)
static bool processMetric(ParsedMetricMatch &results, DeviceMetricsInfo &info, NewMetricCallback newMetricCallback=nullptr)
static size_t bookMetricInfo(DeviceMetricsInfo &metrics, char const *name, MetricType type)
static size_t metricIdxByName(std::string_view const name, const DeviceMetricsInfo &info)
static auto getMetricType() -> MetricType
static size_t bookNumericMetric(DeviceMetricsInfo &metrics, char const *name, NewMetricCallback newMetricsCallback=nullptr)
static std::function< void(DeviceMetricsInfo &, T value, size_t timestamp)> createNumericMetric(DeviceMetricsInfo &metrics, char const *name, NewMetricCallback newMetricsCallback=nullptr)
std::function< void(std::string const &, MetricInfo const &, int value, size_t metricIndex)> NewMetricCallback
static auto getNumericMetricCursor(size_t metricIndex)
Temporary struct to hold a metric after it has been parsed.