acelyc111 commented on code in PR #1351:
URL:
https://github.com/apache/incubator-pegasus/pull/1351#discussion_r1115276683
##########
src/utils/metrics.h:
##########
@@ -133,6 +136,42 @@
#define METRIC_DECLARE_percentile_double(name)
\
extern dsn::floating_percentile_prototype<double> METRIC_##name
+// Following METRIC_*VAR* macros are introduced so that:
+// * only need to use prototype name to operate each metric variable;
+// * uniformly name each variable in user class;
+// * differentiate operations on metrics significantly from main logic,
improving code readability.
+
+// Declare a metric variable in user class.
+//
+// Since a type tends to be a class template where there might be commas, use
variadic arguments
+// instead of a single fixed argumen to represent a type.
Review Comment:
```suggestion
// instead of a single fixed argument to represent a type.
```
##########
src/utils/metrics.h:
##########
@@ -553,6 +592,31 @@ enum class metric_unit
kInvalidUnit,
};
+#define METRIC_ASSERT_UNIT_LATENCY(unit, index)
\
+ static_assert(static_cast<size_t>(metric_unit::unit) == index,
\
+ #unit " should be at index " #index)
+
+METRIC_ASSERT_UNIT_LATENCY(kNanoSeconds, 0);
+METRIC_ASSERT_UNIT_LATENCY(kMicroSeconds, 1);
+METRIC_ASSERT_UNIT_LATENCY(kMilliSeconds, 2);
+METRIC_ASSERT_UNIT_LATENCY(kSeconds, 3);
+
+const std::vector<uint64_t> kMetricLatencyConverterFromNS = {
+ 1, 1000, 1000 * 1000, 1000 * 1000 * 1000};
+
+inline uint64_t convert_metric_latency_from_ns(uint64_t latency_ns,
metric_unit target_unit)
+{
+ if (target_unit == metric_unit::kNanoSeconds) {
+ // Since nanoseconds are used as the latency unit more frequently,
eliminate unnecessary
Review Comment:
How about add `dsn_likely`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]