diff options
| author | Andi Kleen <ak@linux.intel.com> | 2019-03-05 09:47:53 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-03-11 10:56:02 -0400 |
| commit | f8c856cb2c947f4fad0a2dff5e95cdcddb801303 (patch) | |
| tree | 92940115a785364920289795783f92ce54f7faf1 | |
| parent | 52bab8868211b7c504146f6239e101421d4d125b (diff) | |
perf time-utils: Add utility function to print time stamps in nanoseconds
Add a utility function to print nanosecond timestamps.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20190305144758.12397-11-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/util/time-utils.c | 8 | ||||
| -rw-r--r-- | tools/perf/util/time-utils.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index 0f53baec660e..20663a460df3 100644 --- a/tools/perf/util/time-utils.c +++ b/tools/perf/util/time-utils.c | |||
| @@ -453,6 +453,14 @@ int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) | |||
| 453 | return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); | 453 | return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); |
| 454 | } | 454 | } |
| 455 | 455 | ||
| 456 | int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz) | ||
| 457 | { | ||
| 458 | u64 sec = timestamp / NSEC_PER_SEC, | ||
| 459 | nsec = timestamp % NSEC_PER_SEC; | ||
| 460 | |||
| 461 | return scnprintf(buf, sz, "%" PRIu64 ".%09" PRIu64, sec, nsec); | ||
| 462 | } | ||
| 463 | |||
| 456 | int fetch_current_timestamp(char *buf, size_t sz) | 464 | int fetch_current_timestamp(char *buf, size_t sz) |
| 457 | { | 465 | { |
| 458 | struct timeval tv; | 466 | struct timeval tv; |
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index b923de44e36f..72a42ea1d513 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h | |||
| @@ -30,6 +30,7 @@ int perf_time__parse_for_ranges(const char *str, struct perf_session *session, | |||
| 30 | int *range_size, int *range_num); | 30 | int *range_size, int *range_num); |
| 31 | 31 | ||
| 32 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); | 32 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); |
| 33 | int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz); | ||
| 33 | 34 | ||
| 34 | int fetch_current_timestamp(char *buf, size_t sz); | 35 | int fetch_current_timestamp(char *buf, size_t sz); |
| 35 | 36 | ||
