Project
Loading...
Searching...
No Matches
benchmark_InputRecord.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#include <benchmark/benchmark.h>
12
13#include "Headers/DataHeader.h"
14#include "Headers/Stack.h"
19#include "Framework/InputSpan.h"
20#include <Monitoring/Monitoring.h>
21#include <fairmq/TransportFactory.h>
22#include <cstring>
23
24using Monitoring = o2::monitoring::Monitoring;
25using namespace o2::framework;
28
29static void BM_InputRecordGenericGetters(benchmark::State& state)
30{
31 // Create the routes we want for the InputRecord
32 InputSpec spec1{"x", "TPC", "CLUSTERS", 0, Lifetime::Timeframe};
33 InputSpec spec2{"y", "ITS", "CLUSTERS", 0, Lifetime::Timeframe};
34 InputSpec spec3{"z", "TST", "EMPTY", 0, Lifetime::Timeframe};
35
36 size_t i = 0;
37 auto createRoute = [&i](const char* source, InputSpec& spec) {
38 return InputRoute{
39 spec,
40 i++,
41 source};
42 };
43
44 std::vector<InputRoute> schema = {
45 createRoute("x_source", spec1),
46 createRoute("y_source", spec2),
47 createRoute("z_source", spec3)};
48 // First of all we test if an empty registry behaves as expected, raising a
49 // bunch of exceptions.
50 InputSpan span{[](size_t) { return DataRef{nullptr, nullptr, nullptr}; }, 0};
51 ServiceRegistry registry;
52 InputRecord emptyRecord(schema, span, registry);
53
54 std::vector<void*> inputs;
55
56 auto createMessage = [&inputs](DataHeader& dh, int value) {
57 DataProcessingHeader dph{0, 1};
58 Stack stack{dh, dph};
59 void* header = malloc(stack.size());
60 void* payload = malloc(sizeof(int));
61 memcpy(header, stack.data(), stack.size());
62 memcpy(payload, &value, sizeof(int));
63 inputs.emplace_back(header);
64 inputs.emplace_back(payload);
65 };
66
67 auto createEmpty = [&inputs]() {
68 inputs.emplace_back(nullptr);
69 inputs.emplace_back(nullptr);
70 };
71
72 DataHeader dh1;
73 dh1.dataDescription = "CLUSTERS";
74 dh1.dataOrigin = "TPC";
75 dh1.subSpecification = 0;
77 DataHeader dh2;
78 dh2.dataDescription = "CLUSTERS";
79 dh2.dataOrigin = "ITS";
80 dh2.subSpecification = 0;
82 createMessage(dh1, 1);
83 createMessage(dh2, 2);
84 createEmpty();
85 InputSpan span2{[&inputs](size_t i) { return DataRef{nullptr, static_cast<char const*>(inputs[2 * i]), static_cast<char const*>(inputs[2 * i + 1])}; }, inputs.size() / 2};
86 InputRecord record{schema, span2, registry};
87
88 for (auto _ : state) {
89 // Checking we can get the whole ref by name
90 [[maybe_unused]] auto ref00 = record.get("x");
91 [[maybe_unused]] auto ref10 = record.get("y");
92 [[maybe_unused]] auto ref20 = record.get("z");
93
94 // Or we can get it positionally
95 [[maybe_unused]] auto ref01 = record.getByPos(0);
96 [[maybe_unused]] auto ref11 = record.getByPos(1);
97
98 record.isValid("x");
99 record.isValid("y");
100 record.isValid("z");
101 }
102}
103
104BENCHMARK(BM_InputRecordGenericGetters);
105
benchmark::State & state
int32_t i
uint32_t stack
Definition RawData.h:1
o2::monitoring::Monitoring Monitoring
BENCHMARK(BM_InputRecordGenericGetters)
BENCHMARK_MAIN()
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLsizei const GLfloat * value
Definition glcorearb.h:819
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
constexpr o2::header::SerializationMethod gSerializationMethodNone
Definition DataHeader.h:327
void * get(ServiceTypeHash typeHash, Salt salt, ServiceKind kind, char const *name=nullptr) const
the main header struct
Definition DataHeader.h:618
SerializationMethod payloadSerializationMethod
Definition DataHeader.h:651
DataDescription dataDescription
Definition DataHeader.h:636
SubSpecificationType subSpecification
Definition DataHeader.h:656
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition Stack.h:36