diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 034c3d4a7b27b31cf2b345cde676328081596d74..64b44e81c7715a1c38df8e0309bde80b7d24bf86 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -22,6 +22,7 @@ #include "util/build-id.h" #include "util/session.h" #include "util/symbol.h" +#include "util/time-utils.h" static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) { diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 2b1732cfc0beb0b8f4d3a99865f16a7d8a3212fe..d86ac0ac2c99f05e116a3bdbfb3d9a0625e79176 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -24,6 +24,7 @@ #ifdef HAVE_TIMERFD_SUPPORT #include #endif +#include #include #include diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 99156b4363a5005acf846a8f62a388074524e0e7..32a9a68d38a24e680ed8de92457ae0fd3879c339 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -38,6 +38,7 @@ #include "util/bpf-loader.h" #include "util/trigger.h" #include "util/perf-hooks.h" +#include "util/time-utils.h" #include "util/units.h" #include "asm/bug.h" diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index d1b21c72206d8b1a6a52697adb3091ff09e81ec2..5b5d0214debdcb99c563c84abe4d98746ff6a518 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) return false; } + +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); +} + +int fetch_current_timestamp(char *buf, size_t sz) +{ + struct timeval tv; + struct tm tm; + char dt[32]; + + if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) + return -1; + + if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) + return -1; + + scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); + + return 0; +} diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index c1f197c4af6c9aa019cdebc9625b07020f30ad4e..8656be08513b178ab64e4c716ca2d4f0a9378900 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h @@ -1,6 +1,9 @@ #ifndef _TIME_UTILS_H_ #define _TIME_UTILS_H_ +#include +#include + struct perf_time_interval { u64 start, end; }; @@ -11,4 +14,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr); bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); +int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); + +int fetch_current_timestamp(char *buf, size_t sz); + #endif diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 7741d5f6022b2106ccad925c56eebcf928882c1a..e86dba2f791a3574c97fc322f7b255cfd04e98a6 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -381,14 +381,6 @@ void sighandler_dump_stack(int sig) raise(sig); } -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; @@ -692,20 +684,3 @@ const char *perf_tip(const char *dirpath) return tip; } - -int fetch_current_timestamp(char *buf, size_t sz) -{ - struct timeval tv; - struct tm tm; - char dt[32]; - - if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) - return -1; - - if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) - return -1; - - scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); - - return 0; -} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index add9e77369a28d8e754a374ab5fad27d6fe1c087..dc8eb942f92ba5ff8d8eda5d62bf9af94c140c92 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -20,10 +20,7 @@ #include #include #include -#include -#include #include -#include #include #include #include @@ -125,12 +122,9 @@ int fetch_kernel_version(unsigned int *puint, #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) const char *perf_tip(const char *dirpath); -int fetch_current_timestamp(char *buf, size_t sz); #ifndef HAVE_SCHED_GETCPU_SUPPORT int sched_getcpu(void); #endif -int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); - #endif /* GIT_COMPAT_UTIL_H */