rpcsx/rpcs3/util/cpu_stats.hpp

41 lines
745 B
C++
Raw Normal View History

2021-02-23 11:52:07 +01:00
#pragma once
#include "util/types.hpp"
2023-01-10 20:30:03 +01:00
#include <vector>
2021-02-23 11:52:07 +01:00
2022-03-11 21:08:44 +01:00
#ifdef _WIN32
#include <pdh.h>
#include <pdhmsg.h>
#endif
2021-02-23 11:52:07 +01:00
namespace utils
{
class cpu_stats
{
2022-03-11 21:08:44 +01:00
u64 m_last_cpu = 0;
u64 m_sys_cpu = 0;
u64 m_usr_cpu = 0;
#ifdef _WIN32
PDH_HQUERY m_cpu_query = nullptr;
PDH_HCOUNTER m_cpu_cores = nullptr;
#elif __linux__
size_t m_previous_idle_time_total = 0;
size_t m_previous_total_time_total = 0;
std::vector<size_t> m_previous_idle_times_per_cpu;
std::vector<size_t> m_previous_total_times_per_cpu;
#endif
2021-02-23 11:52:07 +01:00
public:
cpu_stats();
~cpu_stats();
2021-02-23 11:52:07 +01:00
double get_usage();
2022-03-11 21:08:44 +01:00
void init_cpu_query();
void get_per_core_usage(std::vector<double>& per_core_usage, double& total_usage);
static u32 get_current_thread_count();
2021-02-23 11:52:07 +01:00
};
}