diff options
author | Chris Mason <chris.mason@fusionio.com> | 2013-01-16 22:25:28 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-09-24 12:02:07 -0700 |
commit | d7d5d7c301b07a235f39ebb6a4f629d19198509c (patch) | |
tree | c7dfd11515c33f99b2725bdbc1f86d8b69526bfa | |
parent | 2203e914a11dc2ccf1b673e1627c50246b2fc904 (diff) | |
download | blktrace-d7d5d7c301b07a235f39ebb6a4f629d19198509c.tar.gz |
iowatcher: 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-- | iowatcher/mpstat.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/iowatcher/mpstat.c b/iowatcher/mpstat.c index 022f589..f76972a 100644 --- a/iowatcher/mpstat.c +++ b/iowatcher/mpstat.c @@ -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, '('); |