1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Fix thread time/cycles report with respect to thread pool

Fix all RUSAGE stats as well (POSIX)
This commit is contained in:
Nekotekina 2021-08-01 09:40:42 +03:00
parent 286e154d05
commit 5ba8daf518

View File

@ -1993,24 +1993,35 @@ u64 thread_base::finalize(thread_state result_state) noexcept
error_code::error_report(0, 0, 0, 0); error_code::error_report(0, 0, 0, 0);
#ifdef _WIN32 #ifdef _WIN32
static thread_local ULONG64 tls_cycles{};
static thread_local u64 tls_time{};
ULONG64 cycles{}; ULONG64 cycles{};
QueryThreadCycleTime(GetCurrentThread(), &cycles); QueryThreadCycleTime(GetCurrentThread(), &cycles);
cycles -= tls_cycles;
tls_cycles += cycles;
FILETIME ctime, etime, ktime, utime; FILETIME ctime, etime, ktime, utime;
GetThreadTimes(GetCurrentThread(), &ctime, &etime, &ktime, &utime); GetThreadTimes(GetCurrentThread(), &ctime, &etime, &ktime, &utime);
const u64 time = ((ktime.dwLowDateTime | (u64)ktime.dwHighDateTime << 32) + (utime.dwLowDateTime | (u64)utime.dwHighDateTime << 32)) * 100ull; const u64 time = ((ktime.dwLowDateTime | (u64)ktime.dwHighDateTime << 32) + (utime.dwLowDateTime | (u64)utime.dwHighDateTime << 32)) * 100ull - tls_time;
tls_time += time;
const u64 fsoft = 0; const u64 fsoft = 0;
const u64 fhard = 0; const u64 fhard = 0;
const u64 ctxvol = 0; const u64 ctxvol = 0;
const u64 ctxinv = 0; const u64 ctxinv = 0;
#elif defined(RUSAGE_THREAD) #elif defined(RUSAGE_THREAD)
static thread_local u64 tls_time{}, tls_fsoft{}, tls_fhard{}, tls_ctxvol{}, tls_ctxinv{};
const u64 cycles = 0; // Not supported const u64 cycles = 0; // Not supported
struct ::rusage stats{}; struct ::rusage stats{};
::getrusage(RUSAGE_THREAD, &stats); ::getrusage(RUSAGE_THREAD, &stats);
const u64 time = (stats.ru_utime.tv_sec + stats.ru_stime.tv_sec) * 1000000000ull + (stats.ru_utime.tv_usec + stats.ru_stime.tv_usec) * 1000ull; const u64 time = (stats.ru_utime.tv_sec + stats.ru_stime.tv_sec) * 1000000000ull + (stats.ru_utime.tv_usec + stats.ru_stime.tv_usec) * 1000ull - tls_time;
const u64 fsoft = stats.ru_minflt; tls_time += time;
const u64 fhard = stats.ru_majflt; const u64 fsoft = stats.ru_minflt - tls_fsoft;
const u64 ctxvol = stats.ru_nvcsw; tls_fsoft += fsoft;
const u64 ctxinv = stats.ru_nivcsw; const u64 fhard = stats.ru_majflt - tls_fhard;
tls_fhard += fhard;
const u64 ctxvol = stats.ru_nvcsw - tls_ctxvol;
tls_ctxvol += ctxvol;
const u64 ctxinv = stats.ru_nivcsw - tls_ctxinv;
tls_ctxinv += ctxinv;
#else #else
const u64 cycles = 0; const u64 cycles = 0;
const u64 time = 0; const u64 time = 0;