Skip to content

Commit

Permalink
[trivial] restrict timer format changes to Logging. (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold authored Dec 18, 2023
1 parent f3ce70a commit 9c5107f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/search/utils/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ static plugins::TypedEnumPlugin<Verbosity> _enum_plugin({
{"verbose", "full output"},
{"debug", "like verbose with additional debug output"}
});

void Log::add_prefix() const {
stream << "[t=";
streamsize previous_precision = cout.precision(TIMER_PRECISION);
ios_base::fmtflags previous_flags = stream.flags();
stream.setf(ios_base::fixed, ios_base::floatfield);
stream << g_timer;
stream.flags(previous_flags);
cout.precision(previous_precision);
stream << ", "
<< get_peak_memory_in_kb() << " KB] ";
}
}
6 changes: 3 additions & 3 deletions src/search/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ enum class Verbosity {
Internal class encapsulated by LogProxy.
*/
class Log {
static const int TIMER_PRECISION = 6;
std::ostream &stream;
const Verbosity verbosity;
bool line_has_started;
void add_prefix() const;

public:
explicit Log(Verbosity verbosity)
Expand All @@ -45,10 +47,8 @@ class Log {
Log &operator<<(const T &elem) {
if (!line_has_started) {
line_has_started = true;
stream << "[t=" << g_timer << ", "
<< get_peak_memory_in_kb() << " KB] ";
add_prefix();
}

stream << elem;
return *this;
}
Expand Down

0 comments on commit 9c5107f

Please sign in to comment.