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 {
for (auto const& name : counterNames_) {
if (auto ptr = folly::get_ptr(datum.counters, name)) {
switch (ptr->type) {
case UserMetric::TIME:
case UserMetric::Type::TIME:
printf(
" %-*s", int(name.length()), readableTime(*ptr, 2).c_str());
" %-*s",
int(name.length()),
readableTime(ptr->value, 2).c_str());
break;
case UserMetric::METRIC:
case UserMetric::Type::METRIC:
printf(
" %-*s",
int(name.length()),
metricReadable(*ptr, 2).c_str());
metricReadable(ptr->value, 2).c_str());
break;
default:
printf(" %-*d", int(name.length()), (int)*ptr);
printf(" %-*d", int(name.length()), ptr->value);
}
} else {
printf(" %-*s", int(name.length()), "NaN");
......
......@@ -53,20 +53,16 @@ inline bool runBenchmarksOnFlag() {
return FLAGS_benchmark;
}
struct UserMetric {
enum Type { CUSTOM, TIME, METRIC };
int value;
Type type{CUSTOM};
class UserMetric {
public:
enum class Type { CUSTOM, TIME, METRIC };
int value{};
Type type{Type::CUSTOM};
UserMetric() = default;
template <typename T>
/* implicit */ UserMetric(T val, Type typ = CUSTOM)
: value(static_cast<int>(val)), type(typ) {}
operator int() const {
return value;
}
operator int&() {
return value;
}
/* implicit */ UserMetric(int val, Type typ = Type::CUSTOM)
: value(val), type(typ) {}
};
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