summaryrefslogtreecommitdiffstats
path: root/src/test/bench_log.cc
blob: 2acbf1de48d83f1de56493be9fab46416aef7dcf (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
63
64
65
66
67
68
69
70
71
72
73
74
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "include/types.h"
#include "common/Thread.h"
#include "common/debug.h"
#include "common/Clock.h"
#include "common/config.h"
#include "common/ceph_argparse.h"
#include "global/global_init.h"

#define dout_context g_ceph_context

struct T : public Thread {
  int num;
  set<int> myset;
  map<int,string> mymap;
  explicit T(int n) : num(n) {
    myset.insert(123);
    myset.insert(456);
    mymap[1] = "foo";
    mymap[10] = "bar";
  }

  void *entry() override {
    while (num-- > 0)
      generic_dout(0) << "this is a typical log line.  set "
		      << myset << " and map " << mymap << dendl;
    return 0;
  }
};

int main(int argc, const char **argv)
{
  int threads = atoi(argv[1]);
  int num = atoi(argv[2]);

  cout << threads << " threads, " << num << " lines per thread" << std::endl;

  vector<const char*> args;
  argv_to_vec(argc, argv, args);

  auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_OSD,
			 CODE_ENVIRONMENT_UTILITY,
			 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);

  utime_t start = ceph_clock_now();

  list<T*> ls;
  for (int i=0; i<threads; i++) {
    T *t = new T(num);
    t->create("t");
    ls.push_back(t);
  }

  for (int i=0; i<threads; i++) {
    T *t = ls.front();
    ls.pop_front();
    t->join();
    delete t;
  }

  utime_t t = ceph_clock_now();
  t -= start;
  cout << " flushing.. " << t << " so far ..." << std::endl;

  g_ceph_context->_log->flush();

  utime_t end = ceph_clock_now();
  utime_t dur = end - start;

  cout << dur << std::endl;
  return 0;
}