diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2020-07-17 22:52:01 +0000 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-01-23 21:36:28 +0100 |
commit | 8834c5c72447f7b8147ec34a4cb12e28c8906e90 (patch) | |
tree | 6559326e2ccedb2ce37d6248f7199525dc85108f /src/common | |
parent | d11c3807b32d51e48ed4557972a627f6366956d9 (diff) |
Core/Metric: Log Map::Update() times (#25067)
* Core/Metric: Log Map::Update() times
* Add more performant version to reduce allocations when metrics are disabled
* Linux build fix
* Add metric stopwatch version that doesnt let users forget to _END it
* Fix linux build
* Code cleanup
* Add Map updates panel to General dashboard
* Add "Recent events" panel to General dashboard
* Apply latest codestyle changes
Co-authored-by: Shauren <shauren.trinity@gmail.com>
(cherry picked from commit 5eb742ee6a892b684b0c4cbde9f02f838b8300e5)
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Metric/Metric.cpp | 5 | ||||
-rw-r--r-- | src/common/Metric/Metric.h | 34 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp index b1302aacb5a..07db8e83f4d 100644 --- a/src/common/Metric/Metric.cpp +++ b/src/common/Metric/Metric.cpp @@ -279,6 +279,11 @@ std::string Metric::FormatInfluxDBTagValue(std::string const& value) return boost::replace_all_copy(value, " ", "\\ "); } +std::string Metric::FormatInfluxDBValue(std::chrono::nanoseconds value) +{ + return FormatInfluxDBValue(std::chrono::duration_cast<std::chrono::milliseconds>(value).count()); +} + Metric::Metric() { } diff --git a/src/common/Metric/Metric.h b/src/common/Metric/Metric.h index 5e843139354..5038338421c 100644 --- a/src/common/Metric/Metric.h +++ b/src/common/Metric/Metric.h @@ -90,6 +90,7 @@ private: static std::string FormatInfluxDBValue(char const* value); static std::string FormatInfluxDBValue(double value); static std::string FormatInfluxDBValue(float value); + static std::string FormatInfluxDBValue(std::chrono::nanoseconds value); static std::string FormatInfluxDBTagValue(std::string const& value); @@ -127,6 +128,34 @@ public: #define sMetric Metric::instance() + +template<typename LoggerType> +class MetricStopWatch +{ +public: + MetricStopWatch(LoggerType&& loggerFunc) : + _logger(std::forward<LoggerType>(loggerFunc)), + _startTime(sMetric->IsEnabled() ? std::chrono::steady_clock::now() : TimePoint()) + { + } + + ~MetricStopWatch() + { + if (sMetric->IsEnabled()) + _logger(_startTime); + } + +private: + LoggerType _logger; + TimePoint _startTime; +}; + +template<typename LoggerType> +MetricStopWatch<LoggerType> MakeMetricStopWatch(LoggerType&& loggerFunc) +{ + return { std::forward<LoggerType>(loggerFunc) }; +} + #define TC_METRIC_TAG(name, value) { name, value } #ifdef PERFORMANCE_PROFILING @@ -161,5 +190,10 @@ public: } while (0) \ __pragma(warning(pop)) #endif +#define TC_METRIC_TIMER(category, ...) \ + MetricStopWatch __tc_metric_stop_watch = MakeMetricStopWatch([&](TimePoint start) \ + { \ + sMetric->LogValue(category, std::chrono::steady_clock::now() - start, { __VA_ARGS__ }); \ + }); #endif // METRIC_H__ |