Skip to content

Commit 935c151

Browse files
authored
Add unit tags (#149)
* Add unit tags * fix * Add test * clang-format
1 parent 688fe9a commit 935c151

File tree

2 files changed

+91
-37
lines changed

2 files changed

+91
-37
lines changed

include/Monitoring/Tags.h

Lines changed: 89 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,100 @@ namespace monitoring
2626

2727
namespace tags
2828
{
29-
using namespace std::string_view_literals;
29+
using namespace std::string_view_literals;
3030

31-
// Tag keys
32-
enum class Key : unsigned short int { Hostname, Rolename, Name, Detector, Subsystem, CRU, FLP, EPN };
31+
// Tag keys
32+
enum class Key : unsigned short int { Hostname,
33+
Rolename,
34+
Name,
35+
Detector,
36+
Subsystem,
37+
CRU,
38+
FLP,
39+
EPN,
40+
Unit };
3341

34-
/// Tag keys array
35-
static constexpr std::array<std::string_view, 8> TAG_KEY = {
36-
"hostname"sv, "rolenane"sv, "name"sv, "detector"sv, "subsystem"sv, "CRU"sv, "FLP"sv, "EPN"sv
37-
};
42+
/// Tag keys array
43+
static constexpr std::array<std::string_view, 9> TAG_KEY = {
44+
"hostname"sv, "rolenane"sv, "name"sv, "detector"sv, "subsystem"sv, "CRU"sv, "FLP"sv, "EPN"sv, "unit"sv
45+
};
3846

39-
// Tag values
40-
enum class Value : unsigned short int { ACO, AD, CPV, EMC, FMD, HMP, MCH, MTR, PHS, PMD, ITS, T0, TOF, TPC, TRD, V0, QC, Readout, DPL, CRU};
47+
// Tag values
48+
enum class Value : unsigned short int { ACO,
49+
AD,
50+
CPV,
51+
EMC,
52+
FMD,
53+
HMP,
54+
MCH,
55+
MTR,
56+
PHS,
57+
PMD,
58+
ITS,
59+
T0,
60+
TOF,
61+
TPC,
62+
TRD,
63+
V0,
64+
QC,
65+
Readout,
66+
DPL,
67+
CRU,
68+
Bytes,
69+
Megabytes,
70+
Gigabytes,
71+
Bits,
72+
Megabits,
73+
Gigabits,
74+
bps,
75+
Mbps,
76+
Gbps,
77+
Nanoseconds,
78+
Microseconds,
79+
Milliseconds,
80+
Seconds };
4181

42-
// Tag value array
43-
static constexpr std::array<std::string_view, 20> TAG_VALUE = {{
44-
"ACO"sv,
45-
"AD"sv, // 1
46-
"CPV"sv, // 2
47-
"EMC"sv, // 3
48-
"FMD"sv, // 4
49-
"HMP"sv, // 5
50-
"MCH"sv, // 6
51-
"MTR"sv, // 7
52-
"PHS"sv, // 8
53-
"PHS"sv, // 9
54-
"PMD"sv, // 10
55-
"ITS"sv, // 11
56-
"TOF"sv, // 12
57-
"TPC"sv, // 13
58-
"TRD"sv, // 14
59-
"V0"sv, // 15
60-
"QC"sv,
61-
"Readout"sv,
62-
"DPL"sv,
63-
"CRU"sv
64-
}};
65-
static constexpr std::string_view GetValue(const int value) {
66-
return value >= 0 ? TAG_VALUE[value] : std::to_string(0 - value);
67-
}
82+
// Tag value array
83+
static constexpr std::array<std::string_view, 33> TAG_VALUE = { {
84+
"ACO"sv,
85+
"AD"sv, // 1
86+
"CPV"sv, // 2
87+
"EMC"sv, // 3
88+
"FMD"sv, // 4
89+
"HMP"sv, // 5
90+
"MCH"sv, // 6
91+
"MTR"sv, // 7
92+
"PHS"sv, // 8
93+
"PHS"sv, // 9
94+
"PMD"sv, // 10
95+
"ITS"sv, // 11
96+
"TOF"sv, // 12
97+
"TPC"sv, // 13
98+
"TRD"sv, // 14
99+
"V0"sv, // 15
100+
"QC"sv, // 16
101+
"Readout"sv, //17
102+
"DPL"sv, // 18
103+
"CRU"sv, // 19
104+
"B"sv, // 20
105+
"MB"sv, // 21
106+
"GB"sv, // 22
107+
"b"sv, // 23
108+
"Mb"sv, // 24
109+
"Gb"sv, // 25
110+
"bps"sv, // 26
111+
"Mbps"sv, // 27
112+
"Gbps"sv, //28
113+
"ns"sv, //29
114+
"us"sv, //30
115+
"ms"sv //31
116+
"s"sv // 32
117+
} };
118+
static constexpr std::string_view GetValue(const int value)
119+
{
120+
return value >= 0 ? TAG_VALUE[value] : std::to_string(0 - value);
68121
}
122+
} // namespace tags
69123

70124
} // namespace monitoring
71125
} // namespace o2

test/testMetric.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ BOOST_AUTO_TEST_CASE(retrieveWrongType) {
7575
}
7676

7777
BOOST_AUTO_TEST_CASE(tags) {
78-
Metric metric = Metric{10, "myMetric"}.addTag(o2::monitoring::tags::Key::Detector, o2::monitoring::tags::Value::TRD);
78+
Metric metric = Metric{10, "myMetric"}.addTag(o2::monitoring::tags::Key::Detector, o2::monitoring::tags::Value::TRD).addTag(o2::monitoring::tags::Key::Unit, o2::monitoring::tags::Value::Milliseconds);
7979
auto tags = metric.getTags();
8080
int sum = 0;
8181
for (auto const& tag: tags) {
8282
sum += tag.second;
8383
}
84-
BOOST_CHECK_EQUAL(sum, 14);
84+
BOOST_CHECK_EQUAL(sum, 45);
8585
}
8686

8787
BOOST_AUTO_TEST_CASE(regexVerbosityPolicy)

0 commit comments

Comments
 (0)