aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2013-05-06 12:28:04 +0200
committerDaniel Lezcano <daniel.lezcano@free.fr>2013-05-06 12:28:04 +0200
commitf0b53ce34662525e5fc2022fbb79c97d34446c71 (patch)
tree223d1b1de95de06e7930aaccfd36ea7f9e1641d6
parentcc595d5f92bfe63f7f551ec9a0ebd7ed20961981 (diff)
downloadidlestat-f0b53ce34662525e5fc2022fbb79c97d34446c71.tar.gz
fix segfault when reading a file with non cpu_idle traces
The code is not designed to handle traces not coming from cpu_idle sub systems. Ignoring these lines. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--idlestat.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/idlestat.c b/idlestat.c
index a827f84..18635c4 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -276,8 +276,7 @@ static struct cpuidle_datas *load_data(const char *path)
FILE *f;
unsigned int state = 0, cpu = 0, nrcpus= 0;
double time, begin, end;
- size_t count;
-
+ size_t count, start;
struct cpuidle_datas *datas;
f = fopen(path, "r");
@@ -302,13 +301,18 @@ static struct cpuidle_datas *load_data(const char *path)
datas->nrcpus = nrcpus;
- for (; fgets(buffer, BUFSIZE, f); count++) {
+ for (start = 1; fgets(buffer, BUFSIZE, f); count++) {
+
+ if (!strstr(buffer, "cpu_idle"))
+ continue;
sscanf(buffer, "%*[^]]] %lf:%*[^=]=%u%*[^=]=%d",
&time, &state, &cpu);
- if (count == 2)
+ if (start) {
begin = time;
+ start = 0;
+ }
end = time;
store_data(time, state, cpu, datas, count);