18#include "absl/strings/str_format.h"
27 static const int64 kDisplayThreshold = 2;
28 static const int64 kKiloByte = 1024;
29 static const int64 kMegaByte = kKiloByte * kKiloByte;
30 static const int64 kGigaByte = kMegaByte * kKiloByte;
31 if (mem > kDisplayThreshold * kGigaByte) {
32 return absl::StrFormat(
"%.2lf GB", mem * 1.0 / kGigaByte);
33 }
else if (mem > kDisplayThreshold * kMegaByte) {
34 return absl::StrFormat(
"%.2lf MB", mem * 1.0 / kMegaByte);
35 }
else if (mem > kDisplayThreshold * kKiloByte) {
36 return absl::StrFormat(
"%2lf KB", mem * 1.0 / kKiloByte);
38 return absl::StrFormat(
"%d", mem);
53 for (
int i = 0; i < stats_.size(); ++i) {
60bool CompareStatPointers(
const Stat* s1,
const Stat* s2) {
63 return (s1->
Sum() > s2->
Sum());
74 int longest_name_size = 0;
75 std::vector<Stat*> sorted_stats;
76 for (
int i = 0; i < stats_.size(); ++i) {
77 if (!stats_[i]->WorthPrinting())
continue;
80 longest_name_size =
std::max(longest_name_size, size);
81 sorted_stats.push_back(stats_[i]);
83 switch (print_order_) {
85 std::sort(sorted_stats.begin(), sorted_stats.end(), CompareStatPointers);
88 std::sort(sorted_stats.begin(), sorted_stats.end(),
89 [](
const Stat* s1,
const Stat* s2) ->
bool {
90 return s1->Name() < s2->Name();
94 LOG(
FATAL) <<
"Unknown print order: " << print_order_;
98 if (sorted_stats.empty())
return "";
101 std::string result(name_ +
" {\n");
102 for (
int i = 0; i < sorted_stats.size(); ++i) {
104 result += sorted_stats[i]->Name();
106 sorted_stats[i]->Name()),
108 result +=
" : " + sorted_stats[i]->ValueAsString();
116 if (ref ==
nullptr) {
127 sum_squares_from_average_(0.0),
136 sum_squares_from_average_(0.0),
171 if (
num_ == 0)
return 0.0;
177 return cycles * seconds_per_cycles;
180std::string TimeDistribution::PrintCyclesAsTime(
double cycles) {
183 double eps1 = 1 + 1e-3;
185 if (sec * eps1 >= 3600.0)
return absl::StrFormat(
"%.2fh", sec / 3600.0);
186 if (sec * eps1 >= 60.0)
return absl::StrFormat(
"%.2fm", sec / 60.0);
187 if (sec * eps1 >= 1.0)
return absl::StrFormat(
"%.2fs", sec);
188 if (sec * eps1 >= 1e-3)
return absl::StrFormat(
"%.2fms", sec * 1e3);
189 if (sec * eps1 >= 1e-6)
return absl::StrFormat(
"%.2fus", sec * 1e6);
190 return absl::StrFormat(
"%.2fns", sec * 1e9);
205 return absl::StrFormat(
206 "%8u [%8s, %8s] %8s %8s %8s\n",
num_, PrintCyclesAsTime(
min_),
207 PrintCyclesAsTime(
max_), PrintCyclesAsTime(
Average()),
217 return absl::StrFormat(
"%8u [%7.2f%%, %7.2f%%] %7.2f%% %7.2f%%\n",
num_,
225 return absl::StrFormat(
"%8u [%8.1e, %8.1e] %8.1e %8.1e\n",
num_,
min_,
max_,
234 return absl::StrFormat(
"%8u [%8.f, %8.f] %8.2f %8.2f %8.f\n",
num_,
min_,
238#ifdef HAS_PERF_SUBSYSTEM
239EnabledScopedInstructionCounter::EnabledScopedInstructionCounter(
243 time_limit_ !=
nullptr ? time_limit_->ReadInstructionCounter() : 0;
246EnabledScopedInstructionCounter::~EnabledScopedInstructionCounter() {
248 time_limit_ !=
nullptr ? time_limit_->ReadInstructionCounter() : 0;
249 LOG(
INFO) << name_ <<
", Instructions: " << ending_count_ - starting_count_;
#define DCHECK_GE(val1, val2)
static double CyclesToSeconds(int64 c)
double StdDeviation() const
void AddToDistribution(double value)
double sum_squares_from_average_
std::string ValueAsString() const override
std::string ValueAsString() const override
std::string ValueAsString() const override
virtual std::string ValueAsString() const =0
virtual double Sum() const
virtual int Priority() const
Stat(const std::string &name)
std::string StatString() const
void Register(Stat *stat)
TimeDistribution * LookupOrCreateTimeDistribution(std::string name)
@ SORT_BY_PRIORITY_THEN_VALUE
std::string StatString() const
static double CyclesToSeconds(double num_cycles)
void AddTimeInCycles(double cycles)
void AddTimeInSec(double seconds)
std::string ValueAsString() const override
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
SharedTimeLimit * time_limit
void STLDeleteValues(T *v)
int64 MemoryUsageProcess()
int UTF8StrLen(StrType str_type)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
std::string MemoryUsage()