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{
51 [](size_t) -> size_t { return 0; },
52 nullptr,
53 [](size_t, DataRefIndices) { return DataRef{nullptr, nullptr, nullptr}; },
54 [](size_t, DataRefIndices) -> DataRefIndices { return {size_t(-1), size_t(-1)}; },
55 nullptr,
56 0};
57 ServiceRegistry registry;
58 InputRecord emptyRecord(schema, span, registry);
59
60 std::vector<void*> inputs;
61
62 auto createMessage = [&inputs](DataHeader& dh, int value) {
63 DataProcessingHeader dph{0, 1};
64 Stack stack{dh, dph};
65 void* header = malloc(stack.size());
66 void* payload = malloc(sizeof(int));
67 memcpy(header, stack.data(), stack.size());
68 memcpy(payload, &value, sizeof(int));
69 inputs.emplace_back(header);
70 inputs.emplace_back(payload);
71 };
72
73 auto createEmpty = [&inputs]() {
74 inputs.emplace_back(nullptr);
75 inputs.emplace_back(nullptr);
76 };
77
78 DataHeader dh1;
79 dh1.dataDescription = "CLUSTERS";
80 dh1.dataOrigin = "TPC";
81 dh1.subSpecification = 0;
83 DataHeader dh2;
84 dh2.dataDescription = "CLUSTERS";
85 dh2.dataOrigin = "ITS";
86 dh2.subSpecification = 0;
88 createMessage(dh1, 1);
89 createMessage(dh2, 2);
90 createEmpty();
91 InputSpan span2{
92 [](size_t) -> size_t { return 1; },
93 nullptr,
94 [&inputs](size_t i, DataRefIndices idx) { return DataRef{nullptr, static_cast<char const*>(inputs[2 * i + idx.headerIdx]), static_cast<char const*>(inputs[2 * i + idx.payloadIdx])}; },
95 [](size_t, DataRefIndices) -> DataRefIndices { return {size_t(-1), size_t(-1)}; },
96 nullptr,
97 inputs.size() / 2};
98 InputRecord record{schema, span2, registry};
99
100 for (auto _ : state) {
101 // Checking we can get the whole ref by name
102 [[maybe_unused]] auto ref00 = record.get("x");
103 [[maybe_unused]] auto ref10 = record.get("y");
104 [[maybe_unused]] auto ref20 = record.get("z");
105
106 // Or we can get it positionally
107 [[maybe_unused]] auto ref01 = record.getByPos(0);
108 [[maybe_unused]] auto ref11 = record.getByPos(1);
109
110 record.isValid("x");
111 record.isValid("y");
112 record.isValid("z");
113 }
114}
115
116BENCHMARK(BM_InputRecordGenericGetters);
117
benchmark::State & state
std::shared_ptr< arrow::Schema > schema
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 ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
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:620
SerializationMethod payloadSerializationMethod
Definition DataHeader.h:653
DataDescription dataDescription
Definition DataHeader.h:638
SubSpecificationType subSpecification
Definition DataHeader.h:658
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition Stack.h:33