5 #include "util/cache.h"
6 #include "util/symbol.h"
7 #include "util/thread.h"
8 #include "util/header.h"
9 #include "util/session.h"
11 #include "util/parse-options.h"
12 #include "util/trace-event.h"
14 #include "util/debug.h"
16 #include <sys/prctl.h>
18 #include <semaphore.h>
22 static const char *file_name
;
23 static char name_buffer
[256];
25 static const char * const kvm_usage
[] = {
26 "perf kvm [<options>] {top|record|report|diff|buildid-list}",
30 static const struct option kvm_options
[] = {
31 OPT_STRING('i', "input", &file_name
, "file",
33 OPT_STRING('o', "output", &file_name
, "file",
35 OPT_BOOLEAN(0, "guest", &perf_guest
,
36 "Collect guest os data"),
37 OPT_BOOLEAN(0, "host", &perf_host
,
38 "Collect host os data"),
39 OPT_STRING(0, "guestmount", &symbol_conf
.guestmount
, "directory",
40 "guest mount directory under which every guest os"
41 " instance has a subdir"),
42 OPT_STRING(0, "guestvmlinux", &symbol_conf
.default_guest_vmlinux_name
,
43 "file", "file saving guest os vmlinux"),
44 OPT_STRING(0, "guestkallsyms", &symbol_conf
.default_guest_kallsyms
,
45 "file", "file saving guest os /proc/kallsyms"),
46 OPT_STRING(0, "guestmodules", &symbol_conf
.default_guest_modules
,
47 "file", "file saving guest os /proc/modules"),
51 static int __cmd_record(int argc
, const char **argv
)
53 int rec_argc
, i
= 0, j
;
54 const char **rec_argv
;
57 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
58 rec_argv
[i
++] = strdup("record");
59 rec_argv
[i
++] = strdup("-o");
60 rec_argv
[i
++] = strdup(file_name
);
61 for (j
= 1; j
< argc
; j
++, i
++)
62 rec_argv
[i
] = argv
[j
];
64 BUG_ON(i
!= rec_argc
);
66 return cmd_record(i
, rec_argv
, NULL
);
69 static int __cmd_report(int argc
, const char **argv
)
71 int rec_argc
, i
= 0, j
;
72 const char **rec_argv
;
75 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
76 rec_argv
[i
++] = strdup("report");
77 rec_argv
[i
++] = strdup("-i");
78 rec_argv
[i
++] = strdup(file_name
);
79 for (j
= 1; j
< argc
; j
++, i
++)
80 rec_argv
[i
] = argv
[j
];
82 BUG_ON(i
!= rec_argc
);
84 return cmd_report(i
, rec_argv
, NULL
);
87 static int __cmd_buildid_list(int argc
, const char **argv
)
89 int rec_argc
, i
= 0, j
;
90 const char **rec_argv
;
93 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
94 rec_argv
[i
++] = strdup("buildid-list");
95 rec_argv
[i
++] = strdup("-i");
96 rec_argv
[i
++] = strdup(file_name
);
97 for (j
= 1; j
< argc
; j
++, i
++)
98 rec_argv
[i
] = argv
[j
];
100 BUG_ON(i
!= rec_argc
);
102 return cmd_buildid_list(i
, rec_argv
, NULL
);
105 int cmd_kvm(int argc
, const char **argv
, const char *prefix __used
)
110 argc
= parse_options(argc
, argv
, kvm_options
, kvm_usage
,
111 PARSE_OPT_STOP_AT_NON_OPTION
);
113 usage_with_options(kvm_usage
, kvm_options
);
119 if (perf_host
&& !perf_guest
)
120 sprintf(name_buffer
, "perf.data.host");
121 else if (!perf_host
&& perf_guest
)
122 sprintf(name_buffer
, "perf.data.guest");
124 sprintf(name_buffer
, "perf.data.kvm");
125 file_name
= name_buffer
;
128 if (!strncmp(argv
[0], "rec", 3))
129 return __cmd_record(argc
, argv
);
130 else if (!strncmp(argv
[0], "rep", 3))
131 return __cmd_report(argc
, argv
);
132 else if (!strncmp(argv
[0], "diff", 4))
133 return cmd_diff(argc
, argv
, NULL
);
134 else if (!strncmp(argv
[0], "top", 3))
135 return cmd_top(argc
, argv
, NULL
);
136 else if (!strncmp(argv
[0], "buildid-list", 12))
137 return __cmd_buildid_list(argc
, argv
);
139 usage_with_options(kvm_usage
, kvm_options
);