-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathemptyLoopBenchmark.cxx
More file actions
121 lines (106 loc) · 4.23 KB
/
emptyLoopBenchmark.cxx
File metadata and controls
121 lines (106 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file emptyLoopBenchmark.cxx
/// \brief A benchmark which measures a maximum rate of doing nothing in a device
///
/// \author Piotr Konopka, piotr.jan.konopka@cern.ch
#include "Framework/ConfigParamSpec.h"
#include "Framework/CompletionPolicy.h"
#include "Framework/CompletionPolicyHelpers.h"
#include "Framework/DeviceSpec.h"
#include "Framework/Monitoring.h"
using namespace o2::framework;
void customize(std::vector<CompletionPolicy>& policies)
{
// consume always, even when there is no data.
policies.push_back(CompletionPolicyHelpers::defineByName("sink", CompletionPolicy::CompletionOp::Consume));
policies.push_back(CompletionPolicyHelpers::consumeWhenAny("exitConsumeAny", [](DeviceSpec const& device) {
return device.name == "heWhoRequestsExit";
}));
}
// we need to add workflow options before including Framework/runDataProcessing
void customize(std::vector<ConfigParamSpec>& workflowOptions)
{
workflowOptions.push_back(ConfigParamSpec{"producers", VariantType::Int, 1, {"number of producers"}});
workflowOptions.push_back(ConfigParamSpec{
"test-duration", VariantType::Int, 300, {"how long should the test run (in seconds, max. 2147)"}});
}
#include "Framework/ControlService.h"
#include "Framework/runDataProcessing.h"
#include <Common/Timer.h>
#include <Monitoring/Monitoring.h>
using namespace AliceO2::Common;
using namespace o2::monitoring;
using SubSpec = o2::header::DataHeader::SubSpecificationType;
// We spawn fake data producers which do absolutely nothing.
// In the receiver we measure how many cycles/second can it do,
// but without taking into account the cost of receiving and sending data.
// clang-format off
WorkflowSpec defineDataProcessing(ConfigContext const& config)
{
size_t producers = config.options().get<int>("producers");
size_t testDuration = config.options().get<int>("test-duration");
WorkflowSpec specs;
for (size_t p = 0; p < producers; p++) {
specs.push_back(DataProcessorSpec{
"dataProducer" + std::to_string(p),
Inputs{},
Outputs{
OutputSpec{ "TST", "NODATA", static_cast<SubSpec>(p) }
},
AlgorithmSpec{
(AlgorithmSpec::ProcessCallback) [=](ProcessingContext& pctx) mutable {
usleep(1000000);
}
}
});
}
DataProcessorSpec sink{
"sink",
Inputs{{ "test-data", { "TST", "NODATA" }},
{ "sink-timer", "TST", "TIMER", 0, Lifetime::Timer }},
Outputs{{{ "output" }, "TST", "ALSONODATA" }},
AlgorithmSpec{
(AlgorithmSpec::InitCallback) [](InitContext& ictx) {
auto timer = std::make_shared<Timer>();
timer->reset(10 * 1000000);
uint64_t loopCounter = 0;
return (AlgorithmSpec::ProcessCallback) [=](ProcessingContext& ctx) mutable {
loopCounter++;
if (timer->isTimeout()) {
timer->increment();
auto& monitoring = ctx.services().get<Monitoring>();
monitoring.send({ loopCounter, "loop_counter" });
}
};
}
},
Options{{"period-sink-timer", VariantType::Int, 0, { "timer period" }}}
};
specs.push_back(sink);
DataProcessorSpec heWhoRequestsExit{
"heWhoRequestsExit",
Inputs{{ "input", "TST", "ALSONODATA" },
{ "test-timer", "TST", "TIMER2", 0, Lifetime::Timer }},
Outputs{},
AlgorithmSpec{
(AlgorithmSpec::ProcessCallback) [](ProcessingContext& ctx) {
if (ctx.inputs().isValid("test-timer")) {
LOG(info) << "Planned exit";
ctx.services().get<ControlService>().readyToQuit(QuitRequest::All);
}
}
},
Options{{"period-test-timer", VariantType::Int, static_cast<int>(testDuration * 1000000), { "timer period" }}}
};
specs.push_back(heWhoRequestsExit);
return specs;
}