Add to_string function to nano::stats class for convenience (#4092)

It is useful to be able to print the stats easily from inside a debugging
session.
This commit is contained in:
Dimitrios Siganos 2023-01-31 14:58:37 +00:00 committed by GitHub
commit 16e5ccf209
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -456,6 +456,25 @@ void nano::stats::stop ()
stopped = true;
}
std::string nano::stats::to_string (std::string type)
{
auto sink = log_sink_json ();
if (type == "counters")
{
log_counters (*sink);
return sink->to_string ();
}
else if (type == "samples")
{
log_samples (*sink);
return sink->to_string ();
}
else
{
return "type not supported: " + type;
}
}
void nano::stats::clear ()
{
nano::unique_lock<nano::mutex> lock{ stat_mutex };

View file

@ -397,6 +397,9 @@ public:
/** Stop stats being output */
void stop ();
/** Return string showing stats counters (convenience function for debugging) */
std::string to_string (std::string type = "counters");
private:
static std::string type_to_string (uint32_t key);
static std::string dir_to_string (uint32_t key);