Skip to content

Commit

Permalink
Templatize log span on duration type.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 26, 2024
1 parent 259a278 commit 5202e74
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 8 additions & 2 deletions include/bitcoin/network/log/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define LIBBITCOIN_NETWORK_LOG_LOGGER_HPP

#include <atomic>
#include <chrono>
#include <ostream>
#include <sstream>
#include <utility>
Expand Down Expand Up @@ -103,8 +104,13 @@ class BCT_API logger final
/// Fire event with optional value, recorded with current time.
void fire(uint8_t event_, uint64_t value=zero) const NOEXCEPT;

/// Fire event with nanosecond duration value, recorded with current time.
void span(uint8_t event_, const time& started) const NOEXCEPT;
/// Fire event with value as duration start to now, in specified unints.
template <typename Time = milliseconds>
inline void span(uint8_t event_, const time& start) const NOEXCEPT
{
// value parameter is time span in Time units.
fire(event_, std::chrono::duration_cast<Time>(now() - start).count());
}

/// If stopped, handler is invoked with error::subscriber_stopped/defaults
/// and dropped. Otherwise it is held until stop/drop. False if failed.
Expand Down
7 changes: 6 additions & 1 deletion include/bitcoin/network/log/reporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ class BCT_API reporter

public:
void fire(uint8_t event, size_t count=zero) const NOEXCEPT;
void span(uint8_t event, const logger::time& started) const NOEXCEPT;

template <typename Time = milliseconds>
void span(uint8_t event, const logger::time& started) const NOEXCEPT
{
log.span<Time>(event, started);
}

// This is thread safe.
const logger& log;
Expand Down
6 changes: 0 additions & 6 deletions src/log/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ void logger::do_subscribe_messages(const message_notifier& handler) NOEXCEPT
// events
// ----------------------------------------------------------------------------

void logger::span(uint8_t event_, const time& started) const NOEXCEPT
{
// value parameter is time span in nanoseconds.
fire(event_, (now() - started).count());
}

void logger::fire(uint8_t event_, uint64_t value) const NOEXCEPT
{
boost::asio::post(strand_,
Expand Down
5 changes: 0 additions & 5 deletions src/log/reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ void reporter::fire(uint8_t event, size_t count) const NOEXCEPT
log.fire(event, count);
}

void reporter::span(uint8_t event, const logger::time& started) const NOEXCEPT
{
log.span(event, started);
}

} // namespace network
} // namespace libbitcoin

0 comments on commit 5202e74

Please sign in to comment.