From 99620a5d0cc8e2dd9aedb629a6e81825f0db020e Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Mon, 24 Oct 2016 11:02:45 +0900 Subject: perf tools: Introduce timestamp__scnprintf_usec() Joonwoo reported that there's a mismatch between timestamps in script and sched commands. This was because of difference in printing the timestamp. Factor out the code and share it so that they can be in sync. Also I found that sched map has similar problem, fix it too. Committer notes: Fixed the max_lat_at bug introduced by Namhyung's original patch, as pointed out by Joonwoo, and made it a function following the scnprintf() model, i.e. returning the number of bytes formatted, and receiving as the first parameter the object from where the data to the formatting is obtained, renaming it from: char *timestamp_in_usec(char *bf, size_t size, u64 timestamp) to int timestamp__scnprintf_usec(u64 timestamp, char *bf, size_t size) Reported-by: Joonwoo Park Signed-off-by: Namhyung Kim Cc: David Ahern Cc: Jiri Olsa Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20161024020246.14928-3-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/util.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools/perf/util/util.c') diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 85c56800f17a..5bbd1f609f1f 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -433,6 +433,14 @@ int parse_nsec_time(const char *str, u64 *ptime) return 0; } +int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) +{ + u64 sec = timestamp / NSEC_PER_SEC; + u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC; + + return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); +} + unsigned long parse_tag_value(const char *str, struct parse_tag *tags) { struct parse_tag *i = tags; -- cgit v1.2.3