Skip to content

Commit

Permalink
Improve rate_observer output (#4257)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jul 29, 2023
1 parent 0684051 commit da9cf6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions nano/test_common/rate_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion nano/test_common/rate_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class rate_observer
/*
* 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);
Expand Down

0 comments on commit da9cf6a

Please sign in to comment.