mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-13 11:25:02 -05:00
DumpMempool: Use std::chrono instead of weird int64_t arthmetics
This makes it so that DumpMempool doesn't depend on MICRO anymore
This commit is contained in:
parent
c84390b741
commit
bd4407817e
2 changed files with 10 additions and 4 deletions
|
@ -24,6 +24,7 @@ struct NodeClock : public std::chrono::system_clock {
|
||||||
};
|
};
|
||||||
using NodeSeconds = std::chrono::time_point<NodeClock, std::chrono::seconds>;
|
using NodeSeconds = std::chrono::time_point<NodeClock, std::chrono::seconds>;
|
||||||
|
|
||||||
|
using SteadyClock = std::chrono::steady_clock;
|
||||||
using SteadySeconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::seconds>;
|
using SteadySeconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::seconds>;
|
||||||
using SteadyMilliseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::milliseconds>;
|
using SteadyMilliseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::milliseconds>;
|
||||||
using SteadyMicroseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::microseconds>;
|
using SteadyMicroseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::microseconds>;
|
||||||
|
|
|
@ -47,12 +47,14 @@
|
||||||
#include <util/rbf.h>
|
#include <util/rbf.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
#include <util/time.h>
|
||||||
#include <util/trace.h>
|
#include <util/trace.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#include <warnings.h>
|
#include <warnings.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -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)
|
bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool skip_file_commit)
|
||||||
{
|
{
|
||||||
int64_t start = GetTimeMicros();
|
auto start = SteadyClock::now();
|
||||||
|
|
||||||
std::map<uint256, CAmount> mapDeltas;
|
std::map<uint256, CAmount> mapDeltas;
|
||||||
std::vector<TxMempoolInfo> vinfo;
|
std::vector<TxMempoolInfo> vinfo;
|
||||||
|
@ -4744,7 +4746,7 @@ bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool s
|
||||||
unbroadcast_txids = pool.GetUnbroadcastTxs();
|
unbroadcast_txids = pool.GetUnbroadcastTxs();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t mid = GetTimeMicros();
|
auto mid = SteadyClock::now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat.new", "wb")};
|
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")) {
|
if (!RenameOver(gArgs.GetDataDirNet() / "mempool.dat.new", gArgs.GetDataDirNet() / "mempool.dat")) {
|
||||||
throw std::runtime_error("Rename failed");
|
throw std::runtime_error("Rename failed");
|
||||||
}
|
}
|
||||||
int64_t last = GetTimeMicros();
|
auto last = SteadyClock::now();
|
||||||
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO);
|
|
||||||
|
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n",
|
||||||
|
Ticks<SecondsDouble>(mid - start),
|
||||||
|
Ticks<SecondsDouble>(last - mid));
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what());
|
LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what());
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue