]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
bench_log: simple util to time how long it takes to log stuff
authorSage Weil <sage@newdream.net>
Mon, 26 Mar 2012 23:08:05 +0000 (16:08 -0700)
committerSage Weil <sage@newdream.net>
Tue, 27 Mar 2012 17:41:15 +0000 (10:41 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/.gitignore
src/Makefile.am
src/test/bench_log.cc [new file with mode: 0644]

index 83c31f5242badb60724b0afd789f20278caa7554..313725a42a63cf44c2620a968650b4cb95b2ad1f 100644 (file)
@@ -25,6 +25,7 @@
 /rbdtool
 /rgw_multiparser
 /streamtest
+/bench_log
 /test_ioctls
 /test_trans
 /testceph
index 86e124cc22060dd018a65249e8221d6d77ff6402..b77c867ae5b7b7ffa42495ecb1e1bea7d067d442 100644 (file)
@@ -460,6 +460,11 @@ testrados_watch_notify_SOURCES = \
 testrados_watch_notify_LDADD = libsystest.la librados.la
 bin_DEBUGPROGRAMS += testrados_watch_notify
 
+bench_log_SOURCES = \
+       test/bench_log.cc
+bench_log_LDADD = libcommon.la libglobal.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS)
+bin_DEBUGPROGRAMS += bench_log
+
 ## unit tests
 
 # target to build but not run the unit tests
diff --git a/src/test/bench_log.cc b/src/test/bench_log.cc
new file mode 100644 (file)
index 0000000..c6e931f
--- /dev/null
@@ -0,0 +1,67 @@
+// -*- 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"
+
+struct T : public Thread {
+  int num;
+  set<int> myset;
+  map<int,string> mymap;
+  T(int n) : num(n) {
+    myset.insert(123);
+    myset.insert(456);
+    mymap[1] = "foo";
+    mymap[10] = "bar";
+  }
+
+  void *entry() {
+    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);
+  env_to_vec(args);
+
+  global_init(NULL, args, CEPH_ENTITY_TYPE_OSD, CODE_ENVIRONMENT_UTILITY, 0);
+
+  utime_t start = ceph_clock_now(NULL);
+
+  list<T*> ls;
+  for (int i=0; i<threads; i++) {
+    T *t = new T(num);
+    t->create();
+    ls.push_back(t);
+  }
+
+  for (int i=0; i<threads; i++) {
+    T *t = ls.front();
+    ls.pop_front();
+    t->join();
+    delete t;    
+  }
+
+  g_ceph_context->_log->flush();
+
+  utime_t end = ceph_clock_now(NULL);
+  utime_t dur = end - start;
+
+  cout << dur << std::endl;
+  return 0;
+}