summaryrefslogtreecommitdiffstats
path: root/src/test/crimson/test_perfcounters.cc
blob: 8aecbf911cc9094311cd67cb7f96e4a9010819a2 (plain)
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
#include <pthread.h>
#include <stdlib.h>
#include <iostream>
#include <fmt/format.h>

#include "common/Formatter.h"
#include "common/perf_counters.h"
#include "crimson/common/perf_counters_collection.h"

#include <seastar/core/app-template.hh>
#include <seastar/core/sharded.hh>

enum {
  PERFTEST_FIRST = 1000000,
  PERFTEST_INDEX,
  PERFTEST_LAST,
};

static constexpr uint64_t PERF_VAL = 42;

static seastar::future<> test_perfcounters(){
  return crimson::common::sharded_perf_coll().start().then([] {
    return crimson::common::sharded_perf_coll().invoke_on_all([] (auto& s){
      std::string name =fmt::format("seastar-osd::shard-{}",seastar::this_shard_id());
      PerfCountersBuilder plb(NULL, name, PERFTEST_FIRST,PERFTEST_LAST);
      plb.add_u64_counter(PERFTEST_INDEX, "perftest_count", "count perftest");
      auto perf_logger = plb.create_perf_counters();
      perf_logger->inc(PERFTEST_INDEX,PERF_VAL);
      s.get_perf_collection()->add(perf_logger);
    });
  }).then([]{
    return crimson::common::sharded_perf_coll().invoke_on_all([] (auto& s){
      auto pcc = s.get_perf_collection();
      pcc->with_counters([](auto& by_path){
        for (auto& perf_counter : by_path) {
          if (PERF_VAL != perf_counter.second.perf_counters->get(PERFTEST_INDEX)) {
             throw std::runtime_error("perf counter does not match");
           }
        }
      });
    });
  }).finally([] {
     return crimson::common::sharded_perf_coll().stop();
  });

}

int main(int argc, char** argv)
{
  seastar::app_template app;
  return app.run(argc, argv, [&] {
    return test_perfcounters().then([] {
      std::cout << "All tests succeeded" << std::endl;
    }).handle_exception([] (auto eptr) {
      std::cout << "Test failure" << std::endl;
      return seastar::make_exception_future<>(eptr);
    });
  });

}