Project
Loading...
Searching...
No Matches
benchmark_DeviceMetricsInfo.cxx
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.
13
14#include <benchmark/benchmark.h>
15#include <regex>
16
17// This is the fastest we could ever get.
18static void BM_MemcmpBaseline(benchmark::State& state)
19{
20 using namespace o2::framework;
21 std::string metric;
24
25 metric = "[METRIC] bkey,0 12 1789372894 hostname=test.cern.ch";
26 for (auto _ : state) {
27 // Parse a simple metric
28 benchmark::DoNotOptimize(metric == "[METRIC] bkey,0 12 1789372894 hostname=test.cern.ch");
29 }
30 state.SetBytesProcessed(state.iterations() * metric.size());
31}
32
33BENCHMARK(BM_MemcmpBaseline);
34
35static void BM_RegexBaseline(benchmark::State& state)
36{
37 using namespace o2::framework;
38 std::string metric;
41 std::regex metricsRE(R"regex(\[METRIC\] ([a-zA-Z0-9/_-]+),(0|1|2|4) ([0-9.a-zA-Z_/" <>()<$:-]+) ([0-9]+))regex", std::regex::optimize);
42 metric = "[METRIC] bkey,0 12 1789372894 hostname=test.cern.ch";
43 char const* key;
44 char const* type;
45 char const* value;
46 char const* timestamp;
47 for (auto _ : state) {
48 std::cregex_token_iterator it(metric.data(), metric.data() + metric.length(), metricsRE, {1, 2, 3, 4});
49 key = it->first;
50 ++it;
51 type = it->first;
52 ++it;
53 value = it->first;
54 ++it;
55 timestamp = it->first;
56 }
57 state.SetBytesProcessed(state.iterations() * metric.size());
58}
59BENCHMARK(BM_RegexBaseline);
60
61static void BM_ParseIntMetric(benchmark::State& state)
62{
63 using namespace o2::framework;
64 std::string metric;
67
68 metric = "[METRIC] bkey,0 12 1789372894 hostname=test.cern.ch";
69 for (auto _ : state) {
70 // Parse a simple metric
71 DeviceMetricsHelper::parseMetric(metric, match);
72 }
73 state.SetBytesProcessed(state.iterations() * metric.size());
74}
75
76BENCHMARK(BM_ParseIntMetric);
77
78static void BM_ProcessIntMetric(benchmark::State& state)
79{
80 using namespace o2::framework;
81 std::string metric;
84
85 metric = "[METRIC] bkey,0 12 1789372894 hostname=test.cern.ch";
86 std::vector<std::string> metrics{1000, metric};
87 // Add the first metric to the store
88 for (auto _ : state) {
89 for (auto& s : metrics) {
90 DeviceMetricsHelper::parseMetric(s, match);
91 DeviceMetricsHelper::processMetric(match, info);
92 }
93 }
94 state.SetBytesProcessed(state.iterations() * metrics.size() * metric.size());
95}
96
97BENCHMARK(BM_ProcessIntMetric);
98
99static void BM_ParseFloatMetric(benchmark::State& state)
100{
101 using namespace o2::framework;
102 std::string metric;
105
106 // Parse a fourth metric, now a float one
107 metric = "[METRIC] key3,2 16.0 1789372894 hostname=test.cern.ch";
108 for (auto _ : state) {
109 DeviceMetricsHelper::parseMetric(metric, match);
110 }
111 state.SetBytesProcessed(state.iterations() * metric.size());
112}
113
114BENCHMARK(BM_ParseFloatMetric);
115
116static void BM_ProcessFloatMetric(benchmark::State& state)
117{
118 using namespace o2::framework;
119 std::string metric;
122
123 metric = "[METRIC] key3,2 16.0 1789372894 hostname=test.cern.ch";
124 for (auto _ : state) {
125 DeviceMetricsHelper::parseMetric(metric, match);
126 DeviceMetricsHelper::processMetric(match, info);
127 }
128 state.SetBytesProcessed(state.iterations() * metric.size());
129}
130
131BENCHMARK(BM_ProcessFloatMetric);
132
133static void BM_ProcessStringMetric(benchmark::State& state)
134{
135 using namespace o2::framework;
136 std::string metric;
139
140 metric = "[METRIC] key3,1 some_string 1789372895 hostname=test.cern.ch";
141 for (auto _ : state) {
142 // Parse a string metric
143 DeviceMetricsHelper::parseMetric(metric, match);
144 DeviceMetricsHelper::processMetric(match, info);
145 }
146 state.SetBytesProcessed(state.iterations() * metric.size());
147}
148
149BENCHMARK(BM_ProcessStringMetric);
150
151static void BM_ProcessMismatchedMetric(benchmark::State& state)
152{
153 using namespace o2::framework;
154 std::string metric;
157
158 metric = "[METRICA] key3,1 some_string 1789372895 hostname=test.cern.ch";
159 for (auto _ : state) {
160 DeviceMetricsHelper::parseMetric(metric, match);
161 }
162 state.SetBytesProcessed(state.iterations() * metric.size());
163}
164
165BENCHMARK(BM_ProcessMismatchedMetric);
166
BENCHMARK_MAIN()
benchmark::State & state
BENCHMARK(BM_MemcmpBaseline)
StringRef key
bool match(const std::vector< std::string > &queries, const char *pattern)
Definition dcs-ccdb.cxx:229
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
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
Temporary struct to hold a metric after it has been parsed.