68 #ifndef OR_TOOLS_UTIL_STATS_H_ 69 #define OR_TOOLS_UTIL_STATS_H_ 74 #ifdef HAS_PERF_SUBSYSTEM 75 #include "absl/strings/str_replace.h" 76 #include "exegesis/exegesis/itineraries/perf_subsystem.h" 78 #endif // HAS_PERF_SUBSYSTEM 90 class TimeDistribution;
102 std::string
Name()
const {
return name_; }
115 virtual double Sum()
const {
return 0; }
124 virtual void Reset() = 0;
127 const std::string name_;
139 : name_(
name), stats_(), time_distributions_() {}
166 std::vector<Stat*> stats_;
167 std::map<std::string, TimeDistribution*> time_distributions_;
181 void Reset()
override;
250 const double cycles = static_cast<double>(timer_.
GetCycles());
258 static std::string PrintCyclesAsTime(
double cycles);
316 : stat_(stat), also_update_(nullptr) {
321 if (also_update_ !=
nullptr) {
352 #ifdef HAS_PERF_SUBSYSTEM 360 class EnabledScopedInstructionCounter {
362 explicit EnabledScopedInstructionCounter(
const std::string&
name,
364 EnabledScopedInstructionCounter(
const EnabledScopedInstructionCounter&) =
366 EnabledScopedInstructionCounter& operator=(
367 const EnabledScopedInstructionCounter&) =
delete;
368 ~EnabledScopedInstructionCounter();
371 double ReadInstructionCount() {
return ending_count_ - starting_count_; }
374 TimeLimit* time_limit_;
376 double starting_count_;
377 double ending_count_;
379 #endif // HAS_PERF_SUBSYSTEM 393 #ifdef HAS_PERF_SUBSYSTEM 395 #else // HAS_PERF_SUBSYSTEM 397 #endif // HAS_PERF_SUBSYSTEM 401 #define IF_STATS_ENABLED(instructions) instructions 410 #define SCOPED_TIME_STAT(stats) \ 411 operations_research::ScopedTimeDistributionUpdater scoped_time_stat( \ 412 (stats)->LookupOrCreateTimeDistribution(__FUNCTION__)) 414 #ifdef HAS_PERF_SUBSYSTEM 416 inline std::string RemoveOperationsResearchAndGlop(
417 const std::string& pretty_function) {
418 return strings::GlobalReplaceSubstrings(
419 pretty_function, {{
"operations_research::",
""}, {
"glop::",
""}});
422 #define SCOPED_INSTRUCTION_COUNT(time_limit) \ 423 operations_research::ScopedInstructionCounter scoped_instruction_count( \ 424 RemoveOperationsResearchAndGlop(__PRETTY_FUNCTION__), time_limit) 426 #else // !HAS_PERF_SUBSYSTEM 427 #define SCOPED_INSTRUCTION_COUNT(time_limit) 428 #endif // HAS_PERF_SUBSYSTEM 437 #define IF_STATS_ENABLED(instructions) 438 #define SCOPED_TIME_STAT(stats) 439 #define SCOPED_INSTRUCTION_COUNT(time_limit) 445 #endif // OR_TOOLS_UTIL_STATS_H_
IntegerDistribution(const std::string &name)
double sum_squares_from_average_
std::string StatString() const
StatsGroup(const std::string &name)
virtual int Priority() const
int64_t GetCycles() const
DisabledScopedInstructionCounter & operator=(const DisabledScopedInstructionCounter &)=delete
void AlsoUpdate(TimeDistribution *also_update)
TimeDistribution(const std::string &name, StatsGroup *group)
ModelSharedTimeLimit * time_limit
void Register(Stat *stat)
IntegerDistribution(const std::string &name, StatsGroup *group)
int Priority() const override
DoubleDistribution(const std::string &name)
void AddTimeInSec(double seconds)
std::string StatString() const
bool WorthPrinting() const override
~EnabledScopedTimeDistributionUpdater()
TimeDistribution(const std::string &name)
void AddToDistribution(double value)
DisabledScopedTimeDistributionUpdater ScopedTimeDistributionUpdater
double StdDeviation() const
~DistributionStat() override
DoubleDistribution(const std::string &name, StatsGroup *group)
RatioDistribution(const std::string &name, StatsGroup *group)
std::string MemoryUsage()
std::string ValueAsString() const override
virtual bool WorthPrinting() const =0
RatioDistribution(const std::string &name)
double StopTimerAndAddElapsedTime()
Stat(const std::string &name)
double Sum() const override
void AddTimeInCycles(double cycles)
DisabledScopedInstructionCounter(const std::string &name)
Collection of objects used to extend the Constraint Solver library.
std::string ValueAsString() const override
TimeDistribution * LookupOrCreateTimeDistribution(std::string name)
std::string ValueAsString() const override=0
DisabledScopedTimeDistributionUpdater(TimeDistribution *stat)
DisabledScopedInstructionCounter ScopedInstructionCounter
static double CyclesToSeconds(double num_cycles)
void AlsoUpdate(TimeDistribution *also_update)
void SetPrintOrder(PrintOrder print_order)
virtual double Sum() const
std::string ValueAsString() const override
std::string ValueAsString() const override
EnabledScopedTimeDistributionUpdater(TimeDistribution *stat)
virtual std::string ValueAsString() const =0