34 static const int64_t kDisplayThreshold = 2;
35 static const int64_t kKiloByte = 1024;
36 static const int64_t kMegaByte = kKiloByte * kKiloByte;
37 static const int64_t kGigaByte = kMegaByte * kKiloByte;
38 if (mem > kDisplayThreshold * kGigaByte) {
39 return absl::StrFormat(
"%.2lf GB", mem * 1.0 / kGigaByte);
40 }
else if (mem > kDisplayThreshold * kMegaByte) {
41 return absl::StrFormat(
"%.2lf MB", mem * 1.0 / kMegaByte);
42 }
else if (mem > kDisplayThreshold * kKiloByte) {
43 return absl::StrFormat(
"%2lf KB", mem * 1.0 / kKiloByte);
45 return absl::StrFormat(
"%d", mem);
98 int longest_name_size = 0;
99 std::vector<Stat*> sorted_stats;
100 for (
int i = 0; i < stats_.size(); ++i) {
101 if (!stats_[i]->WorthPrinting())
continue;
103 const int size = UTF8StrLen(stats_[i]->Name());
104 longest_name_size = std::max(longest_name_size, size);
105 sorted_stats.push_back(stats_[i]);
107 switch (print_order_) {
109 std::sort(sorted_stats.begin(), sorted_stats.end(), CompareStatPointers);
112 std::sort(sorted_stats.begin(), sorted_stats.end(),
113 [](
const Stat* s1,
const Stat* s2) ->
bool {
114 return s1->Name() < s2->Name();
118 LOG(FATAL) <<
"Unknown print order: " << print_order_;
122 if (sorted_stats.empty())
return "";
125 std::string result(name_ +
" {\n");
126 for (
int i = 0; i < sorted_stats.size(); ++i) {
128 result += sorted_stats[i]->Name();
129 result.append(longest_name_size - UTF8StrLen(sorted_stats[i]->Name()),
' ');
130 result +=
" : " + sorted_stats[i]->ValueAsString();