diff options
author | Peter Powell <petpow@saberuk.com> | 2019-12-08 22:08:41 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-12-08 22:08:41 +0000 |
commit | 23a122cb63aae9d5ef5ec80208e79563c88c2660 (patch) | |
tree | a1efc75eb404e7286633465be508bc6f37474e30 /src/inspircd.cpp | |
parent | 6b80d34c9f02693883549c87843f669d567b7bee (diff) |
Extract performance stat code to a function.
Diffstat (limited to 'src/inspircd.cpp')
-rw-r--r-- | src/inspircd.cpp | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 0c8b3ccd1..c88235ce6 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -80,6 +80,32 @@ namespace { void VoidSignalHandler(int); + // Collects performance statistics for the STATS command. + void CollectStats() + { +#ifndef _WIN32 + static rusage ru; + if (getrusage(RUSAGE_SELF, &ru) == -1) + return; // Should never happen. + + ServerInstance->stats.LastSampled.tv_sec = ServerInstance->Time(); + ServerInstance->stats.LastSampled.tv_nsec = ServerInstance->Time_ns(); + ServerInstance->stats.LastCPU = ru.ru_utime; +#else + if (!QueryPerformanceCounter(&ServerInstance->stats.LastSampled)) + return; // Should never happen. + + FILETIME CreationTime; + FILETIME ExitTime; + FILETIME KernelTime; + FILETIME UserTime; + GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime); + + ServerInstance->stats.LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime; + ServerInstance->stats.LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime; +#endif + } + // Deletes a pointer and then zeroes it. template<typename T> void DeleteZero(T*& pr) @@ -597,10 +623,6 @@ void InspIRCd::Run() while (true) { -#ifndef _WIN32 - static rusage ru; -#endif - /* Check if there is a config thread which has finished executing but has not yet been freed */ if (this->ConfigThread && this->ConfigThread->IsDone()) { @@ -623,22 +645,7 @@ void InspIRCd::Run() */ if (TIME.tv_sec != OLDTIME) { -#ifndef _WIN32 - getrusage(RUSAGE_SELF, &ru); - stats.LastSampled = TIME; - stats.LastCPU = ru.ru_utime; -#else - if(QueryPerformanceCounter(&stats.LastSampled)) - { - FILETIME CreationTime; - FILETIME ExitTime; - FILETIME KernelTime; - FILETIME UserTime; - GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime); - stats.LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime; - stats.LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime; - } -#endif + CollectStats(); if (Config->TimeSkipWarn) { |