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