Skip to content

Commit 3c4dc21

Browse files
changbinduacmel
authored andcommitted
perf: ftrace: Add set_tracing_options() to set all trace options
Now the __cmd_ftrace() becomes a bit long. This moves the trace option setting code to a separate function set_tracing_options(). Suggested-by: Namhyung Kim <[email protected]> Signed-off-by: Changbin Du <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt (VMware) <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 42145d7 commit 3c4dc21

File tree

1 file changed

+63
-55
lines changed

1 file changed

+63
-55
lines changed

tools/perf/builtin-ftrace.c

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -465,110 +465,118 @@ static int set_tracing_thresh(struct perf_ftrace *ftrace)
465465
return 0;
466466
}
467467

468-
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
468+
static int set_tracing_options(struct perf_ftrace *ftrace)
469469
{
470-
char *trace_file;
471-
int trace_fd;
472-
char buf[4096];
473-
struct pollfd pollfd = {
474-
.events = POLLIN,
475-
};
476-
477-
if (!(perf_cap__capable(CAP_PERFMON) ||
478-
perf_cap__capable(CAP_SYS_ADMIN))) {
479-
pr_err("ftrace only works for %s!\n",
480-
#ifdef HAVE_LIBCAP_SUPPORT
481-
"users with the CAP_PERFMON or CAP_SYS_ADMIN capability"
482-
#else
483-
"root"
484-
#endif
485-
);
486-
return -1;
487-
}
488-
489-
signal(SIGINT, sig_handler);
490-
signal(SIGUSR1, sig_handler);
491-
signal(SIGCHLD, sig_handler);
492-
signal(SIGPIPE, sig_handler);
493-
494-
if (ftrace->list_avail_functions)
495-
return read_tracing_file_to_stdout("available_filter_functions");
496-
497-
if (reset_tracing_files(ftrace) < 0) {
498-
pr_err("failed to reset ftrace\n");
499-
goto out;
500-
}
501-
502-
/* reset ftrace buffer */
503-
if (write_tracing_file("trace", "0") < 0)
504-
goto out;
505-
506-
if (argc && perf_evlist__prepare_workload(ftrace->evlist,
507-
&ftrace->target, argv, false,
508-
ftrace__workload_exec_failed_signal) < 0) {
509-
goto out;
510-
}
511-
512470
if (set_tracing_pid(ftrace) < 0) {
513471
pr_err("failed to set ftrace pid\n");
514-
goto out_reset;
472+
return -1;
515473
}
516474

517475
if (set_tracing_cpu(ftrace) < 0) {
518476
pr_err("failed to set tracing cpumask\n");
519-
goto out_reset;
477+
return -1;
520478
}
521479

522480
if (set_tracing_func_stack_trace(ftrace) < 0) {
523481
pr_err("failed to set tracing option func_stack_trace\n");
524-
goto out_reset;
482+
return -1;
525483
}
526484

527485
if (set_tracing_func_irqinfo(ftrace) < 0) {
528486
pr_err("failed to set tracing option irq-info\n");
529-
goto out_reset;
487+
return -1;
530488
}
531489

532490
if (set_tracing_filters(ftrace) < 0) {
533491
pr_err("failed to set tracing filters\n");
534-
goto out_reset;
492+
return -1;
535493
}
536494

537495
if (set_tracing_depth(ftrace) < 0) {
538496
pr_err("failed to set graph depth\n");
539-
goto out_reset;
497+
return -1;
540498
}
541499

542500
if (set_tracing_percpu_buffer_size(ftrace) < 0) {
543501
pr_err("failed to set tracing per-cpu buffer size\n");
544-
goto out_reset;
502+
return -1;
545503
}
546504

547505
if (set_tracing_trace_inherit(ftrace) < 0) {
548506
pr_err("failed to set tracing option function-fork\n");
549-
goto out_reset;
507+
return -1;
550508
}
551509

552510
if (set_tracing_sleep_time(ftrace) < 0) {
553511
pr_err("failed to set tracing option sleep-time\n");
554-
goto out_reset;
512+
return -1;
555513
}
556514

557515
if (set_tracing_funcgraph_irqs(ftrace) < 0) {
558516
pr_err("failed to set tracing option funcgraph-irqs\n");
559-
goto out_reset;
517+
return -1;
560518
}
561519

562520
if (set_tracing_funcgraph_verbose(ftrace) < 0) {
563521
pr_err("failed to set tracing option funcgraph-proc/funcgraph-abstime\n");
564-
goto out_reset;
522+
return -1;
565523
}
566524

567525
if (set_tracing_thresh(ftrace) < 0) {
568526
pr_err("failed to set tracing thresh\n");
569-
goto out_reset;
527+
return -1;
528+
}
529+
530+
return 0;
531+
}
532+
533+
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
534+
{
535+
char *trace_file;
536+
int trace_fd;
537+
char buf[4096];
538+
struct pollfd pollfd = {
539+
.events = POLLIN,
540+
};
541+
542+
if (!(perf_cap__capable(CAP_PERFMON) ||
543+
perf_cap__capable(CAP_SYS_ADMIN))) {
544+
pr_err("ftrace only works for %s!\n",
545+
#ifdef HAVE_LIBCAP_SUPPORT
546+
"users with the CAP_PERFMON or CAP_SYS_ADMIN capability"
547+
#else
548+
"root"
549+
#endif
550+
);
551+
return -1;
570552
}
571553

554+
signal(SIGINT, sig_handler);
555+
signal(SIGUSR1, sig_handler);
556+
signal(SIGCHLD, sig_handler);
557+
signal(SIGPIPE, sig_handler);
558+
559+
if (ftrace->list_avail_functions)
560+
return read_tracing_file_to_stdout("available_filter_functions");
561+
562+
if (reset_tracing_files(ftrace) < 0) {
563+
pr_err("failed to reset ftrace\n");
564+
goto out;
565+
}
566+
567+
/* reset ftrace buffer */
568+
if (write_tracing_file("trace", "0") < 0)
569+
goto out;
570+
571+
if (argc && perf_evlist__prepare_workload(ftrace->evlist,
572+
&ftrace->target, argv, false,
573+
ftrace__workload_exec_failed_signal) < 0) {
574+
goto out;
575+
}
576+
577+
if (set_tracing_options(ftrace) < 0)
578+
goto out_reset;
579+
572580
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
573581
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
574582
goto out_reset;

0 commit comments

Comments
 (0)