GNU Linux-libre 4.14.290-gnu1
[releases.git] / tools / perf / builtin-top.c
1 /*
2  * builtin-top.c
3  *
4  * Builtin top command: Display a continuously updated profile of
5  * any workload, CPU or specific PID.
6  *
7  * Copyright (C) 2008, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
8  *               2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
9  *
10  * Improvements and fixes by:
11  *
12  *   Arjan van de Ven <arjan@linux.intel.com>
13  *   Yanmin Zhang <yanmin.zhang@intel.com>
14  *   Wu Fengguang <fengguang.wu@intel.com>
15  *   Mike Galbraith <efault@gmx.de>
16  *   Paul Mackerras <paulus@samba.org>
17  *
18  * Released under the GPL v2. (and only v2, not any later version)
19  */
20 #include "builtin.h"
21
22 #include "perf.h"
23
24 #include "util/annotate.h"
25 #include "util/config.h"
26 #include "util/color.h"
27 #include "util/drv_configs.h"
28 #include "util/evlist.h"
29 #include "util/evsel.h"
30 #include "util/event.h"
31 #include "util/machine.h"
32 #include "util/session.h"
33 #include "util/symbol.h"
34 #include "util/thread.h"
35 #include "util/thread_map.h"
36 #include "util/top.h"
37 #include <linux/rbtree.h>
38 #include <subcmd/parse-options.h>
39 #include "util/parse-events.h"
40 #include "util/cpumap.h"
41 #include "util/xyarray.h"
42 #include "util/sort.h"
43 #include "util/term.h"
44 #include "util/intlist.h"
45 #include "util/parse-branch-options.h"
46 #include "arch/common.h"
47
48 #include "util/debug.h"
49
50 #include <assert.h>
51 #include <elf.h>
52 #include <fcntl.h>
53
54 #include <stdio.h>
55 #include <termios.h>
56 #include <unistd.h>
57 #include <inttypes.h>
58
59 #include <errno.h>
60 #include <time.h>
61 #include <sched.h>
62 #include <signal.h>
63
64 #include <sys/syscall.h>
65 #include <sys/ioctl.h>
66 #include <poll.h>
67 #include <sys/prctl.h>
68 #include <sys/wait.h>
69 #include <sys/uio.h>
70 #include <sys/utsname.h>
71 #include <sys/mman.h>
72
73 #include <linux/stringify.h>
74 #include <linux/time64.h>
75 #include <linux/types.h>
76
77 #include "sane_ctype.h"
78
79 static volatile int done;
80 static volatile int resize;
81
82 #define HEADER_LINE_NR  5
83
84 static void perf_top__update_print_entries(struct perf_top *top)
85 {
86         top->print_entries = top->winsize.ws_row - HEADER_LINE_NR;
87 }
88
89 static void perf_top__sig_winch(int sig __maybe_unused,
90                                 siginfo_t *info __maybe_unused, void *arg __maybe_unused)
91 {
92         resize = 1;
93 }
94
95 static void perf_top__resize(struct perf_top *top)
96 {
97         get_term_dimensions(&top->winsize);
98         perf_top__update_print_entries(top);
99 }
100
101 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
102 {
103         struct symbol *sym;
104         struct annotation *notes;
105         struct map *map;
106         int err = -1;
107
108         if (!he || !he->ms.sym)
109                 return -1;
110
111         sym = he->ms.sym;
112         map = he->ms.map;
113
114         /*
115          * We can't annotate with just /proc/kallsyms
116          */
117         if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
118             !dso__is_kcore(map->dso)) {
119                 pr_err("Can't annotate %s: No vmlinux file was found in the "
120                        "path\n", sym->name);
121                 sleep(1);
122                 return -1;
123         }
124
125         notes = symbol__annotation(sym);
126         if (notes->src != NULL) {
127                 pthread_mutex_lock(&notes->lock);
128                 goto out_assign;
129         }
130
131         pthread_mutex_lock(&notes->lock);
132
133         if (symbol__alloc_hist(sym) < 0) {
134                 pthread_mutex_unlock(&notes->lock);
135                 pr_err("Not enough memory for annotating '%s' symbol!\n",
136                        sym->name);
137                 sleep(1);
138                 return err;
139         }
140
141         err = symbol__disassemble(sym, map, NULL, 0, NULL, NULL);
142         if (err == 0) {
143 out_assign:
144                 top->sym_filter_entry = he;
145         } else {
146                 char msg[BUFSIZ];
147                 symbol__strerror_disassemble(sym, map, err, msg, sizeof(msg));
148                 pr_err("Couldn't annotate %s: %s\n", sym->name, msg);
149         }
150
151         pthread_mutex_unlock(&notes->lock);
152         return err;
153 }
154
155 static void __zero_source_counters(struct hist_entry *he)
156 {
157         struct symbol *sym = he->ms.sym;
158         symbol__annotate_zero_histograms(sym);
159 }
160
161 static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
162 {
163         struct utsname uts;
164         int err = uname(&uts);
165
166         ui__warning("Out of bounds address found:\n\n"
167                     "Addr:   %" PRIx64 "\n"
168                     "DSO:    %s %c\n"
169                     "Map:    %" PRIx64 "-%" PRIx64 "\n"
170                     "Symbol: %" PRIx64 "-%" PRIx64 " %c %s\n"
171                     "Arch:   %s\n"
172                     "Kernel: %s\n"
173                     "Tools:  %s\n\n"
174                     "Not all samples will be on the annotation output.\n\n"
175                     "Please report to linux-kernel@vger.kernel.org\n",
176                     ip, map->dso->long_name, dso__symtab_origin(map->dso),
177                     map->start, map->end, sym->start, sym->end,
178                     sym->binding == STB_GLOBAL ? 'g' :
179                     sym->binding == STB_LOCAL  ? 'l' : 'w', sym->name,
180                     err ? "[unknown]" : uts.machine,
181                     err ? "[unknown]" : uts.release, perf_version_string);
182         if (use_browser <= 0)
183                 sleep(5);
184
185         map->erange_warned = true;
186 }
187
188 static void perf_top__record_precise_ip(struct perf_top *top,
189                                         struct hist_entry *he,
190                                         struct perf_sample *sample,
191                                         int counter, u64 ip)
192 {
193         struct annotation *notes;
194         struct symbol *sym = he->ms.sym;
195         int err = 0;
196
197         if (sym == NULL || (use_browser == 0 &&
198                             (top->sym_filter_entry == NULL ||
199                              top->sym_filter_entry->ms.sym != sym)))
200                 return;
201
202         notes = symbol__annotation(sym);
203
204         if (pthread_mutex_trylock(&notes->lock))
205                 return;
206
207         err = hist_entry__inc_addr_samples(he, sample, counter, ip);
208
209         pthread_mutex_unlock(&notes->lock);
210
211         if (unlikely(err)) {
212                 /*
213                  * This function is now called with he->hists->lock held.
214                  * Release it before going to sleep.
215                  */
216                 pthread_mutex_unlock(&he->hists->lock);
217
218                 if (err == -ERANGE && !he->ms.map->erange_warned)
219                         ui__warn_map_erange(he->ms.map, sym, ip);
220                 else if (err == -ENOMEM) {
221                         pr_err("Not enough memory for annotating '%s' symbol!\n",
222                                sym->name);
223                         sleep(1);
224                 }
225
226                 pthread_mutex_lock(&he->hists->lock);
227         }
228 }
229
230 static void perf_top__show_details(struct perf_top *top)
231 {
232         struct hist_entry *he = top->sym_filter_entry;
233         struct annotation *notes;
234         struct symbol *symbol;
235         int more;
236
237         if (!he)
238                 return;
239
240         symbol = he->ms.sym;
241         notes = symbol__annotation(symbol);
242
243         pthread_mutex_lock(&notes->lock);
244
245         if (notes->src == NULL)
246                 goto out_unlock;
247
248         printf("Showing %s for %s\n", perf_evsel__name(top->sym_evsel), symbol->name);
249         printf("  Events  Pcnt (>=%d%%)\n", top->sym_pcnt_filter);
250
251         more = symbol__annotate_printf(symbol, he->ms.map, top->sym_evsel,
252                                        0, top->sym_pcnt_filter, top->print_entries, 4);
253
254         if (top->evlist->enabled) {
255                 if (top->zero)
256                         symbol__annotate_zero_histogram(symbol, top->sym_evsel->idx);
257                 else
258                         symbol__annotate_decay_histogram(symbol, top->sym_evsel->idx);
259         }
260         if (more != 0)
261                 printf("%d lines not displayed, maybe increase display entries [e]\n", more);
262 out_unlock:
263         pthread_mutex_unlock(&notes->lock);
264 }
265
266 static void perf_top__print_sym_table(struct perf_top *top)
267 {
268         char bf[160];
269         int printed = 0;
270         const int win_width = top->winsize.ws_col - 1;
271         struct perf_evsel *evsel = top->sym_evsel;
272         struct hists *hists = evsel__hists(evsel);
273
274         puts(CONSOLE_CLEAR);
275
276         perf_top__header_snprintf(top, bf, sizeof(bf));
277         printf("%s\n", bf);
278
279         perf_top__reset_sample_counters(top);
280
281         printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
282
283         if (hists->stats.nr_lost_warned !=
284             hists->stats.nr_events[PERF_RECORD_LOST]) {
285                 hists->stats.nr_lost_warned =
286                               hists->stats.nr_events[PERF_RECORD_LOST];
287                 color_fprintf(stdout, PERF_COLOR_RED,
288                               "WARNING: LOST %d chunks, Check IO/CPU overload",
289                               hists->stats.nr_lost_warned);
290                 ++printed;
291         }
292
293         if (top->sym_filter_entry) {
294                 perf_top__show_details(top);
295                 return;
296         }
297
298         if (top->evlist->enabled) {
299                 if (top->zero) {
300                         hists__delete_entries(hists);
301                 } else {
302                         hists__decay_entries(hists, top->hide_user_symbols,
303                                              top->hide_kernel_symbols);
304                 }
305         }
306
307         hists__collapse_resort(hists, NULL);
308         perf_evsel__output_resort(evsel, NULL);
309
310         hists__output_recalc_col_len(hists, top->print_entries - printed);
311         putchar('\n');
312         hists__fprintf(hists, false, top->print_entries - printed, win_width,
313                        top->min_percent, stdout, symbol_conf.use_callchain);
314 }
315
316 static void prompt_integer(int *target, const char *msg)
317 {
318         char *buf = malloc(0), *p;
319         size_t dummy = 0;
320         int tmp;
321
322         fprintf(stdout, "\n%s: ", msg);
323         if (getline(&buf, &dummy, stdin) < 0)
324                 return;
325
326         p = strchr(buf, '\n');
327         if (p)
328                 *p = 0;
329
330         p = buf;
331         while(*p) {
332                 if (!isdigit(*p))
333                         goto out_free;
334                 p++;
335         }
336         tmp = strtoul(buf, NULL, 10);
337         *target = tmp;
338 out_free:
339         free(buf);
340 }
341
342 static void prompt_percent(int *target, const char *msg)
343 {
344         int tmp = 0;
345
346         prompt_integer(&tmp, msg);
347         if (tmp >= 0 && tmp <= 100)
348                 *target = tmp;
349 }
350
351 static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)
352 {
353         char *buf = malloc(0), *p;
354         struct hist_entry *syme = top->sym_filter_entry, *n, *found = NULL;
355         struct hists *hists = evsel__hists(top->sym_evsel);
356         struct rb_node *next;
357         size_t dummy = 0;
358
359         /* zero counters of active symbol */
360         if (syme) {
361                 __zero_source_counters(syme);
362                 top->sym_filter_entry = NULL;
363         }
364
365         fprintf(stdout, "\n%s: ", msg);
366         if (getline(&buf, &dummy, stdin) < 0)
367                 goto out_free;
368
369         p = strchr(buf, '\n');
370         if (p)
371                 *p = 0;
372
373         next = rb_first(&hists->entries);
374         while (next) {
375                 n = rb_entry(next, struct hist_entry, rb_node);
376                 if (n->ms.sym && !strcmp(buf, n->ms.sym->name)) {
377                         found = n;
378                         break;
379                 }
380                 next = rb_next(&n->rb_node);
381         }
382
383         if (!found) {
384                 fprintf(stderr, "Sorry, %s is not active.\n", buf);
385                 sleep(1);
386         } else
387                 perf_top__parse_source(top, found);
388
389 out_free:
390         free(buf);
391 }
392
393 static void perf_top__print_mapped_keys(struct perf_top *top)
394 {
395         char *name = NULL;
396
397         if (top->sym_filter_entry) {
398                 struct symbol *sym = top->sym_filter_entry->ms.sym;
399                 name = sym->name;
400         }
401
402         fprintf(stdout, "\nMapped keys:\n");
403         fprintf(stdout, "\t[d]     display refresh delay.             \t(%d)\n", top->delay_secs);
404         fprintf(stdout, "\t[e]     display entries (lines).           \t(%d)\n", top->print_entries);
405
406         if (top->evlist->nr_entries > 1)
407                 fprintf(stdout, "\t[E]     active event counter.              \t(%s)\n", perf_evsel__name(top->sym_evsel));
408
409         fprintf(stdout, "\t[f]     profile display filter (count).    \t(%d)\n", top->count_filter);
410
411         fprintf(stdout, "\t[F]     annotate display filter (percent). \t(%d%%)\n", top->sym_pcnt_filter);
412         fprintf(stdout, "\t[s]     annotate symbol.                   \t(%s)\n", name?: "NULL");
413         fprintf(stdout, "\t[S]     stop annotation.\n");
414
415         fprintf(stdout,
416                 "\t[K]     hide kernel_symbols symbols.     \t(%s)\n",
417                 top->hide_kernel_symbols ? "yes" : "no");
418         fprintf(stdout,
419                 "\t[U]     hide user symbols.               \t(%s)\n",
420                 top->hide_user_symbols ? "yes" : "no");
421         fprintf(stdout, "\t[z]     toggle sample zeroing.             \t(%d)\n", top->zero ? 1 : 0);
422         fprintf(stdout, "\t[qQ]    quit.\n");
423 }
424
425 static int perf_top__key_mapped(struct perf_top *top, int c)
426 {
427         switch (c) {
428                 case 'd':
429                 case 'e':
430                 case 'f':
431                 case 'z':
432                 case 'q':
433                 case 'Q':
434                 case 'K':
435                 case 'U':
436                 case 'F':
437                 case 's':
438                 case 'S':
439                         return 1;
440                 case 'E':
441                         return top->evlist->nr_entries > 1 ? 1 : 0;
442                 default:
443                         break;
444         }
445
446         return 0;
447 }
448
449 static bool perf_top__handle_keypress(struct perf_top *top, int c)
450 {
451         bool ret = true;
452
453         if (!perf_top__key_mapped(top, c)) {
454                 struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
455                 struct termios save;
456
457                 perf_top__print_mapped_keys(top);
458                 fprintf(stdout, "\nEnter selection, or unmapped key to continue: ");
459                 fflush(stdout);
460
461                 set_term_quiet_input(&save);
462
463                 poll(&stdin_poll, 1, -1);
464                 c = getc(stdin);
465
466                 tcsetattr(0, TCSAFLUSH, &save);
467                 if (!perf_top__key_mapped(top, c))
468                         return ret;
469         }
470
471         switch (c) {
472                 case 'd':
473                         prompt_integer(&top->delay_secs, "Enter display delay");
474                         if (top->delay_secs < 1)
475                                 top->delay_secs = 1;
476                         break;
477                 case 'e':
478                         prompt_integer(&top->print_entries, "Enter display entries (lines)");
479                         if (top->print_entries == 0) {
480                                 struct sigaction act = {
481                                         .sa_sigaction = perf_top__sig_winch,
482                                         .sa_flags     = SA_SIGINFO,
483                                 };
484                                 perf_top__resize(top);
485                                 sigaction(SIGWINCH, &act, NULL);
486                         } else {
487                                 signal(SIGWINCH, SIG_DFL);
488                         }
489                         break;
490                 case 'E':
491                         if (top->evlist->nr_entries > 1) {
492                                 /* Select 0 as the default event: */
493                                 int counter = 0;
494
495                                 fprintf(stderr, "\nAvailable events:");
496
497                                 evlist__for_each_entry(top->evlist, top->sym_evsel)
498                                         fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, perf_evsel__name(top->sym_evsel));
499
500                                 prompt_integer(&counter, "Enter details event counter");
501
502                                 if (counter >= top->evlist->nr_entries) {
503                                         top->sym_evsel = perf_evlist__first(top->evlist);
504                                         fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel));
505                                         sleep(1);
506                                         break;
507                                 }
508                                 evlist__for_each_entry(top->evlist, top->sym_evsel)
509                                         if (top->sym_evsel->idx == counter)
510                                                 break;
511                         } else
512                                 top->sym_evsel = perf_evlist__first(top->evlist);
513                         break;
514                 case 'f':
515                         prompt_integer(&top->count_filter, "Enter display event count filter");
516                         break;
517                 case 'F':
518                         prompt_percent(&top->sym_pcnt_filter,
519                                        "Enter details display event filter (percent)");
520                         break;
521                 case 'K':
522                         top->hide_kernel_symbols = !top->hide_kernel_symbols;
523                         break;
524                 case 'q':
525                 case 'Q':
526                         printf("exiting.\n");
527                         if (top->dump_symtab)
528                                 perf_session__fprintf_dsos(top->session, stderr);
529                         ret = false;
530                         break;
531                 case 's':
532                         perf_top__prompt_symbol(top, "Enter details symbol");
533                         break;
534                 case 'S':
535                         if (!top->sym_filter_entry)
536                                 break;
537                         else {
538                                 struct hist_entry *syme = top->sym_filter_entry;
539
540                                 top->sym_filter_entry = NULL;
541                                 __zero_source_counters(syme);
542                         }
543                         break;
544                 case 'U':
545                         top->hide_user_symbols = !top->hide_user_symbols;
546                         break;
547                 case 'z':
548                         top->zero = !top->zero;
549                         break;
550                 default:
551                         break;
552         }
553
554         return ret;
555 }
556
557 static void perf_top__sort_new_samples(void *arg)
558 {
559         struct perf_top *t = arg;
560         struct perf_evsel *evsel = t->sym_evsel;
561         struct hists *hists;
562
563         perf_top__reset_sample_counters(t);
564
565         if (t->evlist->selected != NULL)
566                 t->sym_evsel = t->evlist->selected;
567
568         hists = evsel__hists(evsel);
569
570         if (t->evlist->enabled) {
571                 if (t->zero) {
572                         hists__delete_entries(hists);
573                 } else {
574                         hists__decay_entries(hists, t->hide_user_symbols,
575                                              t->hide_kernel_symbols);
576                 }
577         }
578
579         hists__collapse_resort(hists, NULL);
580         perf_evsel__output_resort(evsel, NULL);
581 }
582
583 static void *display_thread_tui(void *arg)
584 {
585         struct perf_evsel *pos;
586         struct perf_top *top = arg;
587         const char *help = "For a higher level overview, try: perf top --sort comm,dso";
588         struct hist_browser_timer hbt = {
589                 .timer          = perf_top__sort_new_samples,
590                 .arg            = top,
591                 .refresh        = top->delay_secs,
592         };
593
594         /* In order to read symbols from other namespaces perf to  needs to call
595          * setns(2).  This isn't permitted if the struct_fs has multiple users.
596          * unshare(2) the fs so that we may continue to setns into namespaces
597          * that we're observing.
598          */
599         unshare(CLONE_FS);
600
601         perf_top__sort_new_samples(top);
602
603         /*
604          * Initialize the uid_filter_str, in the future the TUI will allow
605          * Zooming in/out UIDs. For now juse use whatever the user passed
606          * via --uid.
607          */
608         evlist__for_each_entry(top->evlist, pos) {
609                 struct hists *hists = evsel__hists(pos);
610                 hists->uid_filter_str = top->record_opts.target.uid_str;
611         }
612
613         perf_evlist__tui_browse_hists(top->evlist, help, &hbt,
614                                       top->min_percent,
615                                       &top->session->header.env);
616
617         done = 1;
618         return NULL;
619 }
620
621 static void display_sig(int sig __maybe_unused)
622 {
623         done = 1;
624 }
625
626 static void display_setup_sig(void)
627 {
628         signal(SIGSEGV, sighandler_dump_stack);
629         signal(SIGFPE, sighandler_dump_stack);
630         signal(SIGINT,  display_sig);
631         signal(SIGQUIT, display_sig);
632         signal(SIGTERM, display_sig);
633 }
634
635 static void *display_thread(void *arg)
636 {
637         struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
638         struct termios save;
639         struct perf_top *top = arg;
640         int delay_msecs, c;
641
642         /* In order to read symbols from other namespaces perf to  needs to call
643          * setns(2).  This isn't permitted if the struct_fs has multiple users.
644          * unshare(2) the fs so that we may continue to setns into namespaces
645          * that we're observing.
646          */
647         unshare(CLONE_FS);
648
649         display_setup_sig();
650         pthread__unblock_sigwinch();
651 repeat:
652         delay_msecs = top->delay_secs * MSEC_PER_SEC;
653         set_term_quiet_input(&save);
654         /* trash return*/
655         clearerr(stdin);
656         if (poll(&stdin_poll, 1, 0) > 0)
657                 getc(stdin);
658
659         while (!done) {
660                 perf_top__print_sym_table(top);
661                 /*
662                  * Either timeout expired or we got an EINTR due to SIGWINCH,
663                  * refresh screen in both cases.
664                  */
665                 switch (poll(&stdin_poll, 1, delay_msecs)) {
666                 case 0:
667                         continue;
668                 case -1:
669                         if (errno == EINTR)
670                                 continue;
671                         __fallthrough;
672                 default:
673                         c = getc(stdin);
674                         tcsetattr(0, TCSAFLUSH, &save);
675
676                         if (perf_top__handle_keypress(top, c))
677                                 goto repeat;
678                         done = 1;
679                 }
680         }
681
682         tcsetattr(0, TCSAFLUSH, &save);
683         return NULL;
684 }
685
686 static int hist_iter__top_callback(struct hist_entry_iter *iter,
687                                    struct addr_location *al, bool single,
688                                    void *arg)
689 {
690         struct perf_top *top = arg;
691         struct hist_entry *he = iter->he;
692         struct perf_evsel *evsel = iter->evsel;
693
694         if (perf_hpp_list.sym && single)
695                 perf_top__record_precise_ip(top, he, iter->sample, evsel->idx, al->addr);
696
697         hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
698                      !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));
699         return 0;
700 }
701
702 static void perf_event__process_sample(struct perf_tool *tool,
703                                        const union perf_event *event,
704                                        struct perf_evsel *evsel,
705                                        struct perf_sample *sample,
706                                        struct machine *machine)
707 {
708         struct perf_top *top = container_of(tool, struct perf_top, tool);
709         struct addr_location al;
710         int err;
711
712         if (!machine && perf_guest) {
713                 static struct intlist *seen;
714
715                 if (!seen)
716                         seen = intlist__new(NULL);
717
718                 if (!intlist__has_entry(seen, sample->pid)) {
719                         pr_err("Can't find guest [%d]'s kernel information\n",
720                                 sample->pid);
721                         intlist__add(seen, sample->pid);
722                 }
723                 return;
724         }
725
726         if (!machine) {
727                 pr_err("%u unprocessable samples recorded.\r",
728                        top->session->evlist->stats.nr_unprocessable_samples++);
729                 return;
730         }
731
732         if (event->header.misc & PERF_RECORD_MISC_EXACT_IP)
733                 top->exact_samples++;
734
735         if (machine__resolve(machine, &al, sample) < 0)
736                 return;
737
738         if (!machine->kptr_restrict_warned &&
739             symbol_conf.kptr_restrict &&
740             al.cpumode == PERF_RECORD_MISC_KERNEL) {
741                 ui__warning(
742 "Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n"
743 "Check /proc/sys/kernel/kptr_restrict.\n\n"
744 "Kernel%s samples will not be resolved.\n",
745                           al.map && !RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION]) ?
746                           " modules" : "");
747                 if (use_browser <= 0)
748                         sleep(5);
749                 machine->kptr_restrict_warned = true;
750         }
751
752         if (al.sym == NULL) {
753                 const char *msg = "Kernel samples will not be resolved.\n";
754                 /*
755                  * As we do lazy loading of symtabs we only will know if the
756                  * specified vmlinux file is invalid when we actually have a
757                  * hit in kernel space and then try to load it. So if we get
758                  * here and there are _no_ symbols in the DSO backing the
759                  * kernel map, bail out.
760                  *
761                  * We may never get here, for instance, if we use -K/
762                  * --hide-kernel-symbols, even if the user specifies an
763                  * invalid --vmlinux ;-)
764                  */
765                 if (!machine->kptr_restrict_warned && !top->vmlinux_warned &&
766                     al.map == machine->vmlinux_maps[MAP__FUNCTION] &&
767                     RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
768                         if (symbol_conf.vmlinux_name) {
769                                 char serr[256];
770                                 dso__strerror_load(al.map->dso, serr, sizeof(serr));
771                                 ui__warning("The %s file can't be used: %s\n%s",
772                                             symbol_conf.vmlinux_name, serr, msg);
773                         } else {
774                                 ui__warning("A vmlinux file was not found.\n%s",
775                                             msg);
776                         }
777
778                         if (use_browser <= 0)
779                                 sleep(5);
780                         top->vmlinux_warned = true;
781                 }
782         }
783
784         if (al.sym == NULL || !al.sym->idle) {
785                 struct hists *hists = evsel__hists(evsel);
786                 struct hist_entry_iter iter = {
787                         .evsel          = evsel,
788                         .sample         = sample,
789                         .add_entry_cb   = hist_iter__top_callback,
790                 };
791
792                 if (symbol_conf.cumulate_callchain)
793                         iter.ops = &hist_iter_cumulative;
794                 else
795                         iter.ops = &hist_iter_normal;
796
797                 pthread_mutex_lock(&hists->lock);
798
799                 err = hist_entry_iter__add(&iter, &al, top->max_stack, top);
800                 if (err < 0)
801                         pr_err("Problem incrementing symbol period, skipping event\n");
802
803                 pthread_mutex_unlock(&hists->lock);
804         }
805
806         addr_location__put(&al);
807 }
808
809 static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
810 {
811         struct perf_sample sample;
812         struct perf_evsel *evsel;
813         struct perf_session *session = top->session;
814         union perf_event *event;
815         struct machine *machine;
816         int ret;
817
818         while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) {
819                 ret = perf_evlist__parse_sample(top->evlist, event, &sample);
820                 if (ret) {
821                         pr_err("Can't parse sample, err = %d\n", ret);
822                         goto next_event;
823                 }
824
825                 evsel = perf_evlist__id2evsel(session->evlist, sample.id);
826                 assert(evsel != NULL);
827
828                 if (event->header.type == PERF_RECORD_SAMPLE)
829                         ++top->samples;
830
831                 switch (sample.cpumode) {
832                 case PERF_RECORD_MISC_USER:
833                         ++top->us_samples;
834                         if (top->hide_user_symbols)
835                                 goto next_event;
836                         machine = &session->machines.host;
837                         break;
838                 case PERF_RECORD_MISC_KERNEL:
839                         ++top->kernel_samples;
840                         if (top->hide_kernel_symbols)
841                                 goto next_event;
842                         machine = &session->machines.host;
843                         break;
844                 case PERF_RECORD_MISC_GUEST_KERNEL:
845                         ++top->guest_kernel_samples;
846                         machine = perf_session__find_machine(session,
847                                                              sample.pid);
848                         break;
849                 case PERF_RECORD_MISC_GUEST_USER:
850                         ++top->guest_us_samples;
851                         /*
852                          * TODO: we don't process guest user from host side
853                          * except simple counting.
854                          */
855                         goto next_event;
856                 default:
857                         if (event->header.type == PERF_RECORD_SAMPLE)
858                                 goto next_event;
859                         machine = &session->machines.host;
860                         break;
861                 }
862
863
864                 if (event->header.type == PERF_RECORD_SAMPLE) {
865                         perf_event__process_sample(&top->tool, event, evsel,
866                                                    &sample, machine);
867                 } else if (event->header.type < PERF_RECORD_MAX) {
868                         hists__inc_nr_events(evsel__hists(evsel), event->header.type);
869                         machine__process_event(machine, event, &sample);
870                 } else
871                         ++session->evlist->stats.nr_unknown_events;
872 next_event:
873                 perf_evlist__mmap_consume(top->evlist, idx);
874         }
875 }
876
877 static void perf_top__mmap_read(struct perf_top *top)
878 {
879         int i;
880
881         for (i = 0; i < top->evlist->nr_mmaps; i++)
882                 perf_top__mmap_read_idx(top, i);
883 }
884
885 static int perf_top__start_counters(struct perf_top *top)
886 {
887         char msg[BUFSIZ];
888         struct perf_evsel *counter;
889         struct perf_evlist *evlist = top->evlist;
890         struct record_opts *opts = &top->record_opts;
891
892         perf_evlist__config(evlist, opts, &callchain_param);
893
894         evlist__for_each_entry(evlist, counter) {
895 try_again:
896                 if (perf_evsel__open(counter, top->evlist->cpus,
897                                      top->evlist->threads) < 0) {
898                         if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) {
899                                 if (verbose > 0)
900                                         ui__warning("%s\n", msg);
901                                 goto try_again;
902                         }
903
904                         perf_evsel__open_strerror(counter, &opts->target,
905                                                   errno, msg, sizeof(msg));
906                         ui__error("%s\n", msg);
907                         goto out_err;
908                 }
909         }
910
911         if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
912                 ui__error("Failed to mmap with %d (%s)\n",
913                             errno, str_error_r(errno, msg, sizeof(msg)));
914                 goto out_err;
915         }
916
917         return 0;
918
919 out_err:
920         return -1;
921 }
922
923 static int callchain_param__setup_sample_type(struct callchain_param *callchain)
924 {
925         if (!perf_hpp_list.sym) {
926                 if (callchain->enabled) {
927                         ui__error("Selected -g but \"sym\" not present in --sort/-s.");
928                         return -EINVAL;
929                 }
930         } else if (callchain->mode != CHAIN_NONE) {
931                 if (callchain_register_param(callchain) < 0) {
932                         ui__error("Can't register callchain params.\n");
933                         return -EINVAL;
934                 }
935         }
936
937         return 0;
938 }
939
940 static int __cmd_top(struct perf_top *top)
941 {
942         char msg[512];
943         struct perf_evsel *pos;
944         struct perf_evsel_config_term *err_term;
945         struct perf_evlist *evlist = top->evlist;
946         struct record_opts *opts = &top->record_opts;
947         pthread_t thread;
948         int ret;
949
950         top->session = perf_session__new(NULL, false, NULL);
951         if (top->session == NULL)
952                 return -1;
953
954         if (!objdump_path) {
955                 ret = perf_env__lookup_objdump(&top->session->header.env);
956                 if (ret)
957                         goto out_delete;
958         }
959
960         ret = callchain_param__setup_sample_type(&callchain_param);
961         if (ret)
962                 goto out_delete;
963
964         if (perf_session__register_idle_thread(top->session) < 0)
965                 goto out_delete;
966
967         machine__synthesize_threads(&top->session->machines.host, &opts->target,
968                                     top->evlist->threads, false, opts->proc_map_timeout);
969
970         if (perf_hpp_list.socket) {
971                 ret = perf_env__read_cpu_topology_map(&perf_env);
972                 if (ret < 0)
973                         goto out_err_cpu_topo;
974         }
975
976         ret = perf_top__start_counters(top);
977         if (ret)
978                 goto out_delete;
979
980         ret = perf_evlist__apply_drv_configs(evlist, &pos, &err_term);
981         if (ret) {
982                 pr_err("failed to set config \"%s\" on event %s with %d (%s)\n",
983                         err_term->val.drv_cfg, perf_evsel__name(pos), errno,
984                         str_error_r(errno, msg, sizeof(msg)));
985                 goto out_delete;
986         }
987
988         top->session->evlist = top->evlist;
989         perf_session__set_id_hdr_size(top->session);
990
991         /*
992          * When perf is starting the traced process, all the events (apart from
993          * group members) have enable_on_exec=1 set, so don't spoil it by
994          * prematurely enabling them.
995          *
996          * XXX 'top' still doesn't start workloads like record, trace, but should,
997          * so leave the check here.
998          */
999         if (!target__none(&opts->target))
1000                 perf_evlist__enable(top->evlist);
1001
1002         /* Wait for a minimal set of events before starting the snapshot */
1003         perf_evlist__poll(top->evlist, 100);
1004
1005         perf_top__mmap_read(top);
1006
1007         ret = -1;
1008         if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui :
1009                                                             display_thread), top)) {
1010                 ui__error("Could not create display thread.\n");
1011                 goto out_delete;
1012         }
1013
1014         if (top->realtime_prio) {
1015                 struct sched_param param;
1016
1017                 param.sched_priority = top->realtime_prio;
1018                 if (sched_setscheduler(0, SCHED_FIFO, &param)) {
1019                         ui__error("Could not set realtime priority.\n");
1020                         goto out_join;
1021                 }
1022         }
1023
1024         while (!done) {
1025                 u64 hits = top->samples;
1026
1027                 perf_top__mmap_read(top);
1028
1029                 if (hits == top->samples)
1030                         ret = perf_evlist__poll(top->evlist, 100);
1031
1032                 if (resize) {
1033                         perf_top__resize(top);
1034                         resize = 0;
1035                 }
1036         }
1037
1038         ret = 0;
1039 out_join:
1040         pthread_join(thread, NULL);
1041 out_delete:
1042         perf_session__delete(top->session);
1043         top->session = NULL;
1044
1045         return ret;
1046
1047 out_err_cpu_topo: {
1048         char errbuf[BUFSIZ];
1049         const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
1050
1051         ui__error("Could not read the CPU topology map: %s\n", err);
1052         goto out_delete;
1053 }
1054 }
1055
1056 static int
1057 callchain_opt(const struct option *opt, const char *arg, int unset)
1058 {
1059         symbol_conf.use_callchain = true;
1060         return record_callchain_opt(opt, arg, unset);
1061 }
1062
1063 static int
1064 parse_callchain_opt(const struct option *opt, const char *arg, int unset)
1065 {
1066         struct callchain_param *callchain = opt->value;
1067
1068         callchain->enabled = !unset;
1069         callchain->record_mode = CALLCHAIN_FP;
1070
1071         /*
1072          * --no-call-graph
1073          */
1074         if (unset) {
1075                 symbol_conf.use_callchain = false;
1076                 callchain->record_mode = CALLCHAIN_NONE;
1077                 return 0;
1078         }
1079
1080         return parse_callchain_top_opt(arg);
1081 }
1082
1083 static int perf_top_config(const char *var, const char *value, void *cb __maybe_unused)
1084 {
1085         if (!strcmp(var, "top.call-graph")) {
1086                 var = "call-graph.record-mode";
1087                 return perf_default_config(var, value, cb);
1088         }
1089         if (!strcmp(var, "top.children")) {
1090                 symbol_conf.cumulate_callchain = perf_config_bool(var, value);
1091                 return 0;
1092         }
1093
1094         return 0;
1095 }
1096
1097 static int
1098 parse_percent_limit(const struct option *opt, const char *arg,
1099                     int unset __maybe_unused)
1100 {
1101         struct perf_top *top = opt->value;
1102
1103         top->min_percent = strtof(arg, NULL);
1104         return 0;
1105 }
1106
1107 const char top_callchain_help[] = CALLCHAIN_RECORD_HELP CALLCHAIN_REPORT_HELP
1108         "\n\t\t\t\tDefault: fp,graph,0.5,caller,function";
1109
1110 int cmd_top(int argc, const char **argv)
1111 {
1112         char errbuf[BUFSIZ];
1113         struct perf_top top = {
1114                 .count_filter        = 5,
1115                 .delay_secs          = 2,
1116                 .record_opts = {
1117                         .mmap_pages     = UINT_MAX,
1118                         .user_freq      = UINT_MAX,
1119                         .user_interval  = ULLONG_MAX,
1120                         .freq           = 4000, /* 4 KHz */
1121                         .target         = {
1122                                 .uses_mmap   = true,
1123                         },
1124                         .proc_map_timeout    = 500,
1125                 },
1126                 .max_stack           = sysctl_perf_event_max_stack,
1127                 .sym_pcnt_filter     = 5,
1128         };
1129         struct record_opts *opts = &top.record_opts;
1130         struct target *target = &opts->target;
1131         const struct option options[] = {
1132         OPT_CALLBACK('e', "event", &top.evlist, "event",
1133                      "event selector. use 'perf list' to list available events",
1134                      parse_events_option),
1135         OPT_U64('c', "count", &opts->user_interval, "event period to sample"),
1136         OPT_STRING('p', "pid", &target->pid, "pid",
1137                     "profile events on existing process id"),
1138         OPT_STRING('t', "tid", &target->tid, "tid",
1139                     "profile events on existing thread id"),
1140         OPT_BOOLEAN('a', "all-cpus", &target->system_wide,
1141                             "system-wide collection from all CPUs"),
1142         OPT_STRING('C', "cpu", &target->cpu_list, "cpu",
1143                     "list of cpus to monitor"),
1144         OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
1145                    "file", "vmlinux pathname"),
1146         OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux,
1147                     "don't load vmlinux even if found"),
1148         OPT_BOOLEAN('K', "hide_kernel_symbols", &top.hide_kernel_symbols,
1149                     "hide kernel symbols"),
1150         OPT_CALLBACK('m', "mmap-pages", &opts->mmap_pages, "pages",
1151                      "number of mmap data pages",
1152                      perf_evlist__parse_mmap_pages),
1153         OPT_INTEGER('r', "realtime", &top.realtime_prio,
1154                     "collect data with this RT SCHED_FIFO priority"),
1155         OPT_INTEGER('d', "delay", &top.delay_secs,
1156                     "number of seconds to delay between refreshes"),
1157         OPT_BOOLEAN('D', "dump-symtab", &top.dump_symtab,
1158                             "dump the symbol table used for profiling"),
1159         OPT_INTEGER('f', "count-filter", &top.count_filter,
1160                     "only display functions with more events than this"),
1161         OPT_BOOLEAN(0, "group", &opts->group,
1162                             "put the counters into a counter group"),
1163         OPT_BOOLEAN('i', "no-inherit", &opts->no_inherit,
1164                     "child tasks do not inherit counters"),
1165         OPT_STRING(0, "sym-annotate", &top.sym_filter, "symbol name",
1166                     "symbol to annotate"),
1167         OPT_BOOLEAN('z', "zero", &top.zero, "zero history across updates"),
1168         OPT_UINTEGER('F', "freq", &opts->user_freq, "profile at this frequency"),
1169         OPT_INTEGER('E', "entries", &top.print_entries,
1170                     "display this many functions"),
1171         OPT_BOOLEAN('U', "hide_user_symbols", &top.hide_user_symbols,
1172                     "hide user symbols"),
1173         OPT_BOOLEAN(0, "tui", &top.use_tui, "Use the TUI interface"),
1174         OPT_BOOLEAN(0, "stdio", &top.use_stdio, "Use the stdio interface"),
1175         OPT_INCR('v', "verbose", &verbose,
1176                     "be more verbose (show counter open errors, etc)"),
1177         OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1178                    "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
1179                    " Please refer the man page for the complete list."),
1180         OPT_STRING(0, "fields", &field_order, "key[,keys...]",
1181                    "output field(s): overhead, period, sample plus all of sort keys"),
1182         OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
1183                     "Show a column with the number of samples"),
1184         OPT_CALLBACK_NOOPT('g', NULL, &callchain_param,
1185                            NULL, "enables call-graph recording and display",
1186                            &callchain_opt),
1187         OPT_CALLBACK(0, "call-graph", &callchain_param,
1188                      "record_mode[,record_size],print_type,threshold[,print_limit],order,sort_key[,branch]",
1189                      top_callchain_help, &parse_callchain_opt),
1190         OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
1191                     "Accumulate callchains of children and show total overhead as well"),
1192         OPT_INTEGER(0, "max-stack", &top.max_stack,
1193                     "Set the maximum stack depth when parsing the callchain. "
1194                     "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
1195         OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
1196                    "ignore callees of these functions in call graphs",
1197                    report_parse_ignore_callees_opt),
1198         OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
1199                     "Show a column with the sum of periods"),
1200         OPT_STRING(0, "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
1201                    "only consider symbols in these dsos"),
1202         OPT_STRING(0, "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
1203                    "only consider symbols in these comms"),
1204         OPT_STRING(0, "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
1205                    "only consider these symbols"),
1206         OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
1207                     "Interleave source code with assembly code (default)"),
1208         OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
1209                     "Display raw encoding of assembly instructions (default)"),
1210         OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
1211                     "Enable kernel symbol demangling"),
1212         OPT_STRING(0, "objdump", &objdump_path, "path",
1213                     "objdump binary to use for disassembly and annotations"),
1214         OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
1215                    "Specify disassembler style (e.g. -M intel for intel syntax)"),
1216         OPT_STRING('u', "uid", &target->uid_str, "user", "user to profile"),
1217         OPT_CALLBACK(0, "percent-limit", &top, "percent",
1218                      "Don't show entries under that percent", parse_percent_limit),
1219         OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
1220                      "How to display percentage of filtered entries", parse_filter_percentage),
1221         OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
1222                    "width[,width...]",
1223                    "don't try to adjust column width, use these fixed values"),
1224         OPT_UINTEGER(0, "proc-map-timeout", &opts->proc_map_timeout,
1225                         "per thread proc mmap processing timeout in ms"),
1226         OPT_CALLBACK_NOOPT('b', "branch-any", &opts->branch_stack,
1227                      "branch any", "sample any taken branches",
1228                      parse_branch_stack),
1229         OPT_CALLBACK('j', "branch-filter", &opts->branch_stack,
1230                      "branch filter mask", "branch stack filter modes",
1231                      parse_branch_stack),
1232         OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
1233                     "Show raw trace event output (do not use print fmt or plugins)"),
1234         OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
1235                     "Show entries in a hierarchy"),
1236         OPT_BOOLEAN(0, "force", &symbol_conf.force, "don't complain, do it"),
1237         OPT_END()
1238         };
1239         const char * const top_usage[] = {
1240                 "perf top [<options>]",
1241                 NULL
1242         };
1243         int status = hists__init();
1244
1245         if (status < 0)
1246                 return status;
1247
1248         top.evlist = perf_evlist__new();
1249         if (top.evlist == NULL)
1250                 return -ENOMEM;
1251
1252         status = perf_config(perf_top_config, &top);
1253         if (status)
1254                 return status;
1255
1256         argc = parse_options(argc, argv, options, top_usage, 0);
1257         if (argc)
1258                 usage_with_options(top_usage, options);
1259
1260         if (!top.evlist->nr_entries &&
1261             perf_evlist__add_default(top.evlist) < 0) {
1262                 pr_err("Not enough memory for event selector list\n");
1263                 goto out_delete_evlist;
1264         }
1265
1266         if (symbol_conf.report_hierarchy) {
1267                 /* disable incompatible options */
1268                 symbol_conf.event_group = false;
1269                 symbol_conf.cumulate_callchain = false;
1270
1271                 if (field_order) {
1272                         pr_err("Error: --hierarchy and --fields options cannot be used together\n");
1273                         parse_options_usage(top_usage, options, "fields", 0);
1274                         parse_options_usage(NULL, options, "hierarchy", 0);
1275                         goto out_delete_evlist;
1276                 }
1277         }
1278
1279         sort__mode = SORT_MODE__TOP;
1280         /* display thread wants entries to be collapsed in a different tree */
1281         perf_hpp_list.need_collapse = 1;
1282
1283         if (top.use_stdio)
1284                 use_browser = 0;
1285         else if (top.use_tui)
1286                 use_browser = 1;
1287
1288         setup_browser(false);
1289
1290         if (setup_sorting(top.evlist) < 0) {
1291                 if (sort_order)
1292                         parse_options_usage(top_usage, options, "s", 1);
1293                 if (field_order)
1294                         parse_options_usage(sort_order ? NULL : top_usage,
1295                                             options, "fields", 0);
1296                 goto out_delete_evlist;
1297         }
1298
1299         status = target__validate(target);
1300         if (status) {
1301                 target__strerror(target, status, errbuf, BUFSIZ);
1302                 ui__warning("%s\n", errbuf);
1303         }
1304
1305         status = target__parse_uid(target);
1306         if (status) {
1307                 int saved_errno = errno;
1308
1309                 target__strerror(target, status, errbuf, BUFSIZ);
1310                 ui__error("%s\n", errbuf);
1311
1312                 status = -saved_errno;
1313                 goto out_delete_evlist;
1314         }
1315
1316         if (target__none(target))
1317                 target->system_wide = true;
1318
1319         if (perf_evlist__create_maps(top.evlist, target) < 0) {
1320                 ui__error("Couldn't create thread/CPU maps: %s\n",
1321                           errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf)));
1322                 goto out_delete_evlist;
1323         }
1324
1325         symbol_conf.nr_events = top.evlist->nr_entries;
1326
1327         if (top.delay_secs < 1)
1328                 top.delay_secs = 1;
1329
1330         if (record_opts__config(opts)) {
1331                 status = -EINVAL;
1332                 goto out_delete_evlist;
1333         }
1334
1335         top.sym_evsel = perf_evlist__first(top.evlist);
1336
1337         if (!callchain_param.enabled) {
1338                 symbol_conf.cumulate_callchain = false;
1339                 perf_hpp__cancel_cumulate();
1340         }
1341
1342         if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
1343                 callchain_param.order = ORDER_CALLER;
1344
1345         status = symbol__annotation_init();
1346         if (status < 0)
1347                 goto out_delete_evlist;
1348
1349         symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
1350         status = symbol__init(NULL);
1351         if (status < 0)
1352                 goto out_delete_evlist;
1353
1354         sort__setup_elide(stdout);
1355
1356         get_term_dimensions(&top.winsize);
1357         if (top.print_entries == 0) {
1358                 struct sigaction act = {
1359                         .sa_sigaction = perf_top__sig_winch,
1360                         .sa_flags     = SA_SIGINFO,
1361                 };
1362                 perf_top__update_print_entries(&top);
1363                 sigaction(SIGWINCH, &act, NULL);
1364         }
1365
1366         status = __cmd_top(&top);
1367
1368 out_delete_evlist:
1369         perf_evlist__delete(top.evlist);
1370
1371         return status;
1372 }