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");
51 void Log(
const std::string& msg)
53 const std::string full_msg = this->
LogMsg(msg);
62 std::string
LogMsg(
const std::string& 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_v<TimeType, std::chrono::microseconds>) {
72 }
else if constexpr (std::is_same_v<TimeType, std::chrono::milliseconds>) {
74 }
else if constexpr (std::is_same_v<TimeType, std::chrono::seconds>) {
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)
Timer(std::string prefix, std::string end_msg, BCLog::LogFlags log_category=BCLog::LogFlags::ALL, bool msg_on_completion=true)
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
#define LogDebug(category,...)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
constexpr bool ALWAYS_FALSE