mirror of
https://github.com/torvalds/linux
synced 2024-09-20 11:07:02 +00:00
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>
This commit is contained in:
parent
58db1d6e7d
commit
c5e4027e05
|
@ -22,6 +22,7 @@
|
||||||
#include "util/build-id.h"
|
#include "util/build-id.h"
|
||||||
#include "util/session.h"
|
#include "util/session.h"
|
||||||
#include "util/symbol.h"
|
#include "util/symbol.h"
|
||||||
|
#include "util/time-utils.h"
|
||||||
|
|
||||||
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
|
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#ifdef HAVE_TIMERFD_SUPPORT
|
#ifdef HAVE_TIMERFD_SUPPORT
|
||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/time64.h>
|
#include <linux/time64.h>
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "util/bpf-loader.h"
|
#include "util/bpf-loader.h"
|
||||||
#include "util/trigger.h"
|
#include "util/trigger.h"
|
||||||
#include "util/perf-hooks.h"
|
#include "util/perf-hooks.h"
|
||||||
|
#include "util/time-utils.h"
|
||||||
#include "util/units.h"
|
#include "util/units.h"
|
||||||
#include "asm/bug.h"
|
#include "asm/bug.h"
|
||||||
|
|
||||||
|
|
|
@ -117,3 +117,28 @@ bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#ifndef _TIME_UTILS_H_
|
#ifndef _TIME_UTILS_H_
|
||||||
#define _TIME_UTILS_H_
|
#define _TIME_UTILS_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <linux/types.h>
|
||||||
|
|
||||||
struct perf_time_interval {
|
struct perf_time_interval {
|
||||||
u64 start, end;
|
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);
|
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
|
#endif
|
||||||
|
|
|
@ -381,14 +381,6 @@ void sighandler_dump_stack(int sig)
|
||||||
raise(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)
|
unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
|
||||||
{
|
{
|
||||||
struct parse_tag *i = tags;
|
struct parse_tag *i = tags;
|
||||||
|
@ -692,20 +684,3 @@ const char *perf_tip(const char *dirpath)
|
||||||
|
|
||||||
return tip;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,10 +20,7 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <utime.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -125,12 +122,9 @@ int fetch_kernel_version(unsigned int *puint,
|
||||||
#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
|
#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
|
||||||
|
|
||||||
const char *perf_tip(const char *dirpath);
|
const char *perf_tip(const char *dirpath);
|
||||||
int fetch_current_timestamp(char *buf, size_t sz);
|
|
||||||
|
|
||||||
#ifndef HAVE_SCHED_GETCPU_SUPPORT
|
#ifndef HAVE_SCHED_GETCPU_SUPPORT
|
||||||
int sched_getcpu(void);
|
int sched_getcpu(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
|
|
||||||
|
|
||||||
#endif /* GIT_COMPAT_UTIL_H */
|
#endif /* GIT_COMPAT_UTIL_H */
|
||||||
|
|
Loading…
Reference in a new issue