From aea6b963f3e2b686c2f3f1320e46eba035c022d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 13 Jul 2023 17:31:44 +0200 Subject: [PATCH] Improve `rate_observer` output --- nano/test_common/rate_observer.cpp | 22 +++++++++++++++++----- nano/test_common/rate_observer.hpp | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/nano/test_common/rate_observer.cpp b/nano/test_common/rate_observer.cpp index 37f8a60f78..933b5a2e24 100644 --- a/nano/test_common/rate_observer.cpp +++ b/nano/test_common/rate_observer.cpp @@ -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 observe) @@ -86,7 +99,6 @@ void nano::test::rate_observer::observe (std::string name, std::function