]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/bench_log.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / bench_log.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "include/types.h"
5 #include "common/Thread.h"
6 #include "common/debug.h"
7 #include "common/Clock.h"
8 #include "common/config.h"
9 #include "common/ceph_argparse.h"
10 #include "global/global_init.h"
11
12 #define dout_context g_ceph_context
13
14 using namespace std;
15
16 struct T : public Thread {
17 int num;
18 set<int> myset;
19 map<int,string> mymap;
20 explicit T(int n) : num(n) {
21 myset.insert(123);
22 myset.insert(456);
23 mymap[1] = "foo";
24 mymap[10] = "bar";
25 }
26
27 void *entry() override {
28 while (num-- > 0)
29 generic_dout(0) << "this is a typical log line. set "
30 << myset << " and map " << mymap << dendl;
31 return 0;
32 }
33 };
34
35 void usage(const char *name) {
36 cout << name << " <threads> <lines>\n"
37 << "\t threads: the number of threads for this test.\n"
38 << "\t lines: the number of log entries per thread.\n";
39 }
40
41 int main(int argc, const char **argv)
42 {
43 if (argc < 3) {
44 usage(argv[0]);
45 return EXIT_FAILURE;
46 }
47
48 int threads = atoi(argv[1]);
49 int num = atoi(argv[2]);
50
51 cout << threads << " threads, " << num << " lines per thread" << std::endl;
52
53 auto args = argv_to_vec(argc, argv);
54
55 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_OSD,
56 CODE_ENVIRONMENT_UTILITY,
57 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
58
59 utime_t start = ceph_clock_now();
60
61 list<T*> ls;
62 for (int i=0; i<threads; i++) {
63 T *t = new T(num);
64 t->create("t");
65 ls.push_back(t);
66 }
67
68 for (int i=0; i<threads; i++) {
69 T *t = ls.front();
70 ls.pop_front();
71 t->join();
72 delete t;
73 }
74
75 utime_t t = ceph_clock_now();
76 t -= start;
77 cout << " flushing.. " << t << " so far ..." << std::endl;
78
79 g_ceph_context->_log->flush();
80
81 utime_t end = ceph_clock_now();
82 utime_t dur = end - start;
83
84 cout << dur << std::endl;
85 return 0;
86 }