SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEMain
src
lib
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
28
void
ProgressLogger::print
() {
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
48
auto
h
= std::chrono::duration_cast<std::chrono::hours>(
elapsed
);
49
auto
m = std::chrono::duration_cast<std::chrono::minutes>(
elapsed
-
h
);
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
58
void
ProgressLogger::handleMessage
(
const
std::list<ProgressInfo>
& info) {
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.h
Elements::Logging::info
void info(const std::string &logMessage)
SourceXtractor::ProgressLogger::m_progress_info
std::list< ProgressInfo > m_progress_info
Definition
ProgressLogger.h:57
SourceXtractor::ProgressLogger::m_last_logged
std::chrono::steady_clock::time_point m_last_logged
Definition
ProgressLogger.h:56
SourceXtractor::ProgressLogger::print
void print()
Definition
ProgressLogger.cpp:28
SourceXtractor::ProgressLogger::ProgressLogger
ProgressLogger(const std::chrono::steady_clock::duration &min_interval)
Definition
ProgressLogger.cpp:22
SourceXtractor::ProgressLogger::handleMessage
void handleMessage(const std::list< ProgressInfo > &info) override
Definition
ProgressLogger.cpp:58
SourceXtractor::ProgressLogger::m_logger
Elements::Logging m_logger
Definition
ProgressLogger.h:54
SourceXtractor::ProgressLogger::m_done
std::atomic_bool m_done
Definition
ProgressLogger.h:58
SourceXtractor::ProgressLogger::m_min_interval
std::chrono::steady_clock::duration m_min_interval
Definition
ProgressLogger.h:55
SourceXtractor::ProgressLogger::m_started
std::chrono::steady_clock::time_point m_started
Definition
ProgressLogger.h:56
std::fixed
T fixed(T... args)
std::function
Elements
SourceXtractor
Definition
Aperture.h:30
std
STL namespace.
std::chrono::steady_clock::now
T now(T... args)
std::setfill
T setfill(T... args)
std::setprecision
T setprecision(T... args)
std::setw
T setw(T... args)
Generated by
1.10.0