diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index fc7edd69..f231c9f1 100755 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -170,10 +170,28 @@ typedef enum { SC_STATUS_PROCESS_INFO = 0 } SC_STATUS_TYPE; +typedef struct _PERFORMANCE_INFORMATION { + DWORD cb; + SIZE_T CommitTotal; + SIZE_T CommitLimit; + SIZE_T CommitPeak; + SIZE_T PhysicalTotal; + SIZE_T PhysicalAvailable; + SIZE_T SystemCache; + SIZE_T KernelTotal; + SIZE_T KernelPaged; + SIZE_T KernelNonpaged; + SIZE_T PageSize; + DWORD HandleCount; + DWORD ProcessCount; + DWORD ThreadCount; +} PERFORMANCE_INFORMATION, *PPERFORMANCE_INFORMATION; + #ifndef ERROR_DATATYPE_MISMATCH #define ERROR_DATATYPE_MISMATCH 1629L #endif - +#else +#include #endif /* _MSC_VER */ #include @@ -441,6 +459,8 @@ typedef BOOL (CALLBACK *psapi_enum_processes)(DWORD *, DWORD, DWORD *); +typedef BOOL (CALLBACK *psapi_get_perf_info)(PPERFORMANCE_INFORMATION, DWORD); + /* winsta.dll */ typedef BOOLEAN (CALLBACK *winsta_query_info)(HANDLE, ULONG, @@ -518,6 +538,7 @@ typedef struct { SIGAR_DLLFUNC(psapi, enum_modules); SIGAR_DLLFUNC(psapi, enum_processes); SIGAR_DLLFUNC(psapi, get_module_name); + SIGAR_DLLFUNC(psapi, get_perf_info); sigar_dll_func_t end; } sigar_psapi_t; diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index d7e98806..8a3b38ed 100755 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -343,6 +343,7 @@ static sigar_psapi_t sigar_psapi = { { "EnumProcessModules", NULL }, { "EnumProcesses", NULL }, { "GetModuleFileNameExA", NULL }, + { "GetPerformanceInfo", NULL }, { NULL, NULL } }; @@ -632,9 +633,14 @@ char *sigar_os_error_string(sigar_t *sigar, int err) #define sigar_GlobalMemoryStatusEx \ sigar->kernel.memory_status.func +#define sigar_GetPerformanceInfo \ + sigar->psapi.get_perf_info.func + SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) { + sigar_uint64_t kern = 0; DLLMOD_INIT(kernel, TRUE); + DLLMOD_INIT(psapi, FALSE); if (sigar_GlobalMemoryStatusEx) { MEMORYSTATUSEX memstat; @@ -647,6 +653,14 @@ SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) mem->total = memstat.ullTotalPhys; mem->free = memstat.ullAvailPhys; + + if (sigar_GetPerformanceInfo) { + PERFORMANCE_INFORMATION info; + if (sigar_GetPerformanceInfo(&info, sizeof(info))) { + kern = info.SystemCache; + kern *= sigar->pagesize; + } + } } else { MEMORYSTATUS memstat; @@ -657,8 +671,8 @@ SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) mem->used = mem->total - mem->free; - mem->actual_free = mem->free; - mem->actual_used = mem->used; + mem->actual_free = mem->free + kern; + mem->actual_used = mem->used - kern; sigar_mem_calc_ram(sigar, mem);