diff options
author | Chris Mason <chris.mason@fusionio.com> | 2013-01-16 22:25:28 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-01-17 11:54:42 -0500 |
commit | e375df29db98e39de8fccc4db0b6f0208e437016 (patch) | |
tree | abfa27ea7127cb3e43c5e645b217a6f9634013b4 | |
parent | 01173e49b72d767bd2bbdae7e807249e02c57c45 (diff) | |
download | iowatcher-e375df29db98e39de8fccc4db0b6f0208e437016.tar.gz |
Fix mpstat handling when the number of CPUs is not
in the mpstat output
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r-- | mpstat.c | 34 |
1 files changed, 31 insertions, 3 deletions
@@ -68,7 +68,7 @@ int next_mpstat_line(struct trace *trace) char *next_mpstat(struct trace *trace) { - char *cur = trace->mpstat_cur; + char *cur; cur = strstr(trace->mpstat_cur, record_header); if (cur) { @@ -115,6 +115,34 @@ static void find_last_mpstat_time(struct trace *trace) trace->mpstat_seconds = num_mpstats; } +static int guess_mpstat_cpus(struct trace *trace) +{ + char *cur; + int ret; + int count = 0; + + cur = first_mpstat(trace); + if (!cur) + return 0; + + while (1) { + ret = next_mpstat_line(trace); + if (ret) + break; + + cur = trace->mpstat_cur; + count++; + + if (!cur) + break; + + if (cur[0] == '\n') + break; + } + trace->mpstat_num_cpus = count - 1; + return 0; +} + static int count_mpstat_cpus(struct trace *trace) { char *cur = trace->mpstat_start; @@ -123,10 +151,10 @@ static int count_mpstat_cpus(struct trace *trace) int len; char *line; first_mpstat(trace); - cpu = strstr(cur, " CPU)"); if (!cpu) - return 0; + return guess_mpstat_cpus(trace); + line = strndup(cur, cpu - cur); record = strrchr(line, '('); |