Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1 | #include "builtin.h" |
| 2 | #include "perf.h" |
| 3 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 4 | #include "util/evsel.h" |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 5 | #include "util/evlist.h" |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 6 | #include "util/util.h" |
| 7 | #include "util/cache.h" |
| 8 | #include "util/symbol.h" |
| 9 | #include "util/thread.h" |
| 10 | #include "util/header.h" |
| 11 | #include "util/session.h" |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 12 | #include "util/intlist.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 13 | #include <subcmd/parse-options.h> |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 14 | #include "util/trace-event.h" |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 15 | #include "util/debug.h" |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 16 | #include "util/tool.h" |
| 17 | #include "util/stat.h" |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 18 | #include "util/top.h" |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 19 | #include "util/data.h" |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 20 | #include "util/ordered-events.h" |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 21 | |
| 22 | #include <sys/prctl.h> |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 23 | #ifdef HAVE_TIMERFD_SUPPORT |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 24 | #include <sys/timerfd.h> |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 25 | #endif |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 26 | |
Arnaldo Carvalho de Melo | 877a7a1 | 2017-04-17 11:39:06 -0300 | [diff] [blame] | 27 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | bd48c63 | 2016-08-05 15:40:30 -0300 | [diff] [blame] | 28 | #include <linux/time64.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame^] | 29 | #include <inttypes.h> |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 30 | #include <termios.h> |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 31 | #include <semaphore.h> |
| 32 | #include <pthread.h> |
| 33 | #include <math.h> |
| 34 | |
Alexander Yarygin | da50ad6 | 2014-07-03 17:59:49 +0400 | [diff] [blame] | 35 | #ifdef HAVE_KVM_STAT_SUPPORT |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 36 | #include "util/kvm-stat.h" |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 37 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 38 | void exit_event_get_key(struct perf_evsel *evsel, |
| 39 | struct perf_sample *sample, |
| 40 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 41 | { |
| 42 | key->info = 0; |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 43 | key->key = perf_evsel__intval(evsel, sample, kvm_exit_reason); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 44 | } |
| 45 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 46 | bool kvm_exit_event(struct perf_evsel *evsel) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 47 | { |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 48 | return !strcmp(evsel->name, kvm_exit_trace); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 49 | } |
| 50 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 51 | bool exit_event_begin(struct perf_evsel *evsel, |
| 52 | struct perf_sample *sample, struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 53 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 54 | if (kvm_exit_event(evsel)) { |
| 55 | exit_event_get_key(evsel, sample, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 56 | return true; |
| 57 | } |
| 58 | |
| 59 | return false; |
| 60 | } |
| 61 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 62 | bool kvm_entry_event(struct perf_evsel *evsel) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 63 | { |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 64 | return !strcmp(evsel->name, kvm_entry_trace); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 65 | } |
| 66 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 67 | bool exit_event_end(struct perf_evsel *evsel, |
| 68 | struct perf_sample *sample __maybe_unused, |
| 69 | struct event_key *key __maybe_unused) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 70 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 71 | return kvm_entry_event(evsel); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Alexander Yarygin | df74c13 | 2014-07-03 17:59:50 +0400 | [diff] [blame] | 74 | static const char *get_exit_reason(struct perf_kvm_stat *kvm, |
| 75 | struct exit_reasons_table *tbl, |
| 76 | u64 exit_code) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 77 | { |
Alexander Yarygin | df74c13 | 2014-07-03 17:59:50 +0400 | [diff] [blame] | 78 | while (tbl->reason != NULL) { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 79 | if (tbl->exit_code == exit_code) |
| 80 | return tbl->reason; |
| 81 | tbl++; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | pr_err("unknown kvm exit code:%lld on %s\n", |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 85 | (unsigned long long)exit_code, kvm->exit_reasons_isa); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 86 | return "UNKNOWN"; |
| 87 | } |
| 88 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 89 | void exit_event_decode_key(struct perf_kvm_stat *kvm, |
| 90 | struct event_key *key, |
| 91 | char *decode) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 92 | { |
Alexander Yarygin | 3be8e2a | 2014-07-03 18:29:07 +0400 | [diff] [blame] | 93 | const char *exit_reason = get_exit_reason(kvm, key->exit_reasons, |
Alexander Yarygin | df74c13 | 2014-07-03 17:59:50 +0400 | [diff] [blame] | 94 | key->key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 95 | |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 96 | scnprintf(decode, decode_str_len, "%s", exit_reason); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 97 | } |
| 98 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 99 | static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 100 | { |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 101 | struct kvm_reg_events_ops *events_ops = kvm_reg_events_ops; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 102 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 103 | for (events_ops = kvm_reg_events_ops; events_ops->name; events_ops++) { |
| 104 | if (!strcmp(events_ops->name, kvm->report_event)) { |
| 105 | kvm->events_ops = events_ops->ops; |
| 106 | return true; |
| 107 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 108 | } |
| 109 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 110 | return false; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 111 | } |
| 112 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 113 | struct vcpu_event_record { |
| 114 | int vcpu_id; |
| 115 | u64 start_time; |
| 116 | struct kvm_event *last_event; |
| 117 | }; |
| 118 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 119 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 120 | static void init_kvm_event_record(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 121 | { |
David Ahern | b880dee | 2012-10-08 11:17:30 -0600 | [diff] [blame] | 122 | unsigned int i; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 123 | |
David Ahern | b880dee | 2012-10-08 11:17:30 -0600 | [diff] [blame] | 124 | for (i = 0; i < EVENTS_CACHE_SIZE; i++) |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 125 | INIT_LIST_HEAD(&kvm->kvm_events_cache[i]); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 126 | } |
| 127 | |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 128 | #ifdef HAVE_TIMERFD_SUPPORT |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 129 | static void clear_events_cache_stats(struct list_head *kvm_events_cache) |
| 130 | { |
| 131 | struct list_head *head; |
| 132 | struct kvm_event *event; |
| 133 | unsigned int i; |
David Ahern | 62d04db | 2013-08-05 21:41:35 -0400 | [diff] [blame] | 134 | int j; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 135 | |
| 136 | for (i = 0; i < EVENTS_CACHE_SIZE; i++) { |
| 137 | head = &kvm_events_cache[i]; |
| 138 | list_for_each_entry(event, head, hash_entry) { |
| 139 | /* reset stats for event */ |
David Ahern | 62d04db | 2013-08-05 21:41:35 -0400 | [diff] [blame] | 140 | event->total.time = 0; |
| 141 | init_stats(&event->total.stats); |
| 142 | |
| 143 | for (j = 0; j < event->max_vcpu; ++j) { |
| 144 | event->vcpu[j].time = 0; |
| 145 | init_stats(&event->vcpu[j].stats); |
| 146 | } |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | } |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 150 | #endif |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 151 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 152 | static int kvm_events_hash_fn(u64 key) |
| 153 | { |
| 154 | return key & (EVENTS_CACHE_SIZE - 1); |
| 155 | } |
| 156 | |
| 157 | static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) |
| 158 | { |
| 159 | int old_max_vcpu = event->max_vcpu; |
David Ahern | 6ca5f30 | 2013-05-25 18:24:46 -0600 | [diff] [blame] | 160 | void *prev; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 161 | |
| 162 | if (vcpu_id < event->max_vcpu) |
| 163 | return true; |
| 164 | |
| 165 | while (event->max_vcpu <= vcpu_id) |
| 166 | event->max_vcpu += DEFAULT_VCPU_NUM; |
| 167 | |
David Ahern | 6ca5f30 | 2013-05-25 18:24:46 -0600 | [diff] [blame] | 168 | prev = event->vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 169 | event->vcpu = realloc(event->vcpu, |
| 170 | event->max_vcpu * sizeof(*event->vcpu)); |
| 171 | if (!event->vcpu) { |
David Ahern | 6ca5f30 | 2013-05-25 18:24:46 -0600 | [diff] [blame] | 172 | free(prev); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 173 | pr_err("Not enough memory\n"); |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | memset(event->vcpu + old_max_vcpu, 0, |
| 178 | (event->max_vcpu - old_max_vcpu) * sizeof(*event->vcpu)); |
| 179 | return true; |
| 180 | } |
| 181 | |
| 182 | static struct kvm_event *kvm_alloc_init_event(struct event_key *key) |
| 183 | { |
| 184 | struct kvm_event *event; |
| 185 | |
| 186 | event = zalloc(sizeof(*event)); |
| 187 | if (!event) { |
| 188 | pr_err("Not enough memory\n"); |
| 189 | return NULL; |
| 190 | } |
| 191 | |
| 192 | event->key = *key; |
Alexander Yarygin | acb61fc | 2014-04-09 16:21:59 +0200 | [diff] [blame] | 193 | init_stats(&event->total.stats); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 194 | return event; |
| 195 | } |
| 196 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 197 | static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 198 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 199 | { |
| 200 | struct kvm_event *event; |
| 201 | struct list_head *head; |
| 202 | |
| 203 | BUG_ON(key->key == INVALID_KEY); |
| 204 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 205 | head = &kvm->kvm_events_cache[kvm_events_hash_fn(key->key)]; |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 206 | list_for_each_entry(event, head, hash_entry) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 207 | if (event->key.key == key->key && event->key.info == key->info) |
| 208 | return event; |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 209 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 210 | |
| 211 | event = kvm_alloc_init_event(key); |
| 212 | if (!event) |
| 213 | return NULL; |
| 214 | |
| 215 | list_add(&event->hash_entry, head); |
| 216 | return event; |
| 217 | } |
| 218 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 219 | static bool handle_begin_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 220 | struct vcpu_event_record *vcpu_record, |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 221 | struct event_key *key, u64 timestamp) |
| 222 | { |
| 223 | struct kvm_event *event = NULL; |
| 224 | |
| 225 | if (key->key != INVALID_KEY) |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 226 | event = find_create_kvm_event(kvm, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 227 | |
| 228 | vcpu_record->last_event = event; |
| 229 | vcpu_record->start_time = timestamp; |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | static void |
| 234 | kvm_update_event_stats(struct kvm_event_stats *kvm_stats, u64 time_diff) |
| 235 | { |
| 236 | kvm_stats->time += time_diff; |
| 237 | update_stats(&kvm_stats->stats, time_diff); |
| 238 | } |
| 239 | |
| 240 | static double kvm_event_rel_stddev(int vcpu_id, struct kvm_event *event) |
| 241 | { |
| 242 | struct kvm_event_stats *kvm_stats = &event->total; |
| 243 | |
| 244 | if (vcpu_id != -1) |
| 245 | kvm_stats = &event->vcpu[vcpu_id]; |
| 246 | |
| 247 | return rel_stddev_stats(stddev_stats(&kvm_stats->stats), |
| 248 | avg_stats(&kvm_stats->stats)); |
| 249 | } |
| 250 | |
| 251 | static bool update_kvm_event(struct kvm_event *event, int vcpu_id, |
| 252 | u64 time_diff) |
| 253 | { |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 254 | if (vcpu_id == -1) { |
| 255 | kvm_update_event_stats(&event->total, time_diff); |
| 256 | return true; |
| 257 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 258 | |
| 259 | if (!kvm_event_expand(event, vcpu_id)) |
| 260 | return false; |
| 261 | |
| 262 | kvm_update_event_stats(&event->vcpu[vcpu_id], time_diff); |
| 263 | return true; |
| 264 | } |
| 265 | |
Alexander Yarygin | 3be8e2a | 2014-07-03 18:29:07 +0400 | [diff] [blame] | 266 | static bool is_child_event(struct perf_kvm_stat *kvm, |
| 267 | struct perf_evsel *evsel, |
| 268 | struct perf_sample *sample, |
| 269 | struct event_key *key) |
| 270 | { |
| 271 | struct child_event_ops *child_ops; |
| 272 | |
| 273 | child_ops = kvm->events_ops->child_ops; |
| 274 | |
| 275 | if (!child_ops) |
| 276 | return false; |
| 277 | |
| 278 | for (; child_ops->name; child_ops++) { |
| 279 | if (!strcmp(evsel->name, child_ops->name)) { |
| 280 | child_ops->get_key(evsel, sample, key); |
| 281 | return true; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | return false; |
| 286 | } |
| 287 | |
| 288 | static bool handle_child_event(struct perf_kvm_stat *kvm, |
| 289 | struct vcpu_event_record *vcpu_record, |
| 290 | struct event_key *key, |
| 291 | struct perf_sample *sample __maybe_unused) |
| 292 | { |
| 293 | struct kvm_event *event = NULL; |
| 294 | |
| 295 | if (key->key != INVALID_KEY) |
| 296 | event = find_create_kvm_event(kvm, key); |
| 297 | |
| 298 | vcpu_record->last_event = event; |
| 299 | |
| 300 | return true; |
| 301 | } |
| 302 | |
Alexander Yarygin | 54c801f | 2014-07-03 18:29:06 +0400 | [diff] [blame] | 303 | static bool skip_event(const char *event) |
| 304 | { |
| 305 | const char * const *skip_events; |
| 306 | |
| 307 | for (skip_events = kvm_skip_events; *skip_events; skip_events++) |
| 308 | if (!strcmp(event, *skip_events)) |
| 309 | return true; |
| 310 | |
| 311 | return false; |
| 312 | } |
| 313 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 314 | static bool handle_end_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 315 | struct vcpu_event_record *vcpu_record, |
| 316 | struct event_key *key, |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 317 | struct perf_sample *sample) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 318 | { |
| 319 | struct kvm_event *event; |
| 320 | u64 time_begin, time_diff; |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 321 | int vcpu; |
| 322 | |
| 323 | if (kvm->trace_vcpu == -1) |
| 324 | vcpu = -1; |
| 325 | else |
| 326 | vcpu = vcpu_record->vcpu_id; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 327 | |
| 328 | event = vcpu_record->last_event; |
| 329 | time_begin = vcpu_record->start_time; |
| 330 | |
| 331 | /* The begin event is not caught. */ |
| 332 | if (!time_begin) |
| 333 | return true; |
| 334 | |
| 335 | /* |
| 336 | * In some case, the 'begin event' only records the start timestamp, |
| 337 | * the actual event is recognized in the 'end event' (e.g. mmio-event). |
| 338 | */ |
| 339 | |
| 340 | /* Both begin and end events did not get the key. */ |
| 341 | if (!event && key->key == INVALID_KEY) |
| 342 | return true; |
| 343 | |
| 344 | if (!event) |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 345 | event = find_create_kvm_event(kvm, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 346 | |
| 347 | if (!event) |
| 348 | return false; |
| 349 | |
| 350 | vcpu_record->last_event = NULL; |
| 351 | vcpu_record->start_time = 0; |
| 352 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 353 | /* seems to happen once in a while during live mode */ |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 354 | if (sample->time < time_begin) { |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 355 | pr_debug("End time before begin time; skipping event.\n"); |
| 356 | return true; |
| 357 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 358 | |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 359 | time_diff = sample->time - time_begin; |
| 360 | |
| 361 | if (kvm->duration && time_diff > kvm->duration) { |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 362 | char decode[decode_str_len]; |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 363 | |
| 364 | kvm->events_ops->decode_key(kvm, &event->key, decode); |
Alexander Yarygin | 54c801f | 2014-07-03 18:29:06 +0400 | [diff] [blame] | 365 | if (!skip_event(decode)) { |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 366 | pr_info("%" PRIu64 " VM %d, vcpu %d: %s event took %" PRIu64 "usec\n", |
| 367 | sample->time, sample->pid, vcpu_record->vcpu_id, |
Arnaldo Carvalho de Melo | c05a6e1 | 2016-08-08 15:10:44 -0300 | [diff] [blame] | 368 | decode, time_diff / NSEC_PER_USEC); |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 372 | return update_kvm_event(event, vcpu, time_diff); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 373 | } |
| 374 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 375 | static |
| 376 | struct vcpu_event_record *per_vcpu_record(struct thread *thread, |
| 377 | struct perf_evsel *evsel, |
| 378 | struct perf_sample *sample) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 379 | { |
| 380 | /* Only kvm_entry records vcpu id. */ |
Namhyung Kim | 69e865c | 2014-10-06 09:46:02 +0900 | [diff] [blame] | 381 | if (!thread__priv(thread) && kvm_entry_event(evsel)) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 382 | struct vcpu_event_record *vcpu_record; |
| 383 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 384 | vcpu_record = zalloc(sizeof(*vcpu_record)); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 385 | if (!vcpu_record) { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 386 | pr_err("%s: Not enough memory\n", __func__); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 387 | return NULL; |
| 388 | } |
| 389 | |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 390 | vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, |
| 391 | vcpu_id_str); |
Namhyung Kim | 69e865c | 2014-10-06 09:46:02 +0900 | [diff] [blame] | 392 | thread__set_priv(thread, vcpu_record); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 393 | } |
| 394 | |
Namhyung Kim | 69e865c | 2014-10-06 09:46:02 +0900 | [diff] [blame] | 395 | return thread__priv(thread); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 396 | } |
| 397 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 398 | static bool handle_kvm_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 399 | struct thread *thread, |
| 400 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 401 | struct perf_sample *sample) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 402 | { |
| 403 | struct vcpu_event_record *vcpu_record; |
Alexander Yarygin | 3be8e2a | 2014-07-03 18:29:07 +0400 | [diff] [blame] | 404 | struct event_key key = { .key = INVALID_KEY, |
| 405 | .exit_reasons = kvm->exit_reasons }; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 406 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 407 | vcpu_record = per_vcpu_record(thread, evsel, sample); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 408 | if (!vcpu_record) |
| 409 | return true; |
| 410 | |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 411 | /* only process events for vcpus user cares about */ |
| 412 | if ((kvm->trace_vcpu != -1) && |
| 413 | (kvm->trace_vcpu != vcpu_record->vcpu_id)) |
| 414 | return true; |
| 415 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 416 | if (kvm->events_ops->is_begin_event(evsel, sample, &key)) |
| 417 | return handle_begin_event(kvm, vcpu_record, &key, sample->time); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 418 | |
Alexander Yarygin | 3be8e2a | 2014-07-03 18:29:07 +0400 | [diff] [blame] | 419 | if (is_child_event(kvm, evsel, sample, &key)) |
| 420 | return handle_child_event(kvm, vcpu_record, &key, sample); |
| 421 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 422 | if (kvm->events_ops->is_end_event(evsel, sample, &key)) |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 423 | return handle_end_event(kvm, vcpu_record, &key, sample); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 424 | |
| 425 | return true; |
| 426 | } |
| 427 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 428 | #define GET_EVENT_KEY(func, field) \ |
| 429 | static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ |
| 430 | { \ |
| 431 | if (vcpu == -1) \ |
| 432 | return event->total.field; \ |
| 433 | \ |
| 434 | if (vcpu >= event->max_vcpu) \ |
| 435 | return 0; \ |
| 436 | \ |
| 437 | return event->vcpu[vcpu].field; \ |
| 438 | } |
| 439 | |
| 440 | #define COMPARE_EVENT_KEY(func, field) \ |
| 441 | GET_EVENT_KEY(func, field) \ |
| 442 | static int compare_kvm_event_ ## func(struct kvm_event *one, \ |
| 443 | struct kvm_event *two, int vcpu)\ |
| 444 | { \ |
| 445 | return get_event_ ##func(one, vcpu) > \ |
| 446 | get_event_ ##func(two, vcpu); \ |
| 447 | } |
| 448 | |
| 449 | GET_EVENT_KEY(time, time); |
| 450 | COMPARE_EVENT_KEY(count, stats.n); |
| 451 | COMPARE_EVENT_KEY(mean, stats.mean); |
David Ahern | 62d04db | 2013-08-05 21:41:35 -0400 | [diff] [blame] | 452 | GET_EVENT_KEY(max, stats.max); |
| 453 | GET_EVENT_KEY(min, stats.min); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 454 | |
| 455 | #define DEF_SORT_NAME_KEY(name, compare_key) \ |
| 456 | { #name, compare_kvm_event_ ## compare_key } |
| 457 | |
| 458 | static struct kvm_event_key keys[] = { |
| 459 | DEF_SORT_NAME_KEY(sample, count), |
| 460 | DEF_SORT_NAME_KEY(time, mean), |
| 461 | { NULL, NULL } |
| 462 | }; |
| 463 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 464 | static bool select_key(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 465 | { |
| 466 | int i; |
| 467 | |
| 468 | for (i = 0; keys[i].name; i++) { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 469 | if (!strcmp(keys[i].name, kvm->sort_key)) { |
| 470 | kvm->compare = keys[i].key; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 471 | return true; |
| 472 | } |
| 473 | } |
| 474 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 475 | pr_err("Unknown compare key:%s\n", kvm->sort_key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 476 | return false; |
| 477 | } |
| 478 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 479 | static void insert_to_result(struct rb_root *result, struct kvm_event *event, |
| 480 | key_cmp_fun bigger, int vcpu) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 481 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 482 | struct rb_node **rb = &result->rb_node; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 483 | struct rb_node *parent = NULL; |
| 484 | struct kvm_event *p; |
| 485 | |
| 486 | while (*rb) { |
| 487 | p = container_of(*rb, struct kvm_event, rb); |
| 488 | parent = *rb; |
| 489 | |
| 490 | if (bigger(event, p, vcpu)) |
| 491 | rb = &(*rb)->rb_left; |
| 492 | else |
| 493 | rb = &(*rb)->rb_right; |
| 494 | } |
| 495 | |
| 496 | rb_link_node(&event->rb, parent, rb); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 497 | rb_insert_color(&event->rb, result); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 498 | } |
| 499 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 500 | static void |
| 501 | update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 502 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 503 | int vcpu = kvm->trace_vcpu; |
| 504 | |
| 505 | kvm->total_count += get_event_count(event, vcpu); |
| 506 | kvm->total_time += get_event_time(event, vcpu); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static bool event_is_valid(struct kvm_event *event, int vcpu) |
| 510 | { |
| 511 | return !!get_event_count(event, vcpu); |
| 512 | } |
| 513 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 514 | static void sort_result(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 515 | { |
| 516 | unsigned int i; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 517 | int vcpu = kvm->trace_vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 518 | struct kvm_event *event; |
| 519 | |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 520 | for (i = 0; i < EVENTS_CACHE_SIZE; i++) { |
| 521 | list_for_each_entry(event, &kvm->kvm_events_cache[i], hash_entry) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 522 | if (event_is_valid(event, vcpu)) { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 523 | update_total_count(kvm, event); |
| 524 | insert_to_result(&kvm->result, event, |
| 525 | kvm->compare, vcpu); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 526 | } |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 527 | } |
| 528 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* returns left most element of result, and erase it */ |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 532 | static struct kvm_event *pop_from_result(struct rb_root *result) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 533 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 534 | struct rb_node *node = rb_first(result); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 535 | |
| 536 | if (!node) |
| 537 | return NULL; |
| 538 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 539 | rb_erase(node, result); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 540 | return container_of(node, struct kvm_event, rb); |
| 541 | } |
| 542 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 543 | static void print_vcpu_info(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 544 | { |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 545 | int vcpu = kvm->trace_vcpu; |
| 546 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 547 | pr_info("Analyze events for "); |
| 548 | |
Alexander Yarygin | 1f3e5b5 | 2014-09-01 17:44:55 +0400 | [diff] [blame] | 549 | if (kvm->opts.target.system_wide) |
| 550 | pr_info("all VMs, "); |
| 551 | else if (kvm->opts.target.pid) |
| 552 | pr_info("pid(s) %s, ", kvm->opts.target.pid); |
| 553 | else |
| 554 | pr_info("dazed and confused on what is monitored, "); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 555 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 556 | if (vcpu == -1) |
| 557 | pr_info("all VCPUs:\n\n"); |
| 558 | else |
| 559 | pr_info("VCPU %d:\n\n", vcpu); |
| 560 | } |
| 561 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 562 | static void show_timeofday(void) |
| 563 | { |
| 564 | char date[64]; |
| 565 | struct timeval tv; |
| 566 | struct tm ltime; |
| 567 | |
| 568 | gettimeofday(&tv, NULL); |
| 569 | if (localtime_r(&tv.tv_sec, <ime)) { |
| 570 | strftime(date, sizeof(date), "%H:%M:%S", <ime); |
| 571 | pr_info("%s.%06ld", date, tv.tv_usec); |
| 572 | } else |
| 573 | pr_info("00:00:00.000000"); |
| 574 | |
| 575 | return; |
| 576 | } |
| 577 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 578 | static void print_result(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 579 | { |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 580 | char decode[decode_str_len]; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 581 | struct kvm_event *event; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 582 | int vcpu = kvm->trace_vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 583 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 584 | if (kvm->live) { |
| 585 | puts(CONSOLE_CLEAR); |
| 586 | show_timeofday(); |
| 587 | } |
| 588 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 589 | pr_info("\n\n"); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 590 | print_vcpu_info(kvm); |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 591 | pr_info("%*s ", decode_str_len, kvm->events_ops->name); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 592 | pr_info("%10s ", "Samples"); |
| 593 | pr_info("%9s ", "Samples%"); |
| 594 | |
| 595 | pr_info("%9s ", "Time%"); |
Christian Borntraeger | b048a24 | 2014-07-31 13:13:51 +0200 | [diff] [blame] | 596 | pr_info("%11s ", "Min Time"); |
| 597 | pr_info("%11s ", "Max Time"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 598 | pr_info("%16s ", "Avg time"); |
| 599 | pr_info("\n\n"); |
| 600 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 601 | while ((event = pop_from_result(&kvm->result))) { |
David Ahern | 62d04db | 2013-08-05 21:41:35 -0400 | [diff] [blame] | 602 | u64 ecount, etime, max, min; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 603 | |
| 604 | ecount = get_event_count(event, vcpu); |
| 605 | etime = get_event_time(event, vcpu); |
David Ahern | 62d04db | 2013-08-05 21:41:35 -0400 | [diff] [blame] | 606 | max = get_event_max(event, vcpu); |
| 607 | min = get_event_min(event, vcpu); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 608 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 609 | kvm->events_ops->decode_key(kvm, &event->key, decode); |
Hemant Kumar | 162607e | 2016-01-28 12:03:04 +0530 | [diff] [blame] | 610 | pr_info("%*s ", decode_str_len, decode); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 611 | pr_info("%10llu ", (unsigned long long)ecount); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 612 | pr_info("%8.2f%% ", (double)ecount / kvm->total_count * 100); |
| 613 | pr_info("%8.2f%% ", (double)etime / kvm->total_time * 100); |
Arnaldo Carvalho de Melo | c05a6e1 | 2016-08-08 15:10:44 -0300 | [diff] [blame] | 614 | pr_info("%9.2fus ", (double)min / NSEC_PER_USEC); |
| 615 | pr_info("%9.2fus ", (double)max / NSEC_PER_USEC); |
| 616 | pr_info("%9.2fus ( +-%7.2f%% )", (double)etime / ecount / NSEC_PER_USEC, |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 617 | kvm_event_rel_stddev(vcpu, event)); |
| 618 | pr_info("\n"); |
| 619 | } |
| 620 | |
David Ahern | e4f7637 | 2012-10-08 11:17:34 -0600 | [diff] [blame] | 621 | pr_info("\nTotal Samples:%" PRIu64 ", Total events handled time:%.2fus.\n\n", |
Arnaldo Carvalho de Melo | c05a6e1 | 2016-08-08 15:10:44 -0300 | [diff] [blame] | 622 | kvm->total_count, kvm->total_time / (double)NSEC_PER_USEC); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 623 | |
| 624 | if (kvm->lost_events) |
| 625 | pr_info("\nLost events: %" PRIu64 "\n\n", kvm->lost_events); |
| 626 | } |
| 627 | |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 628 | #ifdef HAVE_TIMERFD_SUPPORT |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 629 | static int process_lost_event(struct perf_tool *tool, |
| 630 | union perf_event *event __maybe_unused, |
| 631 | struct perf_sample *sample __maybe_unused, |
| 632 | struct machine *machine __maybe_unused) |
| 633 | { |
| 634 | struct perf_kvm_stat *kvm = container_of(tool, struct perf_kvm_stat, tool); |
| 635 | |
| 636 | kvm->lost_events++; |
| 637 | return 0; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 638 | } |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 639 | #endif |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 640 | |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 641 | static bool skip_sample(struct perf_kvm_stat *kvm, |
| 642 | struct perf_sample *sample) |
| 643 | { |
| 644 | if (kvm->pid_list && intlist__find(kvm->pid_list, sample->pid) == NULL) |
| 645 | return true; |
| 646 | |
| 647 | return false; |
| 648 | } |
| 649 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 650 | static int process_sample_event(struct perf_tool *tool, |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 651 | union perf_event *event, |
| 652 | struct perf_sample *sample, |
| 653 | struct perf_evsel *evsel, |
| 654 | struct machine *machine) |
| 655 | { |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 656 | int err = 0; |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 657 | struct thread *thread; |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 658 | struct perf_kvm_stat *kvm = container_of(tool, struct perf_kvm_stat, |
| 659 | tool); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 660 | |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 661 | if (skip_sample(kvm, sample)) |
| 662 | return 0; |
| 663 | |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 664 | thread = machine__findnew_thread(machine, sample->pid, sample->tid); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 665 | if (thread == NULL) { |
| 666 | pr_debug("problem processing %d event, skipping it.\n", |
| 667 | event->header.type); |
| 668 | return -1; |
| 669 | } |
| 670 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 671 | if (!handle_kvm_event(kvm, thread, evsel, sample)) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 672 | err = -1; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 673 | |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 674 | thread__put(thread); |
| 675 | return err; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 676 | } |
| 677 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 678 | static int cpu_isa_config(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 679 | { |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 680 | char buf[64], *cpuid; |
Alexander Yarygin | 65c647a | 2014-07-03 17:59:51 +0400 | [diff] [blame] | 681 | int err; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 682 | |
| 683 | if (kvm->live) { |
| 684 | err = get_cpuid(buf, sizeof(buf)); |
| 685 | if (err != 0) { |
Alexander Yarygin | 65c647a | 2014-07-03 17:59:51 +0400 | [diff] [blame] | 686 | pr_err("Failed to look up CPU type\n"); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 687 | return err; |
| 688 | } |
| 689 | cpuid = buf; |
| 690 | } else |
| 691 | cpuid = kvm->session->header.env.cpuid; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 692 | |
Alexander Yarygin | 65c647a | 2014-07-03 17:59:51 +0400 | [diff] [blame] | 693 | if (!cpuid) { |
| 694 | pr_err("Failed to look up CPU type\n"); |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
| 698 | err = cpu_isa_init(kvm, cpuid); |
| 699 | if (err == -ENOTSUP) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 700 | pr_err("CPU %s is not supported.\n", cpuid); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 701 | |
Alexander Yarygin | 65c647a | 2014-07-03 17:59:51 +0400 | [diff] [blame] | 702 | return err; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | static bool verify_vcpu(int vcpu) |
| 706 | { |
| 707 | if (vcpu != -1 && vcpu < 0) { |
| 708 | pr_err("Invalid vcpu:%d.\n", vcpu); |
| 709 | return false; |
| 710 | } |
| 711 | |
| 712 | return true; |
| 713 | } |
| 714 | |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 715 | #ifdef HAVE_TIMERFD_SUPPORT |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 716 | /* keeping the max events to a modest level to keep |
| 717 | * the processing of samples per mmap smooth. |
| 718 | */ |
| 719 | #define PERF_KVM__MAX_EVENTS_PER_MMAP 25 |
| 720 | |
| 721 | static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx, |
| 722 | u64 *mmap_time) |
| 723 | { |
| 724 | union perf_event *event; |
| 725 | struct perf_sample sample; |
| 726 | s64 n = 0; |
| 727 | int err; |
| 728 | |
| 729 | *mmap_time = ULLONG_MAX; |
| 730 | while ((event = perf_evlist__mmap_read(kvm->evlist, idx)) != NULL) { |
| 731 | err = perf_evlist__parse_sample(kvm->evlist, event, &sample); |
| 732 | if (err) { |
Zhouyi Zhou | 8e50d38 | 2013-10-24 15:43:33 +0800 | [diff] [blame] | 733 | perf_evlist__mmap_consume(kvm->evlist, idx); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 734 | pr_err("Failed to parse sample\n"); |
| 735 | return -1; |
| 736 | } |
| 737 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 738 | err = perf_session__queue_event(kvm->session, event, &sample, 0); |
Zhouyi Zhou | 8e50d38 | 2013-10-24 15:43:33 +0800 | [diff] [blame] | 739 | /* |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 740 | * FIXME: Here we can't consume the event, as perf_session__queue_event will |
Zhouyi Zhou | 8e50d38 | 2013-10-24 15:43:33 +0800 | [diff] [blame] | 741 | * point to it, and it'll get possibly overwritten by the kernel. |
| 742 | */ |
| 743 | perf_evlist__mmap_consume(kvm->evlist, idx); |
| 744 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 745 | if (err) { |
| 746 | pr_err("Failed to enqueue sample: %d\n", err); |
| 747 | return -1; |
| 748 | } |
| 749 | |
| 750 | /* save time stamp of our first sample for this mmap */ |
| 751 | if (n == 0) |
| 752 | *mmap_time = sample.time; |
| 753 | |
| 754 | /* limit events per mmap handled all at once */ |
| 755 | n++; |
| 756 | if (n == PERF_KVM__MAX_EVENTS_PER_MMAP) |
| 757 | break; |
| 758 | } |
| 759 | |
| 760 | return n; |
| 761 | } |
| 762 | |
| 763 | static int perf_kvm__mmap_read(struct perf_kvm_stat *kvm) |
| 764 | { |
| 765 | int i, err, throttled = 0; |
| 766 | s64 n, ntotal = 0; |
| 767 | u64 flush_time = ULLONG_MAX, mmap_time; |
| 768 | |
| 769 | for (i = 0; i < kvm->evlist->nr_mmaps; i++) { |
| 770 | n = perf_kvm__mmap_read_idx(kvm, i, &mmap_time); |
| 771 | if (n < 0) |
| 772 | return -1; |
| 773 | |
| 774 | /* flush time is going to be the minimum of all the individual |
| 775 | * mmap times. Essentially, we flush all the samples queued up |
| 776 | * from the last pass under our minimal start time -- that leaves |
| 777 | * a very small race for samples to come in with a lower timestamp. |
| 778 | * The ioctl to return the perf_clock timestamp should close the |
| 779 | * race entirely. |
| 780 | */ |
| 781 | if (mmap_time < flush_time) |
| 782 | flush_time = mmap_time; |
| 783 | |
| 784 | ntotal += n; |
| 785 | if (n == PERF_KVM__MAX_EVENTS_PER_MMAP) |
| 786 | throttled = 1; |
| 787 | } |
| 788 | |
| 789 | /* flush queue after each round in which we processed events */ |
| 790 | if (ntotal) { |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 791 | struct ordered_events *oe = &kvm->session->ordered_events; |
| 792 | |
| 793 | oe->next_flush = flush_time; |
| 794 | err = ordered_events__flush(oe, OE_FLUSH__ROUND); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 795 | if (err) { |
| 796 | if (kvm->lost_events) |
| 797 | pr_info("\nLost events: %" PRIu64 "\n\n", |
| 798 | kvm->lost_events); |
| 799 | return err; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | return throttled; |
| 804 | } |
| 805 | |
| 806 | static volatile int done; |
| 807 | |
| 808 | static void sig_handler(int sig __maybe_unused) |
| 809 | { |
| 810 | done = 1; |
| 811 | } |
| 812 | |
| 813 | static int perf_kvm__timerfd_create(struct perf_kvm_stat *kvm) |
| 814 | { |
| 815 | struct itimerspec new_value; |
| 816 | int rc = -1; |
| 817 | |
| 818 | kvm->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); |
| 819 | if (kvm->timerfd < 0) { |
| 820 | pr_err("timerfd_create failed\n"); |
| 821 | goto out; |
| 822 | } |
| 823 | |
| 824 | new_value.it_value.tv_sec = kvm->display_time; |
| 825 | new_value.it_value.tv_nsec = 0; |
| 826 | new_value.it_interval.tv_sec = kvm->display_time; |
| 827 | new_value.it_interval.tv_nsec = 0; |
| 828 | |
| 829 | if (timerfd_settime(kvm->timerfd, 0, &new_value, NULL) != 0) { |
| 830 | pr_err("timerfd_settime failed: %d\n", errno); |
| 831 | close(kvm->timerfd); |
| 832 | goto out; |
| 833 | } |
| 834 | |
| 835 | rc = 0; |
| 836 | out: |
| 837 | return rc; |
| 838 | } |
| 839 | |
| 840 | static int perf_kvm__handle_timerfd(struct perf_kvm_stat *kvm) |
| 841 | { |
| 842 | uint64_t c; |
| 843 | int rc; |
| 844 | |
| 845 | rc = read(kvm->timerfd, &c, sizeof(uint64_t)); |
| 846 | if (rc < 0) { |
| 847 | if (errno == EAGAIN) |
| 848 | return 0; |
| 849 | |
| 850 | pr_err("Failed to read timer fd: %d\n", errno); |
| 851 | return -1; |
| 852 | } |
| 853 | |
| 854 | if (rc != sizeof(uint64_t)) { |
| 855 | pr_err("Error reading timer fd - invalid size returned\n"); |
| 856 | return -1; |
| 857 | } |
| 858 | |
| 859 | if (c != 1) |
| 860 | pr_debug("Missed timer beats: %" PRIu64 "\n", c-1); |
| 861 | |
| 862 | /* update display */ |
| 863 | sort_result(kvm); |
| 864 | print_result(kvm); |
| 865 | |
| 866 | /* reset counts */ |
| 867 | clear_events_cache_stats(kvm->kvm_events_cache); |
| 868 | kvm->total_count = 0; |
| 869 | kvm->total_time = 0; |
| 870 | kvm->lost_events = 0; |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | static int fd_set_nonblock(int fd) |
| 876 | { |
| 877 | long arg = 0; |
| 878 | |
| 879 | arg = fcntl(fd, F_GETFL); |
| 880 | if (arg < 0) { |
| 881 | pr_err("Failed to get current flags for fd %d\n", fd); |
| 882 | return -1; |
| 883 | } |
| 884 | |
| 885 | if (fcntl(fd, F_SETFL, arg | O_NONBLOCK) < 0) { |
| 886 | pr_err("Failed to set non-block option on fd %d\n", fd); |
| 887 | return -1; |
| 888 | } |
| 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | |
Jiri Olsa | d5b4130 | 2014-08-11 10:50:09 +0200 | [diff] [blame] | 893 | static int perf_kvm__handle_stdin(void) |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 894 | { |
| 895 | int c; |
| 896 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 897 | c = getc(stdin); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 898 | if (c == 'q') |
| 899 | return 1; |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | static int kvm_events_live_report(struct perf_kvm_stat *kvm) |
| 905 | { |
Jiri Olsa | 1ca7226 | 2014-10-01 18:00:29 +0200 | [diff] [blame] | 906 | int nr_stdin, ret, err = -EINVAL; |
Jiri Olsa | d5b4130 | 2014-08-11 10:50:09 +0200 | [diff] [blame] | 907 | struct termios save; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 908 | |
| 909 | /* live flag must be set first */ |
| 910 | kvm->live = true; |
| 911 | |
| 912 | ret = cpu_isa_config(kvm); |
| 913 | if (ret < 0) |
| 914 | return ret; |
| 915 | |
| 916 | if (!verify_vcpu(kvm->trace_vcpu) || |
| 917 | !select_key(kvm) || |
| 918 | !register_kvm_events_ops(kvm)) { |
| 919 | goto out; |
| 920 | } |
| 921 | |
Jiri Olsa | d5b4130 | 2014-08-11 10:50:09 +0200 | [diff] [blame] | 922 | set_term_quiet_input(&save); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 923 | init_kvm_event_record(kvm); |
| 924 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 925 | signal(SIGINT, sig_handler); |
| 926 | signal(SIGTERM, sig_handler); |
| 927 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 928 | /* add timer fd */ |
| 929 | if (perf_kvm__timerfd_create(kvm) < 0) { |
| 930 | err = -1; |
| 931 | goto out; |
| 932 | } |
| 933 | |
Jiri Olsa | fe636ad | 2014-10-01 18:00:27 +0200 | [diff] [blame] | 934 | if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0) |
Arnaldo Carvalho de Melo | 0a04c9e | 2014-08-18 17:12:30 -0300 | [diff] [blame] | 935 | goto out; |
| 936 | |
Jiri Olsa | 0cae013 | 2014-10-01 18:00:28 +0200 | [diff] [blame] | 937 | nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)); |
| 938 | if (nr_stdin < 0) |
Arnaldo Carvalho de Melo | 0a04c9e | 2014-08-18 17:12:30 -0300 | [diff] [blame] | 939 | goto out; |
| 940 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 941 | if (fd_set_nonblock(fileno(stdin)) != 0) |
| 942 | goto out; |
| 943 | |
| 944 | /* everything is good - enable the events and process */ |
| 945 | perf_evlist__enable(kvm->evlist); |
| 946 | |
| 947 | while (!done) { |
Jiri Olsa | 1ca7226 | 2014-10-01 18:00:29 +0200 | [diff] [blame] | 948 | struct fdarray *fda = &kvm->evlist->pollfd; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 949 | int rc; |
| 950 | |
| 951 | rc = perf_kvm__mmap_read(kvm); |
| 952 | if (rc < 0) |
| 953 | break; |
| 954 | |
| 955 | err = perf_kvm__handle_timerfd(kvm); |
| 956 | if (err) |
| 957 | goto out; |
| 958 | |
Jiri Olsa | 1ca7226 | 2014-10-01 18:00:29 +0200 | [diff] [blame] | 959 | if (fda->entries[nr_stdin].revents & POLLIN) |
Jiri Olsa | d5b4130 | 2014-08-11 10:50:09 +0200 | [diff] [blame] | 960 | done = perf_kvm__handle_stdin(); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 961 | |
| 962 | if (!rc && !done) |
Jiri Olsa | 1ca7226 | 2014-10-01 18:00:29 +0200 | [diff] [blame] | 963 | err = fdarray__poll(fda, 100); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | perf_evlist__disable(kvm->evlist); |
| 967 | |
| 968 | if (err == 0) { |
| 969 | sort_result(kvm); |
| 970 | print_result(kvm); |
| 971 | } |
| 972 | |
| 973 | out: |
| 974 | if (kvm->timerfd >= 0) |
| 975 | close(kvm->timerfd); |
| 976 | |
Jiri Olsa | d5b4130 | 2014-08-11 10:50:09 +0200 | [diff] [blame] | 977 | tcsetattr(0, TCSAFLUSH, &save); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 978 | return err; |
| 979 | } |
| 980 | |
| 981 | static int kvm_live_open_events(struct perf_kvm_stat *kvm) |
| 982 | { |
| 983 | int err, rc = -1; |
| 984 | struct perf_evsel *pos; |
| 985 | struct perf_evlist *evlist = kvm->evlist; |
Masami Hiramatsu | f9f33fd | 2014-08-14 02:22:51 +0000 | [diff] [blame] | 986 | char sbuf[STRERR_BUFSIZE]; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 987 | |
Arnaldo Carvalho de Melo | e68ae9c | 2016-04-11 18:15:29 -0300 | [diff] [blame] | 988 | perf_evlist__config(evlist, &kvm->opts, NULL); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 989 | |
| 990 | /* |
| 991 | * Note: exclude_{guest,host} do not apply here. |
| 992 | * This command processes KVM tracepoints from host only |
| 993 | */ |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 994 | evlist__for_each_entry(evlist, pos) { |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 995 | struct perf_event_attr *attr = &pos->attr; |
| 996 | |
| 997 | /* make sure these *are* set */ |
Adrian Hunter | e71aa28 | 2013-09-06 22:40:12 +0300 | [diff] [blame] | 998 | perf_evsel__set_sample_bit(pos, TID); |
| 999 | perf_evsel__set_sample_bit(pos, TIME); |
| 1000 | perf_evsel__set_sample_bit(pos, CPU); |
| 1001 | perf_evsel__set_sample_bit(pos, RAW); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1002 | /* make sure these are *not*; want as small a sample as possible */ |
Adrian Hunter | e71aa28 | 2013-09-06 22:40:12 +0300 | [diff] [blame] | 1003 | perf_evsel__reset_sample_bit(pos, PERIOD); |
| 1004 | perf_evsel__reset_sample_bit(pos, IP); |
| 1005 | perf_evsel__reset_sample_bit(pos, CALLCHAIN); |
| 1006 | perf_evsel__reset_sample_bit(pos, ADDR); |
| 1007 | perf_evsel__reset_sample_bit(pos, READ); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1008 | attr->mmap = 0; |
| 1009 | attr->comm = 0; |
| 1010 | attr->task = 0; |
| 1011 | |
| 1012 | attr->sample_period = 1; |
| 1013 | |
| 1014 | attr->watermark = 0; |
| 1015 | attr->wakeup_events = 1000; |
| 1016 | |
| 1017 | /* will enable all once we are ready */ |
| 1018 | attr->disabled = 1; |
| 1019 | } |
| 1020 | |
| 1021 | err = perf_evlist__open(evlist); |
| 1022 | if (err < 0) { |
Masami Hiramatsu | f9f33fd | 2014-08-14 02:22:51 +0000 | [diff] [blame] | 1023 | printf("Couldn't create the events: %s\n", |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 1024 | str_error_r(errno, sbuf, sizeof(sbuf))); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1025 | goto out; |
| 1026 | } |
| 1027 | |
| 1028 | if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages, false) < 0) { |
Masami Hiramatsu | f9f33fd | 2014-08-14 02:22:51 +0000 | [diff] [blame] | 1029 | ui__error("Failed to mmap the events: %s\n", |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 1030 | str_error_r(errno, sbuf, sizeof(sbuf))); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1031 | perf_evlist__close(evlist); |
| 1032 | goto out; |
| 1033 | } |
| 1034 | |
| 1035 | rc = 0; |
| 1036 | |
| 1037 | out: |
| 1038 | return rc; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1039 | } |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 1040 | #endif |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1041 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1042 | static int read_events(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1043 | { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1044 | int ret; |
| 1045 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1046 | struct perf_tool eops = { |
| 1047 | .sample = process_sample_event, |
| 1048 | .comm = perf_event__process_comm, |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 1049 | .namespaces = perf_event__process_namespaces, |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 1050 | .ordered_events = true, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1051 | }; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1052 | struct perf_data_file file = { |
Dongsheng Yang | 476b3a8 | 2013-12-09 18:47:03 -0500 | [diff] [blame] | 1053 | .path = kvm->file_name, |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1054 | .mode = PERF_DATA_MODE_READ, |
Yunlong Song | 8cc5ec1f | 2015-04-02 21:47:13 +0800 | [diff] [blame] | 1055 | .force = kvm->force, |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1056 | }; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1057 | |
| 1058 | kvm->tool = eops; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1059 | kvm->session = perf_session__new(&file, false, &kvm->tool); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1060 | if (!kvm->session) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1061 | pr_err("Initializing perf session failed\n"); |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 1062 | return -1; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1063 | } |
| 1064 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1065 | symbol__init(&kvm->session->header.env); |
Namhyung Kim | 14d37f3 | 2014-08-12 15:40:39 +0900 | [diff] [blame] | 1066 | |
Taeung Song | 41b9836 | 2015-07-01 00:18:44 +0900 | [diff] [blame] | 1067 | if (!perf_session__has_traces(kvm->session, "kvm record")) { |
| 1068 | ret = -EINVAL; |
| 1069 | goto out_delete; |
| 1070 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1071 | |
| 1072 | /* |
| 1073 | * Do not use 'isa' recorded in kvm_exit tracepoint since it is not |
| 1074 | * traced in the old kernel. |
| 1075 | */ |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1076 | ret = cpu_isa_config(kvm); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1077 | if (ret < 0) |
Taeung Song | 41b9836 | 2015-07-01 00:18:44 +0900 | [diff] [blame] | 1078 | goto out_delete; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1079 | |
Taeung Song | 41b9836 | 2015-07-01 00:18:44 +0900 | [diff] [blame] | 1080 | ret = perf_session__process_events(kvm->session); |
| 1081 | |
| 1082 | out_delete: |
| 1083 | perf_session__delete(kvm->session); |
| 1084 | return ret; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1085 | } |
| 1086 | |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 1087 | static int parse_target_str(struct perf_kvm_stat *kvm) |
| 1088 | { |
Alexander Yarygin | 3ae4a76 | 2014-09-01 17:44:53 +0400 | [diff] [blame] | 1089 | if (kvm->opts.target.pid) { |
| 1090 | kvm->pid_list = intlist__new(kvm->opts.target.pid); |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 1091 | if (kvm->pid_list == NULL) { |
| 1092 | pr_err("Error parsing process id string\n"); |
| 1093 | return -EINVAL; |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1100 | static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1101 | { |
| 1102 | int ret = -EINVAL; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1103 | int vcpu = kvm->trace_vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1104 | |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 1105 | if (parse_target_str(kvm) != 0) |
| 1106 | goto exit; |
| 1107 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1108 | if (!verify_vcpu(vcpu)) |
| 1109 | goto exit; |
| 1110 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1111 | if (!select_key(kvm)) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1112 | goto exit; |
| 1113 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1114 | if (!register_kvm_events_ops(kvm)) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1115 | goto exit; |
| 1116 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1117 | init_kvm_event_record(kvm); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1118 | setup_pager(); |
| 1119 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1120 | ret = read_events(kvm); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1121 | if (ret) |
| 1122 | goto exit; |
| 1123 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1124 | sort_result(kvm); |
| 1125 | print_result(kvm); |
| 1126 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1127 | exit: |
| 1128 | return ret; |
| 1129 | } |
| 1130 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1131 | #define STRDUP_FAIL_EXIT(s) \ |
| 1132 | ({ char *_p; \ |
| 1133 | _p = strdup(s); \ |
| 1134 | if (!_p) \ |
| 1135 | return -ENOMEM; \ |
| 1136 | _p; \ |
| 1137 | }) |
| 1138 | |
Hemant Kumar | 066d359 | 2016-01-28 12:03:06 +0530 | [diff] [blame] | 1139 | int __weak setup_kvm_events_tp(struct perf_kvm_stat *kvm __maybe_unused) |
| 1140 | { |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1144 | static int |
| 1145 | kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1146 | { |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1147 | unsigned int rec_argc, i, j, events_tp_size; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1148 | const char **rec_argv; |
David Ahern | 8fdd84c | 2013-08-02 14:05:42 -0600 | [diff] [blame] | 1149 | const char * const record_args[] = { |
| 1150 | "record", |
| 1151 | "-R", |
David Ahern | 8fdd84c | 2013-08-02 14:05:42 -0600 | [diff] [blame] | 1152 | "-m", "1024", |
| 1153 | "-c", "1", |
| 1154 | }; |
Namhyung Kim | f45d20f | 2014-10-23 00:15:47 +0900 | [diff] [blame] | 1155 | const char * const kvm_stat_record_usage[] = { |
| 1156 | "perf kvm stat record [<options>]", |
| 1157 | NULL |
| 1158 | }; |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1159 | const char * const *events_tp; |
Hemant Kumar | 066d359 | 2016-01-28 12:03:06 +0530 | [diff] [blame] | 1160 | int ret; |
| 1161 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1162 | events_tp_size = 0; |
Hemant Kumar | 066d359 | 2016-01-28 12:03:06 +0530 | [diff] [blame] | 1163 | ret = setup_kvm_events_tp(kvm); |
| 1164 | if (ret < 0) { |
| 1165 | pr_err("Unable to setup the kvm tracepoints\n"); |
| 1166 | return ret; |
| 1167 | } |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1168 | |
| 1169 | for (events_tp = kvm_events_tp; *events_tp; events_tp++) |
| 1170 | events_tp_size++; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1171 | |
David Ahern | 8fdd84c | 2013-08-02 14:05:42 -0600 | [diff] [blame] | 1172 | rec_argc = ARRAY_SIZE(record_args) + argc + 2 + |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1173 | 2 * events_tp_size; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1174 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1175 | |
| 1176 | if (rec_argv == NULL) |
| 1177 | return -ENOMEM; |
| 1178 | |
| 1179 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
| 1180 | rec_argv[i] = STRDUP_FAIL_EXIT(record_args[i]); |
| 1181 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1182 | for (j = 0; j < events_tp_size; j++) { |
David Ahern | 8fdd84c | 2013-08-02 14:05:42 -0600 | [diff] [blame] | 1183 | rec_argv[i++] = "-e"; |
| 1184 | rec_argv[i++] = STRDUP_FAIL_EXIT(kvm_events_tp[j]); |
| 1185 | } |
| 1186 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1187 | rec_argv[i++] = STRDUP_FAIL_EXIT("-o"); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1188 | rec_argv[i++] = STRDUP_FAIL_EXIT(kvm->file_name); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1189 | |
| 1190 | for (j = 1; j < (unsigned int)argc; j++, i++) |
| 1191 | rec_argv[i] = argv[j]; |
| 1192 | |
Namhyung Kim | f45d20f | 2014-10-23 00:15:47 +0900 | [diff] [blame] | 1193 | set_option_flag(record_options, 'e', "event", PARSE_OPT_HIDDEN); |
| 1194 | set_option_flag(record_options, 0, "filter", PARSE_OPT_HIDDEN); |
| 1195 | set_option_flag(record_options, 'R', "raw-samples", PARSE_OPT_HIDDEN); |
| 1196 | |
| 1197 | set_option_flag(record_options, 'F', "freq", PARSE_OPT_DISABLED); |
| 1198 | set_option_flag(record_options, 0, "group", PARSE_OPT_DISABLED); |
| 1199 | set_option_flag(record_options, 'g', NULL, PARSE_OPT_DISABLED); |
| 1200 | set_option_flag(record_options, 0, "call-graph", PARSE_OPT_DISABLED); |
| 1201 | set_option_flag(record_options, 'd', "data", PARSE_OPT_DISABLED); |
| 1202 | set_option_flag(record_options, 'T', "timestamp", PARSE_OPT_DISABLED); |
| 1203 | set_option_flag(record_options, 'P', "period", PARSE_OPT_DISABLED); |
| 1204 | set_option_flag(record_options, 'n', "no-samples", PARSE_OPT_DISABLED); |
| 1205 | set_option_flag(record_options, 'N', "no-buildid-cache", PARSE_OPT_DISABLED); |
| 1206 | set_option_flag(record_options, 'B', "no-buildid", PARSE_OPT_DISABLED); |
| 1207 | set_option_flag(record_options, 'G', "cgroup", PARSE_OPT_DISABLED); |
| 1208 | set_option_flag(record_options, 'b', "branch-any", PARSE_OPT_DISABLED); |
| 1209 | set_option_flag(record_options, 'j', "branch-filter", PARSE_OPT_DISABLED); |
| 1210 | set_option_flag(record_options, 'W', "weight", PARSE_OPT_DISABLED); |
| 1211 | set_option_flag(record_options, 0, "transaction", PARSE_OPT_DISABLED); |
| 1212 | |
| 1213 | record_usage = kvm_stat_record_usage; |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1214 | return cmd_record(i, rec_argv); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1215 | } |
| 1216 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1217 | static int |
| 1218 | kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1219 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1220 | const struct option kvm_events_report_options[] = { |
| 1221 | OPT_STRING(0, "event", &kvm->report_event, "report event", |
Alexander Yarygin | 3be8e2a | 2014-07-03 18:29:07 +0400 | [diff] [blame] | 1222 | "event for reporting: vmexit, " |
| 1223 | "mmio (x86 only), ioport (x86 only)"), |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1224 | OPT_INTEGER(0, "vcpu", &kvm->trace_vcpu, |
| 1225 | "vcpu id to report"), |
| 1226 | OPT_STRING('k', "key", &kvm->sort_key, "sort-key", |
| 1227 | "key for sorting: sample(sort by samples number)" |
| 1228 | " time (sort by avg time)"), |
Alexander Yarygin | 3ae4a76 | 2014-09-01 17:44:53 +0400 | [diff] [blame] | 1229 | OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid", |
David Ahern | 2e73f00 | 2013-08-05 21:41:37 -0400 | [diff] [blame] | 1230 | "analyze events only for given process id(s)"), |
Yunlong Song | 8cc5ec1f | 2015-04-02 21:47:13 +0800 | [diff] [blame] | 1231 | OPT_BOOLEAN('f', "force", &kvm->force, "don't complain, do it"), |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1232 | OPT_END() |
| 1233 | }; |
| 1234 | |
| 1235 | const char * const kvm_events_report_usage[] = { |
| 1236 | "perf kvm stat report [<options>]", |
| 1237 | NULL |
| 1238 | }; |
| 1239 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1240 | if (argc) { |
| 1241 | argc = parse_options(argc, argv, |
| 1242 | kvm_events_report_options, |
| 1243 | kvm_events_report_usage, 0); |
| 1244 | if (argc) |
| 1245 | usage_with_options(kvm_events_report_usage, |
| 1246 | kvm_events_report_options); |
| 1247 | } |
| 1248 | |
Alexander Yarygin | f181957 | 2014-09-01 17:44:54 +0400 | [diff] [blame] | 1249 | if (!kvm->opts.target.pid) |
| 1250 | kvm->opts.target.system_wide = true; |
| 1251 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1252 | return kvm_events_report_vcpu(kvm); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1253 | } |
| 1254 | |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 1255 | #ifdef HAVE_TIMERFD_SUPPORT |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1256 | static struct perf_evlist *kvm_live_event_list(void) |
| 1257 | { |
| 1258 | struct perf_evlist *evlist; |
| 1259 | char *tp, *name, *sys; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1260 | int err = -1; |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1261 | const char * const *events_tp; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1262 | |
| 1263 | evlist = perf_evlist__new(); |
| 1264 | if (evlist == NULL) |
| 1265 | return NULL; |
| 1266 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1267 | for (events_tp = kvm_events_tp; *events_tp; events_tp++) { |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1268 | |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1269 | tp = strdup(*events_tp); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1270 | if (tp == NULL) |
| 1271 | goto out; |
| 1272 | |
| 1273 | /* split tracepoint into subsystem and name */ |
| 1274 | sys = tp; |
| 1275 | name = strchr(tp, ':'); |
| 1276 | if (name == NULL) { |
| 1277 | pr_err("Error parsing %s tracepoint: subsystem delimiter not found\n", |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1278 | *events_tp); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1279 | free(tp); |
| 1280 | goto out; |
| 1281 | } |
| 1282 | *name = '\0'; |
| 1283 | name++; |
| 1284 | |
| 1285 | if (perf_evlist__add_newtp(evlist, sys, name, NULL)) { |
Alexander Yarygin | 9daa812 | 2014-07-03 18:29:05 +0400 | [diff] [blame] | 1286 | pr_err("Failed to add %s tracepoint to the list\n", *events_tp); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1287 | free(tp); |
| 1288 | goto out; |
| 1289 | } |
| 1290 | |
| 1291 | free(tp); |
| 1292 | } |
| 1293 | |
| 1294 | err = 0; |
| 1295 | |
| 1296 | out: |
| 1297 | if (err) { |
| 1298 | perf_evlist__delete(evlist); |
| 1299 | evlist = NULL; |
| 1300 | } |
| 1301 | |
| 1302 | return evlist; |
| 1303 | } |
| 1304 | |
| 1305 | static int kvm_events_live(struct perf_kvm_stat *kvm, |
| 1306 | int argc, const char **argv) |
| 1307 | { |
| 1308 | char errbuf[BUFSIZ]; |
| 1309 | int err; |
| 1310 | |
| 1311 | const struct option live_options[] = { |
| 1312 | OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid", |
| 1313 | "record events on existing process id"), |
Jiri Olsa | 994a1f7 | 2013-09-01 12:36:12 +0200 | [diff] [blame] | 1314 | OPT_CALLBACK('m', "mmap-pages", &kvm->opts.mmap_pages, "pages", |
| 1315 | "number of mmap data pages", |
| 1316 | perf_evlist__parse_mmap_pages), |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1317 | OPT_INCR('v', "verbose", &verbose, |
| 1318 | "be more verbose (show counter open errors, etc)"), |
| 1319 | OPT_BOOLEAN('a', "all-cpus", &kvm->opts.target.system_wide, |
| 1320 | "system-wide collection from all CPUs"), |
| 1321 | OPT_UINTEGER('d', "display", &kvm->display_time, |
| 1322 | "time in seconds between display updates"), |
| 1323 | OPT_STRING(0, "event", &kvm->report_event, "report event", |
Alexander Yarygin | 99d348a | 2014-12-10 14:28:10 +0100 | [diff] [blame] | 1324 | "event for reporting: " |
| 1325 | "vmexit, mmio (x86 only), ioport (x86 only)"), |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1326 | OPT_INTEGER(0, "vcpu", &kvm->trace_vcpu, |
| 1327 | "vcpu id to report"), |
| 1328 | OPT_STRING('k', "key", &kvm->sort_key, "sort-key", |
| 1329 | "key for sorting: sample(sort by samples number)" |
| 1330 | " time (sort by avg time)"), |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 1331 | OPT_U64(0, "duration", &kvm->duration, |
Alexander Yarygin | 3be8e2a | 2014-07-03 18:29:07 +0400 | [diff] [blame] | 1332 | "show events other than" |
| 1333 | " HLT (x86 only) or Wait state (s390 only)" |
| 1334 | " that take longer than duration usecs"), |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 1335 | OPT_UINTEGER(0, "proc-map-timeout", &kvm->opts.proc_map_timeout, |
| 1336 | "per thread proc mmap processing timeout in ms"), |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1337 | OPT_END() |
| 1338 | }; |
| 1339 | const char * const live_usage[] = { |
| 1340 | "perf kvm stat live [<options>]", |
| 1341 | NULL |
| 1342 | }; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1343 | struct perf_data_file file = { |
| 1344 | .mode = PERF_DATA_MODE_WRITE, |
| 1345 | }; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1346 | |
| 1347 | |
| 1348 | /* event handling */ |
| 1349 | kvm->tool.sample = process_sample_event; |
| 1350 | kvm->tool.comm = perf_event__process_comm; |
| 1351 | kvm->tool.exit = perf_event__process_exit; |
| 1352 | kvm->tool.fork = perf_event__process_fork; |
| 1353 | kvm->tool.lost = process_lost_event; |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 1354 | kvm->tool.namespaces = perf_event__process_namespaces; |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 1355 | kvm->tool.ordered_events = true; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1356 | perf_tool__fill_defaults(&kvm->tool); |
| 1357 | |
| 1358 | /* set defaults */ |
| 1359 | kvm->display_time = 1; |
| 1360 | kvm->opts.user_interval = 1; |
| 1361 | kvm->opts.mmap_pages = 512; |
| 1362 | kvm->opts.target.uses_mmap = false; |
| 1363 | kvm->opts.target.uid_str = NULL; |
| 1364 | kvm->opts.target.uid = UINT_MAX; |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 1365 | kvm->opts.proc_map_timeout = 500; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1366 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1367 | symbol__init(NULL); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1368 | disable_buildid_cache(); |
| 1369 | |
| 1370 | use_browser = 0; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1371 | |
| 1372 | if (argc) { |
| 1373 | argc = parse_options(argc, argv, live_options, |
| 1374 | live_usage, 0); |
| 1375 | if (argc) |
| 1376 | usage_with_options(live_usage, live_options); |
| 1377 | } |
| 1378 | |
David Ahern | 70f7b4a | 2013-08-07 21:56:38 -0400 | [diff] [blame] | 1379 | kvm->duration *= NSEC_PER_USEC; /* convert usec to nsec */ |
| 1380 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1381 | /* |
| 1382 | * target related setups |
| 1383 | */ |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 1384 | err = target__validate(&kvm->opts.target); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1385 | if (err) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 1386 | target__strerror(&kvm->opts.target, err, errbuf, BUFSIZ); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1387 | ui__warning("%s", errbuf); |
| 1388 | } |
| 1389 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 1390 | if (target__none(&kvm->opts.target)) |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1391 | kvm->opts.target.system_wide = true; |
| 1392 | |
| 1393 | |
| 1394 | /* |
| 1395 | * generate the event list |
| 1396 | */ |
Hemant Kumar | 066d359 | 2016-01-28 12:03:06 +0530 | [diff] [blame] | 1397 | err = setup_kvm_events_tp(kvm); |
| 1398 | if (err < 0) { |
| 1399 | pr_err("Unable to setup the kvm tracepoints\n"); |
| 1400 | return err; |
| 1401 | } |
| 1402 | |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1403 | kvm->evlist = kvm_live_event_list(); |
| 1404 | if (kvm->evlist == NULL) { |
| 1405 | err = -1; |
| 1406 | goto out; |
| 1407 | } |
| 1408 | |
| 1409 | symbol_conf.nr_events = kvm->evlist->nr_entries; |
| 1410 | |
| 1411 | if (perf_evlist__create_maps(kvm->evlist, &kvm->opts.target) < 0) |
| 1412 | usage_with_options(live_usage, live_options); |
| 1413 | |
| 1414 | /* |
| 1415 | * perf session |
| 1416 | */ |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1417 | kvm->session = perf_session__new(&file, false, &kvm->tool); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1418 | if (kvm->session == NULL) { |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 1419 | err = -1; |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1420 | goto out; |
| 1421 | } |
| 1422 | kvm->session->evlist = kvm->evlist; |
| 1423 | perf_session__set_id_hdr_size(kvm->session); |
Alexander Yarygin | 673d659 | 2014-10-03 18:40:12 +0400 | [diff] [blame] | 1424 | ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true); |
Arnaldo Carvalho de Melo | a33fbd5 | 2013-11-11 11:36:12 -0300 | [diff] [blame] | 1425 | machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target, |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 1426 | kvm->evlist->threads, false, kvm->opts.proc_map_timeout); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1427 | err = kvm_live_open_events(kvm); |
| 1428 | if (err) |
| 1429 | goto out; |
| 1430 | |
| 1431 | err = kvm_events_live_report(kvm); |
| 1432 | |
| 1433 | out: |
Arnaldo Carvalho de Melo | e144655 | 2016-06-22 10:02:16 -0300 | [diff] [blame] | 1434 | perf_session__delete(kvm->session); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1435 | kvm->session = NULL; |
Arnaldo Carvalho de Melo | 0b04b3d | 2016-06-21 18:15:45 -0300 | [diff] [blame] | 1436 | perf_evlist__delete(kvm->evlist); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1437 | |
| 1438 | return err; |
| 1439 | } |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 1440 | #endif |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1441 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1442 | static void print_kvm_stat_usage(void) |
| 1443 | { |
| 1444 | printf("Usage: perf kvm stat <command>\n\n"); |
| 1445 | |
| 1446 | printf("# Available commands:\n"); |
| 1447 | printf("\trecord: record kvm events\n"); |
| 1448 | printf("\treport: report statistical data of kvm events\n"); |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1449 | printf("\tlive: live reporting of statistical data of kvm events\n"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1450 | |
| 1451 | printf("\nOtherwise, it is the alias of 'perf stat':\n"); |
| 1452 | } |
| 1453 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1454 | static int kvm_cmd_stat(const char *file_name, int argc, const char **argv) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1455 | { |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1456 | struct perf_kvm_stat kvm = { |
| 1457 | .file_name = file_name, |
| 1458 | |
| 1459 | .trace_vcpu = -1, |
| 1460 | .report_event = "vmexit", |
| 1461 | .sort_key = "sample", |
| 1462 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1463 | }; |
| 1464 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1465 | if (argc == 1) { |
| 1466 | print_kvm_stat_usage(); |
| 1467 | goto perf_stat; |
| 1468 | } |
| 1469 | |
| 1470 | if (!strncmp(argv[1], "rec", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1471 | return kvm_events_record(&kvm, argc - 1, argv + 1); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1472 | |
| 1473 | if (!strncmp(argv[1], "rep", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1474 | return kvm_events_report(&kvm, argc - 1 , argv + 1); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1475 | |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 1476 | #ifdef HAVE_TIMERFD_SUPPORT |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1477 | if (!strncmp(argv[1], "live", 4)) |
| 1478 | return kvm_events_live(&kvm, argc - 1 , argv + 1); |
David Ahern | 87419c9 | 2013-10-29 10:43:16 -0600 | [diff] [blame] | 1479 | #endif |
David Ahern | 1afe1d1 | 2013-08-05 21:41:34 -0400 | [diff] [blame] | 1480 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1481 | perf_stat: |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1482 | return cmd_stat(argc, argv); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1483 | } |
Alexander Yarygin | da50ad6 | 2014-07-03 17:59:49 +0400 | [diff] [blame] | 1484 | #endif /* HAVE_KVM_STAT_SUPPORT */ |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1485 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1486 | static int __cmd_record(const char *file_name, int argc, const char **argv) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1487 | { |
| 1488 | int rec_argc, i = 0, j; |
| 1489 | const char **rec_argv; |
| 1490 | |
| 1491 | rec_argc = argc + 2; |
| 1492 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1493 | rec_argv[i++] = strdup("record"); |
| 1494 | rec_argv[i++] = strdup("-o"); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1495 | rec_argv[i++] = strdup(file_name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1496 | for (j = 1; j < argc; j++, i++) |
| 1497 | rec_argv[i] = argv[j]; |
| 1498 | |
| 1499 | BUG_ON(i != rec_argc); |
| 1500 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1501 | return cmd_record(i, rec_argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1502 | } |
| 1503 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1504 | static int __cmd_report(const char *file_name, int argc, const char **argv) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1505 | { |
| 1506 | int rec_argc, i = 0, j; |
| 1507 | const char **rec_argv; |
| 1508 | |
| 1509 | rec_argc = argc + 2; |
| 1510 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1511 | rec_argv[i++] = strdup("report"); |
| 1512 | rec_argv[i++] = strdup("-i"); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1513 | rec_argv[i++] = strdup(file_name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1514 | for (j = 1; j < argc; j++, i++) |
| 1515 | rec_argv[i] = argv[j]; |
| 1516 | |
| 1517 | BUG_ON(i != rec_argc); |
| 1518 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1519 | return cmd_report(i, rec_argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1520 | } |
| 1521 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1522 | static int |
| 1523 | __cmd_buildid_list(const char *file_name, int argc, const char **argv) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1524 | { |
| 1525 | int rec_argc, i = 0, j; |
| 1526 | const char **rec_argv; |
| 1527 | |
| 1528 | rec_argc = argc + 2; |
| 1529 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1530 | rec_argv[i++] = strdup("buildid-list"); |
| 1531 | rec_argv[i++] = strdup("-i"); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1532 | rec_argv[i++] = strdup(file_name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1533 | for (j = 1; j < argc; j++, i++) |
| 1534 | rec_argv[i] = argv[j]; |
| 1535 | |
| 1536 | BUG_ON(i != rec_argc); |
| 1537 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1538 | return cmd_buildid_list(i, rec_argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1539 | } |
| 1540 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1541 | int cmd_kvm(int argc, const char **argv) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1542 | { |
Arnaldo Carvalho de Melo | 20914ce5 | 2012-12-19 10:59:29 -0300 | [diff] [blame] | 1543 | const char *file_name = NULL; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1544 | const struct option kvm_options[] = { |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1545 | OPT_STRING('i', "input", &file_name, "file", |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1546 | "Input file name"), |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1547 | OPT_STRING('o', "output", &file_name, "file", |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1548 | "Output file name"), |
| 1549 | OPT_BOOLEAN(0, "guest", &perf_guest, |
| 1550 | "Collect guest os data"), |
| 1551 | OPT_BOOLEAN(0, "host", &perf_host, |
| 1552 | "Collect host os data"), |
| 1553 | OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory", |
| 1554 | "guest mount directory under which every guest os" |
| 1555 | " instance has a subdir"), |
| 1556 | OPT_STRING(0, "guestvmlinux", &symbol_conf.default_guest_vmlinux_name, |
| 1557 | "file", "file saving guest os vmlinux"), |
| 1558 | OPT_STRING(0, "guestkallsyms", &symbol_conf.default_guest_kallsyms, |
| 1559 | "file", "file saving guest os /proc/kallsyms"), |
| 1560 | OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, |
| 1561 | "file", "file saving guest os /proc/modules"), |
Dongsheng Yang | 100b907 | 2013-12-09 12:15:11 -0500 | [diff] [blame] | 1562 | OPT_INCR('v', "verbose", &verbose, |
| 1563 | "be more verbose (show counter open errors, etc)"), |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1564 | OPT_END() |
| 1565 | }; |
| 1566 | |
Ramkumar Ramachandra | 09a71b9 | 2014-03-03 20:26:36 -0500 | [diff] [blame] | 1567 | const char *const kvm_subcommands[] = { "top", "record", "report", "diff", |
| 1568 | "buildid-list", "stat", NULL }; |
| 1569 | const char *kvm_usage[] = { NULL, NULL }; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1570 | |
Joerg Roedel | 1aed267 | 2012-01-04 17:54:20 +0100 | [diff] [blame] | 1571 | perf_host = 0; |
| 1572 | perf_guest = 1; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1573 | |
Ramkumar Ramachandra | 09a71b9 | 2014-03-03 20:26:36 -0500 | [diff] [blame] | 1574 | argc = parse_options_subcommand(argc, argv, kvm_options, kvm_subcommands, kvm_usage, |
| 1575 | PARSE_OPT_STOP_AT_NON_OPTION); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1576 | if (!argc) |
| 1577 | usage_with_options(kvm_usage, kvm_options); |
| 1578 | |
| 1579 | if (!perf_host) |
| 1580 | perf_guest = 1; |
| 1581 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1582 | if (!file_name) { |
Dongsheng Yang | e1a2b17 | 2013-12-06 17:25:51 -0500 | [diff] [blame] | 1583 | file_name = get_filename_for_perf_kvm(); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1584 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1585 | if (!file_name) { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1586 | pr_err("Failed to allocate memory for filename\n"); |
| 1587 | return -ENOMEM; |
| 1588 | } |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | if (!strncmp(argv[0], "rec", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1592 | return __cmd_record(file_name, argc, argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1593 | else if (!strncmp(argv[0], "rep", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1594 | return __cmd_report(file_name, argc, argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1595 | else if (!strncmp(argv[0], "diff", 4)) |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1596 | return cmd_diff(argc, argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1597 | else if (!strncmp(argv[0], "top", 3)) |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 1598 | return cmd_top(argc, argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1599 | else if (!strncmp(argv[0], "buildid-list", 12)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1600 | return __cmd_buildid_list(file_name, argc, argv); |
Alexander Yarygin | da50ad6 | 2014-07-03 17:59:49 +0400 | [diff] [blame] | 1601 | #ifdef HAVE_KVM_STAT_SUPPORT |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1602 | else if (!strncmp(argv[0], "stat", 4)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1603 | return kvm_cmd_stat(file_name, argc, argv); |
Xiao Guangrong | 7321090 | 2012-11-19 16:19:21 +0800 | [diff] [blame] | 1604 | #endif |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1605 | else |
| 1606 | usage_with_options(kvm_usage, kvm_options); |
| 1607 | |
| 1608 | return 0; |
| 1609 | } |