fail gracefully if no perf counters are found for disk i/o metrics

This commit is contained in:
Doug MacEachern 2005-11-08 18:16:03 +00:00
parent 30115542c8
commit 147c931d7d
1 changed files with 13 additions and 2 deletions

View File

@ -1485,10 +1485,11 @@ static PERF_INSTANCE_DEFINITION *get_disk_instance(sigar_t *sigar,
DWORD *perf_offsets, DWORD *perf_offsets,
DWORD *num, DWORD *err) DWORD *num, DWORD *err)
{ {
PERF_OBJECT_TYPE *object = get_perf_object(sigar, "236", err); PERF_OBJECT_TYPE *object =
get_perf_object(sigar, PERF_TITLE_DISK_KEY, err);
PERF_INSTANCE_DEFINITION *inst; PERF_INSTANCE_DEFINITION *inst;
PERF_COUNTER_DEFINITION *counter; PERF_COUNTER_DEFINITION *counter;
DWORD i; DWORD i, found=0;
if (!object) { if (!object) {
return NULL; return NULL;
@ -1503,22 +1504,32 @@ static PERF_INSTANCE_DEFINITION *get_disk_instance(sigar_t *sigar,
switch (counter->CounterNameTitleIndex) { switch (counter->CounterNameTitleIndex) {
case PERF_TITLE_DISK_READ: case PERF_TITLE_DISK_READ:
perf_offsets[PERF_IX_DISK_READ] = offset; perf_offsets[PERF_IX_DISK_READ] = offset;
found = 1;
break; break;
case PERF_TITLE_DISK_WRITE: case PERF_TITLE_DISK_WRITE:
perf_offsets[PERF_IX_DISK_WRITE] = offset; perf_offsets[PERF_IX_DISK_WRITE] = offset;
found = 1;
break; break;
case PERF_TITLE_DISK_READ_BYTES: case PERF_TITLE_DISK_READ_BYTES:
perf_offsets[PERF_IX_DISK_READ_BYTES] = offset; perf_offsets[PERF_IX_DISK_READ_BYTES] = offset;
found = 1;
break; break;
case PERF_TITLE_DISK_WRITE_BYTES: case PERF_TITLE_DISK_WRITE_BYTES:
perf_offsets[PERF_IX_DISK_WRITE_BYTES] = offset; perf_offsets[PERF_IX_DISK_WRITE_BYTES] = offset;
found = 1;
break; break;
case PERF_TITLE_DISK_QUEUE: case PERF_TITLE_DISK_QUEUE:
perf_offsets[PERF_IX_DISK_QUEUE] = offset; perf_offsets[PERF_IX_DISK_QUEUE] = offset;
found = 1;
break; break;
} }
} }
if (!found) {
*err = ENOENT;
return NULL;
}
if (num) { if (num) {
*num = object->NumInstances; *num = object->NumInstances;
} }