| 1 |
#include <pbcopper/utility/TimeReporter.h> |
| 2 |
|
| 3 |
#include <pbcopper/logging/Logging.h> |
| 4 |
|
| 5 |
#include <cassert> |
| 6 |
|
| 7 |
namespace PacBio { |
| 8 |
namespace Utility { |
| 9 |
|
| 10 |
TimeReporter::TimeReporter(const Logging::LogLevel lvl) : logLevel_{lvl} |
| 11 |
{ |
| 12 |
// simple default |
| 13 |
callback_ = [](const double nsec) { |
| 14 |
return "Finished in " + Utility::Stopwatch::PrettyPrintNanoseconds(nsec); |
| 15 |
}; |
| 16 |
} |
| 17 |
|
| 18 |
TimeReporter::TimeReporter(const Logging::LogLevel lvl, TimeReporterCallback callback) |
| 19 |
: logLevel_{lvl}, callback_{callback} |
| 20 |
{} |
| 21 |
|
| 22 |
TimeReporter::~TimeReporter() |
| 23 |
{ |
| 24 |
if (logLevel_ < Logging::CurrentLogLevel()) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
const std::string message = callback_(stopwatch_.ElapsedNanoseconds()); |
| 29 |
switch (logLevel_) { |
| 30 |
case Logging::LogLevel::TRACE: |
| 31 |
PBLOG_TRACE << message; |
| 32 |
break; |
| 33 |
case Logging::LogLevel::DEBUG: |
| 34 |
PBLOG_DEBUG << message; |
| 35 |
break; |
| 36 |
case Logging::LogLevel::VERBOSE: |
| 37 |
PBLOG_VERBOSE << message; |
| 38 |
break; |
| 39 |
case Logging::LogLevel::INFO: |
| 40 |
PBLOG_INFO << message; |
| 41 |
break; |
| 42 |
case Logging::LogLevel::NOTICE: |
| 43 |
PBLOG_NOTICE << message; |
| 44 |
break; |
| 45 |
case Logging::LogLevel::WARN: |
| 46 |
PBLOG_WARN << message; |
| 47 |
break; |
| 48 |
case Logging::LogLevel::ERROR: |
| 49 |
PBLOG_ERROR << message; |
| 50 |
break; |
| 51 |
case Logging::LogLevel::CRITICAL: |
| 52 |
PBLOG_CRITICAL << message; |
| 53 |
break; |
| 54 |
case Logging::LogLevel::FATAL: |
| 55 |
PBLOG_FATAL << message; |
| 56 |
break; |
| 57 |
default: |
| 58 |
// can't throw from dtor |
| 59 |
assert(false); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
} // namespace Utility |
| 64 |
} // namespace PacBio |