aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/metrics/timer.h
diff options
context:
space:
mode:
authorIgor Makunin <igor.makunin@gmail.com>2022-02-10 16:49:35 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:35 +0300
commitc617191a3b33c0f5e1be6390361dbe540775d158 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/monlib/metrics/timer.h
parentf7a438035f19b364b5479caf536990e82b174f38 (diff)
downloadydb-c617191a3b33c0f5e1be6390361dbe540775d158.tar.gz
Restoring authorship annotation for Igor Makunin <igor.makunin@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib/metrics/timer.h')
-rw-r--r--library/cpp/monlib/metrics/timer.h56
1 files changed, 28 insertions, 28 deletions
diff --git a/library/cpp/monlib/metrics/timer.h b/library/cpp/monlib/metrics/timer.h
index b45cc0bc9b..5c4e26e37b 100644
--- a/library/cpp/monlib/metrics/timer.h
+++ b/library/cpp/monlib/metrics/timer.h
@@ -1,29 +1,29 @@
-#pragma once
-
+#pragma once
+
#include "metric.h"
-
+
#include <util/generic/typetraits.h>
-#include <chrono>
-
-
-namespace NMonitoring {
-
- /**
- * A timing scope to record elapsed time since creation.
- */
+#include <chrono>
+
+
+namespace NMonitoring {
+
+ /**
+ * A timing scope to record elapsed time since creation.
+ */
template <typename TMetric,
- typename Resolution = std::chrono::milliseconds,
- typename Clock = std::chrono::high_resolution_clock>
+ typename Resolution = std::chrono::milliseconds,
+ typename Clock = std::chrono::high_resolution_clock>
class TMetricTimerScope {
- public:
+ public:
explicit TMetricTimerScope(TMetric* metric)
: Metric_(metric)
- , StartTime_(Clock::now())
- {
+ , StartTime_(Clock::now())
+ {
Y_ENSURE(Metric_);
- }
-
+ }
+
TMetricTimerScope(TMetricTimerScope&) = delete;
TMetricTimerScope& operator=(const TMetricTimerScope&) = delete;
@@ -45,7 +45,7 @@ namespace NMonitoring {
return;
}
- auto duration = std::chrono::duration_cast<Resolution>(Clock::now() - StartTime_).count();
+ auto duration = std::chrono::duration_cast<Resolution>(Clock::now() - StartTime_).count();
if constexpr (std::is_same<TMetric, TGauge>::value) {
Metric_->Set(duration);
} else if constexpr (std::is_same<TMetric, TIntGauge>::value) {
@@ -56,13 +56,13 @@ namespace NMonitoring {
Metric_->Add(duration);
} else if constexpr (std::is_same<TMetric, THistogram>::value) {
Metric_->Record(duration);
- } else {
+ } else {
static_assert(TDependentFalse<TMetric>, "Not supported metric type");
- }
+ }
Metric_ = nullptr;
- }
-
+ }
+
~TMetricTimerScope() {
if (Metric_ == nullptr) {
return;
@@ -71,11 +71,11 @@ namespace NMonitoring {
Record();
}
- private:
+ private:
TMetric* Metric_{nullptr};
- typename Clock::time_point StartTime_;
- };
-
+ typename Clock::time_point StartTime_;
+ };
+
/**
* @brief A class that is supposed to use to measure execution time of an asynchronuous operation.
*
@@ -124,4 +124,4 @@ namespace NMonitoring {
TFutureFriendlyTimer<TMetric> FutureTimer(TMetric* metric) {
return TFutureFriendlyTimer<TMetric>{metric};
}
-}
+}