52 lines
952 B
C++
52 lines
952 B
C++
|
|
#include "utils.h"
|
|
#include <chrono>
|
|
|
|
typedef struct {
|
|
std::chrono::time_point<std::chrono::system_clock> start;
|
|
} timer;
|
|
|
|
|
|
|
|
static int _log_level = LOG_INFO;
|
|
static timer *_timer = nullptr;
|
|
|
|
|
|
|
|
int logLevel()
|
|
{
|
|
return _log_level;
|
|
}
|
|
|
|
void setLogLevel(int l)
|
|
{
|
|
_log_level = l;
|
|
}
|
|
|
|
const char *logIndicator(int l)
|
|
{
|
|
switch(l) {
|
|
case LOG_ERROR: return "ERROR ";
|
|
case LOG_INFO: return "INFO ";
|
|
case LOG_DEBUG: return "DEBUG ";
|
|
case LOG_WARNING: return "WARNING";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
void logElapsed()
|
|
{
|
|
if (_timer == nullptr) {
|
|
_timer = new timer;
|
|
_timer->start = std::chrono::system_clock::now();
|
|
}
|
|
|
|
auto c = std::chrono::system_clock::now();
|
|
auto duration = c - _timer->start;
|
|
auto milliseconds
|
|
= std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
duration)
|
|
.count();
|
|
fprintf(stderr, "%8.3lf: ", milliseconds/ 1000.0);
|
|
}
|