From fefd993989e00525c0ebee7e556ee883bb3a4d5f Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 8 Feb 2022 13:24:23 +0000 Subject: [PATCH] The uint32_t key is an implementation detail of the stat class. This adds an overload and externally exposes detail_to_string with a stat::detail parameter and hides the uint32_t key overload. (#3717) --- nano/lib/stats.cpp | 9 +++++++-- nano/lib/stats.hpp | 3 ++- nano/node/transport/transport.cpp | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nano/lib/stats.cpp b/nano/lib/stats.cpp index bb04ea36..4c04cad5 100644 --- a/nano/lib/stats.cpp +++ b/nano/lib/stats.cpp @@ -538,9 +538,8 @@ std::string nano::stat::type_to_string (uint32_t key) return res; } -std::string nano::stat::detail_to_string (uint32_t key) +std::string nano::stat::detail_to_string (stat::detail detail) { - auto detail = static_cast (key >> 8 & 0x000000ff); std::string res; switch (detail) { @@ -893,6 +892,12 @@ std::string nano::stat::detail_to_string (uint32_t key) return res; } +std::string nano::stat::detail_to_string (uint32_t key) +{ + auto detail = static_cast (key >> 8 & 0x000000ff); + return detail_to_string (detail); +} + std::string nano::stat::dir_to_string (uint32_t key) { auto dir = static_cast (key & 0x000000ff); diff --git a/nano/lib/stats.hpp b/nano/lib/stats.hpp index 4adeb964..ca04d8c9 100644 --- a/nano/lib/stats.hpp +++ b/nano/lib/stats.hpp @@ -583,7 +583,7 @@ public: std::unique_ptr log_sink_json () const; /** Returns string representation of detail */ - static std::string detail_to_string (uint32_t key); + static std::string detail_to_string (stat::detail detail); /** Stop stats being output */ void stop (); @@ -591,6 +591,7 @@ public: private: static std::string type_to_string (uint32_t key); static std::string dir_to_string (uint32_t key); + static std::string detail_to_string (uint32_t key); /** Constructs a key given type, detail and direction. This is used as input to update(...) and get_entry(...) */ uint32_t key_of (stat::type type, stat::detail detail, stat::dir dir) const diff --git a/nano/node/transport/transport.cpp b/nano/node/transport/transport.cpp index d4f09b66..1ca425db 100644 --- a/nano/node/transport/transport.cpp +++ b/nano/node/transport/transport.cpp @@ -128,8 +128,7 @@ void nano::transport::channel::send (nano::message & message_a, std::function (detail) << 8; - node.logger.always_log (boost::str (boost::format ("%1% of size %2% dropped") % node.stats.detail_to_string (key) % buffer.size ())); + node.logger.always_log (boost::str (boost::format ("%1% of size %2% dropped") % node.stats.detail_to_string (detail) % buffer.size ())); } } }