68 #ifndef OR_TOOLS_UTIL_STATS_H_
69 #define OR_TOOLS_UTIL_STATS_H_
75 #ifdef HAS_PERF_SUBSYSTEM
76 #include "absl/strings/str_replace.h"
77 #include "exegesis/exegesis/itineraries/perf_subsystem.h"
81 #include "absl/strings/string_view.h"
92 class TimeDistribution;
104 std::string
Name()
const {
return name_; }
117 virtual double Sum()
const {
return 0; }
129 const std::string name_;
141 : name_(
name), stats_(), time_distributions_() {}
168 std::vector<Stat*> stats_;
169 std::map<std::string, TimeDistribution*> time_distributions_;
183 void Reset()
override;
252 const double cycles =
static_cast<double>(timer_.
GetCycles());
260 static std::string PrintCyclesAsTime(
double cycles);
317 : stat_(stat), also_update_(nullptr) {
322 if (also_update_ !=
nullptr) {
353 #ifdef HAS_PERF_SUBSYSTEM
361 class EnabledScopedInstructionCounter {
363 explicit EnabledScopedInstructionCounter(absl::string_view
name,
365 EnabledScopedInstructionCounter(
const EnabledScopedInstructionCounter&) =
367 EnabledScopedInstructionCounter& operator=(
368 const EnabledScopedInstructionCounter&) =
delete;
369 ~EnabledScopedInstructionCounter();
372 double ReadInstructionCount() {
return ending_count_ - starting_count_; }
375 TimeLimit* time_limit_;
377 double starting_count_;
378 double ending_count_;
394 #ifdef HAS_PERF_SUBSYSTEM
402 #define IF_STATS_ENABLED(instructions) instructions
411 #define SCOPED_TIME_STAT(stats) \
412 operations_research::ScopedTimeDistributionUpdater scoped_time_stat( \
413 (stats)->LookupOrCreateTimeDistribution(__FUNCTION__))
415 #ifdef HAS_PERF_SUBSYSTEM
417 inline std::string RemoveOperationsResearchAndGlop(
418 const std::string& pretty_function) {
419 return strings::GlobalReplaceSubstrings(
420 pretty_function, {{
"operations_research::",
""}, {
"glop::",
""}});
423 #define SCOPED_INSTRUCTION_COUNT(time_limit) \
424 operations_research::ScopedInstructionCounter scoped_instruction_count( \
425 RemoveOperationsResearchAndGlop(__PRETTY_FUNCTION__), time_limit)
428 #define SCOPED_INSTRUCTION_COUNT(time_limit)
438 #define IF_STATS_ENABLED(instructions)
439 #define SCOPED_TIME_STAT(stats)
440 #define SCOPED_INSTRUCTION_COUNT(time_limit)
int64_t GetCycles() const
DisabledScopedInstructionCounter & operator=(const DisabledScopedInstructionCounter &)=delete
DisabledScopedInstructionCounter(absl::string_view)
DisabledScopedInstructionCounter(const DisabledScopedInstructionCounter &)=delete
void AlsoUpdate(TimeDistribution *also_update)
DisabledScopedTimeDistributionUpdater(TimeDistribution *stat)
double StdDeviation() const
double Sum() const override
std::string ValueAsString() const override=0
void AddToDistribution(double value)
double sum_squares_from_average_
bool WorthPrinting() const override
~DistributionStat() override
DoubleDistribution(absl::string_view name, StatsGroup *group)
DoubleDistribution(absl::string_view name)
std::string ValueAsString() const override
void AlsoUpdate(TimeDistribution *also_update)
~EnabledScopedTimeDistributionUpdater()
EnabledScopedTimeDistributionUpdater(TimeDistribution *stat)
IntegerDistribution(absl::string_view name, StatsGroup *group)
IntegerDistribution(absl::string_view name)
std::string ValueAsString() const override
RatioDistribution(absl::string_view name, StatsGroup *group)
RatioDistribution(absl::string_view name)
std::string ValueAsString() const override
virtual bool WorthPrinting() const =0
virtual std::string ValueAsString() const =0
virtual double Sum() const
virtual int Priority() const
Stat(absl::string_view name)
std::string StatString() const
StatsGroup(absl::string_view name)
void Register(Stat *stat)
void SetPrintOrder(PrintOrder print_order)
TimeDistribution * LookupOrCreateTimeDistribution(std::string name)
@ SORT_BY_PRIORITY_THEN_VALUE
std::string StatString() const
TimeDistribution(absl::string_view name, StatsGroup *group)
double StopTimerAndAddElapsedTime()
static double CyclesToSeconds(double num_cycles)
void AddTimeInCycles(double cycles)
int Priority() const override
void AddTimeInSec(double seconds)
TimeDistribution(absl::string_view name)
std::string ValueAsString() const override
ModelSharedTimeLimit * time_limit
Collection of objects used to extend the Constraint Solver library.
std::string MemoryUsage()