From: Chris Mason Date: Thu, 17 Jan 2013 03:25:28 +0000 (-0500) Subject: iowatcher: Fix mpstat handling when the number of CPUs is not X-Git-Tag: blktrace-1.1.0~2^2~28 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=d7d5d7c301b07a235f39ebb6a4f629d19198509c;p=blktrace.git iowatcher: Fix mpstat handling when the number of CPUs is not in the mpstat output Signed-off-by: Chris Mason --- 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, '(');