Improve rate_observer output (#4257)

This commit is contained in:
Piotr Wójcik 2023-07-29 13:27:07 +02:00 committed by GitHub
commit da9cf6ac00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View file

@ -64,17 +64,30 @@ void nano::test::rate_observer::background_print_impl (std::chrono::seconds inte
void nano::test::rate_observer::print_once ()
{
std::stringstream ss;
ss << "-----------------------------------------------------------------------------------------------------------------------"
<< "\n";
for (auto & counter : counters)
{
const auto observation = counter->observe ();
// Convert delta milliseconds to seconds (double precision) and then divide the counter delta to get rate per second
auto per_sec = observation.delta / (observation.time_delta.count () / 1000.0);
auto prettier_name = "'" + counter->name + "'";
std::cout << "rate of '" << counter->name << "': "
<< std::setw (12) << std::setprecision (2) << std::fixed << per_sec << " /s"
<< std::endl;
ss << "counter: " << std::setw (50) << std::left << prettier_name
<< " | "
<< "total: " << std::setw (14) << observation.total
<< " | "
<< "rate /s: " << std::setw (12) << std::setprecision (2) << std::fixed << per_sec
<< "\n";
}
ss << "-----------------------------------------------------------------------------------------------------------------------"
<< "\n";
std::cout << ss.str () << std::endl;
}
void nano::test::rate_observer::observe (std::string name, std::function<int64_t ()> observe)
@ -86,7 +99,6 @@ void nano::test::rate_observer::observe (std::string name, std::function<int64_t
void nano::test::rate_observer::observe (nano::node & node, nano::stat::type type, nano::stat::detail detail, nano::stat::dir dir)
{
auto name = std::string{ nano::to_string (type) } + "::" + std::string{ nano::to_string (detail) } + "::" + std::string{ nano::to_string (dir) };
observe (name, [&node, type, detail, dir] () {
return node.stats.count (type, detail, dir);
});

View file

@ -58,7 +58,7 @@ public:
/*
* Starts observing a particular node stat from stat container
*/
void observe (nano::node &, nano::stat::type type, nano::stat::detail detail, nano::stat::dir dir);
void observe (nano::node &, nano::stat::type type, nano::stat::detail detail, nano::stat::dir dir = nano::stat::dir::in);
private:
void background_print_impl (std::chrono::seconds interval);