Skip to content
Snippets Groups Projects
Commit 0499a076 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

debug utils: improve timer

Change-Id: If08a7cd78de2f792baf7f245b7fcc1acdbd33744
parent 52415a8e
No related branches found
No related tags found
No related merge requests found
...@@ -26,16 +26,21 @@ ...@@ -26,16 +26,21 @@
#include "media_io_handle.h" #include "media_io_handle.h"
#include "system_codec_container.h" #include "system_codec_container.h"
#include <opendht/utils.h>
#include <chrono> #include <chrono>
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
#include <ios> #include <ios>
#include <ratio> #include <ratio>
#include <string_view>
#include "logger.h" #include "logger.h"
#warning Debug utilities included in build #warning Debug utilities included in build
using Clock = std::chrono::steady_clock; using Clock = std::chrono::steady_clock;
using namespace std::literals;
namespace jami { namespace jami {
namespace debug { namespace debug {
...@@ -49,16 +54,25 @@ namespace debug { ...@@ -49,16 +54,25 @@ namespace debug {
class Timer class Timer
{ {
public: 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>> template<class Period = std::ratio<1>>
uint64_t getDuration() uint64_t getDuration() const
{ {
auto diff = std::chrono::duration_cast<Period>(Clock::now() - start_); auto diff = std::chrono::duration_cast<Period>(Clock::now() - start_);
return diff.count(); return diff.count();
} }
void print(std::string_view action) const {
JAMI_DBG() << name_ << ": " << action << " after " << dht::print_duration(Clock::now() - start_);
}
private: private:
std::string_view name_;
std::chrono::time_point<Clock> start_; std::chrono::time_point<Clock> start_;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment