aboutsummaryrefslogtreecommitdiff
path: root/src/logging
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-09-06 21:01:57 +0200
committerJon Atack <jon@atack.com>2021-09-07 00:37:39 +0200
commit498b323425d960274c40472a6a847afc1982201d (patch)
treeda299b7dd1a8d58f8ad248f72e3d2a45db18c3f5 /src/logging
parent8d2f847ed913f15677ae978a412015ac844ffceb (diff)
downloadbitcoin-498b323425d960274c40472a6a847afc1982201d.tar.xz
log, timer: improve BCLog::LogMsg()
- make timer code more homogeneous - replace division with multiplication - log if the time type is unexpected
Diffstat (limited to 'src/logging')
-rw-r--r--src/logging/timer.h18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/logging/timer.h b/src/logging/timer.h
index 647e3fa30e..6d584084ca 100644
--- a/src/logging/timer.h
+++ b/src/logging/timer.h
@@ -60,21 +60,13 @@ public:
if (std::is_same<TimeType, std::chrono::microseconds>::value) {
return strprintf("%s: %s (%iμs)", m_prefix, msg, end_time.count());
- }
-
- std::string units;
- float divisor = 1;
-
- if (std::is_same<TimeType, std::chrono::milliseconds>::value) {
- units = "ms";
- divisor = 1000.;
+ } else if (std::is_same<TimeType, std::chrono::milliseconds>::value) {
+ return strprintf("%s: %s (%.2fms)", m_prefix, msg, end_time.count() * 0.001);
} else if (std::is_same<TimeType, std::chrono::seconds>::value) {
- units = "s";
- divisor = 1000. * 1000.;
+ return strprintf("%s: %s (%.2fs)", m_prefix, msg, end_time.count() * 0.000001);
+ } else {
+ return "Error: unexpected time type";
}
-
- const float time_ms = end_time.count() / divisor;
- return strprintf("%s: %s (%.2f%s)", m_prefix, msg, time_ms, units);
}
private: