6#ifndef BITCOIN_LOGGING_TIMER_H
7#define BITCOIN_LOGGING_TIMER_H
20template <
typename TimeType>
class Timer {
38 this->
Log(
"completed");
42 void Log(
const std::string &msg) {
52 std::string
LogMsg(
const std::string &msg) {
59 std::chrono::microseconds>::value) {
61 }
else if constexpr (std::is_same<
TimeType,
62 std::chrono::milliseconds>::value) {
65 }
else if constexpr (std::is_same<
TimeType,
66 std::chrono::seconds>::value) {
71 "Error: unexpected time type");
94#define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \
95 BCLog::Timer<std::chrono::microseconds> UNIQUE_LOG_NAME(logging_timer)( \
96 __func__, end_msg, log_category)
97#define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \
98 BCLog::Timer<std::chrono::milliseconds> UNIQUE_LOG_NAME(logging_timer)( \
99 __func__, end_msg, log_category)
100#define LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(end_msg, log_category) \
101 BCLog::Timer<std::chrono::milliseconds> UNIQUE_LOG_NAME(logging_timer)( \
102 __func__, end_msg, log_category, false)
103#define LOG_TIME_SECONDS(end_msg) \
104 BCLog::Timer<std::chrono::seconds> UNIQUE_LOG_NAME(logging_timer)( \
RAII-style object that outputs timing information to logs.
Timer(std::string prefix, std::string end_msg, BCLog::LogFlags log_category=BCLog::LogFlags::ALL, bool msg_on_completion=true)
If log_category is left as the default, end_msg will log unconditionally (instead of being filtered b...
const bool m_message_on_completion
Whether to output the message again on completion.
std::string LogMsg(const std::string &msg)
const std::string m_prefix
Log prefix; usually the name of the function this was created in.
const std::string m_title
A descriptive message of what is being timed.
std::chrono::microseconds m_start_t
void Log(const std::string &msg)
const BCLog::LogFlags m_log_category
Forwarded on to LogPrint if specified - has the effect of only outputing the timing log when a partic...
#define LogPrint(category,...)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...