Lines Matching defs:ftrace

3  * builtin-ftrace.c
33 #include "util/ftrace.h"
223 static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
235 static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
256 reset_tracing_options(ftrace);
260 static int set_tracing_pid(struct perf_ftrace *ftrace)
265 if (target__has_cpu(&ftrace->target))
268 for (i = 0; i < perf_thread_map__nr(ftrace->evlist->core.threads); i++) {
270 perf_thread_map__pid(ftrace->evlist->core.threads, i));
302 static int set_tracing_cpu(struct perf_ftrace *ftrace)
304 struct perf_cpu_map *cpumap = ftrace->evlist->core.user_requested_cpus;
306 if (!target__has_cpu(&ftrace->target))
312 static int set_tracing_func_stack_trace(struct perf_ftrace *ftrace)
314 if (!ftrace->func_stack_trace)
323 static int set_tracing_func_irqinfo(struct perf_ftrace *ftrace)
325 if (!ftrace->func_irq_info)
356 static int set_tracing_filters(struct perf_ftrace *ftrace)
360 ret = __set_tracing_filter("set_ftrace_filter", &ftrace->filters);
364 ret = __set_tracing_filter("set_ftrace_notrace", &ftrace->notrace);
368 ret = __set_tracing_filter("set_graph_function", &ftrace->graph_funcs);
373 __set_tracing_filter("set_graph_notrace", &ftrace->nograph_funcs);
386 static int set_tracing_depth(struct perf_ftrace *ftrace)
388 if (ftrace->graph_depth == 0)
391 if (ftrace->graph_depth < 0) {
392 pr_err("invalid graph depth: %d\n", ftrace->graph_depth);
396 if (write_tracing_file_int("max_graph_depth", ftrace->graph_depth) < 0)
402 static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace)
406 if (ftrace->percpu_buffer_size == 0)
410 ftrace->percpu_buffer_size / 1024);
417 static int set_tracing_trace_inherit(struct perf_ftrace *ftrace)
419 if (!ftrace->inherit)
428 static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
430 if (!ftrace->graph_nosleep_time)
439 static int set_tracing_funcgraph_irqs(struct perf_ftrace *ftrace)
441 if (!ftrace->graph_noirqs)
450 static int set_tracing_funcgraph_verbose(struct perf_ftrace *ftrace)
452 if (!ftrace->graph_verbose)
467 static int set_tracing_thresh(struct perf_ftrace *ftrace)
471 if (ftrace->graph_thresh == 0)
474 ret = write_tracing_file_int("tracing_thresh", ftrace->graph_thresh);
481 static int set_tracing_options(struct perf_ftrace *ftrace)
483 if (set_tracing_pid(ftrace) < 0) {
484 pr_err("failed to set ftrace pid\n");
488 if (set_tracing_cpu(ftrace) < 0) {
493 if (set_tracing_func_stack_trace(ftrace) < 0) {
498 if (set_tracing_func_irqinfo(ftrace) < 0) {
503 if (set_tracing_filters(ftrace) < 0) {
508 if (set_tracing_depth(ftrace) < 0) {
513 if (set_tracing_percpu_buffer_size(ftrace) < 0) {
518 if (set_tracing_trace_inherit(ftrace) < 0) {
523 if (set_tracing_sleep_time(ftrace) < 0) {
528 if (set_tracing_funcgraph_irqs(ftrace) < 0) {
533 if (set_tracing_funcgraph_verbose(ftrace) < 0) {
538 if (set_tracing_thresh(ftrace) < 0) {
546 static void select_tracer(struct perf_ftrace *ftrace)
548 bool graph = !list_empty(&ftrace->graph_funcs) ||
549 !list_empty(&ftrace->nograph_funcs);
550 bool func = !list_empty(&ftrace->filters) ||
551 !list_empty(&ftrace->notrace);
555 ftrace->tracer = "function_graph";
557 ftrace->tracer = "function";
560 pr_debug("%s tracer is used\n", ftrace->tracer);
563 static int __cmd_ftrace(struct perf_ftrace *ftrace)
574 pr_err("ftrace only works for %s!\n",
584 select_tracer(ftrace);
586 if (reset_tracing_files(ftrace) < 0) {
587 pr_err("failed to reset ftrace\n");
591 /* reset ftrace buffer */
595 if (set_tracing_options(ftrace) < 0)
598 if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
599 pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
626 if (!ftrace->target.initial_delay) {
633 evlist__start_workload(ftrace->evlist);
635 if (ftrace->target.initial_delay > 0) {
636 usleep(ftrace->target.initial_delay * 1000);
680 reset_tracing_files(ftrace);
799 static int prepare_func_latency(struct perf_ftrace *ftrace)
804 if (ftrace->target.use_bpf)
805 return perf_ftrace__latency_prepare_bpf(ftrace);
807 if (reset_tracing_files(ftrace) < 0) {
808 pr_err("failed to reset ftrace\n");
812 /* reset ftrace buffer */
816 if (set_tracing_options(ftrace) < 0)
839 static int start_func_latency(struct perf_ftrace *ftrace)
841 if (ftrace->target.use_bpf)
842 return perf_ftrace__latency_start_bpf(ftrace);
852 static int stop_func_latency(struct perf_ftrace *ftrace)
854 if (ftrace->target.use_bpf)
855 return perf_ftrace__latency_stop_bpf(ftrace);
861 static int read_func_latency(struct perf_ftrace *ftrace, int buckets[])
863 if (ftrace->target.use_bpf)
864 return perf_ftrace__latency_read_bpf(ftrace, buckets);
869 static int cleanup_func_latency(struct perf_ftrace *ftrace)
871 if (ftrace->target.use_bpf)
872 return perf_ftrace__latency_cleanup_bpf(ftrace);
874 reset_tracing_files(ftrace);
878 static int __cmd_latency(struct perf_ftrace *ftrace)
890 pr_err("ftrace only works for %s!\n",
900 trace_fd = prepare_func_latency(ftrace);
907 if (start_func_latency(ftrace) < 0)
910 evlist__start_workload(ftrace->evlist);
922 make_histogram(buckets, buf, n, line, ftrace->use_nsec);
926 stop_func_latency(ftrace);
935 while (!ftrace->target.use_bpf) {
939 make_histogram(buckets, buf, n, line, ftrace->use_nsec);
942 read_func_latency(ftrace, buckets);
944 display_histogram(buckets, ftrace->use_nsec);
948 cleanup_func_latency(ftrace);
955 struct perf_ftrace *ftrace = cb;
957 if (!strstarts(var, "ftrace."))
960 if (strcmp(var, "ftrace.tracer"))
965 ftrace->tracer = value;
1074 struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value;
1076 { .name = "call-graph", .value_ptr = &ftrace->func_stack_trace },
1077 { .name = "irq-info", .value_ptr = &ftrace->func_irq_info },
1095 struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value;
1097 { .name = "nosleep-time", .value_ptr = &ftrace->graph_nosleep_time },
1098 { .name = "noirqs", .value_ptr = &ftrace->graph_noirqs },
1099 { .name = "verbose", .value_ptr = &ftrace->graph_verbose },
1100 { .name = "thresh", .value_ptr = &ftrace->graph_thresh },
1101 { .name = "depth", .value_ptr = &ftrace->graph_depth },
1125 struct perf_ftrace ftrace = {
1130 OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
1133 OPT_STRING(0, "tid", &ftrace.target.tid, "tid",
1137 OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide,
1139 OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
1144 OPT_STRING('t', "tracer", &ftrace.tracer, "tracer",
1149 OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func",
1152 OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func",
1154 OPT_CALLBACK(0, "func-opts", &ftrace, "options",
1157 OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func",
1160 OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
1162 OPT_CALLBACK(0, "graph-opts", &ftrace, "options",
1165 OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size",
1167 OPT_BOOLEAN(0, "inherit", &ftrace.inherit,
1169 OPT_INTEGER('D', "delay", &ftrace.target.initial_delay,
1174 OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func",
1177 OPT_BOOLEAN('b', "use-bpf", &ftrace.target.use_bpf,
1180 OPT_BOOLEAN('n', "use-nsec", &ftrace.use_nsec,
1187 "perf ftrace [<options>] [<command>]",
1188 "perf ftrace [<options>] -- [<command>] [<options>]",
1189 "perf ftrace {trace|latency} [<options>] [<command>]",
1190 "perf ftrace {trace|latency} [<options>] -- [<command>] [<options>]",
1195 INIT_LIST_HEAD(&ftrace.filters);
1196 INIT_LIST_HEAD(&ftrace.notrace);
1197 INIT_LIST_HEAD(&ftrace.graph_funcs);
1198 INIT_LIST_HEAD(&ftrace.nograph_funcs);
1205 ret = perf_config(perf_ftrace_config, &ftrace);
1234 if (!argc && target__none(&ftrace.target))
1235 ftrace.target.system_wide = true;
1242 if (list_empty(&ftrace.filters)) {
1257 ret = target__validate(&ftrace.target);
1261 target__strerror(&ftrace.target, ret, errbuf, 512);
1266 ftrace.evlist = evlist__new();
1267 if (ftrace.evlist == NULL) {
1272 ret = evlist__create_maps(ftrace.evlist, &ftrace.target);
1277 ret = evlist__prepare_workload(ftrace.evlist, &ftrace.target,
1284 ret = cmd_func(&ftrace);
1287 evlist__delete(ftrace.evlist);
1290 delete_filter_func(&ftrace.filters);
1291 delete_filter_func(&ftrace.notrace);
1292 delete_filter_func(&ftrace.graph_funcs);
1293 delete_filter_func(&ftrace.nograph_funcs);