- add many return value checks and error-messages for system-calls
- fix memory-leak when reading tcp-connection stats
This commit is contained in:
parent
81d79d6568
commit
4437aea144
|
@ -43,6 +43,7 @@
|
||||||
#include <pdh.h>
|
#include <pdh.h>
|
||||||
#include <pdhmsg.h>
|
#include <pdhmsg.h>
|
||||||
#include <lmcons.h>
|
#include <lmcons.h>
|
||||||
|
#include <lmerr.h>
|
||||||
#include <lmwksta.h>
|
#include <lmwksta.h>
|
||||||
#include <lmapibuf.h>
|
#include <lmapibuf.h>
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ static HQUERY pdhQueryHandle = 0;
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
|
|
||||||
// local function protos
|
// local function protos
|
||||||
void initPerfKeyList(void);
|
static void initPerfKeyList(void);
|
||||||
|
|
||||||
static void placePerfKeysFromReg(const PerfKey key, unsigned int index1,
|
static void placePerfKeysFromReg(const PerfKey key, unsigned int index1,
|
||||||
unsigned int index2);
|
unsigned int index2);
|
||||||
|
@ -147,25 +148,26 @@ void gkrellm_sys_main_init(void)
|
||||||
WSADATA wsdata;
|
WSADATA wsdata;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
// initialize winsock
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Starting Winsock\n");
|
printf("Starting Winsock\n");
|
||||||
err = WSAStartup(MAKEWORD(1,1), &wsdata);
|
err = WSAStartup(MAKEWORD(1,1), &wsdata);
|
||||||
if (err != 0 && _GK.debug_level & DEBUG_SYSDEP)
|
if (err != 0)
|
||||||
printf("Starting Winsock failed with error code %i\n", err);
|
|
||||||
|
|
||||||
if (pdhQueryHandle == 0)
|
|
||||||
{
|
{
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
printf("Starting Winsock failed with error code %i\n", err);
|
||||||
printf("Opening Pdh");
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
|
printf("Opening Pdh\n");
|
||||||
status = PdhOpenQuery(NULL, 0, &pdhQueryHandle);
|
status = PdhOpenQuery(NULL, 0, &pdhQueryHandle);
|
||||||
if (status != ERROR_SUCCESS)
|
if (status != ERROR_SUCCESS || pdhQueryHandle == 0)
|
||||||
{
|
{
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Opening Pdh failed with error code %ld\n", status);
|
printf("Opening Pdh failed with error code %ld\n", status);
|
||||||
|
pdhQueryHandle = 0;
|
||||||
}
|
}
|
||||||
}
|
// get perflib localized key names
|
||||||
|
initPerfKeyList();
|
||||||
|
|
||||||
// do this once
|
// do this once
|
||||||
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||||
|
@ -176,37 +178,19 @@ void gkrellm_sys_main_init(void)
|
||||||
|
|
||||||
// initialize call back structure for plugins
|
// initialize call back structure for plugins
|
||||||
win32_init_callbacks();
|
win32_init_callbacks();
|
||||||
|
|
||||||
// get perflib localized key names
|
|
||||||
initPerfKeyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void gkrellm_sys_main_cleanup(void)
|
void gkrellm_sys_main_cleanup(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
#if defined(WIN32_CLIENT)
|
#if defined(WIN32_CLIENT)
|
||||||
NOTIFYICONDATA nid;
|
NOTIFYICONDATA nid;
|
||||||
|
|
||||||
// remove system tray icon
|
// remove system tray icon
|
||||||
nid.cbSize = sizeof(NOTIFYICONDATA);
|
nid.cbSize = sizeof(NOTIFYICONDATA);
|
||||||
nid.hWnd = GDK_WINDOW_HWND(gkrellm_get_top_window()->window);
|
nid.hWnd = GDK_WINDOW_HWND(gkrellm_get_top_window()->window);
|
||||||
nid.uID = 1;
|
nid.uID = 1;
|
||||||
Shell_NotifyIcon(NIM_DELETE, &nid);
|
Shell_NotifyIcon(NIM_DELETE, &nid);
|
||||||
|
|
||||||
if (_GK.withdrawn)
|
|
||||||
{
|
|
||||||
// remove from bluebox slit
|
|
||||||
/*HWND slitHwnd = FindWindowEx(NULL, NULL, "BControl", "BSlitWindow");
|
|
||||||
if (slitHwnd != NULL)
|
|
||||||
{
|
|
||||||
SendMessage(slitHwnd, BM_SLITMESSAGE, BSM_DELETEWINDOW, (LPARAM) GDK_WINDOW_HWND(gkrellm_get_top_window()->window));
|
|
||||||
}
|
|
||||||
RemoveProp(GDK_WINDOW_HWND(gkrellm_get_top_window()->window), "BSlitControl");
|
|
||||||
SetParent(GDK_WINDOW_HWND(gkrellm_get_top_window()->window), NULL);
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
|
||||||
printf("Removing from slit\n");*/
|
|
||||||
//SetWindowPos(0, m_nLeft, m_nTop, m_nWidth, m_nHeight, SWP_NOZORDER);
|
|
||||||
}
|
|
||||||
#endif // WIN32_CLIENT
|
#endif // WIN32_CLIENT
|
||||||
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
|
@ -219,10 +203,6 @@ void gkrellm_sys_main_cleanup(void)
|
||||||
Sleep(500);
|
Sleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop performance gathering
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
|
||||||
printf("Stopping perfomance monitoring.\n");
|
|
||||||
|
|
||||||
// Close PDH query-handle
|
// Close PDH query-handle
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Closing Pdh\n");
|
printf("Closing Pdh\n");
|
||||||
|
@ -245,17 +225,23 @@ void gkrellm_sys_main_cleanup(void)
|
||||||
static void win32_read_proc_stat(void)
|
static void win32_read_proc_stat(void)
|
||||||
{
|
{
|
||||||
static gint data_read_tick = -1;
|
static gint data_read_tick = -1;
|
||||||
|
|
||||||
if (data_read_tick == gkrellm_get_timer_ticks()) /* One read per tick */
|
if (data_read_tick == gkrellm_get_timer_ticks()) /* One read per tick */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data_read_tick = gkrellm_get_timer_ticks();
|
data_read_tick = gkrellm_get_timer_ticks();
|
||||||
|
if (pdhQueryHandle == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (pdhQueryHandle != 0)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
{
|
{
|
||||||
status = PdhCollectQueryData(pdhQueryHandle);
|
printf("Collecting PDH query data\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status = PdhCollectQueryData(pdhQueryHandle);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Collecting PDH query data failed with status %ld\n",
|
||||||
|
status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -370,25 +356,34 @@ typedef struct {
|
||||||
} SharedData;
|
} SharedData;
|
||||||
|
|
||||||
|
|
||||||
static int ReadMBMSharedData(void);
|
static gboolean ReadMBMSharedData(void);
|
||||||
static int ReadSFSharedData(void);
|
static gboolean ReadSFSharedData(void);
|
||||||
|
|
||||||
|
|
||||||
static int ReadSharedData(void)
|
static gboolean ReadSharedData(void)
|
||||||
{
|
{
|
||||||
printf("ReadSharedData()\n");
|
static gint sens_data_read_tick = -1;
|
||||||
|
static gboolean sens_data_valid = FALSE;
|
||||||
|
|
||||||
// try getting data from MBM
|
if (sens_data_read_tick == gkrellm_get_timer_ticks()) /* One read per tick */
|
||||||
if (ReadMBMSharedData() == 1)
|
return sens_data_valid;
|
||||||
{
|
sens_data_read_tick = gkrellm_get_timer_ticks();
|
||||||
// and try SpeedFan in case MBM is absent
|
|
||||||
return ReadSFSharedData();
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
}
|
printf("Reading MBM or SpeedFan data\n");
|
||||||
return 0;
|
|
||||||
}
|
// Try getting data from MBM
|
||||||
|
sens_data_valid = ReadMBMSharedData();
|
||||||
|
|
||||||
|
// Try SpeedFan in case MBM is absent
|
||||||
|
if (!sens_data_valid)
|
||||||
|
sens_data_valid = ReadSFSharedData();
|
||||||
|
|
||||||
|
return sens_data_valid;
|
||||||
|
} // ReadSharedData()
|
||||||
|
|
||||||
|
|
||||||
static int ReadMBMSharedData(void)
|
static gboolean ReadMBMSharedData(void)
|
||||||
{
|
{
|
||||||
SharedData *ptr;
|
SharedData *ptr;
|
||||||
SharedSensor *sens;
|
SharedSensor *sens;
|
||||||
|
@ -398,13 +393,13 @@ static int ReadMBMSharedData(void)
|
||||||
|
|
||||||
hSData=OpenFileMapping(FILE_MAP_READ, FALSE, "$M$B$M$5$S$D$");
|
hSData=OpenFileMapping(FILE_MAP_READ, FALSE, "$M$B$M$5$S$D$");
|
||||||
if (hSData == 0)
|
if (hSData == 0)
|
||||||
return 1;
|
return FALSE;
|
||||||
|
|
||||||
ptr = (SharedData *)MapViewOfFile(hSData, FILE_MAP_READ, 0, 0, 0);
|
ptr = (SharedData *)MapViewOfFile(hSData, FILE_MAP_READ, 0, 0, 0);
|
||||||
if (ptr == 0)
|
if (ptr == 0)
|
||||||
{
|
{
|
||||||
CloseHandle(hSData);
|
CloseHandle(hSData);
|
||||||
return 1;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCount = 0;
|
totalCount = 0;
|
||||||
|
@ -419,11 +414,8 @@ static int ReadMBMSharedData(void)
|
||||||
for (j = 0; j < totalCount; j++)
|
for (j = 0; j < totalCount; j++)
|
||||||
{
|
{
|
||||||
sens = &(ptr->sdSensor[j]);
|
sens = &(ptr->sdSensor[j]);
|
||||||
|
|
||||||
switch (sens->ssType)
|
switch (sens->ssType)
|
||||||
{
|
{
|
||||||
case stUnknown:
|
|
||||||
break;
|
|
||||||
case stTemperature:
|
case stTemperature:
|
||||||
temperatures[tempCount] = sens->ssCurrent;
|
temperatures[tempCount] = sens->ssCurrent;
|
||||||
++tempCount;
|
++tempCount;
|
||||||
|
@ -436,17 +428,13 @@ static int ReadMBMSharedData(void)
|
||||||
fans[fanCount] = sens->ssCurrent;
|
fans[fanCount] = sens->ssCurrent;
|
||||||
++fanCount;
|
++fanCount;
|
||||||
break;
|
break;
|
||||||
case stMhz:
|
default:
|
||||||
break;
|
|
||||||
case stPercentage:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UnmapViewOfFile(ptr);
|
UnmapViewOfFile(ptr);
|
||||||
CloseHandle(hSData);
|
CloseHandle(hSData);
|
||||||
|
return TRUE;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -474,7 +462,8 @@ typedef struct
|
||||||
} SFSharedMemory;
|
} SFSharedMemory;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
static int ReadSFSharedData(void)
|
|
||||||
|
static gboolean ReadSFSharedData(void)
|
||||||
{
|
{
|
||||||
SFSharedMemory *ptr;
|
SFSharedMemory *ptr;
|
||||||
HANDLE hSData;
|
HANDLE hSData;
|
||||||
|
@ -482,13 +471,13 @@ static int ReadSFSharedData(void)
|
||||||
|
|
||||||
hSData = OpenFileMapping(FILE_MAP_READ, FALSE, TEXT("SFSharedMemory_ALM"));
|
hSData = OpenFileMapping(FILE_MAP_READ, FALSE, TEXT("SFSharedMemory_ALM"));
|
||||||
if (hSData == 0)
|
if (hSData == 0)
|
||||||
return 1;
|
return FALSE;
|
||||||
|
|
||||||
ptr = (SFSharedMemory *)MapViewOfFile(hSData, FILE_MAP_READ, 0, 0, 0);
|
ptr = (SFSharedMemory *)MapViewOfFile(hSData, FILE_MAP_READ, 0, 0, 0);
|
||||||
if (ptr == 0)
|
if (ptr == 0)
|
||||||
{
|
{
|
||||||
CloseHandle(hSData);
|
CloseHandle(hSData);
|
||||||
return 1;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
tempCount = min(NrTemperature, ptr->NumTemps);
|
tempCount = min(NrTemperature, ptr->NumTemps);
|
||||||
|
@ -505,71 +494,48 @@ static int ReadSFSharedData(void)
|
||||||
|
|
||||||
UnmapViewOfFile(ptr);
|
UnmapViewOfFile(ptr);
|
||||||
CloseHandle(hSData);
|
CloseHandle(hSData);
|
||||||
return 0;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ======================================================================== */
|
/* ======================================================================== */
|
||||||
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_sensors_get_voltage(gchar *device_name, gint id,
|
gboolean gkrellm_sys_sensors_get_voltage(gchar *device_name, gint id,
|
||||||
gint iodev, gint inter, gfloat *volt)
|
gint iodev, gint inter, gfloat *volt)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (iodev < NrVoltage && iodev >= 0) {
|
|
||||||
if (ReadSharedData() == 1) {
|
|
||||||
*volt = 0;
|
*volt = 0;
|
||||||
|
if (iodev < 0 || iodev >= NrVoltage)
|
||||||
|
return FALSE;
|
||||||
|
if (ReadSharedData() == FALSE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
*volt = voltages[iodev];
|
*volt = voltages[iodev];
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
*volt = 0;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_sensors_get_fan(gchar *device_name, gint id,
|
gboolean gkrellm_sys_sensors_get_fan(gchar *device_name, gint id,
|
||||||
gint iodev, gint inter, gfloat *fan)
|
gint iodev, gint inter, gfloat *fan)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (iodev < NrFan && iodev >= 0) {
|
|
||||||
if (ReadSharedData() == 1) {
|
|
||||||
*fan = 0;
|
*fan = 0;
|
||||||
|
if (iodev >= NrFan || iodev < 0)
|
||||||
|
return FALSE;
|
||||||
|
if (ReadSharedData() == FALSE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
*fan = fans[iodev];
|
*fan = fans[iodev];
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
*fan = 0;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_sensors_get_temperature(gchar *device_name, gint id,
|
gboolean gkrellm_sys_sensors_get_temperature(gchar *device_name, gint id,
|
||||||
gint iodev, gint inter, gfloat *temp)
|
gint iodev, gint inter, gfloat *temp)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (iodev < NrTemperature && iodev >= 0) {
|
|
||||||
if (ReadSharedData() == 1) {
|
|
||||||
*temp = 0;
|
*temp = 0;
|
||||||
|
if (iodev >= NrTemperature || iodev < 0)
|
||||||
|
return FALSE;
|
||||||
|
if (ReadSharedData() == FALSE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
*temp = temperatures[iodev];
|
*temp = temperatures[iodev];
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
*temp = 0;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_sensors_init(void)
|
gboolean gkrellm_sys_sensors_init(void)
|
||||||
{
|
{
|
||||||
|
@ -579,45 +545,47 @@ gboolean gkrellm_sys_sensors_init(void)
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Initializing sensors.\n");
|
printf("Initializing sensors.\n");
|
||||||
|
|
||||||
{
|
//TODO: determine number of sensors at startup? This could cause
|
||||||
|
// user confusion in case mbm/speedfan is started after gkrellm
|
||||||
tempCount = 0;
|
tempCount = 0;
|
||||||
voltCount = 0;
|
voltCount = 0;
|
||||||
fanCount = 0;
|
fanCount = 0;
|
||||||
|
|
||||||
for (i = 0; i < NrTemperature; i++)
|
for (i = 0; i < NrTemperature; i++)
|
||||||
{
|
{
|
||||||
sprintf(buf, "Temp %i", i);
|
//TODO: i18n?
|
||||||
gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, buf,
|
snprintf(buf, sizeof(buf), "Temp %i", i);
|
||||||
tempCount, tempCount, 0,
|
gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, buf, tempCount,
|
||||||
1, 0, NULL, buf);
|
tempCount, 0, 1, 0, NULL, buf);
|
||||||
++tempCount;
|
++tempCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NrVoltage; i++)
|
for (i = 0; i < NrVoltage; i++)
|
||||||
{
|
{
|
||||||
sprintf(buf, "Volt %i", i);
|
snprintf(buf, sizeof(buf), "Volt %i", i);
|
||||||
gkrellm_sensors_add_sensor(SENSOR_VOLTAGE, NULL, buf,
|
gkrellm_sensors_add_sensor(SENSOR_VOLTAGE, NULL, buf, voltCount,
|
||||||
voltCount, voltCount, 0,
|
voltCount, 0, 1, 0, NULL, buf);
|
||||||
1, 0, NULL, buf);
|
|
||||||
++voltCount;
|
++voltCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NrFan; i++)
|
for (i = 0; i < NrFan; i++)
|
||||||
{
|
{
|
||||||
sprintf(buf, "Fan %i", i);
|
snprintf(buf, sizeof(buf), "Fan %i", i);
|
||||||
gkrellm_sensors_add_sensor(SENSOR_FAN, NULL, buf,
|
gkrellm_sensors_add_sensor(SENSOR_FAN, NULL, buf, fanCount, fanCount,
|
||||||
fanCount, fanCount, 0,
|
0, 1, 0, NULL, buf);
|
||||||
1, 0, NULL, buf);
|
|
||||||
++fanCount;
|
++fanCount;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Initialized sensors for %i temps, %i volts, %i fans.\n", tempCount, voltCount, fanCount);
|
{
|
||||||
|
printf("Initialized sensors for %i temps, %i volts and %i fans.\n",
|
||||||
|
tempCount, voltCount, fanCount);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
/* CPU monitor interface */
|
/* CPU monitor interface */
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
|
@ -635,19 +603,38 @@ void gkrellm_sys_cpu_read_data(void)
|
||||||
DWORD type;
|
DWORD type;
|
||||||
PDH_FMT_COUNTERVALUE value;
|
PDH_FMT_COUNTERVALUE value;
|
||||||
int i;
|
int i;
|
||||||
gulong userInt = 0, idleInt = 0, sysInt = 0;
|
gulong userInt = 0;
|
||||||
|
gulong idleInt = 0;
|
||||||
|
gulong sysInt = 0;
|
||||||
|
|
||||||
|
if (pdhQueryHandle == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
win32_read_proc_stat();
|
win32_read_proc_stat();
|
||||||
|
|
||||||
if (pdhQueryHandle != 0)
|
|
||||||
{
|
|
||||||
for (i = 0; i < numCPUs; i++)
|
for (i = 0; i < numCPUs; i++)
|
||||||
{
|
{
|
||||||
status = PdhGetFormattedCounterValue(cpuUserCounter[i], PDH_FMT_LONG, &type, &value);
|
status = PdhGetFormattedCounterValue(cpuUserCounter[i], PDH_FMT_LONG, &type, &value);
|
||||||
userInt = (status != 0 ? 0 : value.longValue);
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (cpu user time) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
userInt = value.longValue;
|
||||||
|
}
|
||||||
|
|
||||||
status = PdhGetFormattedCounterValue(cpuSysCounter[i], PDH_FMT_LONG, &type, &value);
|
status = PdhGetFormattedCounterValue(cpuSysCounter[i], PDH_FMT_LONG, &type, &value);
|
||||||
sysInt = (status != 0 ? 0 : value.longValue);
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (cpu sys time) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sysInt = value.longValue;
|
||||||
|
}
|
||||||
|
|
||||||
// user time defined as total - system
|
// user time defined as total - system
|
||||||
userInt -= sysInt;
|
userInt -= sysInt;
|
||||||
|
@ -661,7 +648,6 @@ void gkrellm_sys_cpu_read_data(void)
|
||||||
gkrellm_cpu_assign_data(i, user[i], 0/*nice[i]*/, sys[i], idle[i]);
|
gkrellm_cpu_assign_data(i, user[i], 0/*nice[i]*/, sys[i], idle[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_cpu_init(void)
|
gboolean gkrellm_sys_cpu_init(void)
|
||||||
|
@ -684,7 +670,7 @@ gboolean gkrellm_sys_cpu_init(void)
|
||||||
if (numCPUs > MAX_CPU)
|
if (numCPUs > MAX_CPU)
|
||||||
numCPUs = MAX_CPU;
|
numCPUs = MAX_CPU;
|
||||||
|
|
||||||
if (pdhQueryHandle != 0)
|
if (pdhQueryHandle != 0 && perfKeyList[CpuStart] != NULL && perfKeyList[CpuTime] != NULL)
|
||||||
{
|
{
|
||||||
for (i = 0; i < numCPUs; i++)
|
for (i = 0; i < numCPUs; i++)
|
||||||
{
|
{
|
||||||
|
@ -727,22 +713,38 @@ void gkrellm_sys_net_read_data(void)
|
||||||
DWORD type;
|
DWORD type;
|
||||||
PDH_FMT_COUNTERVALUE value;
|
PDH_FMT_COUNTERVALUE value;
|
||||||
|
|
||||||
|
if (pdhQueryHandle == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
win32_read_proc_stat();
|
win32_read_proc_stat();
|
||||||
|
|
||||||
if (pdhQueryHandle != 0)
|
|
||||||
{
|
|
||||||
for (i = 0; i < numAdapters; i++)
|
for (i = 0; i < numAdapters; i++)
|
||||||
{
|
{
|
||||||
status = PdhGetFormattedCounterValue(netRecCounter[i], PDH_FMT_LONG, &type, &value);
|
status = PdhGetFormattedCounterValue(netRecCounter[i], PDH_FMT_LONG, &type, &value);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (net recv counter) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
rx[i] += value.longValue / _GK.update_HZ;
|
rx[i] += value.longValue / _GK.update_HZ;
|
||||||
|
}
|
||||||
|
|
||||||
status = PdhGetFormattedCounterValue(netSendCounter[i], PDH_FMT_LONG, &type, &value);
|
status = PdhGetFormattedCounterValue(netSendCounter[i], PDH_FMT_LONG, &type, &value);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (net send counter) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
tx[i] += value.longValue / _GK.update_HZ;
|
tx[i] += value.longValue / _GK.update_HZ;
|
||||||
|
}
|
||||||
|
|
||||||
gkrellm_net_assign_data(netName[i], rx[i], tx[i]);
|
gkrellm_net_assign_data(netName[i], rx[i], tx[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void gkrellm_sys_net_check_routes(void)
|
void gkrellm_sys_net_check_routes(void)
|
||||||
{
|
{
|
||||||
|
@ -879,6 +881,7 @@ gchar * gkrellm_sys_disk_name_from_device(gint device_number, gint unit_number,
|
||||||
{
|
{
|
||||||
static gchar name[32];
|
static gchar name[32];
|
||||||
|
|
||||||
|
//TODO: i18n?
|
||||||
sprintf(name, "Disk%s", diskName[device_number]);
|
sprintf(name, "Disk%s", diskName[device_number]);
|
||||||
*order = device_number;
|
*order = device_number;
|
||||||
return name;
|
return name;
|
||||||
|
@ -896,31 +899,42 @@ void gkrellm_sys_disk_read_data(void)
|
||||||
*/
|
*/
|
||||||
DWORD type;
|
DWORD type;
|
||||||
PDH_FMT_COUNTERVALUE value;
|
PDH_FMT_COUNTERVALUE value;
|
||||||
double readInt = 0, writeInt = 0;
|
double readInt = 0;
|
||||||
|
double writeInt = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (pdhQueryHandle == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
win32_read_proc_stat();
|
win32_read_proc_stat();
|
||||||
|
|
||||||
if (pdhQueryHandle != 0)
|
for (i = 0; i < numDisks; i++)
|
||||||
{
|
{
|
||||||
for (i = 0; i < numDisks; i++) {
|
|
||||||
status = PdhGetFormattedCounterValue(diskReadCounter[i], PDH_FMT_DOUBLE, &type, &value);
|
status = PdhGetFormattedCounterValue(diskReadCounter[i], PDH_FMT_DOUBLE, &type, &value);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (disk read cnt) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
readInt = value.doubleValue / _GK.update_HZ;
|
readInt = value.doubleValue / _GK.update_HZ;
|
||||||
|
|
||||||
status = PdhGetFormattedCounterValue(diskWriteCounter[i], PDH_FMT_DOUBLE, &type, &value);
|
status = PdhGetFormattedCounterValue(diskWriteCounter[i], PDH_FMT_DOUBLE, &type, &value);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (disk write cnt) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
writeInt = value.doubleValue / _GK.update_HZ;
|
writeInt = value.doubleValue / _GK.update_HZ;
|
||||||
|
|
||||||
diskread[i] += readInt;
|
diskread[i] += readInt;
|
||||||
diskwrite[i] += writeInt;
|
diskwrite[i] += writeInt;
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < numDisks; i++)
|
for (i = 0; i < numDisks; i++)
|
||||||
{
|
{
|
||||||
//gkrellm_disk_assign_data_nth(i, diskread[i], diskwrite[i]);
|
//gkrellm_disk_assign_data_nth(i, diskread[i], diskwrite[i]);
|
||||||
gkrellm_disk_assign_data_by_device(i, 0,
|
gkrellm_disk_assign_data_by_device(i, 0, diskread[i], diskwrite[i],
|
||||||
diskread[i], diskwrite[i], FALSE);
|
FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1021,24 +1035,36 @@ gboolean gkrellm_sys_disk_init(void)
|
||||||
|
|
||||||
void gkrellm_sys_proc_read_data(void)
|
void gkrellm_sys_proc_read_data(void)
|
||||||
{
|
{
|
||||||
|
static gulong last_n_forks = 0;
|
||||||
|
static gfloat fload = 0;
|
||||||
|
|
||||||
DWORD type;
|
DWORD type;
|
||||||
PDH_FMT_COUNTERVALUE value;
|
PDH_FMT_COUNTERVALUE value;
|
||||||
gint n_running = 0, n_processes = 0;
|
gint n_running = 0, n_processes = 0;
|
||||||
gulong n_forks = 0;
|
gulong n_forks = 0;
|
||||||
static gulong last_n_forks = 0;
|
|
||||||
gulong new_forks;
|
gulong new_forks;
|
||||||
static gfloat fload = 0;
|
|
||||||
gfloat a;
|
gfloat a;
|
||||||
|
|
||||||
|
if (pdhQueryHandle == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
win32_read_proc_stat();
|
win32_read_proc_stat();
|
||||||
|
|
||||||
if (pdhQueryHandle != 0) {
|
|
||||||
status = PdhGetFormattedCounterValue(processCounter, PDH_FMT_LONG, &type, &value);
|
status = PdhGetFormattedCounterValue(processCounter, PDH_FMT_LONG, &type, &value);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (process cnt) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
n_processes = value.longValue;
|
n_processes = value.longValue;
|
||||||
|
|
||||||
status = PdhGetFormattedCounterValue(threadCounter, PDH_FMT_LONG, &type, &value);
|
status = PdhGetFormattedCounterValue(threadCounter, PDH_FMT_LONG, &type, &value);
|
||||||
n_forks = value.longValue;
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (thread cnt) failed with status %ld\n", status);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
n_forks = value.longValue;
|
||||||
|
|
||||||
n_running = n_processes;
|
n_running = n_processes;
|
||||||
|
|
||||||
|
@ -1070,18 +1096,19 @@ void gkrellm_sys_proc_read_data(void)
|
||||||
|
|
||||||
void gkrellm_sys_proc_read_users(void)
|
void gkrellm_sys_proc_read_users(void)
|
||||||
{
|
{
|
||||||
gint n_users = 0;
|
gint n_users = 1;
|
||||||
DWORD entriesRead;
|
DWORD entriesRead;
|
||||||
DWORD totalEntries;
|
DWORD totalEntries;
|
||||||
LPBYTE ptr;
|
LPBYTE ptr;
|
||||||
NET_API_STATUS err;
|
NET_API_STATUS nerr;
|
||||||
|
|
||||||
err = NetWkstaUserEnum(NULL, 0, &ptr, MAX_PREFERRED_LENGTH, &entriesRead, &totalEntries, NULL);
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
|
printf("Getting number of logged in users.\n");
|
||||||
|
|
||||||
if (err != 0 && err != ERROR_MORE_DATA)
|
nerr = NetWkstaUserEnum(NULL, 0, &ptr, MAX_PREFERRED_LENGTH, &entriesRead,
|
||||||
n_users = 1;
|
&totalEntries, NULL);
|
||||||
else
|
if (nerr == NERR_Success)
|
||||||
n_users = totalEntries;
|
n_users = entriesRead;
|
||||||
|
|
||||||
NetApiBufferFree(ptr);
|
NetApiBufferFree(ptr);
|
||||||
|
|
||||||
|
@ -1094,16 +1121,16 @@ gboolean gkrellm_sys_proc_init(void)
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Initializing process monitor.\n");
|
printf("Initializing process monitor.\n");
|
||||||
|
|
||||||
if (pdhQueryHandle != 0)
|
if (pdhQueryHandle == 0)
|
||||||
{
|
return FALSE;
|
||||||
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Adding %s as process monitor.\n", perfKeyList[NumProcesses]);
|
printf("Adding '%s' as process monitor.\n", perfKeyList[NumProcesses]);
|
||||||
status = PdhAddCounter(pdhQueryHandle, perfKeyList[NumProcesses], 0, &processCounter);
|
status = PdhAddCounter(pdhQueryHandle, perfKeyList[NumProcesses], 0, &processCounter);
|
||||||
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Adding %s as thread monitor.\n", perfKeyList[NumThreads]);
|
printf("Adding '%s' as thread monitor.\n", perfKeyList[NumThreads]);
|
||||||
status = PdhAddCounter(pdhQueryHandle, perfKeyList[NumThreads], 0, &threadCounter);
|
status = PdhAddCounter(pdhQueryHandle, perfKeyList[NumThreads], 0, &threadCounter);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1143,14 +1170,6 @@ void gkrellm_sys_mem_read_data(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void gkrellm_sys_swap_read_data(void)
|
void gkrellm_sys_swap_read_data(void)
|
||||||
{
|
{
|
||||||
SYSTEM_INFO si;
|
SYSTEM_INFO si;
|
||||||
|
@ -1205,11 +1224,11 @@ void gkrellm_sys_swap_read_data(void)
|
||||||
gkrellm_swap_assign_data(swapTotal, swapUsed, swapIn, swapOut);
|
gkrellm_swap_assign_data(swapTotal, swapUsed, swapIn, swapOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_mem_init(void)
|
gboolean gkrellm_sys_mem_init(void)
|
||||||
{
|
{
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Initialized Memory monitor.\n");
|
printf("Initialized Memory monitor.\n");
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1227,31 +1246,34 @@ void gkrellm_sys_battery_read_data(void)
|
||||||
{
|
{
|
||||||
gboolean available, on_line, charging;
|
gboolean available, on_line, charging;
|
||||||
gint percent, time_left;
|
gint percent, time_left;
|
||||||
|
|
||||||
SYSTEM_POWER_STATUS power;
|
SYSTEM_POWER_STATUS power;
|
||||||
|
|
||||||
GetSystemPowerStatus(&power);
|
GetSystemPowerStatus(&power);
|
||||||
|
if ( (power.BatteryFlag & L_NO_BATTERY) == L_NO_BATTERY
|
||||||
if ((power.BatteryFlag & L_NO_BATTERY) == L_NO_BATTERY || (power.BatteryFlag & L_UNKNOWN) == L_UNKNOWN)
|
|| (power.BatteryFlag & L_UNKNOWN) == L_UNKNOWN
|
||||||
|
)
|
||||||
|
{
|
||||||
available = FALSE;
|
available = FALSE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
available = TRUE;
|
available = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
on_line = ((power.ACLineStatus & L_ON_LINE) == L_ON_LINE) ? TRUE : FALSE;
|
on_line = ((power.ACLineStatus & L_ON_LINE) == L_ON_LINE) ? TRUE : FALSE;
|
||||||
charging= ((power.BatteryFlag & L_CHARGING) == L_CHARGING) ? TRUE : FALSE;
|
charging= ((power.BatteryFlag & L_CHARGING) == L_CHARGING) ? TRUE : FALSE;
|
||||||
|
|
||||||
time_left = power.BatteryLifeTime;
|
time_left = power.BatteryLifeTime;
|
||||||
|
|
||||||
percent = power.BatteryLifePercent;
|
percent = power.BatteryLifePercent;
|
||||||
|
|
||||||
gkrellm_battery_assign_data(0, available, on_line, charging, percent, time_left);
|
gkrellm_battery_assign_data(0, available, on_line, charging, percent, time_left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_battery_init()
|
gboolean gkrellm_sys_battery_init()
|
||||||
{
|
{
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Initialized Battery monitor.\n");
|
printf("Initialized Battery monitor.\n");
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1272,7 +1294,7 @@ void eject_win32_cdrom(gchar *device)
|
||||||
char buf[25];
|
char buf[25];
|
||||||
DWORD numBytes;
|
DWORD numBytes;
|
||||||
|
|
||||||
if (!device || strlen(device) <= 0)
|
if (!device || strlen(device) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprintf(buf, "\\\\.\\%c:", device[0]);
|
sprintf(buf, "\\\\.\\%c:", device[0]);
|
||||||
|
@ -1291,14 +1313,13 @@ void eject_win32_cdrom(gchar *device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_fs_init(void)
|
gboolean gkrellm_sys_fs_init(void)
|
||||||
{
|
{
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Initializing file system monitor.\n");
|
printf("Initializing file system monitor.\n");
|
||||||
|
|
||||||
gkrellm_fs_mounting_unsupported();
|
gkrellm_fs_mounting_unsupported();
|
||||||
gkrellm_fs_setup_eject(NULL, NULL, eject_win32_cdrom, NULL);
|
gkrellm_fs_setup_eject(NULL, NULL, eject_win32_cdrom, NULL);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1321,13 +1342,13 @@ void gkrellm_sys_fs_get_fsusage(gpointer fs, gchar *dir)
|
||||||
total = EnlargedUnsignedDivide(totalBytes, 1024, 0);
|
total = EnlargedUnsignedDivide(totalBytes, 1024, 0);
|
||||||
freeCaller = EnlargedUnsignedDivide(freeAvailableToCaller, 1024, 0);
|
freeCaller = EnlargedUnsignedDivide(freeAvailableToCaller, 1024, 0);
|
||||||
free = EnlargedUnsignedDivide(freeBytes, 1024, 0);
|
free = EnlargedUnsignedDivide(freeBytes, 1024, 0);
|
||||||
|
|
||||||
// fs, blocks, avail, free, size
|
// fs, blocks, avail, free, size
|
||||||
gkrellm_fs_assign_fsusage_data(fs, total, freeCaller, free, 1024);
|
gkrellm_fs_assign_fsusage_data(fs, total, freeCaller, free, 1024);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("GetDiskFreeSpaceEx() failed on drive %c: with error %d\n", *dir, err);
|
// may happen on cd/dvd drives, ignore for now
|
||||||
|
//printf("GetDiskFreeSpaceEx() failed on drive %c:, error %d\n", *dir, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1336,30 +1357,29 @@ void gkrellm_sys_fs_get_mounts_list(void)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char* drive;
|
char* drive;
|
||||||
|
|
||||||
GetLogicalDriveStrings(1024, buf);
|
GetLogicalDriveStrings(1024, buf);
|
||||||
for (drive = buf; *drive != 0; drive += lstrlen(drive) + 1)
|
for (drive = buf; *drive != 0; drive += lstrlen(drive) + 1)
|
||||||
{
|
{
|
||||||
// dir, dev, type
|
|
||||||
if (strcmp("A:\\", drive) != 0 && strcmp("a:\\", drive) != 0 &&
|
if (strcmp("A:\\", drive) != 0 && strcmp("a:\\", drive) != 0 &&
|
||||||
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0)
|
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0
|
||||||
|
)
|
||||||
{
|
{
|
||||||
gkrellm_fs_add_to_mounts_list(drive, drive, "");
|
gkrellm_fs_add_to_mounts_list(drive, drive, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void gkrellm_sys_fs_get_fstab_list(void)
|
void gkrellm_sys_fs_get_fstab_list(void)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char* drive;
|
char* drive;
|
||||||
|
|
||||||
GetLogicalDriveStrings(1024, buf);
|
GetLogicalDriveStrings(1024, buf);
|
||||||
for (drive = buf; *drive != 0; drive += lstrlen(drive) + 1)
|
for (drive = buf; *drive != 0; drive += lstrlen(drive) + 1)
|
||||||
{
|
{
|
||||||
// dir, dev, type, opt
|
|
||||||
if (strcmp("A:\\", drive) != 0 && strcmp("a:\\", drive) != 0 &&
|
if (strcmp("A:\\", drive) != 0 && strcmp("a:\\", drive) != 0 &&
|
||||||
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0)
|
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Adding fstab %s\n", drive);
|
printf("Adding fstab %s\n", drive);
|
||||||
|
@ -1377,6 +1397,7 @@ gboolean gkrellm_sys_inet_init(void)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void gkrellm_sys_inet_read_tcp_data(void)
|
void gkrellm_sys_inet_read_tcp_data(void)
|
||||||
{
|
{
|
||||||
PMIB_TCPTABLE pTcpTable = NULL;
|
PMIB_TCPTABLE pTcpTable = NULL;
|
||||||
|
@ -1384,7 +1405,9 @@ void gkrellm_sys_inet_read_tcp_data(void)
|
||||||
|
|
||||||
// Make an initial call to GetTcpTable to
|
// Make an initial call to GetTcpTable to
|
||||||
// get the necessary size into the dwSize variable
|
// get the necessary size into the dwSize variable
|
||||||
if (GetTcpTable(NULL, &dwTableSize, FALSE) == ERROR_INSUFFICIENT_BUFFER)
|
if (GetTcpTable(NULL, &dwTableSize, FALSE) == ERROR_INSUFFICIENT_BUFFER
|
||||||
|
&& dwTableSize > 0
|
||||||
|
)
|
||||||
{
|
{
|
||||||
pTcpTable = (MIB_TCPTABLE *)malloc(dwTableSize);
|
pTcpTable = (MIB_TCPTABLE *)malloc(dwTableSize);
|
||||||
|
|
||||||
|
@ -1409,7 +1432,7 @@ void gkrellm_sys_inet_read_tcp_data(void)
|
||||||
gkrellm_inet_log_tcp_port_data(&tcp);
|
gkrellm_inet_log_tcp_port_data(&tcp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalFree(pTcpTable);
|
free(pTcpTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1429,38 +1452,53 @@ time_t gkrellm_sys_uptime_read_uptime(void)
|
||||||
if (pdhQueryHandle != 0)
|
if (pdhQueryHandle != 0)
|
||||||
{
|
{
|
||||||
status = PdhGetFormattedCounterValue(uptimeCounter, PDH_FMT_LONG, &type, &value);
|
status = PdhGetFormattedCounterValue(uptimeCounter, PDH_FMT_LONG, &type, &value);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Getting PDH-counter (uptime) failed with status %ld\n", status);
|
||||||
|
return (time_t)0;
|
||||||
|
}
|
||||||
l = value.longValue;
|
l = value.longValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (time_t) l;
|
return (time_t) l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean gkrellm_sys_uptime_init(void)
|
gboolean gkrellm_sys_uptime_init(void)
|
||||||
{
|
{
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
printf("Initializing uptime monitor.\n");
|
printf("Initializing uptime monitor.\n");
|
||||||
|
|
||||||
if (pdhQueryHandle != 0)
|
if (pdhQueryHandle == 0)
|
||||||
{
|
return FALSE;
|
||||||
|
|
||||||
status = PdhAddCounter(pdhQueryHandle, perfKeyList[Uptime], 0, &uptimeCounter);
|
status = PdhAddCounter(pdhQueryHandle, perfKeyList[Uptime], 0, &uptimeCounter);
|
||||||
|
if (status != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Adding PDH-counter (uptime) failed with status %ld\n", status);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
/* hostname interface */
|
/* hostname interface */
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
|
|
||||||
gchar *gkrellm_sys_get_host_name(void)
|
gchar *gkrellm_sys_get_host_name(void)
|
||||||
{
|
{
|
||||||
static gboolean have_it = FALSE;
|
static gboolean host_name_fetched = FALSE;
|
||||||
|
|
||||||
if (!have_it)
|
if (!host_name_fetched)
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||||
|
printf("Retrieving host name.\n");
|
||||||
|
|
||||||
err = gethostname(buf, sizeof(buf));
|
err = gethostname(buf, sizeof(buf));
|
||||||
|
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
|
@ -1468,15 +1506,12 @@ gchar *gkrellm_sys_get_host_name(void)
|
||||||
else
|
else
|
||||||
hostname = g_strdup(buf);
|
hostname = g_strdup(buf);
|
||||||
|
|
||||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
host_name_fetched = TRUE;
|
||||||
printf("Retrieving host name.\n");
|
|
||||||
|
|
||||||
have_it = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hostname;
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
/* System name interface */
|
/* System name interface */
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
|
@ -1551,9 +1586,16 @@ gboolean gkrellm_sys_sensors_mbmon_supported(void)
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
|
|
||||||
|
|
||||||
void initPerfKeyList(void)
|
static void initPerfKeyList(void)
|
||||||
{
|
{
|
||||||
printf("initPerfKeyList();\n");
|
int i;
|
||||||
|
for (i = 0; i < PerfKeysSize; i++)
|
||||||
|
{
|
||||||
|
perfKeyList[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdhQueryHandle == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
placePerfKeysFromReg(NumProcesses , 2 , 248);
|
placePerfKeysFromReg(NumProcesses , 2 , 248);
|
||||||
placePerfKeysFromReg(NumThreads , 2 , 250);
|
placePerfKeysFromReg(NumThreads , 2 , 250);
|
||||||
|
@ -1590,17 +1632,18 @@ static void placePerfKeysFromReg(const PerfKey key, unsigned int index1, unsigne
|
||||||
if (stat == ERROR_SUCCESS)
|
if (stat == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
_tcsncat(buf, perfName, 512);
|
_tcsncat(buf, perfName, 512);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("could not find perflib index %d in registry\n", index2);
|
|
||||||
}
|
|
||||||
|
|
||||||
placePerfKey(key, buf);
|
placePerfKey(key, buf);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("could not find perflib index %d in registry\n", index2);
|
||||||
|
placePerfKey(key, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Could not find perflib index %d in registry\n", index1);
|
printf("Could not find perflib index %d in registry\n", index1);
|
||||||
|
placePerfKey(key, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1629,12 +1672,12 @@ static void placePerfKeyFromReg(const PerfKey key, unsigned int index,
|
||||||
{
|
{
|
||||||
_tcsncat(buf, suffix, 512);
|
_tcsncat(buf, suffix, 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
placePerfKey(key, buf);
|
placePerfKey(key, buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("could not find index %d in registry\n", index);
|
printf("could not find index %d in registry\n", index);
|
||||||
|
placePerfKey(key, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1642,19 +1685,24 @@ static void placePerfKeyFromReg(const PerfKey key, unsigned int index,
|
||||||
static void placePerfKey(const PerfKey key, const TCHAR* value)
|
static void placePerfKey(const PerfKey key, const TCHAR* value)
|
||||||
{
|
{
|
||||||
size_t strSize;
|
size_t strSize;
|
||||||
|
|
||||||
if (((int)key > -1) && ((int)key < PerfKeysSize))
|
if (((int)key > -1) && ((int)key < PerfKeysSize))
|
||||||
{
|
{
|
||||||
free(perfKeyList[key]);
|
free(perfKeyList[key]);
|
||||||
|
if (value != NULL)
|
||||||
|
{
|
||||||
strSize = _tcsclen(value);
|
strSize = _tcsclen(value);
|
||||||
perfKeyList[key] = malloc(sizeof(TCHAR) * strSize + 1);
|
perfKeyList[key] = malloc(sizeof(TCHAR) * strSize + 1);
|
||||||
_tcscpy(perfKeyList[key], value);
|
_tcscpy(perfKeyList[key], value);
|
||||||
|
|
||||||
printf("perfKeyList[ %d ] = '%s'\n", key, perfKeyList[key]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Invalid placement for key %d and value %s\n", key, value);
|
perfKeyList[key] = NULL;
|
||||||
|
}
|
||||||
|
//printf("perfKeyList[ %d ] = '%s'\n", key, perfKeyList[key]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Invalid placement for key %d; value was '%s'\n", key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1831,4 +1879,3 @@ if (addr != NULL)
|
||||||
addr->s_addr = htonl(val);
|
addr->s_addr = htonl(val);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue