|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | +#include <benchmark/benchmark.h> |
| 11 | + |
| 12 | +#include "Headers/DataHeader.h" |
| 13 | +#include "Headers/Stack.h" |
| 14 | +#include "Framework/CompletionPolicyHelpers.h" |
| 15 | +#include "Framework/DataRelayer.h" |
| 16 | +#include "Framework/DataProcessingHeader.h" |
| 17 | +#include "Framework/InputRecord.h" |
| 18 | +#include <Monitoring/Monitoring.h> |
| 19 | +#include <fairmq/FairMQTransportFactory.h> |
| 20 | +#include <cstring> |
| 21 | + |
| 22 | +using Monitoring = o2::monitoring::Monitoring; |
| 23 | +using namespace o2::framework; |
| 24 | +using DataHeader = o2::header::DataHeader; |
| 25 | +using Stack = o2::header::Stack; |
| 26 | + |
| 27 | +static void BM_InputRecordGenericGetters(benchmark::State& state) |
| 28 | +{ |
| 29 | + // Create the routes we want for the InputRecord |
| 30 | + InputSpec spec1{ "x", "TPC", "CLUSTERS", 0, Lifetime::Timeframe }; |
| 31 | + InputSpec spec2{ "y", "ITS", "CLUSTERS", 0, Lifetime::Timeframe }; |
| 32 | + InputSpec spec3{ "z", "TST", "EMPTY", 0, Lifetime::Timeframe }; |
| 33 | + |
| 34 | + auto createRoute = [](const char* source, InputSpec& spec) { |
| 35 | + return InputRoute{ |
| 36 | + spec, |
| 37 | + source |
| 38 | + }; |
| 39 | + }; |
| 40 | + |
| 41 | + std::vector<InputRoute> schema = { |
| 42 | + createRoute("x_source", spec1), |
| 43 | + createRoute("y_source", spec2), |
| 44 | + createRoute("z_source", spec3) |
| 45 | + }; |
| 46 | + // First of all we test if an empty registry behaves as expected, raising a |
| 47 | + // bunch of exceptions. |
| 48 | + InputRecord emptyRecord(schema, { [](size_t) { return nullptr; }, 0 }); |
| 49 | + |
| 50 | + std::vector<void*> inputs; |
| 51 | + |
| 52 | + auto createMessage = [&inputs](DataHeader& dh, int value) { |
| 53 | + DataProcessingHeader dph{ 0, 1 }; |
| 54 | + Stack stack{ dh, dph }; |
| 55 | + void* header = malloc(stack.size()); |
| 56 | + void* payload = malloc(sizeof(int)); |
| 57 | + memcpy(header, stack.data(), stack.size()); |
| 58 | + memcpy(payload, &value, sizeof(int)); |
| 59 | + inputs.emplace_back(header); |
| 60 | + inputs.emplace_back(payload); |
| 61 | + }; |
| 62 | + |
| 63 | + auto createEmpty = [&inputs]() { |
| 64 | + inputs.emplace_back(nullptr); |
| 65 | + inputs.emplace_back(nullptr); |
| 66 | + }; |
| 67 | + |
| 68 | + DataHeader dh1; |
| 69 | + dh1.dataDescription = "CLUSTERS"; |
| 70 | + dh1.dataOrigin = "TPC"; |
| 71 | + dh1.subSpecification = 0; |
| 72 | + dh1.payloadSerializationMethod = o2::header::gSerializationMethodNone; |
| 73 | + DataHeader dh2; |
| 74 | + dh2.dataDescription = "CLUSTERS"; |
| 75 | + dh2.dataOrigin = "ITS"; |
| 76 | + dh2.subSpecification = 0; |
| 77 | + dh2.payloadSerializationMethod = o2::header::gSerializationMethodNone; |
| 78 | + createMessage(dh1, 1); |
| 79 | + createMessage(dh2, 2); |
| 80 | + createEmpty(); |
| 81 | + InputSpan span{ [&inputs](size_t i) { return static_cast<char const*>(inputs[i]); }, inputs.size() }; |
| 82 | + InputRecord record{ schema, std::move(span) }; |
| 83 | + |
| 84 | + for (auto _ : state) { |
| 85 | + // Checking we can get the whole ref by name |
| 86 | + auto ref00 = record.get("x"); |
| 87 | + auto ref10 = record.get("y"); |
| 88 | + auto ref20 = record.get("z"); |
| 89 | + |
| 90 | + // Or we can get it positionally |
| 91 | + auto ref01 = record.getByPos(0); |
| 92 | + auto ref11 = record.getByPos(1); |
| 93 | + |
| 94 | + record.isValid("x"); |
| 95 | + record.isValid("y"); |
| 96 | + record.isValid("z"); |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +BENCHMARK(BM_InputRecordGenericGetters); |
| 101 | + |
| 102 | +BENCHMARK_MAIN() |
0 commit comments