Commit 37b20151 authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo

perf tools: Move timestamp creation to util

Timestamp generation becomes a public available helper. Which will
be used by 'perf record', help it output to split output file based
on time.

For example:

 perf.data.2015122620363710
 perf.data.2015122620364092
 perf.data.2015122620365423
 ...
Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1453715801-7732-27-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarHe Kuang <hekuang@huawei.com>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8fd34e1c
...@@ -38,19 +38,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) ...@@ -38,19 +38,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
static int build_id_cache__kcore_dir(char *dir, size_t sz) static int build_id_cache__kcore_dir(char *dir, size_t sz)
{ {
struct timeval tv; return fetch_current_timestamp(dir, sz);
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(dir, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000);
return 0;
} }
static bool same_kallsyms_reloc(const char *from_dir, char *to_dir) static bool same_kallsyms_reloc(const char *from_dir, char *to_dir)
......
...@@ -701,3 +701,20 @@ bool is_regular_file(const char *file) ...@@ -701,3 +701,20 @@ bool is_regular_file(const char *file)
return S_ISREG(st.st_mode); return S_ISREG(st.st_mode);
} }
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;
}
...@@ -344,5 +344,6 @@ int fetch_kernel_version(unsigned int *puint, ...@@ -344,5 +344,6 @@ int fetch_kernel_version(unsigned int *puint,
const char *perf_tip(const char *dirpath); const char *perf_tip(const char *dirpath);
bool is_regular_file(const char *file); bool is_regular_file(const char *file);
int fetch_current_timestamp(char *buf, size_t sz);
#endif /* GIT_COMPAT_UTIL_H */ #endif /* GIT_COMPAT_UTIL_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment