Lines Matching refs:top
91 static void perf_top__update_print_entries(struct perf_top *top) in perf_top__update_print_entries() argument
93 top->print_entries = top->winsize.ws_row - HEADER_LINE_NR; in perf_top__update_print_entries()
101 static void perf_top__resize(struct perf_top *top) in perf_top__resize() argument
103 get_term_dimensions(&top->winsize); in perf_top__resize()
104 perf_top__update_print_entries(top); in perf_top__resize()
107 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) in perf_top__parse_source() argument
137 if (!symbol__hists(sym, top->evlist->core.nr_entries)) { in perf_top__parse_source()
145 err = symbol__annotate(sym, map, evsel, 0, &top->annotation_opts, NULL); in perf_top__parse_source()
147 top->sym_filter_entry = he; in perf_top__parse_source()
191 static void perf_top__record_precise_ip(struct perf_top *top, in perf_top__record_precise_ip() argument
201 (top->sym_filter_entry == NULL || in perf_top__record_precise_ip()
202 top->sym_filter_entry->ms.sym != sym))) in perf_top__record_precise_ip()
233 static void perf_top__show_details(struct perf_top *top) in perf_top__show_details() argument
235 struct hist_entry *he = top->sym_filter_entry; in perf_top__show_details()
256 printf("Showing %s for %s\n", perf_evsel__name(top->sym_evsel), symbol->name); in perf_top__show_details()
257 printf(" Events Pcnt (>=%d%%)\n", top->annotation_opts.min_pcnt); in perf_top__show_details()
259 more = symbol__annotate_printf(symbol, he->ms.map, top->sym_evsel, &top->annotation_opts); in perf_top__show_details()
261 if (top->evlist->enabled) { in perf_top__show_details()
262 if (top->zero) in perf_top__show_details()
263 symbol__annotate_zero_histogram(symbol, top->sym_evsel->idx); in perf_top__show_details()
265 symbol__annotate_decay_histogram(symbol, top->sym_evsel->idx); in perf_top__show_details()
313 static void perf_top__print_sym_table(struct perf_top *top) in perf_top__print_sym_table() argument
317 const int win_width = top->winsize.ws_col - 1; in perf_top__print_sym_table()
318 struct evsel *evsel = top->sym_evsel; in perf_top__print_sym_table()
323 perf_top__header_snprintf(top, bf, sizeof(bf)); in perf_top__print_sym_table()
328 if (!top->record_opts.overwrite && in perf_top__print_sym_table()
339 if (top->sym_filter_entry) { in perf_top__print_sym_table()
340 perf_top__show_details(top); in perf_top__print_sym_table()
344 perf_top__resort_hists(top); in perf_top__print_sym_table()
346 hists__output_recalc_col_len(hists, top->print_entries - printed); in perf_top__print_sym_table()
348 hists__fprintf(hists, false, top->print_entries - printed, win_width, in perf_top__print_sym_table()
349 top->min_percent, stdout, !symbol_conf.use_callchain); in perf_top__print_sym_table()
387 static void perf_top__prompt_symbol(struct perf_top *top, const char *msg) in perf_top__prompt_symbol() argument
390 struct hist_entry *syme = top->sym_filter_entry, *n, *found = NULL; in perf_top__prompt_symbol()
391 struct hists *hists = evsel__hists(top->sym_evsel); in perf_top__prompt_symbol()
398 top->sym_filter_entry = NULL; in perf_top__prompt_symbol()
423 perf_top__parse_source(top, found); in perf_top__prompt_symbol()
429 static void perf_top__print_mapped_keys(struct perf_top *top) in perf_top__print_mapped_keys() argument
433 if (top->sym_filter_entry) { in perf_top__print_mapped_keys()
434 struct symbol *sym = top->sym_filter_entry->ms.sym; in perf_top__print_mapped_keys()
439 fprintf(stdout, "\t[d] display refresh delay. \t(%d)\n", top->delay_secs); in perf_top__print_mapped_keys()
440 fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", top->print_entries); in perf_top__print_mapped_keys()
442 if (top->evlist->core.nr_entries > 1) in perf_top__print_mapped_keys()
443 …fprintf(stdout, "\t[E] active event counter. \t(%s)\n", perf_evsel__name(top->sym… in perf_top__print_mapped_keys()
445 fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", top->count_filter); in perf_top__print_mapped_keys()
447 …fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", top->annotation_opts.mi… in perf_top__print_mapped_keys()
453 top->hide_kernel_symbols ? "yes" : "no"); in perf_top__print_mapped_keys()
456 top->hide_user_symbols ? "yes" : "no"); in perf_top__print_mapped_keys()
457 fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", top->zero ? 1 : 0); in perf_top__print_mapped_keys()
461 static int perf_top__key_mapped(struct perf_top *top, int c) in perf_top__key_mapped() argument
477 return top->evlist->core.nr_entries > 1 ? 1 : 0; in perf_top__key_mapped()
485 static bool perf_top__handle_keypress(struct perf_top *top, int c) in perf_top__handle_keypress() argument
489 if (!perf_top__key_mapped(top, c)) { in perf_top__handle_keypress()
493 perf_top__print_mapped_keys(top); in perf_top__handle_keypress()
503 if (!perf_top__key_mapped(top, c)) in perf_top__handle_keypress()
509 prompt_integer(&top->delay_secs, "Enter display delay"); in perf_top__handle_keypress()
510 if (top->delay_secs < 1) in perf_top__handle_keypress()
511 top->delay_secs = 1; in perf_top__handle_keypress()
514 prompt_integer(&top->print_entries, "Enter display entries (lines)"); in perf_top__handle_keypress()
515 if (top->print_entries == 0) { in perf_top__handle_keypress()
516 perf_top__resize(top); in perf_top__handle_keypress()
523 if (top->evlist->core.nr_entries > 1) { in perf_top__handle_keypress()
529 evlist__for_each_entry(top->evlist, top->sym_evsel) in perf_top__handle_keypress()
530 fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, perf_evsel__name(top->sym_evsel)); in perf_top__handle_keypress()
534 if (counter >= top->evlist->core.nr_entries) { in perf_top__handle_keypress()
535 top->sym_evsel = evlist__first(top->evlist); in perf_top__handle_keypress()
536 fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel)); in perf_top__handle_keypress()
540 evlist__for_each_entry(top->evlist, top->sym_evsel) in perf_top__handle_keypress()
541 if (top->sym_evsel->idx == counter) in perf_top__handle_keypress()
544 top->sym_evsel = evlist__first(top->evlist); in perf_top__handle_keypress()
547 prompt_integer(&top->count_filter, "Enter display event count filter"); in perf_top__handle_keypress()
550 prompt_percent(&top->annotation_opts.min_pcnt, in perf_top__handle_keypress()
554 top->hide_kernel_symbols = !top->hide_kernel_symbols; in perf_top__handle_keypress()
559 if (top->dump_symtab) in perf_top__handle_keypress()
560 perf_session__fprintf_dsos(top->session, stderr); in perf_top__handle_keypress()
564 perf_top__prompt_symbol(top, "Enter details symbol"); in perf_top__handle_keypress()
567 if (!top->sym_filter_entry) in perf_top__handle_keypress()
570 struct hist_entry *syme = top->sym_filter_entry; in perf_top__handle_keypress()
572 top->sym_filter_entry = NULL; in perf_top__handle_keypress()
577 top->hide_user_symbols = !top->hide_user_symbols; in perf_top__handle_keypress()
580 top->zero = !top->zero; in perf_top__handle_keypress()
611 struct perf_top *top = arg; in display_thread_tui() local
615 .arg = top, in display_thread_tui()
616 .refresh = top->delay_secs, in display_thread_tui()
628 perf_top__sort_new_samples(top); in display_thread_tui()
635 evlist__for_each_entry(top->evlist, pos) { in display_thread_tui()
637 hists->uid_filter_str = top->record_opts.target.uid_str; in display_thread_tui()
640 perf_evlist__tui_browse_hists(top->evlist, help, &hbt, in display_thread_tui()
641 top->min_percent, in display_thread_tui()
642 &top->session->header.env, in display_thread_tui()
643 !top->record_opts.overwrite, in display_thread_tui()
644 &top->annotation_opts); in display_thread_tui()
668 struct perf_top *top = arg; in display_thread() local
683 delay_msecs = top->delay_secs * MSEC_PER_SEC; in display_thread()
689 perf_top__print_sym_table(top); in display_thread()
705 if (perf_top__handle_keypress(top, c)) in display_thread()
719 struct perf_top *top = arg; in hist_iter__top_callback() local
724 perf_top__record_precise_ip(top, he, iter->sample, evsel, al->addr); in hist_iter__top_callback()
727 !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY)); in hist_iter__top_callback()
737 struct perf_top *top = container_of(tool, struct perf_top, tool); in perf_event__process_sample() local
757 top->session->evlist->stats.nr_unprocessable_samples++); in perf_event__process_sample()
762 top->exact_samples++; in perf_event__process_sample()
770 if (!perf_evlist__exclude_kernel(top->session->evlist)) { in perf_event__process_sample()
796 if (!machine->kptr_restrict_warned && !top->vmlinux_warned && in perf_event__process_sample()
810 top->vmlinux_warned = true; in perf_event__process_sample()
829 err = hist_entry_iter__add(&iter, &al, top->max_stack, top); in perf_event__process_sample()
840 perf_top__process_lost(struct perf_top *top, union perf_event *event, in perf_top__process_lost() argument
845 top->lost += event->lost.lost; in perf_top__process_lost()
846 top->lost_total += event->lost.lost; in perf_top__process_lost()
851 perf_top__process_lost_samples(struct perf_top *top, in perf_top__process_lost_samples() argument
857 top->lost += event->lost_samples.lost; in perf_top__process_lost_samples()
858 top->lost_total += event->lost_samples.lost; in perf_top__process_lost_samples()
864 static void perf_top__mmap_read_idx(struct perf_top *top, int idx) in perf_top__mmap_read_idx() argument
866 struct record_opts *opts = &top->record_opts; in perf_top__mmap_read_idx()
867 struct evlist *evlist = top->evlist; in perf_top__mmap_read_idx()
882 ret = ordered_events__queue(top->qe.in, event, last_timestamp, 0); in perf_top__mmap_read_idx()
888 if (top->qe.rotate) { in perf_top__mmap_read_idx()
889 pthread_mutex_lock(&top->qe.mutex); in perf_top__mmap_read_idx()
890 top->qe.rotate = false; in perf_top__mmap_read_idx()
891 pthread_cond_signal(&top->qe.cond); in perf_top__mmap_read_idx()
892 pthread_mutex_unlock(&top->qe.mutex); in perf_top__mmap_read_idx()
899 static void perf_top__mmap_read(struct perf_top *top) in perf_top__mmap_read() argument
901 bool overwrite = top->record_opts.overwrite; in perf_top__mmap_read()
902 struct evlist *evlist = top->evlist; in perf_top__mmap_read()
908 for (i = 0; i < top->evlist->core.nr_mmaps; i++) in perf_top__mmap_read()
909 perf_top__mmap_read_idx(top, i); in perf_top__mmap_read()
934 static int perf_top__overwrite_check(struct perf_top *top) in perf_top__overwrite_check() argument
936 struct record_opts *opts = &top->record_opts; in perf_top__overwrite_check()
937 struct evlist *evlist = top->evlist; in perf_top__overwrite_check()
979 static int perf_top_overwrite_fallback(struct perf_top *top, in perf_top_overwrite_fallback() argument
982 struct record_opts *opts = &top->record_opts; in perf_top_overwrite_fallback()
983 struct evlist *evlist = top->evlist; in perf_top_overwrite_fallback()
1000 static int perf_top__start_counters(struct perf_top *top) in perf_top__start_counters() argument
1004 struct evlist *evlist = top->evlist; in perf_top__start_counters()
1005 struct record_opts *opts = &top->record_opts; in perf_top__start_counters()
1007 if (perf_top__overwrite_check(top)) { in perf_top__start_counters()
1017 if (evsel__open(counter, top->evlist->core.cpus, in perf_top__start_counters()
1018 top->evlist->core.threads) < 0) { in perf_top__start_counters()
1031 perf_top_overwrite_fallback(top, counter)) in perf_top__start_counters()
1071 static struct ordered_events *rotate_queues(struct perf_top *top) in rotate_queues() argument
1073 struct ordered_events *in = top->qe.in; in rotate_queues()
1075 if (top->qe.in == &top->qe.data[1]) in rotate_queues()
1076 top->qe.in = &top->qe.data[0]; in rotate_queues()
1078 top->qe.in = &top->qe.data[1]; in rotate_queues()
1085 struct perf_top *top = arg; in process_thread() local
1088 struct ordered_events *out, *in = top->qe.in; in process_thread()
1095 out = rotate_queues(top); in process_thread()
1097 pthread_mutex_lock(&top->qe.mutex); in process_thread()
1098 top->qe.rotate = true; in process_thread()
1099 pthread_cond_wait(&top->qe.cond, &top->qe.mutex); in process_thread()
1100 pthread_mutex_unlock(&top->qe.mutex); in process_thread()
1112 static int should_drop(struct ordered_event *qevent, struct perf_top *top) in should_drop() argument
1120 delay_timestamp = qevent->timestamp + top->delay_secs * NSEC_PER_SEC; in should_drop()
1127 struct perf_top *top = qe->data; in deliver_event() local
1128 struct evlist *evlist = top->evlist; in deliver_event()
1129 struct perf_session *session = top->session; in deliver_event()
1136 if (should_drop(qevent, top)) { in deliver_event()
1137 top->drop++; in deliver_event()
1138 top->drop_total++; in deliver_event()
1152 if (evswitch__discard(&top->evswitch, evsel)) in deliver_event()
1154 ++top->samples; in deliver_event()
1159 ++top->us_samples; in deliver_event()
1160 if (top->hide_user_symbols) in deliver_event()
1165 ++top->kernel_samples; in deliver_event()
1166 if (top->hide_kernel_symbols) in deliver_event()
1171 ++top->guest_kernel_samples; in deliver_event()
1176 ++top->guest_us_samples; in deliver_event()
1190 perf_event__process_sample(&top->tool, event, evsel, in deliver_event()
1193 perf_top__process_lost(top, event, evsel); in deliver_event()
1195 perf_top__process_lost_samples(top, event, evsel); in deliver_event()
1207 static void init_process_thread(struct perf_top *top) in init_process_thread() argument
1209 ordered_events__init(&top->qe.data[0], deliver_event, top); in init_process_thread()
1210 ordered_events__init(&top->qe.data[1], deliver_event, top); in init_process_thread()
1211 ordered_events__set_copy_on_queue(&top->qe.data[0], true); in init_process_thread()
1212 ordered_events__set_copy_on_queue(&top->qe.data[1], true); in init_process_thread()
1213 top->qe.in = &top->qe.data[0]; in init_process_thread()
1214 pthread_mutex_init(&top->qe.mutex, NULL); in init_process_thread()
1215 pthread_cond_init(&top->qe.cond, NULL); in init_process_thread()
1218 static int __cmd_top(struct perf_top *top) in __cmd_top() argument
1220 struct record_opts *opts = &top->record_opts; in __cmd_top()
1224 if (!top->annotation_opts.objdump_path) { in __cmd_top()
1225 ret = perf_env__lookup_objdump(&top->session->header.env, in __cmd_top()
1226 &top->annotation_opts.objdump_path); in __cmd_top()
1235 if (perf_session__register_idle_thread(top->session) < 0) in __cmd_top()
1238 if (top->nr_threads_synthesize > 1) in __cmd_top()
1241 init_process_thread(top); in __cmd_top()
1244 top->tool.namespace_events = true; in __cmd_top()
1246 ret = perf_event__synthesize_bpf_events(top->session, perf_event__process, in __cmd_top()
1247 &top->session->machines.host, in __cmd_top()
1248 &top->record_opts); in __cmd_top()
1252 machine__synthesize_threads(&top->session->machines.host, &opts->target, in __cmd_top()
1253 top->evlist->core.threads, false, in __cmd_top()
1254 top->nr_threads_synthesize); in __cmd_top()
1256 if (top->nr_threads_synthesize > 1) in __cmd_top()
1270 ret = perf_top__start_counters(top); in __cmd_top()
1274 top->session->evlist = top->evlist; in __cmd_top()
1275 perf_session__set_id_hdr_size(top->session); in __cmd_top()
1286 evlist__enable(top->evlist); in __cmd_top()
1289 if (pthread_create(&thread_process, NULL, process_thread, top)) { in __cmd_top()
1295 display_thread), top)) { in __cmd_top()
1300 if (top->realtime_prio) { in __cmd_top()
1303 param.sched_priority = top->realtime_prio; in __cmd_top()
1311 evlist__poll(top->evlist, 100); in __cmd_top()
1313 perf_top__mmap_read(top); in __cmd_top()
1316 u64 hits = top->samples; in __cmd_top()
1318 perf_top__mmap_read(top); in __cmd_top()
1320 if (opts->overwrite || (hits == top->samples)) in __cmd_top()
1321 ret = evlist__poll(top->evlist, 100); in __cmd_top()
1324 perf_top__resize(top); in __cmd_top()
1333 pthread_cond_signal(&top->qe.cond); in __cmd_top()
1383 struct perf_top *top = opt->value; in parse_percent_limit() local
1385 top->min_percent = strtof(arg, NULL); in parse_percent_limit()
1395 struct perf_top top = { in cmd_top() local
1421 struct record_opts *opts = &top.record_opts; in cmd_top()
1424 OPT_CALLBACK('e', "event", &top.evlist, "event", in cmd_top()
1442 OPT_BOOLEAN('K', "hide_kernel_symbols", &top.hide_kernel_symbols, in cmd_top()
1447 OPT_INTEGER('r', "realtime", &top.realtime_prio, in cmd_top()
1449 OPT_INTEGER('d', "delay", &top.delay_secs, in cmd_top()
1451 OPT_BOOLEAN('D', "dump-symtab", &top.dump_symtab, in cmd_top()
1453 OPT_INTEGER('f', "count-filter", &top.count_filter, in cmd_top()
1459 OPT_STRING(0, "sym-annotate", &top.sym_filter, "symbol name", in cmd_top()
1461 OPT_BOOLEAN('z', "zero", &top.zero, "zero history across updates"), in cmd_top()
1462 OPT_CALLBACK('F', "freq", &top.record_opts, "freq or 'max'", in cmd_top()
1465 OPT_INTEGER('E', "entries", &top.print_entries, in cmd_top()
1467 OPT_BOOLEAN('U', "hide_user_symbols", &top.hide_user_symbols, in cmd_top()
1469 OPT_BOOLEAN(0, "tui", &top.use_tui, "Use the TUI interface"), in cmd_top()
1470 OPT_BOOLEAN(0, "stdio", &top.use_stdio, "Use the stdio interface"), in cmd_top()
1488 OPT_INTEGER(0, "max-stack", &top.max_stack, in cmd_top()
1502 OPT_BOOLEAN(0, "source", &top.annotation_opts.annotate_src, in cmd_top()
1504 OPT_BOOLEAN(0, "asm-raw", &top.annotation_opts.show_asm_raw, in cmd_top()
1508 OPT_BOOLEAN(0, "no-bpf-event", &top.record_opts.no_bpf_event, "do not record bpf events"), in cmd_top()
1509 OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path", in cmd_top()
1511 …OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style… in cmd_top()
1514 OPT_CALLBACK(0, "percent-limit", &top, "percent", in cmd_top()
1533 OPT_BOOLEAN(0, "overwrite", &top.record_opts.overwrite, in cmd_top()
1536 OPT_UINTEGER(0, "num-thread-synthesize", &top.nr_threads_synthesize, in cmd_top()
1540 OPTS_EVSWITCH(&top.evswitch), in cmd_top()
1553 top.annotation_opts.min_pcnt = 5; in cmd_top()
1554 top.annotation_opts.context = 4; in cmd_top()
1556 top.evlist = evlist__new(); in cmd_top()
1557 if (top.evlist == NULL) in cmd_top()
1560 status = perf_config(perf_top_config, &top); in cmd_top()
1568 if (!top.evlist->core.nr_entries && in cmd_top()
1569 perf_evlist__add_default(top.evlist) < 0) { in cmd_top()
1574 status = evswitch__init(&top.evswitch, top.evlist, stderr); in cmd_top()
1598 if (top.use_stdio) in cmd_top()
1600 else if (top.use_tui) in cmd_top()
1605 if (setup_sorting(top.evlist) < 0) { in cmd_top()
1634 if (perf_evlist__create_maps(top.evlist, target) < 0) { in cmd_top()
1640 if (top.delay_secs < 1) in cmd_top()
1641 top.delay_secs = 1; in cmd_top()
1648 top.sym_evsel = evlist__first(top.evlist); in cmd_top()
1671 get_term_dimensions(&top.winsize); in cmd_top()
1672 if (top.print_entries == 0) { in cmd_top()
1673 perf_top__update_print_entries(&top); in cmd_top()
1677 top.session = perf_session__new(NULL, false, NULL); in cmd_top()
1678 if (IS_ERR(top.session)) { in cmd_top()
1679 status = PTR_ERR(top.session); in cmd_top()
1683 if (!top.record_opts.no_bpf_event) in cmd_top()
1691 status = __cmd_top(&top); in cmd_top()
1697 evlist__delete(top.evlist); in cmd_top()
1698 perf_session__delete(top.session); in cmd_top()