aboutsummaryrefslogtreecommitdiff
path: root/idlestat.c
diff options
context:
space:
mode:
authorTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-03 10:14:35 +0200
committerTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-05 09:52:39 +0200
commit3f4fdcf1c20e4efd7b17ca1dba8e5965e2fe3f66 (patch)
tree80f4c8d036e14de5cced5593aa31b454d84c3339 /idlestat.c
parentde4374bfaaa19ed53b6cdb037aa51f619e99b7d8 (diff)
idlestat: Fix recording of initial and final P-states
The initial and final pstates were stored only if the display options at the time of creating the trace file included display of P-states. Since the trace may later be imported with the P-state display on, add the pseudo P-state changes to the trace unconditionally. In addition, the return value of get_trace_ts was never checked for error. The error checking has been added. Since floating point comparison for equality is unreliable, the function now returns only status and the actual data is relayed by modifying memory pointed to by a function parameter. Error messages have been added to the get_trace_ts function. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
Diffstat (limited to 'idlestat.c')
-rw-r--r--idlestat.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/idlestat.c b/idlestat.c
index 01827ef..5d9f12e 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -93,25 +93,32 @@ static inline void *ptrerror(const char *str)
#define TRACE_TS_FORMAT "%*[^:]:%lf"
-static double get_trace_ts(void)
+static int get_trace_ts(double *ts)
{
FILE *f;
- double ts;
f = fopen(TRACE_STAT_FILE, "r");
if (!f)
- return -1;
+ return error("fopen " TRACE_STAT_FILE);
while (fgets(buffer, BUFSIZE, f)) {
if (!strstr(buffer, "now ts"))
continue;
- if (!sscanf(buffer, TRACE_TS_FORMAT, &ts))
- ts = -1;
- break;
+
+ fclose(f);
+
+ if (sscanf(buffer, TRACE_TS_FORMAT, ts) == 1)
+ return 0;
+
+ fprintf(stderr, "get_trace_ts: Failed to parse timestamp\n");
+ return -1;
}
+
fclose(f);
- return ts;
+ fprintf(stderr, "get_trace_ts: Failed to find timestamp in %s\n",
+ TRACE_STAT_FILE);
+ return -1;
}
static int display_cstates(struct report_ops *ops, void *arg, char *cpu, void *report_data)
@@ -1607,10 +1614,10 @@ int main(int argc, char *argv[], char *const envp[])
return 1;
/* Get starting timestamp */
- if (options.display & FREQUENCY_DISPLAY) {
- start_ts = get_trace_ts();
- initp = build_init_pstates();
- }
+ if (get_trace_ts(&start_ts) == -1)
+ return 1;
+
+ initp = build_init_pstates();
/* Start the recording */
if (idlestat_trace_enable(true))
@@ -1635,8 +1642,8 @@ int main(int argc, char *argv[], char *const envp[])
return 1;
/* Get ending timestamp */
- if (options.display & FREQUENCY_DISPLAY)
- end_ts = get_trace_ts();
+ if (get_trace_ts(&end_ts) == -1)
+ return 1;
/* At this point we should have some spurious wake up
* at the beginning of the traces and at the end (wake