mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 14:01:25 +12:00
Log timestamp added
This commit is contained in:
parent
47fdaf6902
commit
f08579d201
3 changed files with 53 additions and 6 deletions
|
@ -5,6 +5,12 @@
|
||||||
#include "rpcs3_version.h"
|
#include "rpcs3_version.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <Windows.h>
|
||||||
|
#else
|
||||||
|
#include <chrono>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Thread-specific log prefix provider
|
// Thread-specific log prefix provider
|
||||||
thread_local std::string(*g_tls_log_prefix)() = nullptr;
|
thread_local std::string(*g_tls_log_prefix)() = nullptr;
|
||||||
|
|
||||||
|
@ -56,7 +62,7 @@ namespace logs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode level, current thread name, channel name and write log message
|
// Encode level, current thread name, channel name and write log message
|
||||||
virtual void log(const message& msg, const std::string& prefix, const std::string& text) override;
|
virtual void log(u64 stamp, const message& msg, const std::string& prefix, const std::string& text) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
static file_listener* get_logger()
|
static file_listener* get_logger()
|
||||||
|
@ -66,6 +72,39 @@ namespace logs
|
||||||
return &logger;
|
return &logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u64 get_stamp()
|
||||||
|
{
|
||||||
|
static struct time_initializer
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
LARGE_INTEGER freq;
|
||||||
|
LARGE_INTEGER start;
|
||||||
|
|
||||||
|
time_initializer()
|
||||||
|
{
|
||||||
|
QueryPerformanceFrequency(&freq);
|
||||||
|
QueryPerformanceCounter(&start);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
u64 get() const
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
LARGE_INTEGER now;
|
||||||
|
QueryPerformanceCounter(&now);
|
||||||
|
const LONGLONG diff = now.QuadPart - start.QuadPart;
|
||||||
|
return diff / freq.QuadPart * 1'000'000 + diff % freq.QuadPart * 1'000'000 / freq.QuadPart;
|
||||||
|
#else
|
||||||
|
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} timebase{};
|
||||||
|
|
||||||
|
return timebase.get();
|
||||||
|
}
|
||||||
|
|
||||||
channel GENERAL(nullptr, level::notice);
|
channel GENERAL(nullptr, level::notice);
|
||||||
channel LOADER("LDR", level::notice);
|
channel LOADER("LDR", level::notice);
|
||||||
channel MEMORY("MEM", level::notice);
|
channel MEMORY("MEM", level::notice);
|
||||||
|
@ -94,6 +133,9 @@ void logs::listener::add(logs::listener* _new)
|
||||||
|
|
||||||
void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, const u64* args)
|
void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, const u64* args)
|
||||||
{
|
{
|
||||||
|
// Get timestamp
|
||||||
|
const u64 stamp = get_stamp();
|
||||||
|
|
||||||
std::string text; fmt::raw_append(text, fmt, sup, args);
|
std::string text; fmt::raw_append(text, fmt, sup, args);
|
||||||
std::string prefix(g_tls_log_prefix ? g_tls_log_prefix() : "");
|
std::string prefix(g_tls_log_prefix ? g_tls_log_prefix() : "");
|
||||||
|
|
||||||
|
@ -103,7 +145,7 @@ void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, const u
|
||||||
// Send message to all listeners
|
// Send message to all listeners
|
||||||
while (lis)
|
while (lis)
|
||||||
{
|
{
|
||||||
lis->log(*this, prefix, text);
|
lis->log(stamp, *this, prefix, text);
|
||||||
lis = lis->m_next;
|
lis = lis->m_next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +172,7 @@ void logs::file_writer::log(const char* text, std::size_t size)
|
||||||
m_file.write(text, size);
|
m_file.write(text, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logs::file_listener::log(const logs::message& msg, const std::string& prefix, const std::string& _text)
|
void logs::file_listener::log(u64 stamp, const logs::message& msg, const std::string& prefix, const std::string& _text)
|
||||||
{
|
{
|
||||||
std::string text; text.reserve(prefix.size() + _text.size() + 200);
|
std::string text; text.reserve(prefix.size() + _text.size() + 200);
|
||||||
|
|
||||||
|
@ -147,7 +189,12 @@ void logs::file_listener::log(const logs::message& msg, const std::string& prefi
|
||||||
case level::trace: text = u8"·T "; break;
|
case level::trace: text = u8"·T "; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: print time?
|
// Print miscosecond timestamp
|
||||||
|
const u64 hours = stamp / 3600'000'000;
|
||||||
|
const u64 mins = (stamp % 3600'000'000) / 60'000'000;
|
||||||
|
const u64 secs = (stamp % 60'000'000) / 1'000'000;
|
||||||
|
const u64 frac = (stamp % 1'000'000);
|
||||||
|
fmt::append(text, "%u:%02u:%02u.%06u ", hours, mins, secs, frac);
|
||||||
|
|
||||||
if (prefix.size() > 0)
|
if (prefix.size() > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace logs
|
||||||
virtual ~listener();
|
virtual ~listener();
|
||||||
|
|
||||||
// Process log message
|
// Process log message
|
||||||
virtual void log(const message& msg, const std::string& prefix, const std::string& text) = 0;
|
virtual void log(u64 stamp, const message& msg, const std::string& prefix, const std::string& text) = 0;
|
||||||
|
|
||||||
// Add new listener
|
// Add new listener
|
||||||
static void add(listener*);
|
static void add(listener*);
|
||||||
|
|
|
@ -46,7 +46,7 @@ struct gui_listener : logs::listener
|
||||||
delete read;
|
delete read;
|
||||||
}
|
}
|
||||||
|
|
||||||
void log(const logs::message& msg, const std::string& prefix, const std::string& text)
|
void log(u64 stamp, const logs::message& msg, const std::string& prefix, const std::string& text)
|
||||||
{
|
{
|
||||||
if (msg.sev <= enabled)
|
if (msg.sev <= enabled)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue