17 report_set(false), report_set_public(false),
18 first_frame(true), fr(0), fr_avg(0), fr_count_a(0),
19 time_stamp(chc::high_resolution_clock::now()), unit(
"kHz"),
20 unit_bar(
"#"), unit_space(
"-")
22 this->fr_total = fr_total;
25 this->report_interval = report_interval;
28 int ProgressMonitor::GetBarLength()
35 void ProgressMonitor::ClearBarField()
41 *out <<
"\r" << std::flush;
48 auto mil_secs = chc::duration_cast<float_ms>(chc::high_resolution_clock::now() - time_stamp).count();
49 if (mil_secs > report_interval ||
fr_count >= fr_total)
55 Report(
fr_count, fr_avg / fr_count_a);
66 time_stamp = chc::high_resolution_clock::now();
69 void ProgressMonitor::Report(
unsigned long idx,
float print_val)
82 int bar_size = GetBarLength();
91 for (
int bar_length = 0; bar_length <= bar_size - 1; ++bar_length)
93 if (bar_length * percent_per_unit_bar < progress_percent)
103 *out << std::setprecision(2) << std::fixed << print_val << std::fixed <<
" " << unit << std::flush;
107 *out <<
" " << std::endl
111 catch (
unsigned long e)
114 std::cerr <<
"EXCEPTION: frame index (" << e <<
") went out of bounds (fr_total = " << fr_total <<
")." << std::endl
#define CHARACTER_WIDTH_PERCENTAGE
std::atomic< bool > report_set
std::atomic< size_t > fr_count_i
ProgressMonitor(size_t fr_total, bool b_bar=true, float report_interval=250.0, std::ostream &out=std::cerr)
ProgressMonitor & operator++()
std::atomic< size_t > fr_count
std::atomic< bool > report_set_public