mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-25 20:22:30 +01:00
Move CPUStats.h -> util/cpu_stats.cpp
This commit is contained in:
parent
090a769bf6
commit
cd01a1eb09
@ -40,6 +40,7 @@ target_sources(rpcs3_emu PRIVATE
|
|||||||
../util/vm_native.cpp
|
../util/vm_native.cpp
|
||||||
../util/dyn_lib.cpp
|
../util/dyn_lib.cpp
|
||||||
../util/sysinfo.cpp
|
../util/sysinfo.cpp
|
||||||
|
../util/cpu_stats.cpp
|
||||||
../../Utilities/bin_patch.cpp
|
../../Utilities/bin_patch.cpp
|
||||||
../../Utilities/cheat_info.cpp
|
../../Utilities/cheat_info.cpp
|
||||||
../../Utilities/cond.cpp
|
../../Utilities/cond.cpp
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <charconv>
|
#include <charconv>
|
||||||
|
|
||||||
#include "util/sysinfo.hpp"
|
#include "util/sysinfo.hpp"
|
||||||
|
#include "util/cpu_stats.hpp"
|
||||||
|
|
||||||
namespace rsx
|
namespace rsx
|
||||||
{
|
{
|
||||||
@ -423,7 +424,7 @@ namespace rsx
|
|||||||
|
|
||||||
m_rsx_load = rsx_thread->get_load();
|
m_rsx_load = rsx_thread->get_load();
|
||||||
|
|
||||||
m_total_threads = CPUStats::get_thread_count();
|
m_total_threads = utils::cpu_stats::get_thread_count();
|
||||||
|
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "overlays.h"
|
#include "overlays.h"
|
||||||
#include "Utilities/CPUStats.h"
|
#include "util/cpu_stats.hpp"
|
||||||
#include "Emu/system_config_types.h"
|
#include "Emu/system_config_types.h"
|
||||||
|
|
||||||
namespace rsx
|
namespace rsx
|
||||||
@ -28,7 +28,7 @@ namespace rsx
|
|||||||
graph m_fps_graph;
|
graph m_fps_graph;
|
||||||
graph m_frametime_graph;
|
graph m_frametime_graph;
|
||||||
|
|
||||||
CPUStats m_cpu_stats{};
|
utils::cpu_stats m_cpu_stats{};
|
||||||
Timer m_update_timer{};
|
Timer m_update_timer{};
|
||||||
Timer m_frametime_timer{};
|
Timer m_frametime_timer{};
|
||||||
u32 m_update_interval{}; // in ms
|
u32 m_update_interval{}; // in ms
|
||||||
|
@ -149,6 +149,9 @@
|
|||||||
<ClCompile Include="util\sysinfo.cpp">
|
<ClCompile Include="util\sysinfo.cpp">
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="util\cpu_stats.cpp">
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\Utilities\Thread.cpp" />
|
<ClCompile Include="..\Utilities\Thread.cpp" />
|
||||||
<ClCompile Include="..\Utilities\version.cpp" />
|
<ClCompile Include="..\Utilities\version.cpp" />
|
||||||
<ClCompile Include="util\vm_native.cpp" />
|
<ClCompile Include="util\vm_native.cpp" />
|
||||||
@ -508,6 +511,7 @@
|
|||||||
<ClInclude Include="util\slow_mutex.hpp" />
|
<ClInclude Include="util\slow_mutex.hpp" />
|
||||||
<ClInclude Include="util\fifo_mutex.hpp" />
|
<ClInclude Include="util\fifo_mutex.hpp" />
|
||||||
<ClInclude Include="util\logs.hpp" />
|
<ClInclude Include="util\logs.hpp" />
|
||||||
|
<ClInclude Include="util\cpu_stats.hpp" />
|
||||||
<ClInclude Include="..\Utilities\dyn_lib.hpp" />
|
<ClInclude Include="..\Utilities\dyn_lib.hpp" />
|
||||||
<ClInclude Include="..\Utilities\File.h" />
|
<ClInclude Include="..\Utilities\File.h" />
|
||||||
<ClInclude Include="..\Utilities\Config.h" />
|
<ClInclude Include="..\Utilities\Config.h" />
|
||||||
|
@ -884,6 +884,9 @@
|
|||||||
<ClCompile Include="util\fixed_typemap.cpp">
|
<ClCompile Include="util\fixed_typemap.cpp">
|
||||||
<Filter>Utilities</Filter>
|
<Filter>Utilities</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="util\cpu_stats.cpp">
|
||||||
|
<Filter>Utilities</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="Crypto\aesni.cpp">
|
<ClCompile Include="Crypto\aesni.cpp">
|
||||||
<Filter>Crypto</Filter>
|
<Filter>Crypto</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -1855,6 +1858,9 @@
|
|||||||
<ClInclude Include="util\typeindices.hpp">
|
<ClInclude Include="util\typeindices.hpp">
|
||||||
<Filter>Utilities</Filter>
|
<Filter>Utilities</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="util\cpu_stats.hpp">
|
||||||
|
<Filter>Utilities</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="Emu\RSX\Common\ShaderInterpreter.h">
|
<ClInclude Include="Emu\RSX\Common\ShaderInterpreter.h">
|
||||||
<Filter>Emu\GPU\RSX\Common</Filter>
|
<Filter>Emu\GPU\RSX\Common</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "util/types.hpp"
|
#include "util/types.hpp"
|
||||||
|
#include "util/cpu_stats.hpp"
|
||||||
|
#include "util/sysinfo.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
@ -43,34 +44,18 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class CPUStats
|
namespace utils
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
cpu_stats::cpu_stats()
|
||||||
HANDLE m_self;
|
|
||||||
using time_type = ULARGE_INTEGER;
|
|
||||||
#else
|
|
||||||
using time_type = clock_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
s32 m_num_processors;
|
|
||||||
time_type m_last_cpu, m_sys_cpu, m_usr_cpu;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CPUStats()
|
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
SYSTEM_INFO sysInfo;
|
SYSTEM_INFO sysInfo;
|
||||||
FILETIME ftime, fsys, fuser;
|
FILETIME ftime, fsys, fuser;
|
||||||
|
|
||||||
GetSystemInfo(&sysInfo);
|
|
||||||
m_num_processors = sysInfo.dwNumberOfProcessors;
|
|
||||||
|
|
||||||
GetSystemTimeAsFileTime(&ftime);
|
GetSystemTimeAsFileTime(&ftime);
|
||||||
memcpy(&m_last_cpu, &ftime, sizeof(FILETIME));
|
memcpy(&m_last_cpu, &ftime, sizeof(FILETIME));
|
||||||
|
|
||||||
m_self = GetCurrentProcess();
|
GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fsys, &fuser);
|
||||||
GetProcessTimes(m_self, &ftime, &ftime, &fsys, &fuser);
|
|
||||||
memcpy(&m_sys_cpu, &fsys, sizeof(FILETIME));
|
memcpy(&m_sys_cpu, &fsys, sizeof(FILETIME));
|
||||||
memcpy(&m_usr_cpu, &fuser, sizeof(FILETIME));
|
memcpy(&m_usr_cpu, &fuser, sizeof(FILETIME));
|
||||||
#else
|
#else
|
||||||
@ -79,11 +64,10 @@ public:
|
|||||||
m_last_cpu = times(&timeSample);
|
m_last_cpu = times(&timeSample);
|
||||||
m_sys_cpu = timeSample.tms_stime;
|
m_sys_cpu = timeSample.tms_stime;
|
||||||
m_usr_cpu = timeSample.tms_utime;
|
m_usr_cpu = timeSample.tms_utime;
|
||||||
m_num_processors = sysconf(_SC_NPROCESSORS_ONLN);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_usage()
|
double cpu_stats::get_usage()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
FILETIME ftime, fsys, fusr;
|
FILETIME ftime, fsys, fusr;
|
||||||
@ -92,16 +76,16 @@ public:
|
|||||||
GetSystemTimeAsFileTime(&ftime);
|
GetSystemTimeAsFileTime(&ftime);
|
||||||
memcpy(&now, &ftime, sizeof(FILETIME));
|
memcpy(&now, &ftime, sizeof(FILETIME));
|
||||||
|
|
||||||
GetProcessTimes(m_self, &ftime, &ftime, &fsys, &fusr);
|
GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fsys, &fusr);
|
||||||
memcpy(&sys, &fsys, sizeof(FILETIME));
|
memcpy(&sys, &fsys, sizeof(FILETIME));
|
||||||
memcpy(&usr, &fusr, sizeof(FILETIME));
|
memcpy(&usr, &fusr, sizeof(FILETIME));
|
||||||
double percent = double(sys.QuadPart - m_sys_cpu.QuadPart) + (usr.QuadPart - m_usr_cpu.QuadPart);
|
double percent = 1. * (sys.QuadPart - m_sys_cpu) + (usr.QuadPart - m_usr_cpu);
|
||||||
percent /= (now.QuadPart - m_last_cpu.QuadPart);
|
percent /= (now.QuadPart - m_last_cpu);
|
||||||
percent /= m_num_processors;
|
percent /= utils::get_thread_count();
|
||||||
|
|
||||||
m_last_cpu = now;
|
m_last_cpu = now.QuadPart;
|
||||||
m_usr_cpu = usr;
|
m_usr_cpu = usr.QuadPart;
|
||||||
m_sys_cpu = sys;
|
m_sys_cpu = sys.QuadPart;
|
||||||
|
|
||||||
return std::clamp(percent * 100, 0.0, 100.0);
|
return std::clamp(percent * 100, 0.0, 100.0);
|
||||||
#else
|
#else
|
||||||
@ -110,7 +94,7 @@ public:
|
|||||||
double percent;
|
double percent;
|
||||||
|
|
||||||
now = times(&timeSample);
|
now = times(&timeSample);
|
||||||
if (now <= m_last_cpu || timeSample.tms_stime < m_sys_cpu || timeSample.tms_utime < m_usr_cpu)
|
if (now <= static_cast<clock_t>(m_last_cpu) || timeSample.tms_stime < static_cast<clock_t>(m_sys_cpu) || timeSample.tms_utime < static_cast<clock_t>(m_usr_cpu))
|
||||||
{
|
{
|
||||||
// Overflow detection. Just skip this value.
|
// Overflow detection. Just skip this value.
|
||||||
percent = -1.0;
|
percent = -1.0;
|
||||||
@ -119,7 +103,7 @@ public:
|
|||||||
{
|
{
|
||||||
percent = (timeSample.tms_stime - m_sys_cpu) + (timeSample.tms_utime - m_usr_cpu);
|
percent = (timeSample.tms_stime - m_sys_cpu) + (timeSample.tms_utime - m_usr_cpu);
|
||||||
percent /= (now - m_last_cpu);
|
percent /= (now - m_last_cpu);
|
||||||
percent /= m_num_processors;
|
percent /= utils::get_thread_count();
|
||||||
percent *= 100;
|
percent *= 100;
|
||||||
}
|
}
|
||||||
m_last_cpu = now;
|
m_last_cpu = now;
|
||||||
@ -130,7 +114,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 get_thread_count()
|
u32 cpu_stats::get_thread_count() // static
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// first determine the id of the current process
|
// first determine the id of the current process
|
||||||
@ -240,4 +224,4 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
}
|
18
rpcs3/util/cpu_stats.hpp
Normal file
18
rpcs3/util/cpu_stats.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "util/types.hpp"
|
||||||
|
|
||||||
|
namespace utils
|
||||||
|
{
|
||||||
|
class cpu_stats
|
||||||
|
{
|
||||||
|
u64 m_last_cpu, m_sys_cpu, m_usr_cpu;
|
||||||
|
|
||||||
|
public:
|
||||||
|
cpu_stats();
|
||||||
|
|
||||||
|
double get_usage();
|
||||||
|
|
||||||
|
static u32 get_thread_count();
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user