mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* renamed include guard to be able to use both format lib versions in parallel * build Fmt lib and link it into clib * use std::string instead of format Writer for logging added variant "2" for logging with new fmt lib * use new logging variant for two logs * always add \n to flush log, lets see if the assumption holds * use new lib for tostring * replaced all INFO_PRINTS in clib * formatter for Token, BObject and BObjectImp * started with bsccript * use function instead of actual object for logging * remaining bscript, started plib * logvariant without newline added, more template magic * format support for base types, added test for format padding new version for fdump * chanhed ecompile/runecl fixed compilation with ESCRIPT_PROFILE * rewrite INFO_PRINT in plib,poltool/uoconvert/uotool * replaced remaining INFO_PRINTS, renamed macros INFO_PRINT for logging without newline, INFO_PRINTLN for newline addition. Replaced also INFO_PRINT_TRACE and renamed it to INFO_PRINTLN_TRACE * gitignore for fmt lib * cleanup vim leftovers
79 lines
1.7 KiB
C++
79 lines
1.7 KiB
C++
#include "timer.h"
|
|
|
|
#include "logfacility.h"
|
|
|
|
namespace Pol
|
|
{
|
|
namespace Tools
|
|
{
|
|
void DebugT::print( const std::string& name, long long time )
|
|
{
|
|
INFO_PRINTLN(
|
|
"\n----------------------------------\n"
|
|
"{}: {} ms"
|
|
"\n----------------------------------",
|
|
name, time );
|
|
}
|
|
void SilentT::print( const std::string&, long long ) {}
|
|
|
|
template <class printer>
|
|
Timer<printer>::Timer( std::string name ) : _name( std::move( name ) )
|
|
{
|
|
start();
|
|
}
|
|
template <class printer>
|
|
Timer<printer>::Timer() : _name( "" )
|
|
{
|
|
start();
|
|
}
|
|
template <class printer>
|
|
Timer<printer>::~Timer()
|
|
{
|
|
if ( _start == _end )
|
|
stop();
|
|
printer::print( _name, ellapsed() );
|
|
}
|
|
template <class printer>
|
|
void Timer<printer>::start()
|
|
{
|
|
_start = _end = Clock::now();
|
|
}
|
|
template <class printer>
|
|
void Timer<printer>::stop()
|
|
{
|
|
_end = Clock::now();
|
|
}
|
|
|
|
template <class printer>
|
|
long long Timer<printer>::ellapsed() const
|
|
{
|
|
Clock::time_point _now = Clock::now();
|
|
if ( _start != _end ) // already stopped
|
|
_now = _end;
|
|
return std::chrono::duration_cast<ms>( _now - _start ).count();
|
|
}
|
|
template <class printer>
|
|
double Timer<printer>::ellapsed_s() const
|
|
{
|
|
return ellapsed() * static_cast<double>( ms::period::num ) / ms::period::den;
|
|
}
|
|
template <class printer>
|
|
void Timer<printer>::print() const
|
|
{
|
|
DebugT::print( _name, ellapsed() );
|
|
}
|
|
|
|
|
|
HighPerfTimer::HighPerfTimer() : _start( Clock::now() ) {}
|
|
|
|
HighPerfTimer::time_mu HighPerfTimer::ellapsed() const
|
|
{
|
|
Clock::time_point _now = Clock::now();
|
|
return std::chrono::duration_cast<time_mu>( _now - _start );
|
|
}
|
|
|
|
// forward declarce both versions
|
|
template class Timer<DebugT>;
|
|
template class Timer<SilentT>;
|
|
} // namespace Tools
|
|
} // namespace Pol
|