]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tool/ceph_kvstore_tool: extract duration calc out 26041/head
authorKefu Chai <kchai@redhat.com>
Sat, 19 Jan 2019 16:48:40 +0000 (00:48 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 19 Jan 2019 16:49:14 +0000 (00:49 +0800)
simplify the code a little bit

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/tools/kvstore_tool.cc

index ee2b3d7864a3451966d6347cc972fec3dfa5502c..7a65ff96baee43c964ed921ce56755a8e7136576 100644 (file)
@@ -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<double>(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<double>(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<double>(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;
 }