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 0};
56 ServiceRegistry registry;
57 InputRecord emptyRecord(schema, span, registry);
58
59 std::vector<void*> inputs;
60
61 auto createMessage = [&inputs](DataHeader& dh, int value) {
62 DataProcessingHeader dph{0, 1};
63 Stack stack{dh, dph};
64 void* header = malloc(stack.size());
65 void* payload = malloc(sizeof(int));
66 memcpy(header, stack.data(), stack.size());
67 memcpy(payload, &value, sizeof(int));
68 inputs.emplace_back(header);
69 inputs.emplace_back(payload);
70 };
71
72 auto createEmpty = [&inputs]() {
73 inputs.emplace_back(nullptr);
74 inputs.emplace_back(nullptr);
75 };
76
77 DataHeader dh1;
78 dh1.dataDescription = "CLUSTERS";
79 dh1.dataOrigin = "TPC";
80 dh1.subSpecification = 0;
82 DataHeader dh2;
83 dh2.dataDescription = "CLUSTERS";
84 dh2.dataOrigin = "ITS";
85 dh2.subSpecification = 0;
87 createMessage(dh1, 1);
88 createMessage(dh2, 2);
89 createEmpty();
90 InputSpan span2{
91 [](size_t) -> size_t { return 1; },
92 nullptr,
93 [&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])}; },
94 [](size_t, DataRefIndices) -> DataRefIndices { return {size_t(-1), size_t(-1)}; },
95 inputs.size() / 2};
96 InputRecord record{schema, span2, registry};
97
98 for (auto _ : state) {
99 // Checking we can get the whole ref by name
100 [[maybe_unused]] auto ref00 = record.get("x");
101 [[maybe_unused]] auto ref10 = record.get("y");
102 [[maybe_unused]] auto ref20 = record.get("z");
103
104 // Or we can get it positionally
105 [[maybe_unused]] auto ref01 = record.getByPos(0);
106 [[maybe_unused]] auto ref11 = record.getByPos(1);
107
108 record.isValid("x");
109 record.isValid("y");
110 record.isValid("z");
111 }
112}
113
114BENCHMARK(BM_InputRecordGenericGetters);
115
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