6#ifndef BITCOIN_LOGGING_TIMER_H
7#define BITCOIN_LOGGING_TIMER_H
22template <
typename TimeType>
32 bool msg_on_completion =
true)
39 m_start_t = std::chrono::steady_clock::now();
47 this->
Log(
"completed");
53 const std::string full_msg = this->
LogMsg(msg);
64 const auto end_time{std::chrono::steady_clock::now()};
68 const auto duration{end_time - *
m_start_t};
70 if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) {
72 }
else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) {
74 }
else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) {
77 static_assert(ALWAYS_FALSE<TimeType>,
"Error: unexpected time type");
82 std::optional<std::chrono::steady_clock::time_point>
m_start_t{};
101#define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \
102 BCLog::Timer<std::chrono::microseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
103#define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \
104 BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
105#define LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(end_msg, log_category) \
106 BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, false)
107#define LOG_TIME_SECONDS(end_msg) \
108 BCLog::Timer<std::chrono::seconds> UNIQUE_NAME(logging_timer)(__func__, end_msg)
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::optional< std::chrono::steady_clock::time_point > m_start_t
void Log(const std::string &msg)
const BCLog::LogFlags m_log_category
Forwarded on to LogDebug if specified - has the effect of only outputting the timing log when a parti...
#define LogDebug(category,...)