fix get_perf_object error handling.
morg experienced an ERROR_BUSY which crashed the agent, this is properly handled now.
This commit is contained in:
parent
a23ff178db
commit
003d416408
|
@ -70,12 +70,15 @@ typedef enum {
|
||||||
perf_offsets[ix] ? \
|
perf_offsets[ix] ? \
|
||||||
*((DWORD *)((BYTE *)counter_block + perf_offsets[ix])) : 0
|
*((DWORD *)((BYTE *)counter_block + perf_offsets[ix])) : 0
|
||||||
|
|
||||||
static PERF_OBJECT_TYPE *get_perf_object(sigar_t *sigar, char *counter_key)
|
static PERF_OBJECT_TYPE *get_perf_object(sigar_t *sigar, char *counter_key,
|
||||||
|
DWORD *err)
|
||||||
{
|
{
|
||||||
DWORD retval, type;
|
DWORD retval, type;
|
||||||
WCHAR wcounter_key[MAX_PATH+1];
|
WCHAR wcounter_key[MAX_PATH+1];
|
||||||
PERF_DATA_BLOCK *block;
|
PERF_DATA_BLOCK *block;
|
||||||
|
|
||||||
|
*err = SIGAR_OK;
|
||||||
|
|
||||||
if (!sigar->perfbuf) {
|
if (!sigar->perfbuf) {
|
||||||
sigar->perfbuf = (char *)malloc(PERFBUF_SIZE);
|
sigar->perfbuf = (char *)malloc(PERFBUF_SIZE);
|
||||||
sigar->perfbuf_size = PERFBUF_SIZE;
|
sigar->perfbuf_size = PERFBUF_SIZE;
|
||||||
|
@ -93,7 +96,7 @@ static PERF_OBJECT_TYPE *get_perf_object(sigar_t *sigar, char *counter_key)
|
||||||
sigar->perfbuf_size);
|
sigar->perfbuf_size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("RegQueryValueEx failed: %d\n", retval);
|
*err = retval;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,9 +273,9 @@ SIGAR_DECLARE(int) sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
|
||||||
|
|
||||||
static PERF_INSTANCE_DEFINITION *get_cpu_instance(sigar_t *sigar,
|
static PERF_INSTANCE_DEFINITION *get_cpu_instance(sigar_t *sigar,
|
||||||
DWORD *perf_offsets,
|
DWORD *perf_offsets,
|
||||||
DWORD *num)
|
DWORD *num, DWORD *err)
|
||||||
{
|
{
|
||||||
PERF_OBJECT_TYPE *object = get_perf_object(sigar, "238");
|
PERF_OBJECT_TYPE *object = get_perf_object(sigar, "238", err);
|
||||||
PERF_INSTANCE_DEFINITION *inst;
|
PERF_INSTANCE_DEFINITION *inst;
|
||||||
PERF_COUNTER_DEFINITION *counter;
|
PERF_COUNTER_DEFINITION *counter;
|
||||||
DWORD i;
|
DWORD i;
|
||||||
|
@ -311,12 +314,12 @@ SIGAR_DECLARE(int) sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
||||||
{
|
{
|
||||||
PERF_INSTANCE_DEFINITION *inst;
|
PERF_INSTANCE_DEFINITION *inst;
|
||||||
PERF_COUNTER_BLOCK *counter_block;
|
PERF_COUNTER_BLOCK *counter_block;
|
||||||
DWORD perf_offsets[PERF_IX_CPU_MAX];
|
DWORD perf_offsets[PERF_IX_CPU_MAX], err;
|
||||||
|
|
||||||
SIGAR_ZERO(cpu);
|
SIGAR_ZERO(cpu);
|
||||||
memset(&perf_offsets, 0, sizeof(perf_offsets));
|
memset(&perf_offsets, 0, sizeof(perf_offsets));
|
||||||
|
|
||||||
inst = get_cpu_instance(sigar, (DWORD*)&perf_offsets, 0);
|
inst = get_cpu_instance(sigar, (DWORD*)&perf_offsets, 0, &err);
|
||||||
|
|
||||||
if (!inst) {
|
if (!inst) {
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
|
@ -338,16 +341,16 @@ SIGAR_DECLARE(int) sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
|
||||||
{
|
{
|
||||||
int status, i, j, hthread=0;
|
int status, i, j, hthread=0;
|
||||||
PERF_INSTANCE_DEFINITION *inst;
|
PERF_INSTANCE_DEFINITION *inst;
|
||||||
DWORD perf_offsets[PERF_IX_CPU_MAX], num;
|
DWORD perf_offsets[PERF_IX_CPU_MAX], num, err;
|
||||||
|
|
||||||
memset(&perf_offsets, 0, sizeof(perf_offsets));
|
memset(&perf_offsets, 0, sizeof(perf_offsets));
|
||||||
|
|
||||||
/* first instance is total, rest are per-cpu */
|
/* first instance is total, rest are per-cpu */
|
||||||
inst = get_cpu_instance(sigar, (DWORD*)&perf_offsets, &num);
|
inst = get_cpu_instance(sigar, (DWORD*)&perf_offsets, &num, &err);
|
||||||
--num;
|
--num;
|
||||||
|
|
||||||
if (!inst) {
|
if (!inst) {
|
||||||
return GetLastError();
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
sigar_cpu_count(sigar);
|
sigar_cpu_count(sigar);
|
||||||
|
@ -410,8 +413,8 @@ SIGAR_DECLARE(int) sigar_loadavg_get(sigar_t *sigar,
|
||||||
return SIGAR_ENOTIMPL;
|
return SIGAR_ENOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define get_process_object(sigar) \
|
#define get_process_object(sigar, err) \
|
||||||
get_perf_object(sigar, PERF_TITLE_PROC_KEY)
|
get_perf_object(sigar, PERF_TITLE_PROC_KEY, err)
|
||||||
|
|
||||||
SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
|
SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
|
||||||
sigar_proc_list_t *proclist)
|
sigar_proc_list_t *proclist)
|
||||||
|
@ -419,15 +422,15 @@ SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
|
||||||
PERF_OBJECT_TYPE *object;
|
PERF_OBJECT_TYPE *object;
|
||||||
PERF_INSTANCE_DEFINITION *inst;
|
PERF_INSTANCE_DEFINITION *inst;
|
||||||
PERF_COUNTER_DEFINITION *counter;
|
PERF_COUNTER_DEFINITION *counter;
|
||||||
DWORD i;
|
DWORD i, err;
|
||||||
DWORD perf_offsets[PERF_IX_MAX];
|
DWORD perf_offsets[PERF_IX_MAX];
|
||||||
|
|
||||||
perf_offsets[PERF_IX_PID] = 0;
|
perf_offsets[PERF_IX_PID] = 0;
|
||||||
|
|
||||||
object = get_process_object(sigar);
|
object = get_process_object(sigar, &err);
|
||||||
|
|
||||||
if (!object) {
|
if (!object) {
|
||||||
return GetLastError();
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
sigar_proc_list_create(proclist);
|
sigar_proc_list_create(proclist);
|
||||||
|
@ -646,7 +649,7 @@ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
|
||||||
PERF_OBJECT_TYPE *object;
|
PERF_OBJECT_TYPE *object;
|
||||||
PERF_INSTANCE_DEFINITION *inst;
|
PERF_INSTANCE_DEFINITION *inst;
|
||||||
PERF_COUNTER_DEFINITION *counter;
|
PERF_COUNTER_DEFINITION *counter;
|
||||||
DWORD i;
|
DWORD i, err;
|
||||||
DWORD perf_offsets[PERF_IX_MAX];
|
DWORD perf_offsets[PERF_IX_MAX];
|
||||||
sigar_win32_pinfo_t *pinfo = &sigar->pinfo;
|
sigar_win32_pinfo_t *pinfo = &sigar->pinfo;
|
||||||
time_t timenow = time(NULL);
|
time_t timenow = time(NULL);
|
||||||
|
@ -662,7 +665,11 @@ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
|
||||||
|
|
||||||
memset(&perf_offsets, 0, sizeof(perf_offsets));
|
memset(&perf_offsets, 0, sizeof(perf_offsets));
|
||||||
|
|
||||||
object = get_process_object(sigar);
|
object = get_process_object(sigar, &err);
|
||||||
|
|
||||||
|
if (object == NULL) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* note we assume here:
|
* note we assume here:
|
||||||
|
|
Loading…
Reference in New Issue