loader: wrap elapsed time in Timer::GetTime (#679)

loader: format elapsed log timestamps beyond 24 hours

Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
Saadi
2026-09-24 19:02:19 +01:00
committed by GitHub
parent 96874909ab
commit b9a0bd2791
5 changed files with 11 additions and 25 deletions
+1 -10
View File
@@ -38,16 +38,7 @@ bool Timer::IsPaused() const {
// return time in milliseconds // return time in milliseconds
double Timer::GetTimeMs() const { double Timer::GetTimeMs() const {
if (m_is_paused) { return GetTimeS() * 1000.0;
return 1000.0 * (static_cast<double>(m_PauseTime - m_StartTime)) /
static_cast<double>(m_Frequency);
}
uint64_t current_time = 0;
SysQueryPerformanceCounter(&current_time);
return 1000.0 * (static_cast<double>(current_time - m_StartTime)) /
static_cast<double>(m_Frequency);
} }
// return time in seconds // return time in seconds
+6 -1
View File
@@ -7,6 +7,8 @@
#include "common/threads.h" #include "common/threads.h"
#include "loader/timer.h" // IWYU pragma: keep #include "loader/timer.h" // IWYU pragma: keep
#include <fmt/format.h>
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define PRINT_NAME_ENABLED g_print_name #define PRINT_NAME_ENABLED g_print_name
@@ -50,7 +52,10 @@
#define PRINT_NAME() \ #define PRINT_NAME() \
if (PRINT_NAME_ENABLED) { \ if (PRINT_NAME_ENABLED) { \
if (Log::GetDirection() != Log::Direction::Silent) { \ if (Log::GetDirection() != Log::Direction::Silent) { \
const auto print_name_time = Loader::Timer::GetTime().ToString("HH24:MI:SS.FFF"); \ const auto elapsed_ms = static_cast<uint64_t>(Loader::Timer::GetTimeMs()); \
const auto print_name_time = fmt::format( \
"{:02}:{:02}:{:02}.{:03}", elapsed_ms / 3600000, (elapsed_ms / 60000) % 60, \
(elapsed_ms / 1000) % 60, elapsed_ms % 1000); \
LOGF_COLOR(Log::Color::Cyan, "[%d][%s] %s::%s::%s()\n", \ LOGF_COLOR(Log::Color::Cyan, "[%d][%s] %s::%s::%s()\n", \
Common::Thread::GetThreadIdUnique(), print_name_time.c_str(), g_library, \ Common::Thread::GetThreadIdUnique(), print_name_time.c_str(), g_library, \
g_module, __func__); \ g_module, __func__); \
-6
View File
@@ -1,7 +1,5 @@
#include "common/timer.h" #include "common/timer.h"
#include "common/abi.h"
#include "common/dateTime.h"
#include "loader/timer.h" #include "loader/timer.h"
namespace Loader::Timer { namespace Loader::Timer {
@@ -16,8 +14,4 @@ double GetTimeMs() {
return g_timer.GetTimeMs(); return g_timer.GetTimeMs();
} }
Common::Time GetTime() {
return Common::Time(static_cast<int>(GetTimeMs()));
}
} // namespace Loader::Timer } // namespace Loader::Timer
+2 -6
View File
@@ -1,14 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_LOADER_TIMER_H_ #ifndef EMULATOR_INCLUDE_EMULATOR_LOADER_TIMER_H_
#define EMULATOR_INCLUDE_EMULATOR_LOADER_TIMER_H_ #define EMULATOR_INCLUDE_EMULATOR_LOADER_TIMER_H_
#include "common/abi.h"
#include "common/common.h"
#include "common/dateTime.h"
namespace Loader::Timer { namespace Loader::Timer {
void Start(); void Start();
double GetTimeMs(); double GetTimeMs();
Common::Time GetTime();
struct Lifecycle { struct Lifecycle {
static constexpr const char* name = "Timer"; static constexpr const char* name = "Timer";
+2 -2
View File
@@ -27,8 +27,8 @@ bool SystemContentParamSfoGetString(const char*, std::string* value) {
} }
void SymbolDatabase::Add(const SymbolResolve&, uint64_t, const std::string&) {} void SymbolDatabase::Add(const SymbolResolve&, uint64_t, const std::string&) {}
namespace Timer { namespace Timer {
Common::Time GetTime() { double GetTimeMs() {
return Common::Time(0); return 0.0;
} }
} // namespace Timer } // namespace Timer
} // namespace Loader } // namespace Loader