|
|
|
@ -7,14 +7,17 @@ |
|
|
|
|
//
|
|
|
|
|
#include "google/protobuf/port.h" |
|
|
|
|
|
|
|
|
|
#include <cstdint> |
|
|
|
|
#include <cstdio> |
|
|
|
|
#include <cstdlib> |
|
|
|
|
#include <map> |
|
|
|
|
#include <utility> |
|
|
|
|
|
|
|
|
|
#include "absl/strings/numbers.h" |
|
|
|
|
#include "absl/strings/str_format.h" |
|
|
|
|
#include "absl/strings/str_split.h" |
|
|
|
|
#include "absl/strings/string_view.h" |
|
|
|
|
#include "absl/types/variant.h" |
|
|
|
|
|
|
|
|
|
// Must be included last
|
|
|
|
|
#include "google/protobuf/port_def.inc" |
|
|
|
@ -35,7 +38,8 @@ void protobuf_assumption_failed(const char* pred, const char* file, int line) { |
|
|
|
|
static void PrintAllCounters(); |
|
|
|
|
static auto& CounterMap() { |
|
|
|
|
using Map = std::map<absl::string_view, |
|
|
|
|
std::map<absl::string_view, const RealDebugCounter*>>; |
|
|
|
|
std::map<absl::variant<int64_t, absl::string_view>, |
|
|
|
|
const RealDebugCounter*>>; |
|
|
|
|
static auto* counter_map = new Map{}; |
|
|
|
|
static bool dummy = std::atexit(PrintAllCounters); |
|
|
|
|
(void)dummy; |
|
|
|
@ -60,7 +64,15 @@ static void PrintAllCounters() { |
|
|
|
|
} |
|
|
|
|
for (auto& count : category.second) { |
|
|
|
|
size_t value = count.second->value(); |
|
|
|
|
absl::FPrintF(stderr, " %-10s: %10zu", count.first, value); |
|
|
|
|
if (absl::holds_alternative<int64_t>(count.first)) { |
|
|
|
|
// For integers, right align
|
|
|
|
|
absl::FPrintF(stderr, " %9d : %10zu", |
|
|
|
|
absl::get<int64_t>(count.first), value); |
|
|
|
|
} else { |
|
|
|
|
// For strings, left align
|
|
|
|
|
absl::FPrintF(stderr, " %-10s: %10zu", |
|
|
|
|
absl::get<absl::string_view>(count.first), value); |
|
|
|
|
} |
|
|
|
|
if (total != 0 && category.second.size() > 1) { |
|
|
|
|
absl::FPrintF( |
|
|
|
|
stderr, " (%5.2f%%)", |
|
|
|
@ -77,7 +89,12 @@ static void PrintAllCounters() { |
|
|
|
|
void RealDebugCounter::Register(absl::string_view name) { |
|
|
|
|
std::pair<absl::string_view, absl::string_view> parts = |
|
|
|
|
absl::StrSplit(name, '.'); |
|
|
|
|
CounterMap()[parts.first][parts.second] = this; |
|
|
|
|
int64_t as_int; |
|
|
|
|
if (absl::SimpleAtoi(parts.second, &as_int)) { |
|
|
|
|
CounterMap()[parts.first][as_int] = this; |
|
|
|
|
} else { |
|
|
|
|
CounterMap()[parts.first][parts.second] = this; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|