14#ifndef ORTOOLS_UTIL_LOGGING_H_
15#define ORTOOLS_UTIL_LOGGING_H_
22#include "absl/strings/str_cat.h"
63 std::function<
void(
const std::string& message)> callback);
72 void LogInfo(
const char* source_filename,
int source_line,
73 const std::string& message);
87 struct ThrottlingData {
88 int64_t num_displayed_logs = 0;
89 int64_t num_last_skipped_logs = 0;
90 std::string last_skipped_message;
92 void UpdateWhenDisplayed() {
94 num_last_skipped_logs = 0;
95 last_skipped_message =
"";
98 bool RateIsOk(
const ThrottlingData& data);
100 bool is_enabled_ =
false;
101 bool log_to_stdout_ =
false;
102 std::vector<std::function<void(
const std::string& message)>> info_callbacks_;
107 const int throttling_threshold_ = 20;
108 const double throttling_rate_ = 1.0;
111 std::vector<ThrottlingData> id_to_throttling_data_;
114#define SOLVER_LOG(logger, ...) \
115 if ((logger)->LoggingIsEnabled()) \
116 (logger)->LogInfo(__FILE__, __LINE__, absl::StrCat(__VA_ARGS__))
118#define FORCED_SOLVER_LOG(logger, ...) \
119 (logger)->LogInfo(__FILE__, __LINE__, absl::StrCat(__VA_ARGS__))
130 : name_(
std::move(name)),
131 dtime_at_start_(time_limit->GetElapsedDeterministicTime()),
133 time_limit_(time_limit) {
148 if (count == 0)
return;
149 counters_.emplace_back(std::move(name), count);
153 void AddMessage(std::string name) { extra_infos_.push_back(std::move(name)); }
161 override_logging_ =
true;
162 log_when_override_ = value;
166 double wtime()
const {
return timer_.Get(); }
169 const std::string name_;
170 const double dtime_at_start_;
176 bool override_logging_ =
false;
177 bool log_when_override_ =
false;
179 std::vector<std::pair<std::string, int64_t>> counters_;
180 std::vector<std::string> extra_infos_;
void AddMessage(std::string name)
void OverrideLogging(bool value)
double deterministic_time() const
void TrackSimpleLoop(int size)
void AddCounter(std::string name, int64_t count)
void AddToWork(double dtime)
PresolveTimer(std::string name, SolverLogger *logger, TimeLimit *time_limit)
void TrackFastLoop(int size)
void TrackHashLookups(int size)
bool WorkLimitIsReached() const
void EnableLogging(bool enable)
void ThrottledLog(int id, const std::string &message)
void SetLogToStdOut(bool enable)
void FlushPendingThrottledLogs(bool ignore_rates=false)
bool LoggingIsEnabled() const
void AddInfoLoggingCallback(std::function< void(const std::string &message)> callback)
void ClearInfoLoggingCallbacks()
int NumInfoLoggingCallbacks() const
void LogInfo(const char *source_filename, int source_line, const std::string &message)
std::string FormatCounter(int64_t num)