Project
Loading...
Searching...
No Matches
DeviceMetricsInfo.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_DEVICEMETRICSINFO_H_
13#define O2_FRAMEWORK_DEVICEMETRICSINFO_H_
14
16#include "Framework/Traits.h"
17#include <array>
18#include <cstddef>
19#include <cstdint>
20#include <span>
21#include <string>
22#include <vector>
23#include <iosfwd>
24
25namespace o2::framework
26{
27
28enum class MetricType {
29 Int = 0,
30 String = 1,
31 Float = 2,
32 Uint64 = 3,
33 // DPL specific type, used for the GUI. Maximum 8 bits
34 // and we keep only the last 8 entries in the history.
35 Enum = 16,
37};
38
39std::ostream& operator<<(std::ostream& oss, MetricType const& val);
40
41struct MetricInfo {
43 size_t storeIdx = -1; // Index in the actual store
44 size_t pos = 0; // Last position in the circular buffer
45 size_t filledMetrics = 0; // How many metrics were filled
46};
47
48// We keep only fixed lenght strings for metrics, as in the end this is not
49// really needed. They should be nevertheless 0 terminated.
51 static constexpr ptrdiff_t MAX_SIZE = 512;
53};
54
55// Also for the keys it does not make much sense to keep more than 255 chars.
56// They should be nevertheless 0 terminated.
58 static constexpr size_t MAX_METRIC_LABEL_SIZE = 256 - sizeof(unsigned char); // Maximum size for a metric name.
59 unsigned char size = 0;
61};
62
64 static constexpr size_t MAX_METRIC_PREFIX_SIZE = 256 - sizeof(unsigned char); // Maximum size for a metric name.
65 unsigned char size = 0;
67 int begin = 0;
68 int end = 0;
69};
70
72 size_t index;
73};
74
76 size_t index;
77};
78
81 // Pointer to the first character of the metric name.
82 char const* beginKey;
83 // Pointer to the last character of the metric name.
84 char const* endKey;
85 // If the metric is in the form name/<begin>-<end>, this is /
86 // nullptr otherwise. If not nullptr, the actual
87 // metric name is given by the range [beginKey, beginRange) applied
88 // the key. I.e.:
89 // name/<begin>-<end> -> name/<begin>...name/<end>
90 // If the metric is in the form name/<begin>-<end>, this is <begin>
91 int firstIndex = -1;
92 // If the metric is in the form name/<begin>-<end>, this is <end>
93 int lastIndex = -1;
94 size_t timestamp;
99 char const* beginStringValue;
100 char const* endStringValue;
101};
102
103template <typename T>
104inline constexpr size_t metricStorageSize()
105{
106 if constexpr (std::is_same_v<T, int>) {
107 return 1024;
108 } else if constexpr (std::is_same_v<T, uint64_t>) {
109 return 1024;
110 } else if constexpr (std::is_same_v<T, StringMetric>) {
111 return 32;
112 } else if constexpr (std::is_same_v<T, float>) {
113 return 1024;
114 } else if constexpr (std::is_same_v<T, int8_t>) {
115 return 8;
116 } else {
117 static_assert(always_static_assert_v<T>, "Unsupported type");
118 }
119}
120
121static inline constexpr size_t metricStorageSize(enum MetricType type)
122{
123 switch (type) {
124 case MetricType::Int:
125 return 1024;
127 return 1024;
129 return 1024;
131 return 32;
132 case MetricType::Enum:
133 return 8;
135 return 0;
136 }
138}
139
140template <typename T>
141using MetricsStorage = std::array<T, metricStorageSize<T>()>;
142
143template <typename T>
144using TimestampsStorage = std::array<size_t, metricStorageSize<T>()>;
145
150 // We keep the size of each metric to 4096 bytes. No need for more
151 // for the debug GUI
152 std::vector<MetricsStorage<int>> intMetrics;
153 std::vector<MetricsStorage<uint64_t>> uint64Metrics;
154 std::vector<MetricsStorage<StringMetric>> stringMetrics; // We do not keep so many strings as metrics as history is less relevant.
155 std::vector<MetricsStorage<float>> floatMetrics;
156 std::vector<MetricsStorage<int8_t>> enumMetrics;
157 std::vector<TimestampsStorage<int>> intTimestamps;
158 std::vector<TimestampsStorage<uint64_t>> uint64Timestamps;
159 std::vector<TimestampsStorage<float>> floatTimestamps;
160 std::vector<TimestampsStorage<StringMetric>> stringTimestamps;
161 std::vector<TimestampsStorage<int8_t>> enumTimestamps;
162 std::vector<float> max;
163 std::vector<float> min;
164 std::vector<float> average;
165 std::vector<size_t> minDomain;
166 std::vector<size_t> maxDomain;
167 std::vector<MetricLabel> metricLabels;
168 std::vector<MetricPrefix> metricPrefixes;
169 std::vector<MetricLabelIndex> metricLabelsAlphabeticallySortedIdx;
170 std::vector<MetricPrefixIndex> metricLabelsPrefixesSortedIdx;
171 std::vector<MetricInfo> metrics;
172 std::vector<bool> changed;
173};
174
176 template <typename T, size_t I = metricStorageSize<T>()>
177 static std::array<T, I> const& get(DeviceMetricsInfo const& info, size_t metricIdx)
178 {
179 if constexpr (std::is_same_v<T, int>) {
180 return info.intMetrics[metricIdx];
181 } else if constexpr (std::is_same_v<T, uint64_t>) {
182 return info.uint64Metrics[metricIdx];
183 } else if constexpr (std::is_same_v<T, StringMetric>) {
184 return info.stringMetrics[metricIdx];
185 } else if constexpr (std::is_same_v<T, float>) {
186 return info.floatMetrics[metricIdx];
187 } else if constexpr (std::is_same_v<T, int8_t>) {
188 return info.enumMetrics[metricIdx];
189 } else {
190 static_assert(always_static_assert_v<T>, "Unsupported type");
191 }
192 }
193
194 static void clearMetrics(std::vector<DeviceMetricsInfo>& infos);
195 static size_t metricsStorageSize(std::span<DeviceMetricsInfo const> infos);
196};
197
198} // namespace o2::framework
199
200#endif // O2_FRAMEWORK_DEVICEMETRICSINFO_H_
#define O2_BUILTIN_UNREACHABLE
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
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLuint GLfloat * val
Definition glcorearb.h:1582
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::array< size_t, metricStorageSize< T >()> TimestampsStorage
constexpr size_t metricStorageSize()
std::ostream & operator<<(std::ostream &s, ChannelType const &type)
Stream operators so that we can use ChannelType with Boost.Test.
std::array< T, metricStorageSize< T >()> MetricsStorage
static std::array< T, I > const & get(DeviceMetricsInfo const &info, size_t metricIdx)
static size_t metricsStorageSize(std::span< DeviceMetricsInfo const > infos)
static void clearMetrics(std::vector< DeviceMetricsInfo > &infos)
std::vector< MetricsStorage< float > > floatMetrics
std::vector< TimestampsStorage< int > > intTimestamps
std::vector< TimestampsStorage< float > > floatTimestamps
std::vector< MetricsStorage< StringMetric > > stringMetrics
std::vector< MetricsStorage< uint64_t > > uint64Metrics
std::vector< MetricsStorage< int > > intMetrics
std::vector< MetricPrefix > metricPrefixes
std::vector< MetricLabel > metricLabels
std::vector< TimestampsStorage< int8_t > > enumTimestamps
std::vector< MetricPrefixIndex > metricLabelsPrefixesSortedIdx
std::vector< TimestampsStorage< uint64_t > > uint64Timestamps
std::vector< MetricLabelIndex > metricLabelsAlphabeticallySortedIdx
std::vector< MetricInfo > metrics
std::vector< MetricsStorage< int8_t > > enumMetrics
std::vector< TimestampsStorage< StringMetric > > stringTimestamps
static constexpr size_t MAX_METRIC_LABEL_SIZE
static constexpr size_t MAX_METRIC_PREFIX_SIZE
char prefix[MAX_METRIC_PREFIX_SIZE]
Temporary struct to hold a metric after it has been parsed.
static constexpr ptrdiff_t MAX_SIZE