Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier rate_observer output #4257

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading