log: add scoped timer
This commit is contained in:
parent
ea953ec024
commit
8738192476
20
log.cpp
20
log.cpp
@ -19,6 +19,7 @@
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "types.hpp"
|
||||
#include "time.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <ctime>
|
||||
@ -158,3 +159,22 @@ scoped_logger::~scoped_logger ()
|
||||
{
|
||||
log (m_level, m_message);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
scoped_timer::scoped_timer (level_t _level,
|
||||
std::string &&_message):
|
||||
m_level (_level),
|
||||
m_message (_message),
|
||||
m_start (util::nanoseconds ())
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
scoped_timer::~scoped_timer ()
|
||||
{
|
||||
auto finish = util::nanoseconds ();
|
||||
auto duration = finish - m_start;
|
||||
|
||||
log (m_level, "%fs, %s", duration / 1'000'000'000.f, m_message);
|
||||
}
|
||||
|
12
log.hpp
12
log.hpp
@ -87,6 +87,18 @@ namespace util {
|
||||
std::string m_message;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class scoped_timer : public nocopy {
|
||||
public:
|
||||
scoped_timer (const level_t, std::string&&);
|
||||
~scoped_timer ();
|
||||
|
||||
private:
|
||||
const level_t m_level;
|
||||
const std::string m_message;
|
||||
uint64_t m_start;
|
||||
};
|
||||
}
|
||||
|
||||
#include "log.ipp"
|
||||
|
Loading…
Reference in New Issue
Block a user