From bd4407817e523e3c5b347bc6be25ed007cb27034 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 16 May 2022 14:09:48 -0400 Subject: [PATCH] DumpMempool: Use std::chrono instead of weird int64_t arthmetics This makes it so that DumpMempool doesn't depend on MICRO anymore --- src/util/time.h | 1 + src/validation.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/util/time.h b/src/util/time.h index 9df69a953c..fc49f23ce3 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -24,6 +24,7 @@ struct NodeClock : public std::chrono::system_clock { }; using NodeSeconds = std::chrono::time_point; +using SteadyClock = std::chrono::steady_clock; using SteadySeconds = std::chrono::time_point; using SteadyMilliseconds = std::chrono::time_point; using SteadyMicroseconds = std::chrono::time_point; diff --git a/src/validation.cpp b/src/validation.cpp index 4c694a2c21..48535d32a9 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -47,12 +47,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -4726,7 +4728,7 @@ bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mocka bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool skip_file_commit) { - int64_t start = GetTimeMicros(); + auto start = SteadyClock::now(); std::map mapDeltas; std::vector vinfo; @@ -4744,7 +4746,7 @@ bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool s unbroadcast_txids = pool.GetUnbroadcastTxs(); } - int64_t mid = GetTimeMicros(); + auto mid = SteadyClock::now(); try { FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat.new", "wb")}; @@ -4776,8 +4778,11 @@ bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool s if (!RenameOver(gArgs.GetDataDirNet() / "mempool.dat.new", gArgs.GetDataDirNet() / "mempool.dat")) { throw std::runtime_error("Rename failed"); } - int64_t last = GetTimeMicros(); - LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO); + auto last = SteadyClock::now(); + + LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", + Ticks(mid - start), + Ticks(last - mid)); } catch (const std::exception& e) { LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what()); return false;