From 147c931d7d4e51312abcbfc870d9f13e8bcb47e9 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 8 Nov 2005 18:16:03 +0000 Subject: [PATCH] fail gracefully if no perf counters are found for disk i/o metrics --- src/os/win32/win32_sigar.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index f10fd40c..fa3be9b9 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -1485,10 +1485,11 @@ static PERF_INSTANCE_DEFINITION *get_disk_instance(sigar_t *sigar, DWORD *perf_offsets, 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_COUNTER_DEFINITION *counter; - DWORD i; + DWORD i, found=0; if (!object) { return NULL; @@ -1503,22 +1504,32 @@ static PERF_INSTANCE_DEFINITION *get_disk_instance(sigar_t *sigar, switch (counter->CounterNameTitleIndex) { case PERF_TITLE_DISK_READ: perf_offsets[PERF_IX_DISK_READ] = offset; + found = 1; break; case PERF_TITLE_DISK_WRITE: perf_offsets[PERF_IX_DISK_WRITE] = offset; + found = 1; break; case PERF_TITLE_DISK_READ_BYTES: perf_offsets[PERF_IX_DISK_READ_BYTES] = offset; + found = 1; break; case PERF_TITLE_DISK_WRITE_BYTES: perf_offsets[PERF_IX_DISK_WRITE_BYTES] = offset; + found = 1; break; case PERF_TITLE_DISK_QUEUE: perf_offsets[PERF_IX_DISK_QUEUE] = offset; + found = 1; break; } } + if (!found) { + *err = ENOENT; + return NULL; + } + if (num) { *num = object->NumInstances; }