68#ifndef OR_TOOLS_UTIL_STATS_H_ 
   69#define OR_TOOLS_UTIL_STATS_H_ 
   78#include "absl/container/flat_hash_map.h" 
   79#include "absl/strings/string_view.h" 
   80#include "absl/time/time.h" 
   95  explicit Stat(absl::string_view name) : name_(name) {}
 
  102  std::string 
Name()
 const { 
return name_; }
 
  115  virtual double Sum()
 const { 
return 0; }
 
  127  const std::string name_;
 
 
  139      : name_(name), stats_(), time_distributions_() {}
 
 
  170  std::vector<Stat*> stats_;
 
  171  absl::flat_hash_map<std::string, std::unique_ptr<TimeDistribution>>
 
 
  184  void Reset() 
override;
 
 
  256    const double cycles = 
static_cast<double>(timer_.GetCycles());
 
 
  264  static std::string PrintCyclesAsTime(
double cycles);
 
 
  276  void Add(
double value);
 
 
  288  void Add(
double value);
 
 
  300  void Add(int64_t value);
 
 
  321      : stat_(stat), also_update_(nullptr) {
 
 
  331    const double cycles = stat_->StopTimerAndAddElapsedTime();
 
  332    if (also_update_ != 
nullptr) {
 
  333      also_update_->AddTimeInCycles(cycles);
 
 
 
  384                                  absl::string_view function_name)
 
  386            stats->LookupOrCreateTimeDistribution(function_name)) {}
 
 
 
  403#define IF_STATS_ENABLED(instructions) instructions 
  414#define IF_STATS_ENABLED(instructions) \ 
  415  if constexpr (false) {               \ 
 
  421#define SCOPED_TIME_STAT(stats) \ 
  422  operations_research::ScopedTimeStats scoped_time_stat(stats, __FUNCTION__); 
 
  424#define SCOPED_INSTRUCTION_COUNT(time_limit) 
void AlsoUpdate(TimeDistribution *)
 
DisabledScopedTimeDistributionUpdater(const DisabledScopedTimeDistributionUpdater &)=delete
This type is neither copyable nor movable.
 
DisabledScopedTimeDistributionUpdater(TimeDistribution *)
 
DisabledScopedTimeDistributionUpdater & operator=(const DisabledScopedTimeDistributionUpdater &)=delete
 
DisabledScopedTimeStats(StatsGroup *, const char *)
 
DisabledScopedTimeStats & operator=(DisabledScopedTimeStats &&)=delete
 
DisabledScopedTimeStats(const DisabledScopedTimeStats &)=delete
 
DisabledScopedTimeStats(DisabledScopedTimeStats &&)=delete
 
DisabledScopedTimeStats & operator=(const DisabledScopedTimeStats &)=delete
 
double Average() const
Get the average of the distribution or 0.0 if empty.
 
bool WorthPrinting() const override
Is this stat worth printing? Usually false if nothing was measured.
 
double Sum() const override
Trivial statistics on all the values added so far.
 
double StdDeviation() const
 
~DistributionStat() override
 
void AddToDistribution(double value)
Adds a value to this sequence and updates the stats.
 
double sum_squares_from_average_
 
std::string ValueAsString() const override=0
Implemented by the subclasses.
 
void Reset() override
Reset this statistic to the same state as if it was newly created.
 
DistributionStat(absl::string_view name)
 
std::string ValueAsString() const override
Implemented by the subclasses.
 
DoubleDistribution(absl::string_view name, StatsGroup *group)
 
DoubleDistribution(absl::string_view name)
 
EnabledScopedTimeDistributionUpdater(TimeDistribution *stat)
 
EnabledScopedTimeDistributionUpdater(const EnabledScopedTimeDistributionUpdater &)=delete
This type is neither copyable nor movable.
 
void AlsoUpdate(TimeDistribution *also_update)
 
~EnabledScopedTimeDistributionUpdater()
 
EnabledScopedTimeDistributionUpdater & operator=(const EnabledScopedTimeDistributionUpdater &)=delete
 
EnabledScopedTimeStats & operator=(const EnabledScopedTimeStats &)=delete
 
EnabledScopedTimeStats(StatsGroup *stats, absl::string_view function_name)
 
EnabledScopedTimeStats(const EnabledScopedTimeStats &)=delete
 
EnabledScopedTimeStats & operator=(EnabledScopedTimeStats &&)=delete
 
EnabledScopedTimeStats(EnabledScopedTimeStats &&)=delete
 
IntegerDistribution(absl::string_view name, StatsGroup *group)
 
std::string ValueAsString() const override
Implemented by the subclasses.
 
IntegerDistribution(absl::string_view name)
 
std::string ValueAsString() const override
Implemented by the subclasses.
 
RatioDistribution(absl::string_view name, StatsGroup *group)
 
RatioDistribution(absl::string_view name)
 
Base class for a statistic that can be pretty-printed.
 
std::string Name() const
Only used for display purposes.
 
virtual bool WorthPrinting() const =0
Is this stat worth printing? Usually false if nothing was measured.
 
virtual int Priority() const
 
virtual std::string ValueAsString() const =0
Prints information about this statistic.
 
Stat(absl::string_view name)
 
std::string StatString() const
 
virtual double Sum() const
 
virtual void Reset()=0
Reset this statistic to the same state as if it was newly created.
 
Base class to print a nice summary of a group of statistics.
 
StatsGroup(const StatsGroup &)=delete
This type is neither copyable nor movable.
 
void SetPrintOrder(PrintOrder print_order)
 
StatsGroup & operator=(const StatsGroup &)=delete
 
TimeDistribution * LookupOrCreateTimeDistribution(absl::string_view name)
 
StatsGroup(absl::string_view name)
 
@ SORT_BY_PRIORITY_THEN_VALUE
 
std::string StatString() const
 
void Reset()
Calls Reset() on all the statistics registered with this group.
 
void Register(Stat *stat)
 
std::string ValueAsString() const override
Implemented by the subclasses.
 
void AddTimeInSec(double seconds)
Adds a time in seconds to this distribution.
 
TimeDistribution(absl::string_view name)
 
TimeDistribution(absl::string_view name, StatsGroup *group)
 
static double CyclesToSeconds(double num_cycles)
 
void StartTimer()
Starts the timer in preparation of a StopTimerAndAddElapsedTime().
 
double StopTimerAndAddElapsedTime()
 
void AddTime(absl::Duration duration)
 
int Priority() const override
Time distributions have a high priority to be displayed first.
 
void AddTimeInCycles(double cycles)
Adds a time in CPU cycles to this distribution.
 
In SWIG mode, we don't want anything besides these top-level includes.
 
DisabledScopedTimeDistributionUpdater ScopedTimeDistributionUpdater
 
DisabledScopedTimeStats ScopedTimeStats
 
std::string MemoryUsage()
Returns the current thread's total memory usage in an human-readable string.