6 #ifndef BITCOIN_LOGGING_TIMER_H 7 #define BITCOIN_LOGGING_TIMER_H 21 template <
typename TimeType>
31 bool msg_on_completion =
true) :
38 m_start_t = GetTime<std::chrono::microseconds>();
46 this->
Log(
"completed");
50 void Log(
const std::string& msg)
52 const std::string full_msg = this->
LogMsg(msg);
61 std::string
LogMsg(
const std::string& msg)
63 const auto end_time = GetTime<std::chrono::microseconds>() -
m_start_t;
68 if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) {
70 }
else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) {
72 }
else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) {
75 static_assert(ALWAYS_FALSE<TimeType>,
"Error: unexpected time type");
99 #define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \ 100 BCLog::Timer<std::chrono::microseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) 101 #define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \ 102 BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) 103 #define LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(end_msg, log_category) \ 104 BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, false) 105 #define LOG_TIME_SECONDS(end_msg) \ 106 BCLog::Timer<std::chrono::seconds> UNIQUE_NAME(logging_timer)(__func__, end_msg) 109 #endif // BITCOIN_LOGGING_TIMER_H
#define LogPrint(category,...)
RAII-style object that outputs timing information to logs.
const std::string m_title
A descriptive message of what is being timed.
std::string LogMsg(const std::string &msg)
const bool m_message_on_completion
Whether to output the message again on completion.
void Log(const std::string &msg)
const BCLog::LogFlags m_log_category
Forwarded on to LogPrint if specified - has the effect of only outputting the timing log when a parti...
std::chrono::microseconds m_start_t
const std::string m_prefix
Log prefix; usually the name of the function this was created in.
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...