aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/time-utils.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-04-19 15:12:39 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-04-20 12:22:44 -0400
commitc5e4027e056c3027f682f0d69fe9fd75083b65f8 (patch)
tree19c278858df6393728458f22cb4c8dc71a746788 /tools/perf/util/time-utils.c
parent58db1d6e7d5d24afa2d32e916fd6f6b6d240ba93 (diff)
perf tools: Move timestamp routines from util.h to time-utils.h
We already have a header for time utilities, so use it. Link: http://lkml.kernel.org/n/tip-sijzpbvutlg0c3oxn49hy9ca@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/time-utils.c')
-rw-r--r--tools/perf/util/time-utils.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index d1b21c72206d..5b5d0214debd 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -117,3 +117,28 @@ bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
117 117
118 return false; 118 return false;
119} 119}
120
121int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
122{
123 u64 sec = timestamp / NSEC_PER_SEC;
124 u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC;
125
126 return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec);
127}
128
129int fetch_current_timestamp(char *buf, size_t sz)
130{
131 struct timeval tv;
132 struct tm tm;
133 char dt[32];
134
135 if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm))
136 return -1;
137
138 if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm))
139 return -1;
140
141 scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000);
142
143 return 0;
144}