mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 10:39:02 -04:00
Fix measuring the CPU load on Windows.
This commit is contained in:
parent
56b9a4e48e
commit
491d82677d
@ -127,17 +127,14 @@ public:
|
||||
size_t Recv = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
/** Cpu usage at last sample
|
||||
*/
|
||||
FILETIME LastCPU;
|
||||
/** CPU performance frequency on boot. */
|
||||
LARGE_INTEGER BootCPU;
|
||||
|
||||
/** Time QP sample was read
|
||||
*/
|
||||
LARGE_INTEGER LastSampled;
|
||||
/** CPU performance frequency at the last sample. */
|
||||
LARGE_INTEGER LastCPU;
|
||||
|
||||
/** QP frequency
|
||||
*/
|
||||
LARGE_INTEGER QPFrequency;
|
||||
/** Time the last sample was read. */
|
||||
FILETIME LastSampled;
|
||||
#else
|
||||
/** CPU usage at the last sample. */
|
||||
timeval LastCPU;
|
||||
|
@ -309,8 +309,8 @@ void CommandStats::DoStats(Stats::Context& stats)
|
||||
{
|
||||
KernelTime.dwHighDateTime += UserTime.dwHighDateTime;
|
||||
KernelTime.dwLowDateTime += UserTime.dwLowDateTime;
|
||||
double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->Stats.LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->Stats.LastCPU.dwLowDateTime) )/100000;
|
||||
double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->Stats.LastSampled.QuadPart) / ServerInstance->Stats.QPFrequency.QuadPart;
|
||||
double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->Stats.LastSampled.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->Stats.LastSampled.dwLowDateTime) )/100000;
|
||||
double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->Stats.LastCPU.QuadPart) / ServerInstance->Stats.BootCPU.QuadPart;
|
||||
double per = (n_eaten/n_elapsed);
|
||||
|
||||
stats.AddRow(249, INSP_FORMAT("CPU Use (now): {:03.5}%", per));
|
||||
|
@ -105,7 +105,7 @@ namespace
|
||||
ServerInstance->Stats.LastSampled.tv_nsec = ServerInstance->Time_ns();
|
||||
ServerInstance->Stats.LastCPU = ru.ru_utime;
|
||||
#else
|
||||
if (!QueryPerformanceCounter(&ServerInstance->Stats.LastSampled))
|
||||
if (!QueryPerformanceCounter(&ServerInstance->Stats.LastCPU))
|
||||
return; // Should never happen.
|
||||
|
||||
FILETIME CreationTime;
|
||||
@ -114,8 +114,8 @@ namespace
|
||||
FILETIME UserTime;
|
||||
GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
|
||||
|
||||
ServerInstance->Stats.LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
|
||||
ServerInstance->Stats.LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
|
||||
ServerInstance->Stats.LastSampled.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
|
||||
ServerInstance->Stats.LastSampled.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -588,7 +588,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
|
||||
FreeConsole();
|
||||
}
|
||||
|
||||
QueryPerformanceFrequency(&this->Stats.QPFrequency);
|
||||
QueryPerformanceFrequency(&this->Stats.BootCPU);
|
||||
#endif
|
||||
|
||||
WritePID();
|
||||
|
Loading…
x
Reference in New Issue
Block a user