Project
Loading...
Searching...
No Matches
benchmark_WorkflowHelpers.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.
17#include "../src/WorkflowHelpers.h"
18#include <benchmark/benchmark.h>
19#include <algorithm>
20
21using namespace o2::framework;
22
23std::unique_ptr<ConfigContext> makeEmptyConfigContext()
24{
25 // FIXME: Ugly... We need to fix ownership and make sure the ConfigContext
26 // either owns or shares ownership of the registry.
27 std::vector<std::unique_ptr<ParamRetriever>> retrievers;
28 static std::vector<ConfigParamSpec> specs;
29 auto store = std::make_unique<ConfigParamStore>(specs, std::move(retrievers));
30 store->preload();
31 store->activate();
32 static ConfigParamRegistry registry(std::move(store));
33 static ServiceRegistry services;
34 auto context = std::make_unique<ConfigContext>(registry, ServiceRegistryRef{services}, 0, nullptr);
35 return context;
36}
37
38static void BM_CreateGraphOverhead(benchmark::State& state)
39{
40
41 for (auto _ : state) {
42 std::vector<InputSpec> inputSpecs;
43 std::vector<OutputSpec> outputSpecs;
44
45 for (size_t i = 0; i < state.range(); ++i) {
46 auto subSpec = static_cast<o2::header::DataHeader::SubSpecificationType>(i);
47 inputSpecs.emplace_back(InputSpec{"y", "TST", "A", subSpec});
48 outputSpecs.emplace_back(OutputSpec{{"y"}, "TST", "A", subSpec});
49 }
50
51 WorkflowSpec workflow{
52 {"A",
53 {},
54 outputSpecs},
55 {"B", inputSpecs}};
56
57 std::vector<DeviceConnectionEdge> logicalEdges;
58 std::vector<OutputSpec> outputs;
59 std::vector<LogicalForwardInfo> availableForwardsInfo;
60
61 if (WorkflowHelpers::verifyWorkflow(workflow) != WorkflowParsingState::Valid) {
62 throw std::runtime_error("invalid workflow");
63 };
64 auto context = makeEmptyConfigContext();
65 WorkflowHelpers::injectServiceDevices(workflow, *context);
67 logicalEdges,
68 outputs,
69 availableForwardsInfo);
70 }
71}
72
73BENCHMARK(BM_CreateGraphOverhead)->Range(1, 1 << 10);
74
75static void BM_CreateGraphReverseOverhead(benchmark::State& state)
76{
77
78 for (auto _ : state) {
79 std::vector<InputSpec> inputSpecs;
80 std::vector<OutputSpec> outputSpecs;
81
82 for (size_t i = 0; i < state.range(); ++i) {
83 auto subSpec = static_cast<o2::header::DataHeader::SubSpecificationType>(i);
84 auto subSpecReverse = static_cast<o2::header::DataHeader::SubSpecificationType>(state.range() - i - 1);
85 inputSpecs.emplace_back(InputSpec{"y", "TST", "A", subSpec});
86 outputSpecs.emplace_back(OutputSpec{{"y"}, "TST", "A", subSpecReverse});
87 }
88
89 WorkflowSpec workflow{
90 {"A",
91 {},
92 outputSpecs},
93 {"B", inputSpecs}};
94
95 std::vector<DeviceConnectionEdge> logicalEdges;
96 std::vector<OutputSpec> outputs;
97 std::vector<LogicalForwardInfo> availableForwardsInfo;
98
99 if (WorkflowHelpers::verifyWorkflow(workflow) != WorkflowParsingState::Valid) {
100 throw std::runtime_error("invalid workflow");
101 };
102 auto context = makeEmptyConfigContext();
103 WorkflowHelpers::injectServiceDevices(workflow, *context);
104 WorkflowHelpers::constructGraph(workflow, logicalEdges,
105 outputs,
106 availableForwardsInfo);
107 }
108}
109
110BENCHMARK(BM_CreateGraphReverseOverhead)->Range(1, 1 << 10);
benchmark::State & state
int32_t i
BENCHMARK_MAIN()
std::unique_ptr< ConfigContext > makeEmptyConfigContext()
BENCHMARK(BM_CreateGraphOverhead) -> Range(1, 1<< 10)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< DataProcessorSpec > WorkflowSpec
static void constructGraph(const WorkflowSpec &workflow, std::vector< DeviceConnectionEdge > &logicalEdges, std::vector< OutputSpec > &outputs, std::vector< LogicalForwardInfo > &availableForwardsInfo)
static void injectServiceDevices(WorkflowSpec &workflow, ConfigContext &ctx)
static WorkflowParsingState verifyWorkflow(const WorkflowSpec &workflow)
uint32_t SubSpecificationType
Definition DataHeader.h:620