|
| 1 | +/// |
| 2 | +/// \file 7-InternalBenchmark.cxx |
| 3 | +/// \author Adam Wegrzynek <[email protected]> |
| 4 | +/// |
| 5 | + |
| 6 | +#include "Monitoring/MonitoringFactory.h" |
| 7 | +#include <iomanip> |
| 8 | + |
| 9 | +using namespace o2::monitoring; |
| 10 | +using namespace std::chrono; |
| 11 | + |
| 12 | +void test(std::unique_ptr<Monitoring>& monitoring) { |
| 13 | + for (int i = 0; i < 100000; i++) { |
| 14 | + monitoring->send({10, "myMetricInt"}); |
| 15 | + monitoring->send({10.10, "myMetricFloat"}); |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +void testWithTags(std::unique_ptr<Monitoring>& monitoring) { |
| 20 | + monitoring->addGlobalTag("benchmark", "yes"); |
| 21 | + for (int i = 0; i < 100000; i++) { |
| 22 | + monitoring->send(Metric{10, "myMetricInt"}.addTags({{"tag1", "val1"}})); |
| 23 | + monitoring->send(Metric{10.10, "myMetricFloat"}.addTags({{"tag2", "val2"}})); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +int main(int argc, char** argv) { |
| 28 | + static constexpr std::array<std::string_view,4> backends = { |
| 29 | + "no-op://", |
| 30 | + "flume://localhost:1234", |
| 31 | + "influxdb-udp://localhost:1234", |
| 32 | + "stdout://" |
| 33 | + }; |
| 34 | + std::cout << "| " << std::setw(30) << "Backend" << " |" |
| 35 | + << std::setw(10) << "no tags" << " |" |
| 36 | + << std::setw(10) << " (2+1) tags" << " |" << std::endl; |
| 37 | + std::cout << "+--------------------------------+-------------+-------------+" << std::endl; |
| 38 | + for(auto& backend : backends) { |
| 39 | + std::cout.setstate(std::ios_base::failbit); |
| 40 | + auto monitoring = MonitoringFactory::Get(std::string(backend)); |
| 41 | + |
| 42 | + high_resolution_clock::time_point t1 = high_resolution_clock::now(); |
| 43 | + test(monitoring); |
| 44 | + high_resolution_clock::time_point t2 = high_resolution_clock::now(); |
| 45 | + |
| 46 | + high_resolution_clock::time_point t3 = high_resolution_clock::now(); |
| 47 | + testWithTags(monitoring); |
| 48 | + high_resolution_clock::time_point t4 = high_resolution_clock::now(); |
| 49 | + |
| 50 | + std::cout.clear(); |
| 51 | + std::cout << "| " << std::setw(30) << backend << " |"; |
| 52 | + std::cout << std::setw(10) << duration_cast<milliseconds>(t2 - t1).count() << "us |"; |
| 53 | + std::cout << std::setw(10) << duration_cast<milliseconds>(t4 - t3).count() << "us |" << std::endl; |
| 54 | + } |
| 55 | +} |
0 commit comments