Make util::profiler use the logging system

This commit is contained in:
Nikita Lisitsa 2020-11-29 12:30:02 +03:00
parent 8ea508ee20
commit abd40bfa4d
2 changed files with 18 additions and 8 deletions

View file

@ -1,26 +1,22 @@
#pragma once #pragma once
#include <psemek/util/clock.hpp> #include <psemek/util/clock.hpp>
#include <psemek/util/pretty_print.hpp>
#include <string> #include <string_view>
namespace psemek::util namespace psemek::util
{ {
struct profiler struct profiler
{ {
profiler(std::string name) profiler(std::string_view name)
: name_(std::move(name)) : name_(std::move(name))
{} {}
~ profiler() ~ profiler();
{
std::cout << name_ << ": " << util::pretty(clock_.duration(), std::chrono::microseconds{1}) << "\n";
}
private: private:
std::string const name_; std::string_view const name_;
util::clock<> clock_; util::clock<> clock_;
}; };

View file

@ -0,0 +1,14 @@
#include <psemek/util/profiler.hpp>
#include <psemek/util/pretty_print.hpp>
#include <psemek/log/log.hpp>
namespace psemek::util
{
profiler::~profiler()
{
log::info() << name_ << ": " << util::pretty(clock_.duration(), std::chrono::microseconds{1});
}
}