mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-04-16 03:46:54 -04:00
Using <chrono> to measure time in the LogManager
`clock()`, which was used previously, behaves differently on various platform. So switching to this lets us use a standard part of the language which avoids this. Signed-off-by: B Horn <b@horn.uk>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
@@ -13,7 +13,7 @@ static const char* log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "[ver
|
||||
|
||||
LogManager::LogManager()
|
||||
{
|
||||
base_clock = clock();
|
||||
base_clock = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
LogManager* LogManager::get()
|
||||
@@ -136,8 +136,8 @@ void LogManager::_flush()
|
||||
if(temp_messages[msg]->level <= loglevel)
|
||||
{
|
||||
// Put the timestamp here
|
||||
clock_t counter = temp_messages[msg]->counted_second;
|
||||
log_stream << std::left << std::setw(6) << counter/ ( CLOCKS_PER_SEC / 1000 ) << "|";
|
||||
std::chrono::milliseconds counter = std::chrono::duration_cast<std::chrono::milliseconds>(temp_messages[msg]->counted_second);
|
||||
log_stream << std::left << std::setw(6) << counter.count() << "|";
|
||||
log_stream << std::left << std::setw(9) << log_codes[temp_messages[msg]->level];
|
||||
log_stream << temp_messages[msg]->buffer;
|
||||
|
||||
@@ -202,7 +202,7 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
||||
mes->level = level;
|
||||
mes->filename = filename;
|
||||
mes->line = line;
|
||||
mes->counted_second = clock() - base_clock;
|
||||
mes->counted_second = std::chrono::steady_clock::now() - base_clock;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the message is within the current verbosity, |
|
||||
|
||||
Reference in New Issue
Block a user