Project
Loading...
Searching...
No Matches
test_DataProcessingStates.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.
11
15#include <catch_amalgamated.hpp>
16#include <fmt/format.h>
17#include <uv.h>
18
19using namespace o2::framework;
20
26
27using namespace o2::framework;
28
29TEST_CASE("DataProcessingStates")
30{
33
34 states.registerState({"dummy_metric", DummyMetric});
36 REQUIRE_THROWS(states.registerState({"dummy_metric", DummyMetric2}));
38 REQUIRE_THROWS(states.registerState({"dummy_metric2", DummyMetric}));
39
41
42 states.registerState({"dummy_metric2", DummyMetric2});
43 INFO("Next state is " << states.nextState.load());
44 states.updateState({DummyMetric, (int)strlen("foo"), "foo"});
45 memcpy(&header, states.store.data() + states.nextState.load(), sizeof(header));
46 REQUIRE(header.size == 3);
47 REQUIRE(header.id == DummyMetric);
48 INFO("Timestamp is " << header.timestamp);
49 REQUIRE_THROWS(states.updateState({Missing, int(strlen("foo")), "foo"}));
50 INFO("Next state is " << states.nextState.load());
51 REQUIRE(states.nextState.load() == (1 << 18) - sizeof(DataProcessingStates::CommandHeader) - 3);
52 REQUIRE(states.updatedMetricsLapse.load() == 1);
53 REQUIRE(states.pushedMetricsLapse == 0);
54 REQUIRE(states.publishedMetricsLapse == 0);
55
56 INFO("Next state is " << states.nextState.load());
57 states.updateState({DummyMetric, (int)strlen("barbar"), "barbar"});
58 INFO("Next state is " << states.nextState.load());
59 REQUIRE(states.nextState.load() == (1 << 18) - 2 * sizeof(DataProcessingStates::CommandHeader) - 3 - 6);
60 memcpy(&header, states.store.data() + states.nextState.load(), sizeof(header));
61 REQUIRE(header.size == 6);
62 REQUIRE(header.id == DummyMetric);
63 INFO("Timestamp is " << header.timestamp);
64 REQUIRE(std::string_view(states.store.data() + states.nextState.load() + sizeof(header), header.size) == "barbar");
65 REQUIRE(states.updatedMetricsLapse.load() == 2);
66 REQUIRE(states.pushedMetricsLapse == 0);
67 REQUIRE(states.publishedMetricsLapse == 0);
69 REQUIRE(states.statesViews[0].first == 0);
70 REQUIRE(states.statesViews[0].capacity == 0);
71 REQUIRE(states.statesViews[0].size == 0);
72
73 states.processCommandQueue();
74 REQUIRE(states.nextState.load() == (1 << 18));
75
76 REQUIRE(states.statesViews[0].first == 0);
77 REQUIRE(states.statesViews[0].size == 6);
78 REQUIRE(states.statesViews[0].capacity == 64);
79
80 std::vector<std::string> updated;
81 std::vector<std::string> values;
82 auto simpleFlush = [&updated, &values](std::string const& name, int64_t timestamp, std::string_view value) {
83 updated.emplace_back(name);
84 values.emplace_back(value);
85 };
86
87 states.flushChangedStates(simpleFlush);
88 REQUIRE(states.updatedMetricsLapse.load() == 2);
89 CHECK(states.pushedMetricsLapse == 1);
90 CHECK(states.publishedMetricsLapse == 1);
91 REQUIRE(updated.size() == 1);
92 REQUIRE(updated[0] == "dummy_metric");
93 REQUIRE(values.size() == 1);
94 REQUIRE(values[0] == "barbar");
95
96 states.updateState({DummyMetric, (int)strlen("foofo"), "foofo"});
98 memcpy(&header, states.store.data() + states.nextState.load(), sizeof(header));
99 REQUIRE(header.size == 5);
100 REQUIRE(header.id == DummyMetric);
101 INFO("Timestamp is " << header.timestamp);
102 states.processCommandQueue();
103
104 REQUIRE(states.nextState.load() == (1 << 18));
105
106 REQUIRE(states.statesViews[0].first == 0);
107 REQUIRE(states.statesViews[0].size == 5);
108 REQUIRE(states.statesViews[0].capacity == 64);
109 // Test the insertion of a differet state
110 states.updateState({DummyMetric2, (int)strlen("foofo"), "foofo"});
112 memcpy(&header, states.store.data() + states.nextState.load(), sizeof(header));
113 REQUIRE(header.size == 5);
114 REQUIRE(header.id == DummyMetric2);
115 INFO("Timestamp is " << header.timestamp);
116 states.processCommandQueue();
117
118 REQUIRE(states.nextState.load() == (1 << 18));
119 REQUIRE(states.statesViews[0].first == 0);
120 REQUIRE(states.statesViews[0].size == 5);
121 REQUIRE(states.statesViews[0].capacity == 64);
122 REQUIRE(states.statesViews[1].first == 64);
123 REQUIRE(states.statesViews[1].size == 5);
124 REQUIRE(states.statesViews[1].capacity == 64);
125
126 // Test going above capacity
127 SECTION("Test capacity handling")
128 {
129 states.updateState({DummyMetric2, (int)strlen("foofofoofo"), "foofofoofo"});
130 states.updateState({DummyMetric, 70, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"});
131 states.processCommandQueue();
132 REQUIRE(states.nextState.load() == (1 << 18));
133 CHECK(states.statesViews[0].first == 128);
134 CHECK(states.statesViews[0].size == 70);
135 CHECK(states.statesViews[0].capacity == 70);
136 CHECK(states.statesViews[1].first == 64);
137 CHECK(states.statesViews[1].size == 10);
138 CHECK(states.statesViews[1].capacity == 64);
139 states.updateState({DummyMetric2, 70, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"});
140 states.processCommandQueue();
141 CHECK(states.statesViews[0].first == 128);
142 CHECK(states.statesViews[0].size == 70);
143 CHECK(states.statesViews[0].capacity == 70);
144 CHECK(states.statesViews[1].first == 128 + 70);
145 CHECK(states.statesViews[1].size == 70);
146 CHECK(states.statesViews[1].capacity == 70);
147 states.updateState({DummyMetric2, 70, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"});
148 states.processCommandQueue();
149 CHECK(states.statesViews[1].first == 128 + 70);
150 CHECK(states.statesViews[1].size == 70);
151 CHECK(states.statesViews[1].capacity == 70);
152 states.updateState({DummyMetric2, 68, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"});
153 states.processCommandQueue();
154 CHECK(states.statesViews[1].first == 128 + 70);
155 CHECK(states.statesViews[1].size == 68);
156 CHECK(states.statesViews[1].capacity == 70);
157 states.repack();
158 CHECK(states.statesViews[0].first == 0);
159 CHECK(states.statesViews[0].size == 70);
160 CHECK(states.statesViews[0].capacity == 70);
161 CHECK(states.statesViews[1].first == 70);
162 CHECK(states.statesViews[1].size == 68);
163 CHECK(states.statesViews[1].capacity == 68);
164 }
165
166 SECTION("Test inserting many states")
167 {
168 for (size_t i = 0; i < 5000; i++) {
169 INFO("Inserting state " << i);
170 auto foo = fmt::format("foo{}", i);
171 states.updateState({DummyMetric, (int)foo.size(), foo.data()});
172 }
173 auto foo = fmt::format("foo{}", 2897);
174 states.updateState({DummyMetric, (int)foo.size(), foo.data()});
175 foo = fmt::format("foo{}", 2898);
176 states.updateState({DummyMetric, (int)foo.size(), foo.data()});
177 }
178
179 BENCHMARK("Inserting many states")
180 {
181 for (size_t i = 0; i < 5000; i++) {
182 auto foo = fmt::format("foo{}", i);
183 states.updateState({DummyMetric, (int)foo.size(), foo.data()});
184 }
185 };
186 states.processCommandQueue();
187
188 BENCHMARK("Inserting few states")
189 {
190 for (size_t i = 0; i < 50; i++) {
191 auto foo = fmt::format("foo{}", i);
192 states.updateState({DummyMetric, (int)foo.size(), foo.data()});
193 }
194 };
195}
BENCHMARK(benchCathodeSegmentationConstructionAll) -> Unit(benchmark::kMillisecond)
int32_t i
#define CHECK
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
GLuint * states
Definition glcorearb.h:4932
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
static std::function< int64_t(int64_t base, int64_t offset)> defaultCPUTimeConfigurator(uv_loop_t *loop)
static std::function< void(int64_t &base, int64_t &offset)> defaultRealtimeBaseConfigurator(uint64_t offset, uv_loop_t *loop)
TEST_CASE("DataProcessingStates")
HistogramRegistry foo()