[SIGAR-8] Change win32 mem_get to use GlobalMemoryStatusEx

This commit is contained in:
Doug MacEachern 2006-07-07 20:29:22 +00:00
parent ea4f9c7ee4
commit 4f75602888
3 changed files with 61 additions and 5 deletions

View File

@ -1,3 +1,7 @@
2006-07-07 Doug MacEachern <dougm@hyperic.net>
* [SIGAR-8] Change win32 mem_get to use GlobalMemoryStatusEx
2006-06-30 Doug MacEachern <dougm@hyperic.com>
* Remove mem.shared, gone in Linux 2.6 and which only left Solaris and Win32

View File

@ -192,6 +192,19 @@ typedef struct _WINSTATION_INFO {
/* end wtsapi32.h */
/* from winbase.h not in vs6.0 */
typedef struct {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX;
#include <iprtrmib.h>
/* undocumented structures */
@ -349,6 +362,9 @@ typedef BOOLEAN (CALLBACK *winsta_query_info)(HANDLE,
ULONG,
PULONG);
/* kernel32.dll */
typedef BOOL (CALLBACK *kernel_memory_status)(MEMORYSTATUSEX *);
#define SIGAR_DLLFUNC(api, name) \
struct { \
const char *name; \
@ -415,6 +431,14 @@ typedef struct {
sigar_dll_func_t end;
} sigar_winsta_t;
typedef struct {
sigar_dll_handle_t handle;
SIGAR_DLLFUNC(kernel, memory_status);
sigar_dll_func_t end;
} sigar_kernel_t;
struct sigar_t {
SIGAR_T_BASE;
char *machine;
@ -429,6 +453,7 @@ struct sigar_t {
sigar_ntdll_t ntdll;
sigar_psapi_t psapi;
sigar_winsta_t winsta;
sigar_kernel_t kernel;
sigar_win32_pinfo_t pinfo;
WORD ws_version;
int ws_error;

View File

@ -223,6 +223,13 @@ static sigar_psapi_t sigar_winsta = {
{ NULL, NULL }
};
static sigar_psapi_t sigar_kernel = {
"kernel32.dll",
NULL,
{ "GlobalMemoryStatusEx", NULL },
{ NULL, NULL }
};
#define DLLMOD_COPY(name) \
memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##name))
@ -349,6 +356,7 @@ int sigar_os_open(sigar_t **sigar_ptr)
DLLMOD_COPY(ntdll);
DLLMOD_COPY(psapi);
DLLMOD_COPY(winsta);
DLLMOD_COPY(kernel);
sigar->log_level = -1; /* else below segfaults */
/* XXX init early for use by javasigar.c */
@ -374,6 +382,7 @@ int sigar_os_close(sigar_t *sigar)
DLLMOD_FREE(ntdll);
DLLMOD_FREE(psapi);
DLLMOD_FREE(winsta);
DLLMOD_FREE(kernel);
if (sigar->perfbuf) {
free(sigar->perfbuf);
@ -404,14 +413,32 @@ char *sigar_os_error_string(sigar_t *sigar, int err)
return NULL;
}
#define sigar_GlobalMemoryStatusEx \
sigar->kernel.memory_status.func
SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
{
DLLMOD_INIT(kernel, TRUE);
if (sigar_GlobalMemoryStatusEx) {
MEMORYSTATUSEX memstat;
memstat.dwLength = sizeof(memstat);
if (!sigar_GlobalMemoryStatusEx(&memstat)) {
return GetLastError();
}
mem->total = memstat.ullTotalPhys;
mem->free = memstat.ullAvailPhys;
}
else {
MEMORYSTATUS memstat;
GlobalMemoryStatus(&memstat);
mem->total = memstat.dwTotalPhys;
mem->free = memstat.dwAvailPhys;
}
mem->used = mem->total - mem->free;
sigar_mem_calc_ram(sigar, mem);