-
Notifications
You must be signed in to change notification settings - Fork 37
/
benchmark_main.cpp
74 lines (58 loc) · 2.1 KB
/
benchmark_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#include "application/impl/app_configuration_impl.hpp"
#include "benchmark/block_execution_benchmark.hpp"
#include "common/visitor.hpp"
#include "injector/application_injector.hpp"
#include "runtime/runtime_api/impl/core.hpp"
namespace kagome {
int benchmark_main(int argc, const char **argv) {
auto logger = kagome::log::createLogger("Configuration",
kagome::log::defaultGroupName);
if (argc == 1) {
SL_ERROR(logger,
"Usage: kagome benchmark BENCHMARK-TYPE BENCHMARK-OPTIONS\n"
"Available benchmark types are: block");
return -1;
}
auto app_config = std::make_shared<application::AppConfigurationImpl>();
if (!app_config->initializeFromArgs(argc, argv)) {
SL_ERROR(logger, "Failed to initialize kagome!");
return -1;
}
kagome::log::tuneLoggingSystem(app_config->log());
injector::KagomeNodeInjector injector{app_config};
auto config_opt = app_config->getBenchmarkConfig();
if (!config_opt) {
SL_ERROR(logger, "CLI params for benchmark are missing!");
return -1;
}
auto &benchmark_config = *config_opt;
auto block_benchmark = injector.injectBlockBenchmark();
auto res = visit_in_place(
benchmark_config,
[&](application::BlockBenchmarkConfig config) -> outcome::result<void> {
benchmark::BlockExecutionBenchmark::Config config_{
.start = config.from,
.end = config.to,
.times = config.times,
};
SL_INFO(logger,
"Kagome started. Version: {} ",
app_config->nodeVersion());
OUTCOME_TRY(block_benchmark->run(config_));
return outcome::success();
});
if (res.has_error()) {
SL_ERROR(logger, "Failed to run benchmark: {}", res.error());
logger->flush();
return res.error().value();
}
SL_INFO(logger, "Kagome benchmark stopped");
logger->flush();
return 0;
}
} // namespace kagome