diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-19 15:12:39 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-20 12:22:44 -0400 |
commit | c5e4027e056c3027f682f0d69fe9fd75083b65f8 (patch) | |
tree | 19c278858df6393728458f22cb4c8dc71a746788 /tools/perf | |
parent | 58db1d6e7d5d24afa2d32e916fd6f6b6d240ba93 (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')
-rw-r--r-- | tools/perf/builtin-buildid-cache.c | 1 | ||||
-rw-r--r-- | tools/perf/builtin-kvm.c | 1 | ||||
-rw-r--r-- | tools/perf/builtin-record.c | 1 | ||||
-rw-r--r-- | tools/perf/util/time-utils.c | 25 | ||||
-rw-r--r-- | tools/perf/util/time-utils.h | 7 | ||||
-rw-r--r-- | tools/perf/util/util.c | 25 | ||||
-rw-r--r-- | tools/perf/util/util.h | 6 |
7 files changed, 35 insertions, 31 deletions
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 034c3d4a7b27..64b44e81c771 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "util/build-id.h" | 22 | #include "util/build-id.h" |
23 | #include "util/session.h" | 23 | #include "util/session.h" |
24 | #include "util/symbol.h" | 24 | #include "util/symbol.h" |
25 | #include "util/time-utils.h" | ||
25 | 26 | ||
26 | static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) | 27 | static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) |
27 | { | 28 | { |
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 2b1732cfc0be..d86ac0ac2c99 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #ifdef HAVE_TIMERFD_SUPPORT | 24 | #ifdef HAVE_TIMERFD_SUPPORT |
25 | #include <sys/timerfd.h> | 25 | #include <sys/timerfd.h> |
26 | #endif | 26 | #endif |
27 | #include <sys/time.h> | ||
27 | 28 | ||
28 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
29 | #include <linux/time64.h> | 30 | #include <linux/time64.h> |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 99156b4363a5..32a9a68d38a2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "util/bpf-loader.h" | 38 | #include "util/bpf-loader.h" |
39 | #include "util/trigger.h" | 39 | #include "util/trigger.h" |
40 | #include "util/perf-hooks.h" | 40 | #include "util/perf-hooks.h" |
41 | #include "util/time-utils.h" | ||
41 | #include "util/units.h" | 42 | #include "util/units.h" |
42 | #include "asm/bug.h" | 43 | #include "asm/bug.h" |
43 | 44 | ||
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 | |||
121 | int 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 | |||
129 | int 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 | } | ||
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index c1f197c4af6c..8656be08513b 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h | |||
@@ -1,6 +1,9 @@ | |||
1 | #ifndef _TIME_UTILS_H_ | 1 | #ifndef _TIME_UTILS_H_ |
2 | #define _TIME_UTILS_H_ | 2 | #define _TIME_UTILS_H_ |
3 | 3 | ||
4 | #include <stddef.h> | ||
5 | #include <linux/types.h> | ||
6 | |||
4 | struct perf_time_interval { | 7 | struct perf_time_interval { |
5 | u64 start, end; | 8 | u64 start, end; |
6 | }; | 9 | }; |
@@ -11,4 +14,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr); | |||
11 | 14 | ||
12 | bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); | 15 | bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); |
13 | 16 | ||
17 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); | ||
18 | |||
19 | int fetch_current_timestamp(char *buf, size_t sz); | ||
20 | |||
14 | #endif | 21 | #endif |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 7741d5f6022b..e86dba2f791a 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -381,14 +381,6 @@ void sighandler_dump_stack(int sig) | |||
381 | raise(sig); | 381 | raise(sig); |
382 | } | 382 | } |
383 | 383 | ||
384 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) | ||
385 | { | ||
386 | u64 sec = timestamp / NSEC_PER_SEC; | ||
387 | u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC; | ||
388 | |||
389 | return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); | ||
390 | } | ||
391 | |||
392 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags) | 384 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags) |
393 | { | 385 | { |
394 | struct parse_tag *i = tags; | 386 | struct parse_tag *i = tags; |
@@ -692,20 +684,3 @@ out: | |||
692 | 684 | ||
693 | return tip; | 685 | return tip; |
694 | } | 686 | } |
695 | |||
696 | int fetch_current_timestamp(char *buf, size_t sz) | ||
697 | { | ||
698 | struct timeval tv; | ||
699 | struct tm tm; | ||
700 | char dt[32]; | ||
701 | |||
702 | if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) | ||
703 | return -1; | ||
704 | |||
705 | if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) | ||
706 | return -1; | ||
707 | |||
708 | scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); | ||
709 | |||
710 | return 0; | ||
711 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index add9e77369a2..dc8eb942f92b 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -20,10 +20,7 @@ | |||
20 | #include <limits.h> | 20 | #include <limits.h> |
21 | #include <sys/param.h> | 21 | #include <sys/param.h> |
22 | #include <sys/types.h> | 22 | #include <sys/types.h> |
23 | #include <sys/time.h> | ||
24 | #include <time.h> | ||
25 | #include <assert.h> | 23 | #include <assert.h> |
26 | #include <utime.h> | ||
27 | #include <sys/wait.h> | 24 | #include <sys/wait.h> |
28 | #include <poll.h> | 25 | #include <poll.h> |
29 | #include <sys/socket.h> | 26 | #include <sys/socket.h> |
@@ -125,12 +122,9 @@ int fetch_kernel_version(unsigned int *puint, | |||
125 | #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) | 122 | #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) |
126 | 123 | ||
127 | const char *perf_tip(const char *dirpath); | 124 | const char *perf_tip(const char *dirpath); |
128 | int fetch_current_timestamp(char *buf, size_t sz); | ||
129 | 125 | ||
130 | #ifndef HAVE_SCHED_GETCPU_SUPPORT | 126 | #ifndef HAVE_SCHED_GETCPU_SUPPORT |
131 | int sched_getcpu(void); | 127 | int sched_getcpu(void); |
132 | #endif | 128 | #endif |
133 | 129 | ||
134 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); | ||
135 | |||
136 | #endif /* GIT_COMPAT_UTIL_H */ | 130 | #endif /* GIT_COMPAT_UTIL_H */ |