From 0499a076f110c31943e05c58aa2a51d5367c436e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 30 Mar 2021 10:23:59 -0400 Subject: [PATCH] debug utils: improve timer Change-Id: If08a7cd78de2f792baf7f245b7fcc1acdbd33744 --- src/debug_utils.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/debug_utils.h b/src/debug_utils.h index c69b25b28a..7ade0781ce 100644 --- a/src/debug_utils.h +++ b/src/debug_utils.h @@ -26,16 +26,21 @@ #include "media_io_handle.h" #include "system_codec_container.h" +#include <opendht/utils.h> + #include <chrono> #include <cstdio> #include <fstream> #include <ios> #include <ratio> +#include <string_view> + #include "logger.h" #warning Debug utilities included in build using Clock = std::chrono::steady_clock; +using namespace std::literals; namespace jami { namespace debug { @@ -49,16 +54,25 @@ namespace debug { class Timer { public: - Timer() { start_ = Clock::now(); } + Timer(std::string_view name) : name_(name), start_(Clock::now()) {} + + ~Timer() { + print("end"sv); + } template<class Period = std::ratio<1>> - uint64_t getDuration() + uint64_t getDuration() const { auto diff = std::chrono::duration_cast<Period>(Clock::now() - start_); return diff.count(); } + void print(std::string_view action) const { + JAMI_DBG() << name_ << ": " << action << " after " << dht::print_duration(Clock::now() - start_); + } + private: + std::string_view name_; std::chrono::time_point<Clock> start_; }; -- GitLab