From 889abad3baf7f56128a66550911b27935f4b00ef Mon Sep 17 00:00:00 2001 From: Mohamad Gebai Date: Thu, 30 Nov 2017 13:36:46 -0500 Subject: [PATCH] tools/rbd: use steady clock in bencher Signed-off-by: Mohamad Gebai --- src/tools/rbd/action/Bench.cc | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/tools/rbd/action/Bench.cc b/src/tools/rbd/action/Bench.cc index b6592bfda73..b5c79fd83d5 100644 --- a/src/tools/rbd/action/Bench.cc +++ b/src/tools/rbd/action/Bench.cc @@ -14,6 +14,8 @@ #include #include +using namespace std::chrono; + namespace rbd { namespace action { namespace bench { @@ -228,8 +230,8 @@ int do_bench(librbd::Image& image, io_type_t io_type, srand(time(NULL) % (unsigned long) -1); - utime_t start = ceph_clock_now(); - utime_t last; + coarse_mono_time start = coarse_mono_clock::now(); + chrono::duration last = chrono::duration::zero(); unsigned ios = 0; vector thread_offset; @@ -301,12 +303,12 @@ int do_bench(librbd::Image& image, io_type_t io_type, write_ops++; } - utime_t now = ceph_clock_now(); - utime_t elapsed = now - start; - if (last.is_zero()) { + coarse_mono_time now = coarse_mono_clock::now(); + chrono::duration elapsed = now - start; + if (last == chrono::duration::zero()) { last = elapsed; - } else if (elapsed.sec() != last.sec()) { - time_acc(elapsed - last); + } else if ((int)elapsed.count() != (int)last.count()) { + time_acc((elapsed - last).count()); ios_acc(static_cast(cur_ios)); off_acc(static_cast(cur_off)); cur_ios = 0; @@ -314,7 +316,7 @@ int do_bench(librbd::Image& image, io_type_t io_type, double time_sum = boost::accumulators::rolling_sum(time_acc); printf("%5d %8d %8.2lf %8.2lf\n", - (int)elapsed, + (int)elapsed.count(), (int)(ios - io_threads), boost::accumulators::rolling_sum(ios_acc) / time_sum, boost::accumulators::rolling_sum(off_acc) / time_sum); @@ -331,18 +333,21 @@ int do_bench(librbd::Image& image, io_type_t io_type, } } - utime_t now = ceph_clock_now(); - double elapsed = now - start; + coarse_mono_time now = coarse_mono_clock::now(); + chrono::duration elapsed = now - start; printf("elapsed: %5d ops: %8d ops/sec: %8.2lf bytes/sec: %8.2lf\n", - (int)elapsed, ios, (double)ios / elapsed, (double)off / elapsed); + (int)elapsed.count(), ios, (double)ios / elapsed.count(), + (double)off / elapsed.count()); if (io_type == IO_TYPE_RW) { printf("read_ops: %5d read_ops/sec: %8.2lf read_bytes/sec: %8.2lf\n", - read_ops, (double)read_ops / elapsed, (double)read_ops * io_size / elapsed); + read_ops, (double)read_ops / elapsed.count(), + (double)read_ops * io_size / elapsed.count()); printf("write_ops: %5d write_ops/sec: %8.2lf write_bytes/sec: %8.2lf\n", - write_ops, (double)write_ops / elapsed, (double)write_ops * io_size / elapsed); + write_ops, (double)write_ops / elapsed.count(), + (double)write_ops * io_size / elapsed.count()); } return 0;