Commit 65fa2c4b authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix odd UserMetric design in folly/Benchmark.h

Summary: [Folly] Fix odd `UserMetric` design in `folly/Benchmark.h`.

Reviewed By: phoad

Differential Revision: D14494202

fbshipit-source-id: c1be1d9b5bdfe07677713ef00401c85270bbe627
parent 3874d423
...@@ -323,18 +323,20 @@ class BenchmarkResultsPrinter { ...@@ -323,18 +323,20 @@ class BenchmarkResultsPrinter {
for (auto const& name : counterNames_) { for (auto const& name : counterNames_) {
if (auto ptr = folly::get_ptr(datum.counters, name)) { if (auto ptr = folly::get_ptr(datum.counters, name)) {
switch (ptr->type) { switch (ptr->type) {
case UserMetric::TIME: case UserMetric::Type::TIME:
printf( printf(
" %-*s", int(name.length()), readableTime(*ptr, 2).c_str()); " %-*s",
int(name.length()),
readableTime(ptr->value, 2).c_str());
break; break;
case UserMetric::METRIC: case UserMetric::Type::METRIC:
printf( printf(
" %-*s", " %-*s",
int(name.length()), int(name.length()),
metricReadable(*ptr, 2).c_str()); metricReadable(ptr->value, 2).c_str());
break; break;
default: default:
printf(" %-*d", int(name.length()), (int)*ptr); printf(" %-*d", int(name.length()), ptr->value);
} }
} else { } else {
printf(" %-*s", int(name.length()), "NaN"); printf(" %-*s", int(name.length()), "NaN");
......
...@@ -53,20 +53,16 @@ inline bool runBenchmarksOnFlag() { ...@@ -53,20 +53,16 @@ inline bool runBenchmarksOnFlag() {
return FLAGS_benchmark; return FLAGS_benchmark;
} }
struct UserMetric { class UserMetric {
enum Type { CUSTOM, TIME, METRIC }; public:
int value; enum class Type { CUSTOM, TIME, METRIC };
Type type{CUSTOM};
int value{};
Type type{Type::CUSTOM};
UserMetric() = default; UserMetric() = default;
template <typename T> /* implicit */ UserMetric(int val, Type typ = Type::CUSTOM)
/* implicit */ UserMetric(T val, Type typ = CUSTOM) : value(val), type(typ) {}
: value(static_cast<int>(val)), type(typ) {}
operator int() const {
return value;
}
operator int&() {
return value;
}
}; };
using UserCounters = std::unordered_map<std::string, UserMetric>; using UserCounters = std::unordered_map<std::string, UserMetric>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment