]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/test_c2c.cc
import ceph quincy 17.2.6
[ceph.git] / ceph / src / test / test_c2c.cc
CommitLineData
20effc67
TL
1#include "common/ceph_argparse.h"
2#include "common/debug.h"
3#include "common/config.h"
4#include "global/global_init.h"
5#include "global/signal_handler.h"
6
7#include "include/mempool.h"
8
9#include <iostream>
10#include <string>
11
12using std::cerr;
13using std::string;
14
15static void usage(void)
16{
17 cerr << "--threads number of threads (default 1)" << std::endl;
18 cerr << "--sharding activate sharding optimization" << std::endl;
19}
20
21
22mempool::shard_t shards[mempool::num_shards] = {0};
23
24void sigterm_handler(int signum)
25{
26 size_t total = 0;
27 for (auto& shard : shards) {
28 total += shard.bytes;
29 }
30 std::cout << total << std::endl;
31 exit(0);
32}
33
34int main(int argc, const char **argv)
35{
36 int ret = 0;
37 auto args = argv_to_vec(argc, argv);
38 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
39 CODE_ENVIRONMENT_UTILITY,
40 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
41 common_init_finish(g_ceph_context);
42
43 int threads = 1;
44 bool sharding = false;
45 for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
46 if (ceph_argparse_double_dash(args, i)) {
47 break;
48 }
49 else if (ceph_argparse_witharg(args, i, &threads, cerr, "--threads", "-t", (char*)NULL)) {
50 }
51 else if (ceph_argparse_flag(args, i, "--sharding", "-s", (char*)NULL)) {
52 sharding = true;
53 }
54 else {
55 cerr << "unknown command line option: " << *i << std::endl;
56 cerr << std::endl;
57 usage();
58 return 2;
59 }
60 }
61
62 init_async_signal_handler();
63 register_async_signal_handler(SIGTERM, sigterm_handler);
64
65
66 std::vector<std::thread> workers;
67 for (int i = 0; i < threads; i++) {
68 workers.push_back(
69 std::thread([&](){
70 while(1) {
71 size_t i;
72 if (sharding) {
73 i = mempool::pool_t::pick_a_shard_int();
74 } else {
75 i = 0;
76 }
77 shards[i].bytes++;
78 }
79 }));
80 }
81
82 for (auto& t:workers) {
83 t.join();
84 }
85 workers.clear();
86
87 return ret;
88}