diff options
author | Adam <adam@sigterm.info> | 2012-10-12 14:50:05 -0700 |
---|---|---|
committer | Adam <adam@sigterm.info> | 2012-10-12 14:50:05 -0700 |
commit | c05ad37bfd03486475889485606ed5cffc7bf5a2 (patch) | |
tree | fe01825889769500a0f080371a0714aa15505b9a /src/commands | |
parent | e496d321efe3e9b27f2f116bd22a05ec44aec564 (diff) | |
parent | 5b9682275e384635a1fd9f7320cf4d9a604a43b4 (diff) |
Merge pull request #320 from ChrisTX/insp20+cleanupwin
Windows: In-depth cleanup (see details)
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/cmd_stats.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp index 3b0507175..1d3130bd4 100644 --- a/src/commands/cmd_stats.cpp +++ b/src/commands/cmd_stats.cpp @@ -23,8 +23,9 @@ #include "xline.h" #include "commands/cmd_whowas.h" -#ifdef WINDOWS -# pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo() +#ifdef _WIN32 +#include <psapi.h> +#pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo() #endif /** Handle /STATS. These command handlers can be reloaded by the core, @@ -240,7 +241,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results) results.push_back(sn+" 249 "+user->nick+" :Bandwidth out: "+ConvToStr(kbitpersec_out_s)+" kilobits/sec"); results.push_back(sn+" 249 "+user->nick+" :Bandwidth in: "+ConvToStr(kbitpersec_in_s)+" kilobits/sec"); -#ifndef WIN32 +#ifndef _WIN32 /* Moved this down here so all the not-windows stuff (look w00tie, I didn't say win32!) is in one ifndef. * Also cuts out some identical code in both branches of the ifndef. -- Om */ @@ -278,7 +279,32 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results) results.push_back(sn+" 249 "+user->nick+" :Total allocation: "+ConvToStr((MemCounters.WorkingSetSize + MemCounters.PagefileUsage) / 1024)+"K"); results.push_back(sn+" 249 "+user->nick+" :Pagefile usage: "+ConvToStr(MemCounters.PagefileUsage / 1024)+"K"); results.push_back(sn+" 249 "+user->nick+" :Page faults: "+ConvToStr(MemCounters.PageFaultCount)); - results.push_back(sn+" 249 "+user->nick+" :CPU Usage: " + ConvToStr(getcpu()) + "%"); + } + + FILETIME CreationTime; + FILETIME ExitTime; + FILETIME KernelTime; + FILETIME UserTime; + LARGE_INTEGER ThisSample; + if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) && + QueryPerformanceCounter(&ThisSample)) + { + 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 per = (n_eaten/n_elapsed); + + char percent[30]; + + snprintf(percent, 30, "%03.5f%%", per); + results.push_back(sn+" 249 "+user->nick+" :CPU Use (now): "+percent); + + n_elapsed = ServerInstance->Time() - ServerInstance->startup_time; + n_eaten = (double)(( (uint64_t)(KernelTime.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime))/100000; + per = (n_eaten / n_elapsed); + snprintf(percent, 30, "%03.5f%%", per); + results.push_back(sn+" 249 "+user->nick+" :CPU Use (total): "+percent); } #endif } |