Skip to content

Commit bd44078

Browse files
committed
DumpMempool: Use std::chrono instead of weird int64_t arthmetics
This makes it so that DumpMempool doesn't depend on MICRO anymore
1 parent c84390b commit bd44078

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/util/time.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct NodeClock : public std::chrono::system_clock {
2424
};
2525
using NodeSeconds = std::chrono::time_point<NodeClock, std::chrono::seconds>;
2626

27+
using SteadyClock = std::chrono::steady_clock;
2728
using SteadySeconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::seconds>;
2829
using SteadyMilliseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::milliseconds>;
2930
using SteadyMicroseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::microseconds>;

src/validation.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@
4747
#include <util/rbf.h>
4848
#include <util/strencodings.h>
4949
#include <util/system.h>
50+
#include <util/time.h>
5051
#include <util/trace.h>
5152
#include <util/translation.h>
5253
#include <validationinterface.h>
5354
#include <warnings.h>
5455

5556
#include <algorithm>
57+
#include <chrono>
5658
#include <deque>
5759
#include <numeric>
5860
#include <optional>
@@ -4726,7 +4728,7 @@ bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mocka
47264728

47274729
bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool skip_file_commit)
47284730
{
4729-
int64_t start = GetTimeMicros();
4731+
auto start = SteadyClock::now();
47304732

47314733
std::map<uint256, CAmount> mapDeltas;
47324734
std::vector<TxMempoolInfo> vinfo;
@@ -4744,7 +4746,7 @@ bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool s
47444746
unbroadcast_txids = pool.GetUnbroadcastTxs();
47454747
}
47464748

4747-
int64_t mid = GetTimeMicros();
4749+
auto mid = SteadyClock::now();
47484750

47494751
try {
47504752
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
47764778
if (!RenameOver(gArgs.GetDataDirNet() / "mempool.dat.new", gArgs.GetDataDirNet() / "mempool.dat")) {
47774779
throw std::runtime_error("Rename failed");
47784780
}
4779-
int64_t last = GetTimeMicros();
4780-
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO);
4781+
auto last = SteadyClock::now();
4782+
4783+
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n",
4784+
Ticks<SecondsDouble>(mid - start),
4785+
Ticks<SecondsDouble>(last - mid));
47814786
} catch (const std::exception& e) {
47824787
LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what());
47834788
return false;

0 commit comments

Comments
 (0)