Common: Remove ThreadCPUTimer as it's unused now

This commit is contained in:
Connor McLaughlin 2022-05-02 16:07:36 +10:00 committed by refractionpcsx2
parent 4bdf180145
commit 6a6ecbf826
2 changed files with 0 additions and 235 deletions

View File

@ -21,23 +21,13 @@
#if defined(_WIN32)
#include "RedtapeWindows.h"
#include "Threading.h"
#elif defined(__APPLE__)
#include <mach/mach_init.h>
#include <mach/thread_act.h>
#include <mach/mach_port.h>
#else
#include <pthread.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#endif
namespace Common
{
#ifdef _WIN32
static double s_counter_frequency;
static bool s_counter_initialized = false;
@ -86,9 +76,7 @@ namespace Common
{
return static_cast<Value>(ns * s_counter_frequency);
}
#else
Timer::Value Timer::GetCurrentValue()
{
struct timespec tv;
@ -125,7 +113,6 @@ namespace Common
{
return static_cast<Value>(ns);
}
#endif
Timer::Timer()
@ -176,184 +163,4 @@ namespace Common
m_tvStartValue = value;
return ret;
}
ThreadCPUTimer::ThreadCPUTimer() = default;
ThreadCPUTimer::ThreadCPUTimer(ThreadCPUTimer&& move)
: m_thread_handle(move.m_thread_handle)
{
move.m_thread_handle = nullptr;
}
ThreadCPUTimer::~ThreadCPUTimer()
{
#ifdef _WIN32
if (m_thread_handle)
CloseHandle(reinterpret_cast<HANDLE>(m_thread_handle));
#endif
}
ThreadCPUTimer& ThreadCPUTimer::operator=(ThreadCPUTimer&& move)
{
#ifdef _WIN32
if (m_thread_handle)
CloseHandle(reinterpret_cast<HANDLE>(m_thread_handle));
#endif
m_thread_handle = move.m_thread_handle;
move.m_thread_handle = nullptr;
return *this;
}
void ThreadCPUTimer::Reset()
{
m_start_value = GetCurrentValue();
}
ThreadCPUTimer::Value ThreadCPUTimer::GetCurrentValue() const
{
#if defined(_WIN32)
ULONG64 ret = 0;
QueryThreadCycleTime((HANDLE)m_thread_handle, &ret);
return ret;
#elif defined(__APPLE__)
thread_basic_info_data_t info;
mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
const kern_return_t kr = thread_info((mach_port_t) reinterpret_cast<uintptr_t>(m_thread_handle), THREAD_BASIC_INFO, (thread_info_t)&info, &count);
if (kr != KERN_SUCCESS)
return 0;
Value value = (static_cast<Value>(info.user_time.seconds) * 1000000) + (static_cast<Value>(info.user_time.microseconds));
value += (static_cast<Value>(info.system_time.seconds) * 1000000) + (static_cast<Value>(info.system_time.microseconds));
return value;
#else
clockid_t cid;
if (!m_thread_handle || pthread_getcpuclockid((pthread_t)m_thread_handle, &cid) != 0)
return 0;
struct timespec ts;
if (clock_gettime(cid, &ts) != 0)
return 0;
return (static_cast<Value>(ts.tv_nsec) + static_cast<Value>(ts.tv_sec) * 1000000000LL);
#endif
}
double ThreadCPUTimer::GetTimeSeconds() const
{
return ConvertValueToSeconds(GetCurrentValue() - m_start_value);
}
double ThreadCPUTimer::GetTimeMilliseconds() const
{
return ConvertValueToMilliseconds(GetCurrentValue() - m_start_value);
}
double ThreadCPUTimer::GetTimeNanoseconds() const
{
return ConvertValueToNanoseconds(GetCurrentValue() - m_start_value);
}
void ThreadCPUTimer::GetUsageInSecondsAndReset(Value time_diff, double* usage_time, double* usage_percent)
{
const Value new_value = GetCurrentValue();
const Value diff = new_value - m_start_value;
m_start_value = new_value;
*usage_time = ConvertValueToSeconds(diff);
*usage_percent = GetUtilizationPercentage(time_diff, diff);
}
void ThreadCPUTimer::GetUsageInMillisecondsAndReset(Value time_diff, double* usage_time, double* usage_percent)
{
const Value new_value = GetCurrentValue();
const Value diff = new_value - m_start_value;
m_start_value = new_value;
*usage_time = ConvertValueToMilliseconds(diff);
*usage_percent = GetUtilizationPercentage(time_diff, diff);
}
void ThreadCPUTimer::GetUsageInNanosecondsAndReset(Value time_diff, double* usage_time, double* usage_percent)
{
const Value new_value = GetCurrentValue();
const Value diff = new_value - m_start_value;
m_start_value = new_value;
*usage_time = ConvertValueToNanoseconds(diff);
*usage_percent = GetUtilizationPercentage(time_diff, diff);
}
double ThreadCPUTimer::GetUtilizationPercentage(Timer::Value time_diff, Value cpu_time_diff)
{
#if defined(_WIN32)
// we need to convert from the rdtsc domain to the QPC domain (may not necessarily match)
static bool ratio_initialized = false;
static double ratio = 0.0;
if (unlikely(!ratio_initialized))
{
ratio = (static_cast<double>(Threading::GetThreadTicksPerSecond()) / static_cast<double>(GetTickFrequency())) / 100.0;
ratio_initialized = true;
}
return (static_cast<double>(cpu_time_diff) / (static_cast<double>(time_diff) * ratio));
#elif defined(__APPLE__)
// microseconds, but time_tiff is in nanoseconds, so multiply by 1000 * 100
return (static_cast<double>(cpu_time_diff) * 100000.0) / static_cast<double>(time_diff);
#else
// nanoseconds
return (static_cast<double>(cpu_time_diff) * 100.0) / static_cast<double>(time_diff);
#endif
}
double ThreadCPUTimer::ConvertValueToSeconds(Value value)
{
#if defined(_WIN32)
return (static_cast<double>(value) / Threading::GetThreadTicksPerSecond());
#elif defined(__APPLE__)
// microseconds
return (static_cast<double>(value) / 1000000.0);
#else
// nanoseconds
return (static_cast<double>(value) / 1000000000.0);
#endif
}
double ThreadCPUTimer::ConvertValueToMilliseconds(Value value)
{
#if defined(_WIN32)
return (static_cast<double>(value) / (Threading::GetThreadTicksPerSecond() / 1000.0));
#elif defined(__APPLE__)
return (static_cast<double>(value) / 1000.0);
#else
return (static_cast<double>(value) / 1000000.0);
#endif
}
double ThreadCPUTimer::ConvertValueToNanoseconds(Value value)
{
#if defined(_WIN32)
return (static_cast<double>(value) / (Threading::GetThreadTicksPerSecond() / 1000000000.0));
#elif defined(__APPLE__)
return (static_cast<double>(value) * 1000.0);
#else
return static_cast<double>(value);
#endif
}
ThreadCPUTimer ThreadCPUTimer::GetForCallingThread()
{
ThreadCPUTimer ret;
#if defined(_WIN32)
ret.m_thread_handle = (void*)OpenThread(THREAD_QUERY_INFORMATION, FALSE, GetCurrentThreadId());
#elif defined(__APPLE__)
ret.m_thread_handle = reinterpret_cast<void*>((uintptr_t)mach_thread_self());
#else
ret.m_thread_handle = (void*)pthread_self();
#endif
ret.Reset();
return ret;
}
} // namespace Common

View File

@ -18,7 +18,6 @@
namespace Common
{
class Timer
{
public:
@ -50,45 +49,4 @@ namespace Common
private:
Value m_tvStartValue;
};
class ThreadCPUTimer
{
public:
using Value = std::uint64_t;
ThreadCPUTimer();
ThreadCPUTimer(ThreadCPUTimer&& move);
ThreadCPUTimer(const ThreadCPUTimer&) = delete;
~ThreadCPUTimer();
void Reset();
void ResetTo(Value value) { m_start_value = value; }
Value GetStartValue() const { return m_start_value; }
Value GetCurrentValue() const;
double GetTimeSeconds() const;
double GetTimeMilliseconds() const;
double GetTimeNanoseconds() const;
void GetUsageInSecondsAndReset(Value time_diff, double* usage_time, double* usage_percent);
void GetUsageInMillisecondsAndReset(Value time_diff, double* usage_time, double* usage_percent);
void GetUsageInNanosecondsAndReset(Value time_diff, double* usage_time, double* usage_percent);
static double GetUtilizationPercentage(Timer::Value time_diff, Value cpu_time_diff);
static double ConvertValueToSeconds(Value value);
static double ConvertValueToMilliseconds(Value value);
static double ConvertValueToNanoseconds(Value value);
static ThreadCPUTimer GetForCallingThread();
ThreadCPUTimer& operator=(const ThreadCPUTimer&) = delete;
ThreadCPUTimer& operator=(ThreadCPUTimer&& move);
private:
void* m_thread_handle = nullptr;
Value m_start_value = 0;
};
} // namespace Common