Common: Fix Darwin thread times

Percentages will now actually be percentages instead of permille (units of 1/1000)
Was caused by trying to match Windows's returns of 100ns units, but then reporting 1µs units from `GetThreadTicksPerSecond()`
This commit is contained in:
tellowkrinkle 2021-11-04 21:46:39 -05:00
parent 1e5f1de12c
commit 37e2142cca
1 changed files with 3 additions and 7 deletions

View File

@ -82,11 +82,7 @@ static u64 getthreadtime(thread_port_t thread)
(u64)info.system_time.microseconds; (u64)info.system_time.microseconds;
} }
// Returns the current timestamp (not relative to a real world clock) in // Returns the current timestamp (not relative to a real world clock) in microseconds
// units of 100 nanoseconds. The weird units are to mirror the Windows
// counterpart in WinThreads.cpp, which uses the GetThreadTimes() API. On
// OSX/Darwin, this is only accurate up until 1ms (and possibly less), so
// not very good.
u64 Threading::GetThreadCpuTime() u64 Threading::GetThreadCpuTime()
{ {
// we could also use mach_thread_self() and mach_port_deallocate(), but // we could also use mach_thread_self() and mach_port_deallocate(), but
@ -95,7 +91,7 @@ u64 Threading::GetThreadCpuTime()
// to be user-space instead. In contract, // to be user-space instead. In contract,
// pthread_mach_thread_np(pthread_self()) is entirely in user-space. // pthread_mach_thread_np(pthread_self()) is entirely in user-space.
u64 us = getthreadtime(pthread_mach_thread_np(pthread_self())); u64 us = getthreadtime(pthread_mach_thread_np(pthread_self()));
return us * 10ULL; return us;
} }
u64 Threading::pxThread::GetCpuTime() const u64 Threading::pxThread::GetCpuTime() const
@ -109,7 +105,7 @@ u64 Threading::pxThread::GetCpuTime() const
return 0; return 0;
} }
return getthreadtime((thread_port_t)m_native_id) * 10ULL; return getthreadtime((thread_port_t)m_native_id);
} }
void Threading::pxThread::_platform_specific_OnStartInThread() void Threading::pxThread::_platform_specific_OnStartInThread()