diff options
author | Earle F. Philhower III <earle@ziplabel.com> | 2004-03-14 03:11:02 +0000 |
---|---|---|
committer | Earle F. Philhower III <earle@ziplabel.com> | 2004-03-14 03:11:02 +0000 |
commit | dbb0e949c323a22778c6e21c75787b386ea362ee (patch) | |
tree | 83e2dd1ab5de880af3f3eae881ab46ec2a4225dd /get_load.c | |
parent | d8ff970419a46b901ddf676a2ca8fd71bbca8e55 (diff) |
Compiles and runs under CYGWIN using performance counters
Diffstat (limited to 'get_load.c')
-rw-r--r-- | get_load.c | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -46,6 +46,61 @@ from the X Consortium. #include <stdlib.h> #include "xload.h" +#if defined(__CYGWIN__) +#include <windows.h> +typedef struct { + DWORD stat; + union { + LONG vLong; + double vDouble; + LONGLONG vLongLong; + void *string; + } u; +} COUNTER; +static HANDLE query; +static HANDLE counter; +static HINSTANCE hdll; +static long (__stdcall *pdhopen)(LPCSTR, DWORD, HANDLE); +static long (__stdcall *pdhaddcounter)(HANDLE, LPCSTR, DWORD, HANDLE*); +static long (__stdcall *pdhcollectquerydata)(HANDLE); +static long (__stdcall *pdhgetformattedcountervalue)(HANDLE, DWORD, LPDWORD, COUNTER*); +#define CYGWIN_PERF +void InitLoadPoint() +{ + long ret; + hdll=LoadLibrary("pdh.dll"); + if (!hdll) exit(-1); + pdhopen=(void*)GetProcAddress(hdll, "PdhOpenQueryA"); + if (!pdhopen) exit(-1); + pdhaddcounter=(void*)GetProcAddress(hdll, "PdhAddCounterA"); + if (!pdhaddcounter) exit(-1); + pdhcollectquerydata=(void*)GetProcAddress(hdll, "PdhCollectQueryData"); + if (!pdhcollectquerydata) exit(-1); + pdhgetformattedcountervalue=(void*)GetProcAddress(hdll, "PdhGetFormattedCounterValue"); + if (!pdhgetformattedcountervalue) exit(-1); + ret = pdhopen( NULL , 0, &query ); + if (ret!=0) exit(-1); + ret = pdhaddcounter(query, "\\Processor(_Total)\\% Processor Time", 0, &counter); + if (ret!=0) exit(-1); +} +void GetLoadPoint( w, closure, call_data ) /* SYSV386 version */ + Widget w; /* unused */ + XtPointer closure; /* unused */ + XtPointer call_data; /* pointer to (double) return value */ +{ + double *loadavg = (double *)call_data; + COUNTER fmtvalue; + long ret; + *loadavg = 0.0; + ret = pdhcollectquerydata(query); + if (ret!=0) return; + ret = pdhgetformattedcountervalue(counter, 0x200, NULL, &fmtvalue); + if (ret!=0) return; + *loadavg = (fmtvalue.u.vDouble-0.01)/100.0; +} +#else + + #if !defined(DGUX) #if defined(att) || defined(QNX4) #define LOADSTUB @@ -1170,3 +1225,4 @@ getloadavg (double loadavg[], int nelem) #endif /* END OF DG/ux */ +#endif /* END of __CYGWIN__ */ |