Skip to content

Commit

Permalink
perf ftrace: Move out common code from __cmd_ftrace
Browse files Browse the repository at this point in the history
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 <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Changbin Du <changbin.du@gmail.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20211215185154.360314-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Dec 16, 2021
1 parent 416e15a commit a9b8ae8
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions tools/perf/builtin-ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,24 @@ static int set_tracing_options(struct perf_ftrace *ftrace)
return 0;
}

static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
static void select_tracer(struct perf_ftrace *ftrace)
{
bool graph = !list_empty(&ftrace->graph_funcs) ||
!list_empty(&ftrace->nograph_funcs);
bool func = !list_empty(&ftrace->filters) ||
!list_empty(&ftrace->notrace);

/* The function_graph has priority over function tracer. */
if (graph)
ftrace->tracer = "function_graph";
else if (func)
ftrace->tracer = "function";
/* Otherwise, the default tracer is used. */

pr_debug("%s tracer is used\n", ftrace->tracer);
}

static int __cmd_ftrace(struct perf_ftrace *ftrace)
{
char *trace_file;
int trace_fd;
Expand All @@ -586,10 +603,7 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
return -1;
}

signal(SIGINT, sig_handler);
signal(SIGUSR1, sig_handler);
signal(SIGCHLD, sig_handler);
signal(SIGPIPE, sig_handler);
select_tracer(ftrace);

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

if (argc && evlist__prepare_workload(ftrace->evlist, &ftrace->target, argv, false,
ftrace__workload_exec_failed_signal) < 0) {
goto out;
}

if (set_tracing_options(ftrace) < 0)
goto out_reset;

Expand Down Expand Up @@ -855,23 +864,6 @@ static int parse_graph_tracer_opts(const struct option *opt,
return 0;
}

static void select_tracer(struct perf_ftrace *ftrace)
{
bool graph = !list_empty(&ftrace->graph_funcs) ||
!list_empty(&ftrace->nograph_funcs);
bool func = !list_empty(&ftrace->filters) ||
!list_empty(&ftrace->notrace);

/* The function_graph has priority over function tracer. */
if (graph)
ftrace->tracer = "function_graph";
else if (func)
ftrace->tracer = "function";
/* Otherwise, the default tracer is used. */

pr_debug("%s tracer is used\n", ftrace->tracer);
}

int cmd_ftrace(int argc, const char **argv)
{
int ret;
Expand Down Expand Up @@ -937,6 +929,11 @@ int cmd_ftrace(int argc, const char **argv)
INIT_LIST_HEAD(&ftrace.graph_funcs);
INIT_LIST_HEAD(&ftrace.nograph_funcs);

signal(SIGINT, sig_handler);
signal(SIGUSR1, sig_handler);
signal(SIGCHLD, sig_handler);
signal(SIGPIPE, sig_handler);

ret = perf_config(perf_ftrace_config, &ftrace);
if (ret < 0)
return -1;
Expand All @@ -951,8 +948,6 @@ int cmd_ftrace(int argc, const char **argv)
if (!argc && target__none(&ftrace.target))
ftrace.target.system_wide = true;

select_tracer(&ftrace);

ret = target__validate(&ftrace.target);
if (ret) {
char errbuf[512];
Expand All @@ -972,7 +967,15 @@ int cmd_ftrace(int argc, const char **argv)
if (ret < 0)
goto out_delete_evlist;

ret = __cmd_ftrace(&ftrace, argc, argv);
if (argc) {
ret = evlist__prepare_workload(ftrace.evlist, &ftrace.target,
argv, false,
ftrace__workload_exec_failed_signal);
if (ret < 0)
goto out_delete_evlist;
}

ret = __cmd_ftrace(&ftrace);

out_delete_evlist:
evlist__delete(ftrace.evlist);
Expand Down

0 comments on commit a9b8ae8

Please sign in to comment.