• Home
  • Raw
  • Download

Lines Matching +full:set +full:- +full:top

1 // SPDX-License-Identifier: GPL-2.0-only
3 * builtin-top.c
5 * Builtin top command: Display a continuously updated profile of
24 #include "util/bpf-event.h"
38 #include "util/synthetic-events.h"
39 #include "util/top.h"
42 #include <subcmd/parse-options.h>
43 #include "util/parse-events.h"
50 #include "util/parse-branch-options.h"
55 #include "util/ordered-events.h"
94 static void perf_top__update_print_entries(struct perf_top *top) in perf_top__update_print_entries() argument
96 top->print_entries = top->winsize.ws_row - HEADER_LINE_NR; in perf_top__update_print_entries()
104 static void perf_top__resize(struct perf_top *top) in perf_top__resize() argument
106 get_term_dimensions(&top->winsize); in perf_top__resize()
107 perf_top__update_print_entries(top); in perf_top__resize()
110 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) in perf_top__parse_source() argument
116 int err = -1; in perf_top__parse_source()
118 if (!he || !he->ms.sym) in perf_top__parse_source()
119 return -1; in perf_top__parse_source()
121 evsel = hists_to_evsel(he->hists); in perf_top__parse_source()
123 sym = he->ms.sym; in perf_top__parse_source()
124 map = he->ms.map; in perf_top__parse_source()
129 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && in perf_top__parse_source()
130 !dso__is_kcore(map->dso)) { in perf_top__parse_source()
132 "path\n", sym->name); in perf_top__parse_source()
134 return -1; in perf_top__parse_source()
138 pthread_mutex_lock(&notes->lock); in perf_top__parse_source()
140 if (!symbol__hists(sym, top->evlist->core.nr_entries)) { in perf_top__parse_source()
141 pthread_mutex_unlock(&notes->lock); in perf_top__parse_source()
143 sym->name); in perf_top__parse_source()
148 err = symbol__annotate(&he->ms, evsel, &top->annotation_opts, NULL); in perf_top__parse_source()
150 top->sym_filter_entry = he; in perf_top__parse_source()
153 symbol__strerror_disassemble(&he->ms, err, msg, sizeof(msg)); in perf_top__parse_source()
154 pr_err("Couldn't annotate %s: %s\n", sym->name, msg); in perf_top__parse_source()
157 pthread_mutex_unlock(&notes->lock); in perf_top__parse_source()
163 struct symbol *sym = he->ms.sym; in __zero_source_counters()
175 "Map: %" PRIx64 "-%" PRIx64 "\n" in ui__warn_map_erange()
176 "Symbol: %" PRIx64 "-%" PRIx64 " %c %s\n" in ui__warn_map_erange()
181 "Please report to linux-kernel@vger.kernel.org\n", in ui__warn_map_erange()
182 ip, map->dso->long_name, dso__symtab_origin(map->dso), in ui__warn_map_erange()
183 map->start, map->end, sym->start, sym->end, in ui__warn_map_erange()
184 sym->binding == STB_GLOBAL ? 'g' : in ui__warn_map_erange()
185 sym->binding == STB_LOCAL ? 'l' : 'w', sym->name, in ui__warn_map_erange()
191 map->erange_warned = true; in ui__warn_map_erange()
194 static void perf_top__record_precise_ip(struct perf_top *top, in perf_top__record_precise_ip() argument
200 struct symbol *sym = he->ms.sym; in perf_top__record_precise_ip()
204 (top->sym_filter_entry == NULL || in perf_top__record_precise_ip()
205 top->sym_filter_entry->ms.sym != sym))) in perf_top__record_precise_ip()
210 if (pthread_mutex_trylock(&notes->lock)) in perf_top__record_precise_ip()
215 pthread_mutex_unlock(&notes->lock); in perf_top__record_precise_ip()
219 * This function is now called with he->hists->lock held. in perf_top__record_precise_ip()
222 pthread_mutex_unlock(&he->hists->lock); in perf_top__record_precise_ip()
224 if (err == -ERANGE && !he->ms.map->erange_warned) in perf_top__record_precise_ip()
225 ui__warn_map_erange(he->ms.map, sym, ip); in perf_top__record_precise_ip()
226 else if (err == -ENOMEM) { in perf_top__record_precise_ip()
228 sym->name); in perf_top__record_precise_ip()
232 pthread_mutex_lock(&he->hists->lock); in perf_top__record_precise_ip()
236 static void perf_top__show_details(struct perf_top *top) in perf_top__show_details() argument
238 struct hist_entry *he = top->sym_filter_entry; in perf_top__show_details()
247 evsel = hists_to_evsel(he->hists); in perf_top__show_details()
249 symbol = he->ms.sym; in perf_top__show_details()
252 pthread_mutex_lock(&notes->lock); in perf_top__show_details()
256 if (notes->src == NULL) in perf_top__show_details()
259 printf("Showing %s for %s\n", evsel__name(top->sym_evsel), symbol->name); in perf_top__show_details()
260 printf(" Events Pcnt (>=%d%%)\n", top->annotation_opts.min_pcnt); in perf_top__show_details()
262 more = symbol__annotate_printf(&he->ms, top->sym_evsel, &top->annotation_opts); in perf_top__show_details()
264 if (top->evlist->enabled) { in perf_top__show_details()
265 if (top->zero) in perf_top__show_details()
266 symbol__annotate_zero_histogram(symbol, top->sym_evsel->idx); in perf_top__show_details()
268 symbol__annotate_decay_histogram(symbol, top->sym_evsel->idx); in perf_top__show_details()
273 pthread_mutex_unlock(&notes->lock); in perf_top__show_details()
278 struct evlist *evlist = t->evlist; in perf_top__resort_hists()
290 if (evlist->enabled) { in perf_top__resort_hists()
291 if (t->zero) { in perf_top__resort_hists()
294 hists__decay_entries(hists, t->hide_user_symbols, in perf_top__resort_hists()
295 t->hide_kernel_symbols); in perf_top__resort_hists()
301 /* Non-group events are considered as leader */ in perf_top__resort_hists()
303 struct hists *leader_hists = evsel__hists(pos->leader); in perf_top__resort_hists()
315 static void perf_top__print_sym_table(struct perf_top *top) in perf_top__print_sym_table() argument
319 const int win_width = top->winsize.ws_col - 1; in perf_top__print_sym_table()
320 struct evsel *evsel = top->sym_evsel; in perf_top__print_sym_table()
325 perf_top__header_snprintf(top, bf, sizeof(bf)); in perf_top__print_sym_table()
328 printf("%-*.*s\n", win_width, win_width, graph_dotted_line); in perf_top__print_sym_table()
330 if (!top->record_opts.overwrite && in perf_top__print_sym_table()
331 (hists->stats.nr_lost_warned != in perf_top__print_sym_table()
332 hists->stats.nr_events[PERF_RECORD_LOST])) { in perf_top__print_sym_table()
333 hists->stats.nr_lost_warned = in perf_top__print_sym_table()
334 hists->stats.nr_events[PERF_RECORD_LOST]; in perf_top__print_sym_table()
337 hists->stats.nr_lost_warned); in perf_top__print_sym_table()
341 if (top->sym_filter_entry) { in perf_top__print_sym_table()
342 perf_top__show_details(top); in perf_top__print_sym_table()
346 perf_top__resort_hists(top); in perf_top__print_sym_table()
348 hists__output_recalc_col_len(hists, top->print_entries - printed); in perf_top__print_sym_table()
350 hists__fprintf(hists, false, top->print_entries - printed, win_width, in perf_top__print_sym_table()
351 top->min_percent, stdout, !symbol_conf.use_callchain); in perf_top__print_sym_table()
389 static void perf_top__prompt_symbol(struct perf_top *top, const char *msg) in perf_top__prompt_symbol() argument
392 struct hist_entry *syme = top->sym_filter_entry, *n, *found = NULL; in perf_top__prompt_symbol()
393 struct hists *hists = evsel__hists(top->sym_evsel); in perf_top__prompt_symbol()
400 top->sym_filter_entry = NULL; in perf_top__prompt_symbol()
411 next = rb_first_cached(&hists->entries); in perf_top__prompt_symbol()
414 if (n->ms.sym && !strcmp(buf, n->ms.sym->name)) { in perf_top__prompt_symbol()
418 next = rb_next(&n->rb_node); in perf_top__prompt_symbol()
425 perf_top__parse_source(top, found); in perf_top__prompt_symbol()
431 static void perf_top__print_mapped_keys(struct perf_top *top) in perf_top__print_mapped_keys() argument
435 if (top->sym_filter_entry) { in perf_top__print_mapped_keys()
436 struct symbol *sym = top->sym_filter_entry->ms.sym; in perf_top__print_mapped_keys()
437 name = sym->name; in perf_top__print_mapped_keys()
441 fprintf(stdout, "\t[d] display refresh delay. \t(%d)\n", top->delay_secs); in perf_top__print_mapped_keys()
442 fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", top->print_entries); in perf_top__print_mapped_keys()
444 if (top->evlist->core.nr_entries > 1) in perf_top__print_mapped_keys()
445 …fprintf(stdout, "\t[E] active event counter. \t(%s)\n", evsel__name(top->sym_evse… in perf_top__print_mapped_keys()
447 fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", top->count_filter); in perf_top__print_mapped_keys()
449 …fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", top->annotation_opts.mi… in perf_top__print_mapped_keys()
455 top->hide_kernel_symbols ? "yes" : "no"); in perf_top__print_mapped_keys()
458 top->hide_user_symbols ? "yes" : "no"); in perf_top__print_mapped_keys()
459 fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", top->zero ? 1 : 0); in perf_top__print_mapped_keys()
463 static int perf_top__key_mapped(struct perf_top *top, int c) in perf_top__key_mapped() argument
479 return top->evlist->core.nr_entries > 1 ? 1 : 0; in perf_top__key_mapped()
487 static bool perf_top__handle_keypress(struct perf_top *top, int c) in perf_top__handle_keypress() argument
491 if (!perf_top__key_mapped(top, c)) { in perf_top__handle_keypress()
495 perf_top__print_mapped_keys(top); in perf_top__handle_keypress()
501 poll(&stdin_poll, 1, -1); in perf_top__handle_keypress()
505 if (!perf_top__key_mapped(top, c)) in perf_top__handle_keypress()
511 prompt_integer(&top->delay_secs, "Enter display delay"); in perf_top__handle_keypress()
512 if (top->delay_secs < 1) in perf_top__handle_keypress()
513 top->delay_secs = 1; in perf_top__handle_keypress()
516 prompt_integer(&top->print_entries, "Enter display entries (lines)"); in perf_top__handle_keypress()
517 if (top->print_entries == 0) { in perf_top__handle_keypress()
518 perf_top__resize(top); in perf_top__handle_keypress()
525 if (top->evlist->core.nr_entries > 1) { in perf_top__handle_keypress()
531 evlist__for_each_entry(top->evlist, top->sym_evsel) in perf_top__handle_keypress()
532 fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, evsel__name(top->sym_evsel)); in perf_top__handle_keypress()
536 if (counter >= top->evlist->core.nr_entries) { in perf_top__handle_keypress()
537 top->sym_evsel = evlist__first(top->evlist); in perf_top__handle_keypress()
538 fprintf(stderr, "Sorry, no such event, using %s.\n", evsel__name(top->sym_evsel)); in perf_top__handle_keypress()
542 evlist__for_each_entry(top->evlist, top->sym_evsel) in perf_top__handle_keypress()
543 if (top->sym_evsel->idx == counter) in perf_top__handle_keypress()
546 top->sym_evsel = evlist__first(top->evlist); in perf_top__handle_keypress()
549 prompt_integer(&top->count_filter, "Enter display event count filter"); in perf_top__handle_keypress()
552 prompt_percent(&top->annotation_opts.min_pcnt, in perf_top__handle_keypress()
556 top->hide_kernel_symbols = !top->hide_kernel_symbols; in perf_top__handle_keypress()
561 if (top->dump_symtab) in perf_top__handle_keypress()
562 perf_session__fprintf_dsos(top->session, stderr); in perf_top__handle_keypress()
566 perf_top__prompt_symbol(top, "Enter details symbol"); in perf_top__handle_keypress()
569 if (!top->sym_filter_entry) in perf_top__handle_keypress()
572 struct hist_entry *syme = top->sym_filter_entry; in perf_top__handle_keypress()
574 top->sym_filter_entry = NULL; in perf_top__handle_keypress()
579 top->hide_user_symbols = !top->hide_user_symbols; in perf_top__handle_keypress()
582 top->zero = !top->zero; in perf_top__handle_keypress()
595 if (t->evlist->selected != NULL) in perf_top__sort_new_samples()
596 t->sym_evsel = t->evlist->selected; in perf_top__sort_new_samples()
600 if (t->lost || t->drop) in perf_top__sort_new_samples()
601 pr_warning("Too slow to read ring buffer (change period (-c/-F) or limit CPUs (-C)\n"); in perf_top__sort_new_samples()
613 struct perf_top *top = arg; in display_thread_tui() local
614 const char *help = "For a higher level overview, try: perf top --sort comm,dso"; in display_thread_tui()
617 .arg = top, in display_thread_tui()
618 .refresh = top->delay_secs, in display_thread_tui()
629 prctl(PR_SET_NAME, "perf-top-UI", 0, 0, 0); in display_thread_tui()
632 perf_top__sort_new_samples(top); in display_thread_tui()
637 * via --uid. in display_thread_tui()
639 evlist__for_each_entry(top->evlist, pos) { in display_thread_tui()
641 hists->uid_filter_str = top->record_opts.target.uid_str; in display_thread_tui()
644 ret = perf_evlist__tui_browse_hists(top->evlist, help, &hbt, in display_thread_tui()
645 top->min_percent, in display_thread_tui()
646 &top->session->header.env, in display_thread_tui()
647 !top->record_opts.overwrite, in display_thread_tui()
648 &top->annotation_opts); in display_thread_tui()
651 top->zero = true; in display_thread_tui()
677 struct perf_top *top = arg; in display_thread() local
687 prctl(PR_SET_NAME, "perf-top-UI", 0, 0, 0); in display_thread()
692 delay_msecs = top->delay_secs * MSEC_PER_SEC; in display_thread()
700 perf_top__print_sym_table(top); in display_thread()
708 case -1: in display_thread()
716 if (perf_top__handle_keypress(top, c)) in display_thread()
730 struct perf_top *top = arg; in hist_iter__top_callback() local
731 struct hist_entry *he = iter->he; in hist_iter__top_callback()
732 struct evsel *evsel = iter->evsel; in hist_iter__top_callback()
735 perf_top__record_precise_ip(top, he, iter->sample, evsel, al->addr); in hist_iter__top_callback()
737 hist__account_cycles(iter->sample->branch_stack, al, iter->sample, in hist_iter__top_callback()
738 !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY), in hist_iter__top_callback()
749 struct perf_top *top = container_of(tool, struct perf_top, tool); in perf_event__process_sample() local
759 if (!intlist__has_entry(seen, sample->pid)) { in perf_event__process_sample()
761 sample->pid); in perf_event__process_sample()
762 intlist__add(seen, sample->pid); in perf_event__process_sample()
769 top->session->evlist->stats.nr_unprocessable_samples++); in perf_event__process_sample()
773 if (event->header.misc & PERF_RECORD_MISC_EXACT_IP) in perf_event__process_sample()
774 top->exact_samples++; in perf_event__process_sample()
779 if (top->stitch_lbr) in perf_event__process_sample()
780 al.thread->lbr_stitch_enable = true; in perf_event__process_sample()
782 if (!machine->kptr_restrict_warned && in perf_event__process_sample()
785 if (!perf_evlist__exclude_kernel(top->session->evlist)) { in perf_event__process_sample()
795 machine->kptr_restrict_warned = true; in perf_event__process_sample()
807 * We may never get here, for instance, if we use -K/ in perf_event__process_sample()
808 * --hide-kernel-symbols, even if the user specifies an in perf_event__process_sample()
809 * invalid --vmlinux ;-) in perf_event__process_sample()
811 if (!machine->kptr_restrict_warned && !top->vmlinux_warned && in perf_event__process_sample()
815 dso__strerror_load(al.map->dso, serr, sizeof(serr)); in perf_event__process_sample()
825 top->vmlinux_warned = true; in perf_event__process_sample()
829 if (al.sym == NULL || !al.sym->idle) { in perf_event__process_sample()
842 pthread_mutex_lock(&hists->lock); in perf_event__process_sample()
844 err = hist_entry_iter__add(&iter, &al, top->max_stack, top); in perf_event__process_sample()
848 pthread_mutex_unlock(&hists->lock); in perf_event__process_sample()
855 perf_top__process_lost(struct perf_top *top, union perf_event *event, in perf_top__process_lost() argument
860 top->lost += event->lost.lost; in perf_top__process_lost()
861 top->lost_total += event->lost.lost; in perf_top__process_lost()
862 hists->stats.total_lost += event->lost.lost; in perf_top__process_lost()
866 perf_top__process_lost_samples(struct perf_top *top, in perf_top__process_lost_samples() argument
872 top->lost += event->lost_samples.lost; in perf_top__process_lost_samples()
873 top->lost_total += event->lost_samples.lost; in perf_top__process_lost_samples()
874 hists->stats.total_lost_samples += event->lost_samples.lost; in perf_top__process_lost_samples()
879 static void perf_top__mmap_read_idx(struct perf_top *top, int idx) in perf_top__mmap_read_idx() argument
881 struct record_opts *opts = &top->record_opts; in perf_top__mmap_read_idx()
882 struct evlist *evlist = top->evlist; in perf_top__mmap_read_idx()
886 md = opts->overwrite ? &evlist->overwrite_mmap[idx] : &evlist->mmap[idx]; in perf_top__mmap_read_idx()
887 if (perf_mmap__read_init(&md->core) < 0) in perf_top__mmap_read_idx()
890 while ((event = perf_mmap__read_event(&md->core)) != NULL) { in perf_top__mmap_read_idx()
894 if (ret && ret != -1) in perf_top__mmap_read_idx()
897 ret = ordered_events__queue(top->qe.in, event, last_timestamp, 0); in perf_top__mmap_read_idx()
901 perf_mmap__consume(&md->core); in perf_top__mmap_read_idx()
903 if (top->qe.rotate) { in perf_top__mmap_read_idx()
904 pthread_mutex_lock(&top->qe.mutex); in perf_top__mmap_read_idx()
905 top->qe.rotate = false; in perf_top__mmap_read_idx()
906 pthread_cond_signal(&top->qe.cond); in perf_top__mmap_read_idx()
907 pthread_mutex_unlock(&top->qe.mutex); in perf_top__mmap_read_idx()
911 perf_mmap__read_done(&md->core); in perf_top__mmap_read_idx()
914 static void perf_top__mmap_read(struct perf_top *top) in perf_top__mmap_read() argument
916 bool overwrite = top->record_opts.overwrite; in perf_top__mmap_read()
917 struct evlist *evlist = top->evlist; in perf_top__mmap_read()
923 for (i = 0; i < top->evlist->core.nr_mmaps; i++) in perf_top__mmap_read()
924 perf_top__mmap_read_idx(top, i); in perf_top__mmap_read()
933 * Check per-event overwrite term.
934 * perf top should support consistent term for all events.
935 * - All events don't have per-event term
936 * E.g. "cpu/cpu-cycles/,cpu/instructions/"
938 * - All events have same per-event term
939 * E.g. "cpu/cpu-cycles,no-overwrite/,cpu/instructions,no-overwrite/
940 * Using the per-event setting to replace the opts->overwrite if
942 * - Events have different per-event term
943 * E.g. "cpu/cpu-cycles,overwrite/,cpu/instructions,no-overwrite/"
944 * Return -1
945 * - Some of the event set per-event term, but some not.
946 * E.g. "cpu/cpu-cycles/,cpu/instructions,no-overwrite/"
947 * Return -1
949 static int perf_top__overwrite_check(struct perf_top *top) in perf_top__overwrite_check() argument
951 struct record_opts *opts = &top->record_opts; in perf_top__overwrite_check()
952 struct evlist *evlist = top->evlist; in perf_top__overwrite_check()
956 int set, overwrite = -1; in perf_top__overwrite_check() local
959 set = -1; in perf_top__overwrite_check()
960 config_terms = &evsel->config_terms; in perf_top__overwrite_check()
962 if (term->type == EVSEL__CONFIG_TERM_OVERWRITE) in perf_top__overwrite_check()
963 set = term->val.overwrite ? 1 : 0; in perf_top__overwrite_check()
967 if ((overwrite < 0) && (set < 0)) in perf_top__overwrite_check()
971 if ((overwrite >= 0) && (set >= 0) && (overwrite != set)) in perf_top__overwrite_check()
972 return -1; in perf_top__overwrite_check()
975 if ((overwrite >= 0) && (set < 0)) in perf_top__overwrite_check()
976 return -1; in perf_top__overwrite_check()
979 if ((overwrite < 0) && (set >= 0)) { in perf_top__overwrite_check()
980 /* if it's first event, set overwrite */ in perf_top__overwrite_check()
982 overwrite = set; in perf_top__overwrite_check()
984 return -1; in perf_top__overwrite_check()
988 if ((overwrite >= 0) && (opts->overwrite != overwrite)) in perf_top__overwrite_check()
989 opts->overwrite = overwrite; in perf_top__overwrite_check()
994 static int perf_top_overwrite_fallback(struct perf_top *top, in perf_top_overwrite_fallback() argument
997 struct record_opts *opts = &top->record_opts; in perf_top_overwrite_fallback()
998 struct evlist *evlist = top->evlist; in perf_top_overwrite_fallback()
1001 if (!opts->overwrite) in perf_top_overwrite_fallback()
1009 counter->core.attr.write_backward = false; in perf_top_overwrite_fallback()
1010 opts->overwrite = false; in perf_top_overwrite_fallback()
1011 pr_debug2("fall back to non-overwrite mode\n"); in perf_top_overwrite_fallback()
1015 static int perf_top__start_counters(struct perf_top *top) in perf_top__start_counters() argument
1019 struct evlist *evlist = top->evlist; in perf_top__start_counters()
1020 struct record_opts *opts = &top->record_opts; in perf_top__start_counters()
1022 if (perf_top__overwrite_check(top)) { in perf_top__start_counters()
1023 ui__error("perf top only support consistent per-event " in perf_top__start_counters()
1032 if (evsel__open(counter, top->evlist->core.cpus, in perf_top__start_counters()
1033 top->evlist->core.threads) < 0) { in perf_top__start_counters()
1037 * Because perf top is the only tool which has in perf_top__start_counters()
1039 * both overwrite and non-overwrite mode, and in perf_top__start_counters()
1046 perf_top_overwrite_fallback(top, counter)) in perf_top__start_counters()
1055 evsel__open_strerror(counter, &opts->target, errno, msg, sizeof(msg)); in perf_top__start_counters()
1061 if (evlist__mmap(evlist, opts->mmap_pages) < 0) { in perf_top__start_counters()
1070 return -1; in perf_top__start_counters()
1075 if (callchain->mode != CHAIN_NONE) { in callchain_param__setup_sample_type()
1078 return -EINVAL; in callchain_param__setup_sample_type()
1085 static struct ordered_events *rotate_queues(struct perf_top *top) in rotate_queues() argument
1087 struct ordered_events *in = top->qe.in; in rotate_queues()
1089 if (top->qe.in == &top->qe.data[1]) in rotate_queues()
1090 top->qe.in = &top->qe.data[0]; in rotate_queues()
1092 top->qe.in = &top->qe.data[1]; in rotate_queues()
1099 struct perf_top *top = arg; in process_thread() local
1102 struct ordered_events *out, *in = top->qe.in; in process_thread()
1104 if (!in->nr_events) { in process_thread()
1109 out = rotate_queues(top); in process_thread()
1111 pthread_mutex_lock(&top->qe.mutex); in process_thread()
1112 top->qe.rotate = true; in process_thread()
1113 pthread_cond_wait(&top->qe.cond, &top->qe.mutex); in process_thread()
1114 pthread_mutex_unlock(&top->qe.mutex); in process_thread()
1124 * Allow only 'top->delay_secs' seconds behind samples.
1126 static int should_drop(struct ordered_event *qevent, struct perf_top *top) in should_drop() argument
1128 union perf_event *event = qevent->event; in should_drop()
1131 if (event->header.type != PERF_RECORD_SAMPLE) in should_drop()
1134 delay_timestamp = qevent->timestamp + top->delay_secs * NSEC_PER_SEC; in should_drop()
1141 struct perf_top *top = qe->data; in deliver_event() local
1142 struct evlist *evlist = top->evlist; in deliver_event()
1143 struct perf_session *session = top->session; in deliver_event()
1144 union perf_event *event = qevent->event; in deliver_event()
1148 int ret = -1; in deliver_event()
1150 if (should_drop(qevent, top)) { in deliver_event()
1151 top->drop++; in deliver_event()
1152 top->drop_total++; in deliver_event()
1162 evsel = perf_evlist__id2evsel(session->evlist, sample.id); in deliver_event()
1165 if (event->header.type == PERF_RECORD_SAMPLE) { in deliver_event()
1166 if (evswitch__discard(&top->evswitch, evsel)) in deliver_event()
1168 ++top->samples; in deliver_event()
1173 ++top->us_samples; in deliver_event()
1174 if (top->hide_user_symbols) in deliver_event()
1176 machine = &session->machines.host; in deliver_event()
1179 ++top->kernel_samples; in deliver_event()
1180 if (top->hide_kernel_symbols) in deliver_event()
1182 machine = &session->machines.host; in deliver_event()
1185 ++top->guest_kernel_samples; in deliver_event()
1190 ++top->guest_us_samples; in deliver_event()
1197 if (event->header.type == PERF_RECORD_SAMPLE) in deliver_event()
1199 machine = &session->machines.host; in deliver_event()
1203 if (event->header.type == PERF_RECORD_SAMPLE) { in deliver_event()
1204 perf_event__process_sample(&top->tool, event, evsel, in deliver_event()
1206 } else if (event->header.type == PERF_RECORD_LOST) { in deliver_event()
1207 perf_top__process_lost(top, event, evsel); in deliver_event()
1208 } else if (event->header.type == PERF_RECORD_LOST_SAMPLES) { in deliver_event()
1209 perf_top__process_lost_samples(top, event, evsel); in deliver_event()
1210 } else if (event->header.type < PERF_RECORD_MAX) { in deliver_event()
1211 hists__inc_nr_events(evsel__hists(evsel), event->header.type); in deliver_event()
1214 ++session->evlist->stats.nr_unknown_events; in deliver_event()
1221 static void init_process_thread(struct perf_top *top) in init_process_thread() argument
1223 ordered_events__init(&top->qe.data[0], deliver_event, top); in init_process_thread()
1224 ordered_events__init(&top->qe.data[1], deliver_event, top); in init_process_thread()
1225 ordered_events__set_copy_on_queue(&top->qe.data[0], true); in init_process_thread()
1226 ordered_events__set_copy_on_queue(&top->qe.data[1], true); in init_process_thread()
1227 top->qe.in = &top->qe.data[0]; in init_process_thread()
1228 pthread_mutex_init(&top->qe.mutex, NULL); in init_process_thread()
1229 pthread_cond_init(&top->qe.cond, NULL); in init_process_thread()
1232 static int __cmd_top(struct perf_top *top) in __cmd_top() argument
1234 struct record_opts *opts = &top->record_opts; in __cmd_top()
1238 if (!top->annotation_opts.objdump_path) { in __cmd_top()
1239 ret = perf_env__lookup_objdump(&top->session->header.env, in __cmd_top()
1240 &top->annotation_opts.objdump_path); in __cmd_top()
1249 if (perf_session__register_idle_thread(top->session) < 0) in __cmd_top()
1252 if (top->nr_threads_synthesize > 1) in __cmd_top()
1255 init_process_thread(top); in __cmd_top()
1257 if (opts->record_namespaces) in __cmd_top()
1258 top->tool.namespace_events = true; in __cmd_top()
1259 if (opts->record_cgroup) { in __cmd_top()
1261 top->tool.cgroup_events = true; in __cmd_top()
1264 return -1; in __cmd_top()
1268 ret = perf_event__synthesize_bpf_events(top->session, perf_event__process, in __cmd_top()
1269 &top->session->machines.host, in __cmd_top()
1270 &top->record_opts); in __cmd_top()
1272 …pr_debug("Couldn't synthesize BPF events: Pre-existing BPF programs won't have symbols resolved.\n… in __cmd_top()
1274 ret = perf_event__synthesize_cgroups(&top->tool, perf_event__process, in __cmd_top()
1275 &top->session->machines.host); in __cmd_top()
1279 machine__synthesize_threads(&top->session->machines.host, &opts->target, in __cmd_top()
1280 top->evlist->core.threads, false, in __cmd_top()
1281 top->nr_threads_synthesize); in __cmd_top()
1283 if (top->nr_threads_synthesize > 1) in __cmd_top()
1290 const char *err = str_error_r(-ret, errbuf, sizeof(errbuf)); in __cmd_top()
1297 ret = perf_top__start_counters(top); in __cmd_top()
1301 top->session->evlist = top->evlist; in __cmd_top()
1302 perf_session__set_id_hdr_size(top->session); in __cmd_top()
1306 * group members) have enable_on_exec=1 set, so don't spoil it by in __cmd_top()
1309 * XXX 'top' still doesn't start workloads like record, trace, but should, in __cmd_top()
1312 if (!target__none(&opts->target)) in __cmd_top()
1313 evlist__enable(top->evlist); in __cmd_top()
1315 ret = -1; in __cmd_top()
1316 if (pthread_create(&thread_process, NULL, process_thread, top)) { in __cmd_top()
1322 display_thread), top)) { in __cmd_top()
1327 if (top->realtime_prio) { in __cmd_top()
1330 param.sched_priority = top->realtime_prio; in __cmd_top()
1332 ui__error("Could not set realtime priority.\n"); in __cmd_top()
1337 /* Wait for a minimal set of events before starting the snapshot */ in __cmd_top()
1338 evlist__poll(top->evlist, 100); in __cmd_top()
1340 perf_top__mmap_read(top); in __cmd_top()
1343 u64 hits = top->samples; in __cmd_top()
1345 perf_top__mmap_read(top); in __cmd_top()
1347 if (opts->overwrite || (hits == top->samples)) in __cmd_top()
1348 ret = evlist__poll(top->evlist, 100); in __cmd_top()
1351 perf_top__resize(top); in __cmd_top()
1360 pthread_cond_signal(&top->qe.cond); in __cmd_top()
1375 struct callchain_param *callchain = opt->value; in parse_callchain_opt()
1377 callchain->enabled = !unset; in parse_callchain_opt()
1378 callchain->record_mode = CALLCHAIN_FP; in parse_callchain_opt()
1381 * --no-call-graph in parse_callchain_opt()
1385 callchain->record_mode = CALLCHAIN_NONE; in parse_callchain_opt()
1394 if (!strcmp(var, "top.call-graph")) { in perf_top_config()
1395 var = "call-graph.record-mode"; in perf_top_config()
1398 if (!strcmp(var, "top.children")) { in perf_top_config()
1410 struct perf_top *top = opt->value; in parse_percent_limit() local
1412 top->min_percent = strtof(arg, NULL); in parse_percent_limit()
1422 struct perf_top top = { in cmd_top() local
1436 * separate evlist with a dummy event, i.e. a non-overwrite in cmd_top()
1438 * stays in overwrite mode. -acme in cmd_top()
1448 struct record_opts *opts = &top.record_opts; in cmd_top()
1449 struct target *target = &opts->target; in cmd_top()
1451 OPT_CALLBACK('e', "event", &top.evlist, "event", in cmd_top()
1454 OPT_U64('c', "count", &opts->user_interval, "event period to sample"), in cmd_top()
1455 OPT_STRING('p', "pid", &target->pid, "pid", in cmd_top()
1457 OPT_STRING('t', "tid", &target->tid, "tid", in cmd_top()
1459 OPT_BOOLEAN('a', "all-cpus", &target->system_wide, in cmd_top()
1460 "system-wide collection from all CPUs"), in cmd_top()
1461 OPT_STRING('C', "cpu", &target->cpu_list, "cpu", in cmd_top()
1465 OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux, in cmd_top()
1469 OPT_BOOLEAN('K', "hide_kernel_symbols", &top.hide_kernel_symbols, in cmd_top()
1471 OPT_CALLBACK('m', "mmap-pages", &opts->mmap_pages, "pages", in cmd_top()
1474 OPT_INTEGER('r', "realtime", &top.realtime_prio, in cmd_top()
1476 OPT_INTEGER('d', "delay", &top.delay_secs, in cmd_top()
1478 OPT_BOOLEAN('D', "dump-symtab", &top.dump_symtab, in cmd_top()
1480 OPT_INTEGER('f', "count-filter", &top.count_filter, in cmd_top()
1482 OPT_BOOLEAN(0, "group", &opts->group, in cmd_top()
1484 OPT_BOOLEAN('i', "no-inherit", &opts->no_inherit, in cmd_top()
1486 OPT_STRING(0, "sym-annotate", &top.sym_filter, "symbol name", in cmd_top()
1488 OPT_BOOLEAN('z', "zero", &top.zero, "zero history across updates"), in cmd_top()
1489 OPT_CALLBACK('F', "freq", &top.record_opts, "freq or 'max'", in cmd_top()
1492 OPT_INTEGER('E', "entries", &top.print_entries, in cmd_top()
1494 OPT_BOOLEAN('U', "hide_user_symbols", &top.hide_user_symbols, in cmd_top()
1496 OPT_BOOLEAN(0, "tui", &top.use_tui, "Use the TUI interface"), in cmd_top()
1497 OPT_BOOLEAN(0, "stdio", &top.use_stdio, "Use the stdio interface"), in cmd_top()
1505 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples, in cmd_top()
1508 NULL, "enables call-graph recording and display", in cmd_top()
1510 OPT_CALLBACK(0, "call-graph", &callchain_param, in cmd_top()
1515 OPT_INTEGER(0, "max-stack", &top.max_stack, in cmd_top()
1516 "Set the maximum stack depth when parsing the callchain. " in cmd_top()
1518 OPT_CALLBACK(0, "ignore-callees", NULL, "regex", in cmd_top()
1521 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period, in cmd_top()
1529 OPT_BOOLEAN(0, "source", &top.annotation_opts.annotate_src, in cmd_top()
1531 OPT_BOOLEAN(0, "asm-raw", &top.annotation_opts.show_asm_raw, in cmd_top()
1533 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, in cmd_top()
1535 OPT_BOOLEAN(0, "no-bpf-event", &top.record_opts.no_bpf_event, "do not record bpf events"), in cmd_top()
1536 OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path", in cmd_top()
1538 …OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style… in cmd_top()
1539 "Specify disassembler style (e.g. -M intel for intel syntax)"), in cmd_top()
1540 OPT_STRING(0, "prefix", &top.annotation_opts.prefix, "prefix", in cmd_top()
1541 "Add prefix to source file path names in programs (with --prefix-strip)"), in cmd_top()
1542 OPT_STRING(0, "prefix-strip", &top.annotation_opts.prefix_strip, "N", in cmd_top()
1543 "Strip first N entries of source file path name in programs (with --prefix)"), in cmd_top()
1544 OPT_STRING('u', "uid", &target->uid_str, "user", "user to profile"), in cmd_top()
1545 OPT_CALLBACK(0, "percent-limit", &top, "percent", in cmd_top()
1549 OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str, in cmd_top()
1552 OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout, in cmd_top()
1554 OPT_CALLBACK_NOOPT('b', "branch-any", &opts->branch_stack, in cmd_top()
1557 OPT_CALLBACK('j', "branch-filter", &opts->branch_stack, in cmd_top()
1560 OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace, in cmd_top()
1564 OPT_BOOLEAN(0, "overwrite", &top.record_opts.overwrite, in cmd_top()
1567 OPT_UINTEGER(0, "num-thread-synthesize", &top.nr_threads_synthesize, in cmd_top()
1569 OPT_BOOLEAN(0, "namespaces", &opts->record_namespaces, in cmd_top()
1571 OPT_BOOLEAN(0, "all-cgroups", &opts->record_cgroup, in cmd_top()
1573 OPT_INTEGER(0, "group-sort-idx", &symbol_conf.group_sort_idx, in cmd_top()
1577 OPT_BOOLEAN(0, "stitch-lbr", &top.stitch_lbr, in cmd_top()
1580 OPT_CALLBACK(0, "pfm-events", &top.evlist, "event", in cmd_top()
1584 OPTS_EVSWITCH(&top.evswitch), in cmd_top()
1588 "perf top [<options>]", in cmd_top()
1596 top.annotation_opts.min_pcnt = 5; in cmd_top()
1597 top.annotation_opts.context = 4; in cmd_top()
1599 top.evlist = evlist__new(); in cmd_top()
1600 if (top.evlist == NULL) in cmd_top()
1601 return -ENOMEM; in cmd_top()
1603 status = perf_config(perf_top_config, &top); in cmd_top()
1620 top.evlist->env = &perf_env; in cmd_top()
1626 if (annotate_check_args(&top.annotation_opts) < 0) in cmd_top()
1629 if (!top.evlist->core.nr_entries && in cmd_top()
1630 evlist__add_default(top.evlist) < 0) { in cmd_top()
1635 status = evswitch__init(&top.evswitch, top.evlist, stderr); in cmd_top()
1645 pr_err("Error: --hierarchy and --fields options cannot be used together\n"); in cmd_top()
1652 if (top.stitch_lbr && !(callchain_param.record_mode == CALLCHAIN_LBR)) { in cmd_top()
1653 pr_err("Error: --stitch-lbr must be used with --call-graph lbr\n"); in cmd_top()
1657 if (opts->branch_stack && callchain_param.enabled) in cmd_top()
1664 if (top.use_stdio) in cmd_top()
1666 else if (top.use_tui) in cmd_top()
1671 if (setup_sorting(top.evlist) < 0) { in cmd_top()
1693 status = -saved_errno; in cmd_top()
1698 target->system_wide = true; in cmd_top()
1700 if (perf_evlist__create_maps(top.evlist, target) < 0) { in cmd_top()
1706 if (top.delay_secs < 1) in cmd_top()
1707 top.delay_secs = 1; in cmd_top()
1710 status = -EINVAL; in cmd_top()
1714 top.sym_evsel = evlist__first(top.evlist); in cmd_top()
1728 annotation_config__init(&top.annotation_opts); in cmd_top()
1737 get_term_dimensions(&top.winsize); in cmd_top()
1738 if (top.print_entries == 0) { in cmd_top()
1739 perf_top__update_print_entries(&top); in cmd_top()
1743 top.session = perf_session__new(NULL, false, NULL); in cmd_top()
1744 if (IS_ERR(top.session)) { in cmd_top()
1745 status = PTR_ERR(top.session); in cmd_top()
1746 top.session = NULL; in cmd_top()
1751 if (!top.record_opts.no_bpf_event) { in cmd_top()
1752 top.sb_evlist = evlist__new(); in cmd_top()
1754 if (top.sb_evlist == NULL) { in cmd_top()
1759 if (evlist__add_bpf_sb_event(top.sb_evlist, &perf_env)) { in cmd_top()
1766 if (perf_evlist__start_sb_thread(top.sb_evlist, target)) { in cmd_top()
1768 opts->no_bpf_event = true; in cmd_top()
1771 status = __cmd_top(&top); in cmd_top()
1773 if (!opts->no_bpf_event) in cmd_top()
1774 perf_evlist__stop_sb_thread(top.sb_evlist); in cmd_top()
1777 evlist__delete(top.evlist); in cmd_top()
1778 perf_session__delete(top.session); in cmd_top()