perf kvm: Move code to generate filename for perf-kvm to function.
authorDongsheng Yang <yangds.fnst@cn.fujitsu.com>
Fri, 6 Dec 2013 22:25:51 +0000 (17:25 -0500)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Dec 2013 18:23:56 +0000 (15:23 -0300)
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: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Link: http://lkml.kernel.org/r/5e09a5c47e8a495e888cbdc65a6fafb2c950f529.1386368672.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kvm.c
tools/perf/util/util.c
tools/perf/util/util.h

index c2e5d56a291dcf3d8bdb140cfffbb42d6c5ab6f6..c6fa3cbd45a9c0b374c5d2fc361b72f10699e3a5 100644 (file)
@@ -1713,12 +1713,7 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
                perf_guest = 1;
 
        if (!file_name) {
-               if (perf_host && !perf_guest)
-                       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");
+               file_name = get_filename_for_perf_kvm();
 
                if (!file_name) {
                        pr_err("Failed to allocate memory for filename\n");
index bae8756a4eb1ed7221518879bb1e841c7f9c8e0c..4a57609c0b43ba1f89ae3fee149aea8cc2755d7a 100644 (file)
@@ -482,3 +482,17 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
        close(fd);
        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;
+}
index 659abf30e01bf3a13779a712b3ec50031420b852..0171213d1d4db8c5cff8cda8a1458f1bf170735c 100644 (file)
@@ -321,4 +321,6 @@ void free_srcline(char *srcline);
 
 int filename__read_int(const char *filename, int *value);
 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 */