Simplify process_loop log timing by using nano::timer (#2229)

This commit is contained in:
cryptocode 2019-08-23 18:47:50 +02:00 committed by GitHub
commit f8c637fc8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
#include <nano/lib/timer.hpp>
#include <nano/node/node.hpp>
#include <nano/node/vote_processor.hpp>
@ -20,10 +21,7 @@ thread ([this]() {
void nano::vote_processor::process_loop ()
{
std::chrono::steady_clock::time_point start_time, end_time;
std::chrono::steady_clock::duration elapsed_time;
std::chrono::milliseconds elapsed_time_ms;
uint64_t elapsed_time_ms_int;
nano::timer<std::chrono::milliseconds> elapsed;
bool log_this_iteration;
std::unique_lock<std::mutex> lock (mutex);
@ -48,7 +46,7 @@ void nano::vote_processor::process_loop ()
* there are a sufficient number of items for it to be relevant
*/
log_this_iteration = true;
start_time = std::chrono::steady_clock::now ();
elapsed.start ();
}
active = true;
lock.unlock ();
@ -77,22 +75,9 @@ void nano::vote_processor::process_loop ()
condition.notify_all ();
lock.lock ();
if (log_this_iteration)
if (log_this_iteration && elapsed.stop () > std::chrono::milliseconds (100))
{
end_time = std::chrono::steady_clock::now ();
elapsed_time = end_time - start_time;
elapsed_time_ms = std::chrono::duration_cast<std::chrono::milliseconds> (elapsed_time);
elapsed_time_ms_int = elapsed_time_ms.count ();
if (elapsed_time_ms_int >= 100)
{
/*
* If the time spent was less than 100ms then
* the results are probably not useful as well,
* so don't spam the logs.
*/
node.logger.try_log (boost::str (boost::format ("Processed %1% votes in %2% milliseconds (rate of %3% votes per second)") % votes_l.size () % elapsed_time_ms_int % ((votes_l.size () * 1000ULL) / elapsed_time_ms_int)));
}
node.logger.try_log (boost::str (boost::format ("Processed %1% votes in %2% milliseconds (rate of %3% votes per second)") % votes_l.size () % elapsed.value ().count () % ((votes_l.size () * 1000ULL) / elapsed.value ().count ())));
}
}
else