From ffd4de74e53319f11b12e5b4382f4fedca13fa8c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 20 Jan 2019 00:48:40 +0800 Subject: [PATCH] tool/ceph_kvstore_tool: extract duration calc out simplify the code a little bit Signed-off-by: Kefu Chai --- src/tools/kvstore_tool.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tools/kvstore_tool.cc b/src/tools/kvstore_tool.cc index ee2b3d7864a34..7a65ff96baee4 100644 --- a/src/tools/kvstore_tool.cc +++ b/src/tools/kvstore_tool.cc @@ -204,7 +204,11 @@ int StoreTool::copy_store_to(const string& type, const string& other_path, uint64_t total_size = 0; uint64_t total_txs = 0; - auto started_at = coarse_mono_clock::now(); + auto duration = [start=coarse_mono_clock::now()] { + const auto now = coarse_mono_clock::now(); + auto seconds = std::chrono::duration(now - start); + return seconds.count(); + }; do { int num_keys = 0; @@ -228,23 +232,19 @@ int StoreTool::copy_store_to(const string& type, const string& other_path, if (num_keys > 0) other->submit_transaction_sync(tx); - auto cur_duration = std::chrono::duration(coarse_mono_clock::now() - - started_at); - std::cout << "ts = " << cur_duration.count() << "s, copied " << total_keys + std::cout << "ts = " << duration() << "s, copied " << total_keys << " keys so far (" << byte_u_t(total_size) << ")" << std::endl; } while (it->valid()); - auto time_taken = std::chrono::duration(coarse_mono_clock::now() - started_at); - std::cout << "summary:" << std::endl; std::cout << " copied " << total_keys << " keys" << std::endl; std::cout << " used " << total_txs << " transactions" << std::endl; std::cout << " total size " << byte_u_t(total_size) << std::endl; std::cout << " from '" << store_path << "' to '" << other_path << "'" << std::endl; - std::cout << " duration " << time_taken.count() << " seconds" << std::endl; + std::cout << " duration " << duration() << " seconds" << std::endl; return 0; } -- 2.39.5