mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
log, timer: add timing macro in usec LOG_TIME_MICROS_WITH_CATEGORY
and update BCLog::LogMsg() to omit irrelevant decimals for microseconds and skip unneeded code and math.
This commit is contained in:
@@ -58,12 +58,14 @@ public:
|
|||||||
return strprintf("%s: %s", m_prefix, msg);
|
return strprintf("%s: %s", m_prefix, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string units = "";
|
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;
|
float divisor = 1;
|
||||||
|
|
||||||
if (std::is_same<TimeType, std::chrono::microseconds>::value) {
|
if (std::is_same<TimeType, std::chrono::milliseconds>::value) {
|
||||||
units = "μs";
|
|
||||||
} else if (std::is_same<TimeType, std::chrono::milliseconds>::value) {
|
|
||||||
units = "ms";
|
units = "ms";
|
||||||
divisor = 1000.;
|
divisor = 1000.;
|
||||||
} else if (std::is_same<TimeType, std::chrono::seconds>::value) {
|
} else if (std::is_same<TimeType, std::chrono::seconds>::value) {
|
||||||
@@ -93,6 +95,8 @@ private:
|
|||||||
} // namespace BCLog
|
} // namespace BCLog
|
||||||
|
|
||||||
|
|
||||||
|
#define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \
|
||||||
|
BCLog::Timer<std::chrono::microseconds> PASTE2(logging_timer, __COUNTER__)(__func__, end_msg, log_category)
|
||||||
#define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \
|
#define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \
|
||||||
BCLog::Timer<std::chrono::milliseconds> PASTE2(logging_timer, __COUNTER__)(__func__, end_msg, log_category)
|
BCLog::Timer<std::chrono::milliseconds> PASTE2(logging_timer, __COUNTER__)(__func__, end_msg, log_category)
|
||||||
#define LOG_TIME_SECONDS(end_msg) \
|
#define LOG_TIME_SECONDS(end_msg) \
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(logging_timer)
|
|||||||
SetMockTime(1);
|
SetMockTime(1);
|
||||||
auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
|
auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
|
||||||
SetMockTime(2);
|
SetMockTime(2);
|
||||||
BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000.00μs)");
|
BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000μs)");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
Reference in New Issue
Block a user