mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Performance optimizations for large unit counts
This commit is contained in:
@@ -3,4 +3,4 @@
|
||||
|
||||
void DllExport log(const std::string& sMessage);
|
||||
void DllExport log(const std::wstring& sMessage);
|
||||
void DllExport getLogsJSON(json::value& json, unsigned int logsNumber = NULL);
|
||||
void DllExport getLogsJSON(json::value& json, unsigned long long time);
|
||||
|
||||
@@ -7,7 +7,7 @@ class Logger
|
||||
public:
|
||||
void log(const string& sMessage);
|
||||
void log(const wstring& sMessage);
|
||||
void toJSON(json::value& json, unsigned int logsNumber = NULL);
|
||||
void toJSON(json::value& json, unsigned long long time);
|
||||
|
||||
static Logger* GetLogger();
|
||||
|
||||
@@ -19,7 +19,7 @@ private:
|
||||
static const string m_sFileName;
|
||||
static Logger* m_pThis;
|
||||
static ofstream m_Logfile;
|
||||
static std::list<std::string> m_logs;
|
||||
static std::map<unsigned long long, std::string> m_logs;
|
||||
|
||||
mutex mutexLock;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ void log(const wstring& message)
|
||||
LOGGER->log(message);
|
||||
}
|
||||
|
||||
void getLogsJSON(json::value& json, unsigned int logsNumber)
|
||||
void getLogsJSON(json::value& json, unsigned long long time)
|
||||
{
|
||||
LOGGER->toJSON(json, logsNumber);
|
||||
LOGGER->toJSON(json, time);
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "logger.h"
|
||||
#include "utils.h"
|
||||
#include "defines.h"
|
||||
#include <chrono>
|
||||
using namespace std::chrono;
|
||||
|
||||
const string Logger::m_sFileName = LOG_NAME;
|
||||
Logger* Logger::m_pThis = NULL;
|
||||
ofstream Logger::m_Logfile;
|
||||
std::list<std::string> Logger::m_logs;
|
||||
std::map<unsigned long long, std::string> Logger::m_logs;
|
||||
|
||||
Logger::Logger()
|
||||
{
|
||||
@@ -32,15 +34,18 @@ void Logger::Close()
|
||||
m_Logfile.close();
|
||||
}
|
||||
|
||||
void Logger::toJSON(json::value& json, unsigned int logsNumber)
|
||||
void Logger::toJSON(json::value& json, unsigned long long time)
|
||||
{
|
||||
lock_guard<mutex> guard(mutexLock);
|
||||
unsigned int i = 0;
|
||||
for (auto itr = m_logs.end(); itr != m_logs.begin(); --itr)
|
||||
json[L"requestTime"] = time;
|
||||
|
||||
/* Loop on the logs in reverse since we are usually only interested in the very last added logs */
|
||||
auto itr = m_logs.end();
|
||||
while (itr != m_logs.begin())
|
||||
{
|
||||
json[to_wstring(m_logs.size() - 1 - i)] = json::value::string(to_wstring(*itr));
|
||||
if (logsNumber != 0 && i > logsNumber)
|
||||
break;
|
||||
--itr;
|
||||
if (itr->first < time) return;
|
||||
json[to_wstring(itr->first)] = json::value::string(to_wstring(itr->second));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +53,10 @@ void Logger::log(const string& message)
|
||||
{
|
||||
lock_guard<mutex> guard(mutexLock);
|
||||
Open();
|
||||
milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
|
||||
m_Logfile << CurrentDateTime() << ":\t";
|
||||
m_Logfile << message << "\n";
|
||||
m_logs.push_back(CurrentDateTime() + ": " + message);
|
||||
m_logs[static_cast<unsigned long long>(ms.count())] = CurrentDateTime() + ": " + message;
|
||||
Close();
|
||||
}
|
||||
|
||||
@@ -58,8 +64,9 @@ void Logger::log(const wstring& message)
|
||||
{
|
||||
lock_guard<mutex> guard(mutexLock);
|
||||
Open();
|
||||
milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
|
||||
m_Logfile << CurrentDateTime() << ":\t";
|
||||
m_Logfile << to_string(message) << "\n";
|
||||
m_logs.push_back(CurrentDateTime() + ": " + to_string(message));
|
||||
m_logs[static_cast<unsigned long long>(ms.count())] = CurrentDateTime() + ": " + to_string(message);
|
||||
Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user