SourceXtractorPlusPlus  0.13
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProgressLogger.cpp
Go to the documentation of this file.
1 
17 #include <iomanip>
18 #include "SEMain/ProgressLogger.h"
19 
20 namespace SourceXtractor {
21 
22 ProgressLogger::ProgressLogger(const std::chrono::steady_clock::duration& min_interval) :
23  m_logger{Elements::Logging::getLogger("Progress")}, m_min_interval{min_interval},
24  m_started{std::chrono::steady_clock::now()},
25  m_last_logged{m_started - m_min_interval}, m_done{false} {
26 }
27 
29  auto now = std::chrono::steady_clock::now();
30 
31  if (now - m_last_logged > m_min_interval || m_done) {
32  auto elapsed = now - m_started;
33  m_last_logged = now;
34 
35  for (auto entry : m_progress_info) {
36  // When there is no total, log an absolute count
37  if (entry.m_total <= 0) {
38  m_logger.info() << entry.m_label << ": " << entry.m_done;
39  }
40  // Otherwise, report progress
41  else {
42  float percent = (entry.m_done * 100.) / entry.m_total;
43  m_logger.info() << entry.m_label << ": " << entry.m_done << " / " << entry.m_total
44  << " (" << std::fixed << std::setprecision(2) << percent << "%)";
45  }
46  }
47 
50  auto s = std::chrono::duration_cast<std::chrono::seconds>(elapsed - h - m);
51  m_logger.info() << "Elapsed: " << std::setfill('0')
52  << std::setw(2) << h.count() << ':'
53  << std::setw(2) << m.count() << ':'
54  << std::setw(2) << s.count();
55  }
56 }
57 
59  m_progress_info = info;
60  print();
61 }
62 
63 void ProgressLogger::handleMessage(const bool& done) {
64  m_done = done;
65  print();
66 }
67 
68 } // end SourceXtractor
ProgressLogger(const std::chrono::steady_clock::duration &min_interval)
std::chrono::steady_clock::time_point m_last_logged
constexpr double s
void info(const std::string &logMessage)
T duration_cast(T...args)
T setw(T...args)
constexpr double m
T setfill(T...args)
STL class.
T fixed(T...args)
std::list< ProgressInfo > m_progress_info
T setprecision(T...args)
static Logging getLogger(const std::string &name="")
void handleMessage(const std::list< ProgressInfo > &info) override
std::chrono::steady_clock::time_point m_started
std::chrono::steady_clock::duration m_min_interval