Skip to content

Commit a9b8ae8

Browse files
namhyungacmel
authored andcommitted
perf ftrace: Move out common code from __cmd_ftrace
The signal setup code and evlist__prepare_workload() can be used for other subcommands. Let's move them out of the __cmd_ftrace(). Then it doesn't need to pass argc and argv. On the other hand, select_tracer() is specific to the 'trace' subcommand so it'd better moving it into the __cmd_ftrace(). Signed-off-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Athira Jajeev <[email protected]> Cc: Changbin Du <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Stephane Eranian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 416e15a commit a9b8ae8

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

tools/perf/builtin-ftrace.c

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,24 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
565565
return 0;
566566
}
567567

568-
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
568+
static void select_tracer(struct perf_ftrace *ftrace)
569+
{
570+
bool graph = !list_empty(&ftrace->graph_funcs) ||
571+
!list_empty(&ftrace->nograph_funcs);
572+
bool func = !list_empty(&ftrace->filters) ||
573+
!list_empty(&ftrace->notrace);
574+
575+
/* The function_graph has priority over function tracer. */
576+
if (graph)
577+
ftrace->tracer = "function_graph";
578+
else if (func)
579+
ftrace->tracer = "function";
580+
/* Otherwise, the default tracer is used. */
581+
582+
pr_debug("%s tracer is used\n", ftrace->tracer);
583+
}
584+
585+
static int __cmd_ftrace(struct perf_ftrace *ftrace)
569586
{
570587
char *trace_file;
571588
int trace_fd;
@@ -586,10 +603,7 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
586603
return -1;
587604
}
588605

589-
signal(SIGINT, sig_handler);
590-
signal(SIGUSR1, sig_handler);
591-
signal(SIGCHLD, sig_handler);
592-
signal(SIGPIPE, sig_handler);
606+
select_tracer(ftrace);
593607

594608
if (reset_tracing_files(ftrace) < 0) {
595609
pr_err("failed to reset ftrace\n");
@@ -600,11 +614,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
600614
if (write_tracing_file("trace", "0") < 0)
601615
goto out;
602616

603-
if (argc && evlist__prepare_workload(ftrace->evlist, &ftrace->target, argv, false,
604-
ftrace__workload_exec_failed_signal) < 0) {
605-
goto out;
606-
}
607-
608617
if (set_tracing_options(ftrace) < 0)
609618
goto out_reset;
610619

@@ -855,23 +864,6 @@ static int parse_graph_tracer_opts(const struct option *opt,
855864
return 0;
856865
}
857866

858-
static void select_tracer(struct perf_ftrace *ftrace)
859-
{
860-
bool graph = !list_empty(&ftrace->graph_funcs) ||
861-
!list_empty(&ftrace->nograph_funcs);
862-
bool func = !list_empty(&ftrace->filters) ||
863-
!list_empty(&ftrace->notrace);
864-
865-
/* The function_graph has priority over function tracer. */
866-
if (graph)
867-
ftrace->tracer = "function_graph";
868-
else if (func)
869-
ftrace->tracer = "function";
870-
/* Otherwise, the default tracer is used. */
871-
872-
pr_debug("%s tracer is used\n", ftrace->tracer);
873-
}
874-
875867
int cmd_ftrace(int argc, const char **argv)
876868
{
877869
int ret;
@@ -937,6 +929,11 @@ int cmd_ftrace(int argc, const char **argv)
937929
INIT_LIST_HEAD(&ftrace.graph_funcs);
938930
INIT_LIST_HEAD(&ftrace.nograph_funcs);
939931

932+
signal(SIGINT, sig_handler);
933+
signal(SIGUSR1, sig_handler);
934+
signal(SIGCHLD, sig_handler);
935+
signal(SIGPIPE, sig_handler);
936+
940937
ret = perf_config(perf_ftrace_config, &ftrace);
941938
if (ret < 0)
942939
return -1;
@@ -951,8 +948,6 @@ int cmd_ftrace(int argc, const char **argv)
951948
if (!argc && target__none(&ftrace.target))
952949
ftrace.target.system_wide = true;
953950

954-
select_tracer(&ftrace);
955-
956951
ret = target__validate(&ftrace.target);
957952
if (ret) {
958953
char errbuf[512];
@@ -972,7 +967,15 @@ int cmd_ftrace(int argc, const char **argv)
972967
if (ret < 0)
973968
goto out_delete_evlist;
974969

975-
ret = __cmd_ftrace(&ftrace, argc, argv);
970+
if (argc) {
971+
ret = evlist__prepare_workload(ftrace.evlist, &ftrace.target,
972+
argv, false,
973+
ftrace__workload_exec_failed_signal);
974+
if (ret < 0)
975+
goto out_delete_evlist;
976+
}
977+
978+
ret = __cmd_ftrace(&ftrace);
976979

977980
out_delete_evlist:
978981
evlist__delete(ftrace.evlist);

0 commit comments

Comments
 (0)