]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/crimson/test_perfcounters.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / crimson / test_perfcounters.cc
1 #include <pthread.h>
2 #include <stdlib.h>
3 #include <iostream>
4 #include <fmt/format.h>
5
6 #include "common/Formatter.h"
7 #include "common/perf_counters.h"
8 #include "crimson/common/perf_counters_collection.h"
9
10 #include <seastar/core/app-template.hh>
11 #include <seastar/core/sharded.hh>
12
13 enum {
14 PERFTEST_FIRST = 1000000,
15 PERFTEST_INDEX,
16 PERFTEST_LAST,
17 };
18
19 static constexpr uint64_t PERF_VAL = 42;
20
21 static seastar::future<> test_perfcounters(){
22 return crimson::common::sharded_perf_coll().start().then([] {
23 return crimson::common::sharded_perf_coll().invoke_on_all([] (auto& s){
24 std::string name =fmt::format("seastar-osd::shard-{}",seastar::this_shard_id());
25 PerfCountersBuilder plb(NULL, name, PERFTEST_FIRST,PERFTEST_LAST);
26 plb.add_u64_counter(PERFTEST_INDEX, "perftest_count", "count perftest");
27 auto perf_logger = plb.create_perf_counters();
28 perf_logger->inc(PERFTEST_INDEX,PERF_VAL);
29 s.get_perf_collection()->add(perf_logger);
30 });
31 }).then([]{
32 return crimson::common::sharded_perf_coll().invoke_on_all([] (auto& s){
33 auto pcc = s.get_perf_collection();
34 pcc->with_counters([](auto& by_path){
35 for (auto& perf_counter : by_path) {
36 if (PERF_VAL != perf_counter.second.perf_counters->get(PERFTEST_INDEX)) {
37 throw std::runtime_error("perf counter does not match");
38 }
39 }
40 });
41 });
42 }).finally([] {
43 return crimson::common::sharded_perf_coll().stop();
44 });
45
46 }
47
48 int main(int argc, char** argv)
49 {
50 seastar::app_template app;
51 return app.run(argc, argv, [&] {
52 return test_perfcounters().then([] {
53 std::cout << "All tests succeeded" << std::endl;
54 }).handle_exception([] (auto eptr) {
55 std::cout << "Test failure" << std::endl;
56 return seastar::make_exception_future<>(eptr);
57 });
58 });
59
60 }
61
62