Lines Matching +full:reset +full:- +full:duration +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0-only
3 * builtin-ftrace.c
25 #include <subcmd/parse-options.h>
39 #include "util/parse-sublevel-options.h"
62 workload_exec_errno = info->si_value.sival_int; in ftrace__workload_exec_failed_signal()
104 int fd, ret = -1; in __write_tracing_file()
113 return -1; in __write_tracing_file()
166 int ret = -1; in read_tracing_file_to_stdout()
171 return -1; in read_tracing_file_to_stdout()
213 return -1; in read_tracing_file_by_line()
220 return -1; in read_tracing_file_by_line()
223 while (getline(&line, &len, fp) != -1) { in read_tracing_file_by_line()
241 return -1; in write_tracing_file_int()
252 return -1; in write_tracing_option_file()
264 write_tracing_option_file("function-fork", "0"); in reset_tracing_options()
266 write_tracing_option_file("sleep-time", "1"); in reset_tracing_options()
267 write_tracing_option_file("funcgraph-irqs", "1"); in reset_tracing_options()
268 write_tracing_option_file("funcgraph-proc", "0"); in reset_tracing_options()
269 write_tracing_option_file("funcgraph-abstime", "0"); in reset_tracing_options()
270 write_tracing_option_file("funcgraph-tail", "0"); in reset_tracing_options()
271 write_tracing_option_file("latency-format", "0"); in reset_tracing_options()
272 write_tracing_option_file("irq-info", "0"); in reset_tracing_options()
278 return -1; in reset_tracing_files()
281 return -1; in reset_tracing_files()
284 return -1; in reset_tracing_files()
287 return -1; in reset_tracing_files()
290 return -1; in reset_tracing_files()
293 return -1; in reset_tracing_files()
305 if (target__has_cpu(&ftrace->target)) in set_tracing_pid()
308 for (i = 0; i < perf_thread_map__nr(ftrace->evlist->core.threads); i++) { in set_tracing_pid()
310 perf_thread_map__pid(ftrace->evlist->core.threads, i)); in set_tracing_pid()
312 return -1; in set_tracing_pid()
324 last_cpu = perf_cpu_map__cpu(cpumap, perf_cpu_map__nr(cpumap) - 1).cpu; in set_tracing_cpumask()
331 return -1; in set_tracing_cpumask()
344 struct perf_cpu_map *cpumap = ftrace->evlist->core.user_requested_cpus; in set_tracing_cpu()
346 if (!target__has_cpu(&ftrace->target)) in set_tracing_cpu()
354 if (!ftrace->func_stack_trace) in set_tracing_func_stack_trace()
358 return -1; in set_tracing_func_stack_trace()
365 if (!ftrace->func_irq_info) in set_tracing_func_irqinfo()
368 if (write_tracing_option_file("irq-info", "1") < 0) in set_tracing_func_irqinfo()
369 return -1; in set_tracing_func_irqinfo()
389 if (append_tracing_file(filter_file, pos->name) < 0) in __set_tracing_filter()
390 return -1; in __set_tracing_filter()
400 ret = __set_tracing_filter("set_ftrace_filter", &ftrace->filters); in set_tracing_filters()
404 ret = __set_tracing_filter("set_ftrace_notrace", &ftrace->notrace); in set_tracing_filters()
408 ret = __set_tracing_filter("set_graph_function", &ftrace->graph_funcs); in set_tracing_filters()
413 __set_tracing_filter("set_graph_notrace", &ftrace->nograph_funcs); in set_tracing_filters()
428 if (ftrace->graph_depth == 0) in set_tracing_depth()
431 if (ftrace->graph_depth < 0) { in set_tracing_depth()
432 pr_err("invalid graph depth: %d\n", ftrace->graph_depth); in set_tracing_depth()
433 return -1; in set_tracing_depth()
436 if (write_tracing_file_int("max_graph_depth", ftrace->graph_depth) < 0) in set_tracing_depth()
437 return -1; in set_tracing_depth()
446 if (ftrace->percpu_buffer_size == 0) in set_tracing_percpu_buffer_size()
450 ftrace->percpu_buffer_size / 1024); in set_tracing_percpu_buffer_size()
459 if (!ftrace->inherit) in set_tracing_trace_inherit()
462 if (write_tracing_option_file("function-fork", "1") < 0) in set_tracing_trace_inherit()
463 return -1; in set_tracing_trace_inherit()
470 if (!ftrace->graph_nosleep_time) in set_tracing_sleep_time()
473 if (write_tracing_option_file("sleep-time", "0") < 0) in set_tracing_sleep_time()
474 return -1; in set_tracing_sleep_time()
481 if (!ftrace->graph_noirqs) in set_tracing_funcgraph_irqs()
484 if (write_tracing_option_file("funcgraph-irqs", "0") < 0) in set_tracing_funcgraph_irqs()
485 return -1; in set_tracing_funcgraph_irqs()
492 if (!ftrace->graph_verbose) in set_tracing_funcgraph_verbose()
495 if (write_tracing_option_file("funcgraph-proc", "1") < 0) in set_tracing_funcgraph_verbose()
496 return -1; in set_tracing_funcgraph_verbose()
498 if (write_tracing_option_file("funcgraph-abstime", "1") < 0) in set_tracing_funcgraph_verbose()
499 return -1; in set_tracing_funcgraph_verbose()
501 if (write_tracing_option_file("latency-format", "1") < 0) in set_tracing_funcgraph_verbose()
502 return -1; in set_tracing_funcgraph_verbose()
509 if (!ftrace->graph_tail) in set_tracing_funcgraph_tail()
512 if (write_tracing_option_file("funcgraph-tail", "1") < 0) in set_tracing_funcgraph_tail()
513 return -1; in set_tracing_funcgraph_tail()
522 if (ftrace->graph_thresh == 0) in set_tracing_thresh()
525 ret = write_tracing_file_int("tracing_thresh", ftrace->graph_thresh); in set_tracing_thresh()
536 return -1; in set_tracing_options()
541 return -1; in set_tracing_options()
546 return -1; in set_tracing_options()
550 pr_err("failed to set tracing option irq-info\n"); in set_tracing_options()
551 return -1; in set_tracing_options()
556 return -1; in set_tracing_options()
561 return -1; in set_tracing_options()
565 pr_err("failed to set tracing per-cpu buffer size\n"); in set_tracing_options()
566 return -1; in set_tracing_options()
570 pr_err("failed to set tracing option function-fork\n"); in set_tracing_options()
571 return -1; in set_tracing_options()
575 pr_err("failed to set tracing option sleep-time\n"); in set_tracing_options()
576 return -1; in set_tracing_options()
580 pr_err("failed to set tracing option funcgraph-irqs\n"); in set_tracing_options()
581 return -1; in set_tracing_options()
585 pr_err("failed to set tracing option funcgraph-proc/funcgraph-abstime\n"); in set_tracing_options()
586 return -1; in set_tracing_options()
591 return -1; in set_tracing_options()
595 pr_err("failed to set tracing option funcgraph-tail\n"); in set_tracing_options()
596 return -1; in set_tracing_options()
604 bool graph = !list_empty(&ftrace->graph_funcs) || in select_tracer()
605 !list_empty(&ftrace->nograph_funcs); in select_tracer()
606 bool func = !list_empty(&ftrace->filters) || in select_tracer()
607 !list_empty(&ftrace->notrace); in select_tracer()
611 ftrace->tracer = "function_graph"; in select_tracer()
613 ftrace->tracer = "function"; in select_tracer()
616 pr_debug("%s tracer is used\n", ftrace->tracer); in select_tracer()
631 pr_err("failed to reset ftrace\n"); in __cmd_ftrace()
635 /* reset ftrace buffer */ in __cmd_ftrace()
642 if (write_tracing_file("current_tracer", ftrace->tracer) < 0) { in __cmd_ftrace()
643 pr_err("failed to set current_tracer to %s\n", ftrace->tracer); in __cmd_ftrace()
670 if (!ftrace->target.initial_delay) { in __cmd_ftrace()
677 evlist__start_workload(ftrace->evlist); in __cmd_ftrace()
679 if (ftrace->target.initial_delay > 0) { in __cmd_ftrace()
680 usleep(ftrace->target.initial_delay * 1000); in __cmd_ftrace()
688 if (poll(&pollfd, 1, -1) < 0) in __cmd_ftrace()
726 return (done && !workload_exec_errno) ? 0 : -1; in __cmd_ftrace()
747 * parse trace output to get function duration like in in make_histogram()
751 * # CPU DURATION FUNCTION CALLS in make_histogram()
769 /* no duration */ in make_histogram()
784 i = NUM_BUCKET - 1; in make_histogram()
813 printf("# %14s | %10s | %-*s |\n", in display_histogram()
814 " DURATION ", "COUNT", bar_total, "GRAPH"); in display_histogram()
817 printf(" %4d - %-4d %s | %10d | %.*s%*s |\n", in display_histogram()
818 0, 1, "us", buckets[0], bar_len, bar, bar_total - bar_len, ""); in display_histogram()
820 for (i = 1; i < NUM_BUCKET - 1; i++) { in display_histogram()
821 int start = (1 << (i - 1)); in display_histogram()
828 unit = use_nsec ? "us" : "ms"; in display_histogram()
831 printf(" %4d - %-4d %s | %10d | %.*s%*s |\n", in display_histogram()
833 bar_total - bar_len, ""); in display_histogram()
836 bar_len = buckets[NUM_BUCKET - 1] * bar_total / total; in display_histogram()
837 printf(" %4d - %-4s %s | %10d | %.*s%*s |\n", in display_histogram()
838 1, "...", use_nsec ? "ms" : " s", buckets[NUM_BUCKET - 1], in display_histogram()
839 bar_len, bar, bar_total - bar_len, ""); in display_histogram()
848 if (ftrace->target.use_bpf) in prepare_func_latency()
852 pr_err("failed to reset ftrace\n"); in prepare_func_latency()
853 return -1; in prepare_func_latency()
856 /* reset ftrace buffer */ in prepare_func_latency()
858 return -1; in prepare_func_latency()
861 return -1; in prepare_func_latency()
863 /* force to use the function_graph tracer to track duration */ in prepare_func_latency()
866 return -1; in prepare_func_latency()
872 return -1; in prepare_func_latency()
885 if (ftrace->target.use_bpf) in start_func_latency()
890 return -1; in start_func_latency()
898 if (ftrace->target.use_bpf) in stop_func_latency()
907 if (ftrace->target.use_bpf) in read_func_latency()
915 if (ftrace->target.use_bpf) in cleanup_func_latency()
942 evlist__start_workload(ftrace->evlist); in __cmd_latency()
946 if (poll(&pollfd, 1, -1) < 0) in __cmd_latency()
950 int n = read(trace_fd, buf, sizeof(buf) - 1); in __cmd_latency()
954 make_histogram(buckets, buf, n, line, ftrace->use_nsec); in __cmd_latency()
967 while (!ftrace->target.use_bpf) { in __cmd_latency()
968 int n = read(trace_fd, buf, sizeof(buf) - 1); in __cmd_latency()
971 make_histogram(buckets, buf, n, line, ftrace->use_nsec); in __cmd_latency()
976 display_histogram(buckets, ftrace->use_nsec); in __cmd_latency()
982 return (done && !workload_exec_errno) ? 0 : -1; in __cmd_latency()
997 ftrace->tracer = "function_graph"; in prepare_func_profile()
998 ftrace->graph_tail = 1; in prepare_func_profile()
1000 ftrace->profile_hash = hashmap__new(profile_hash, profile_equal, NULL); in prepare_func_profile()
1001 if (ftrace->profile_hash == NULL) in prepare_func_profile()
1002 return -ENOMEM; in prepare_func_profile()
1016 if (!hashmap__find(ftrace->profile_hash, func, &prof)) { in add_func_duration()
1020 return -ENOMEM; in add_func_duration()
1025 return -ENOMEM; in add_func_duration()
1028 init_stats(&prof->st); in add_func_duration()
1029 hashmap__add(ftrace->profile_hash, key, prof); in add_func_duration()
1032 update_stats(&prof->st, time_ns); in add_func_duration()
1039 * CPU DURATION FUNCTION
1051 * Parse the line and get the duration and function name.
1057 double duration; in parse_func_duration() local
1064 /* get duration */ in parse_func_duration()
1067 /* no duration? */ in parse_func_duration()
1071 /* skip markers like '*' or '!' for longer than ms */ in parse_func_duration()
1075 duration = strtod(p, &p); in parse_func_duration()
1078 pr_debug("non-usec time found.. ignoring\n"); in parse_func_duration()
1086 duration *= 1000; in parse_func_duration()
1093 return -EINVAL; in parse_func_duration()
1102 /* remove semi-colon or end of comment at the end */ in parse_func_duration()
1103 p = line + len - 1; in parse_func_duration()
1106 --p; in parse_func_duration()
1109 return add_func_duration(ftrace, func, duration); in parse_func_duration()
1126 struct ftrace_profile_data *p1 = e1->pvalue; in cmp_profile_data()
1127 struct ftrace_profile_data *p2 = e2->pvalue; in cmp_profile_data()
1132 return strcmp(e1->pkey, e2->pkey); in cmp_profile_data()
1134 v1 = p1->st.mean; in cmp_profile_data()
1135 v2 = p2->st.mean; in cmp_profile_data()
1138 v1 = p1->st.max; in cmp_profile_data()
1139 v2 = p2->st.max; in cmp_profile_data()
1142 v1 = p1->st.n; in cmp_profile_data()
1143 v2 = p2->st.n; in cmp_profile_data()
1147 v1 = p1->st.n * p1->st.mean; in cmp_profile_data()
1148 v2 = p2->st.n * p2->st.mean; in cmp_profile_data()
1153 return -1; in cmp_profile_data()
1163 nr = hashmap__size(ftrace->profile_hash); in print_profile_result()
1174 hashmap__for_each_entry(ftrace->profile_hash, entry, bkt) in print_profile_result()
1186 const char *name = profile[i]->pkey; in print_profile_result()
1187 struct ftrace_profile_data *p = profile[i]->pvalue; in print_profile_result()
1190 p->st.n * p->st.mean / 1000, p->st.mean / 1000, in print_profile_result()
1191 p->st.max / 1000, p->st.max % 1000, p->st.n, name); in print_profile_result()
1196 hashmap__for_each_entry(ftrace->profile_hash, entry, bkt) { in print_profile_result()
1197 free((char *)entry->pkey); in print_profile_result()
1198 free(entry->pvalue); in print_profile_result()
1201 hashmap__free(ftrace->profile_hash); in print_profile_result()
1202 ftrace->profile_hash = NULL; in print_profile_result()
1220 pr_err("failed to reset ftrace\n"); in __cmd_profile()
1224 /* reset ftrace buffer */ in __cmd_profile()
1229 return -1; in __cmd_profile()
1231 if (write_tracing_file("current_tracer", ftrace->tracer) < 0) { in __cmd_profile()
1232 pr_err("failed to set current_tracer to %s\n", ftrace->tracer); in __cmd_profile()
1260 evlist__start_workload(ftrace->evlist); in __cmd_profile()
1263 io.timeout_ms = -1; in __cmd_profile()
1302 return (done && !workload_exec_errno) ? 0 : -1; in __cmd_profile()
1313 return -1; in perf_ftrace_config()
1317 ftrace->tracer = value; in perf_ftrace_config()
1322 return -1; in perf_ftrace_config()
1341 return -1; in opt_list_avail_functions()
1345 return err ? -EINVAL : -ENOMEM; in opt_list_avail_functions()
1348 if (ret == -EINVAL) { in opt_list_avail_functions()
1349 pr_err("Filter parse error at %td.\n", err - str + 1); in opt_list_avail_functions()
1351 pr_err(" %*c\n", (int)(err - str + 1), '^'); in opt_list_avail_functions()
1368 struct list_head *head = opt->value; in parse_filter_func()
1373 return -ENOMEM; in parse_filter_func()
1375 strcpy(entry->name, str); in parse_filter_func()
1376 list_add_tail(&entry->list, head); in parse_filter_func()
1386 list_del_init(&pos->list); in delete_filter_func()
1394 unsigned long *s = (unsigned long *)opt->value; in parse_buffer_size()
1410 if (val != (unsigned long) -1) { in parse_buffer_size()
1413 return -1; in parse_buffer_size()
1419 return -1; in parse_buffer_size()
1426 struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value; in parse_func_tracer_opts()
1428 { .name = "call-graph", .value_ptr = &ftrace->func_stack_trace }, in parse_func_tracer_opts()
1429 { .name = "irq-info", .value_ptr = &ftrace->func_irq_info }, in parse_func_tracer_opts()
1447 struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value; in parse_graph_tracer_opts()
1449 { .name = "nosleep-time", .value_ptr = &ftrace->graph_nosleep_time }, in parse_graph_tracer_opts()
1450 { .name = "noirqs", .value_ptr = &ftrace->graph_noirqs }, in parse_graph_tracer_opts()
1451 { .name = "verbose", .value_ptr = &ftrace->graph_verbose }, in parse_graph_tracer_opts()
1452 { .name = "thresh", .value_ptr = &ftrace->graph_thresh }, in parse_graph_tracer_opts()
1453 { .name = "depth", .value_ptr = &ftrace->graph_depth }, in parse_graph_tracer_opts()
1454 { .name = "tail", .value_ptr = &ftrace->graph_tail }, in parse_graph_tracer_opts()
1470 enum perf_ftrace_profile_sort_key *key = (void *)opt->value; in parse_sort_key()
1487 return -1; in parse_sort_key()
1510 /* TODO: Add short option -t after -t/--tracer can be removed. */ in cmd_ftrace()
1512 "Trace on existing thread id (exclusive to --pid)"), in cmd_ftrace()
1515 OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide, in cmd_ftrace()
1516 "System-wide collection from all CPUs"), in cmd_ftrace()
1527 OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func", in cmd_ftrace()
1530 OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func", in cmd_ftrace()
1532 OPT_CALLBACK(0, "func-opts", &ftrace, "options", in cmd_ftrace()
1533 "Function tracer options, available options: call-graph,irq-info", in cmd_ftrace()
1535 OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func", in cmd_ftrace()
1538 OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func", in cmd_ftrace()
1540 OPT_CALLBACK(0, "graph-opts", &ftrace, "options", in cmd_ftrace()
1541 "Graph tracer options, available options: nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>", in cmd_ftrace()
1543 OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size", in cmd_ftrace()
1552 OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func", in cmd_ftrace()
1555 OPT_BOOLEAN('b', "use-bpf", &ftrace.target.use_bpf, in cmd_ftrace()
1558 OPT_BOOLEAN('n', "use-nsec", &ftrace.use_nsec, in cmd_ftrace()
1559 "Use nano-second histogram"), in cmd_ftrace()
1563 OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func", in cmd_ftrace()
1566 OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func", in cmd_ftrace()
1568 OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func", in cmd_ftrace()
1571 OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func", in cmd_ftrace()
1573 OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size", in cmd_ftrace()
1584 "perf ftrace [<options>] -- [<command>] [<options>]", in cmd_ftrace()
1586 "perf ftrace {trace|latency|profile} [<options>] -- [<command>] [<options>]", in cmd_ftrace()
1602 return -1; in cmd_ftrace()
1606 return -ENOTSUP; in cmd_ftrace()
1611 return -1; in cmd_ftrace()
1625 argc--; in cmd_ftrace()
1636 ret = -EINVAL; in cmd_ftrace()
1640 /* Make system wide (-a) the default target. */ in cmd_ftrace()
1652 ret = -EINVAL; in cmd_ftrace()
1663 ret = -EINVAL; in cmd_ftrace()
1678 ret = -ENOMEM; in cmd_ftrace()