Commit e1a2b174 authored by Dongsheng Yang's avatar Dongsheng Yang Committed by Arnaldo Carvalho de Melo

perf kvm: Move code to generate filename for perf-kvm to function.

The code in builtin-kvm.c to generate filename for perf-kvm is useful to
other command such as builtin-diff.

This patch move the related code form builtin-kvm.c to util/util.c and
wrap them in a function named get_filename_for_perf_kvm.
Signed-off-by: default avatarDongsheng Yang <yangds.fnst@cn.fujitsu.com>
Link: http://lkml.kernel.org/r/5e09a5c47e8a495e888cbdc65a6fafb2c950f529.1386368672.git.yangds.fnst@cn.fujitsu.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 6f1d0c86
...@@ -1713,12 +1713,7 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -1713,12 +1713,7 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
perf_guest = 1; perf_guest = 1;
if (!file_name) { if (!file_name) {
if (perf_host && !perf_guest) file_name = get_filename_for_perf_kvm();
file_name = strdup("perf.data.host");
else if (!perf_host && perf_guest)
file_name = strdup("perf.data.guest");
else
file_name = strdup("perf.data.kvm");
if (!file_name) { if (!file_name) {
pr_err("Failed to allocate memory for filename\n"); pr_err("Failed to allocate memory for filename\n");
......
...@@ -482,3 +482,17 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep) ...@@ -482,3 +482,17 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
close(fd); close(fd);
return err; return err;
} }
const char *get_filename_for_perf_kvm(void)
{
const char *filename;
if (perf_host && !perf_guest)
filename = strdup("perf.data.host");
else if (!perf_host && perf_guest)
filename = strdup("perf.data.guest");
else
filename = strdup("perf.data.kvm");
return filename;
}
...@@ -321,4 +321,6 @@ void free_srcline(char *srcline); ...@@ -321,4 +321,6 @@ void free_srcline(char *srcline);
int filename__read_int(const char *filename, int *value); int filename__read_int(const char *filename, int *value);
int filename__read_str(const char *filename, char **buf, size_t *sizep); int filename__read_str(const char *filename, char **buf, size_t *sizep);
const char *get_filename_for_perf_kvm(void);
#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