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