diff options
author | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2015-01-21 15:43:33 +0200 |
---|---|---|
committer | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2015-01-22 03:47:03 +0200 |
commit | 637fb48a9ae66053cc73d1e5b9bc22edf1eb9b93 (patch) | |
tree | c3df163c188fd991457a7351fcf734ac13ea1175 /tracefile_idlestat.c | |
parent | 4dfba97d23dc098a2c7c27e7d9d4b8216be1c33f (diff) |
Simplify event counting while loading a trace
load_text_data_line() has been split out of the original trace
file loading loop. The original code incremented event count
at the points of code that had successfully completed importing
a single event. As the new function additionally now returns
a return code indicating success, this incrementation can be
done at the call site. This removes the need to pass a pointer
to the count variable and allows further cleanup of the code.
Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
Diffstat (limited to 'tracefile_idlestat.c')
-rw-r--r-- | tracefile_idlestat.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/tracefile_idlestat.c b/tracefile_idlestat.c index 6067bfa..45b3b93 100644 --- a/tracefile_idlestat.c +++ b/tracefile_idlestat.c @@ -113,11 +113,10 @@ static struct cpuidle_cstates *load_and_build_cstate_info(FILE* f, char *buffer, return cstates; } -int load_text_data_line(char *buffer, struct cpuidle_datas *datas, char *format, double *begin, double *end, size_t *count, size_t *start) +int load_text_data_line(char *buffer, struct cpuidle_datas *datas, char *format, double *begin, double *end, size_t *start) { unsigned int state, freq, cpu; double time; - int ret; if (strstr(buffer, "cpu_idle")) { if (sscanf(buffer, format, &time, &state, &cpu) @@ -134,24 +133,20 @@ int load_text_data_line(char *buffer, struct cpuidle_datas *datas, char *format, } *end = time; - store_data(time, state, cpu, datas); - (*count)++; - return 0; - } else if (strstr(buffer, "cpu_frequency")) { + return store_data(time, state, cpu, datas); + } + + if (strstr(buffer, "cpu_frequency")) { if (sscanf(buffer, format, &time, &freq, &cpu) != 3) { fprintf(stderr, "warning: Unrecognized cpufreq " "record. The result of analysis might " "be wrong.\n"); return -1; } - cpu_change_pstate(datas, cpu, freq, time); - (*count)++; - return 0; + return cpu_change_pstate(datas, cpu, freq, time); } - ret = get_wakeup_irq(datas, buffer, *count); - *count += (0 == ret) ? 1 : 0; - return 0; + return get_wakeup_irq(datas, buffer); } void load_text_data_lines(FILE *f, char *buffer, struct cpuidle_datas *datas) @@ -162,7 +157,10 @@ void load_text_data_lines(FILE *f, char *buffer, struct cpuidle_datas *datas) setup_topo_states(datas); do { - load_text_data_line(buffer, datas, TRACE_FORMAT, &begin, &end, &count, &start); + if (load_text_data_line(buffer, datas, TRACE_FORMAT, + &begin, &end, &start) != -1) { + count++; + } } while (fgets(buffer, BUFSIZE, f)); fprintf(stderr, "Log is %lf secs long with %zd events\n", |