Skip to content

Commit 416e15a

Browse files
namhyungacmel
authored andcommitted
perf ftrace: Add 'trace' subcommand
This is a preparation to add more sub-commands for ftrace. The 'trace' subcommand does the same thing when no subcommand is given. Committer testing: The previous mode, i.e. no subcommand and the new 'perf ftrace trace' are equivalent: # perf ftrace -G check_preempt_curr sleep 0.00001 # tracer: function_graph # # CPU DURATION FUNCTION CALLS # | | | | | | | 25) | check_preempt_curr() { 25) | resched_curr() { 25) | native_smp_send_reschedule() { 25) | default_send_IPI_single_phys() { 25) 0.110 us | __default_send_IPI_dest_field(); 25) 0.490 us | } 25) 0.640 us | } 25) 0.850 us | } 25) 2.060 us | } # perf ftrace trace -G check_preempt_curr sleep 0.00001 # tracer: function_graph # # CPU DURATION FUNCTION CALLS # | | | | | | | 10) | check_preempt_curr() { 10) | resched_curr() { 10) | native_smp_send_reschedule() { 10) | default_send_IPI_single_phys() { 10) 0.080 us | __default_send_IPI_dest_field(); 10) 0.460 us | } 10) 0.610 us | } 10) 0.830 us | } 10) 2.020 us | } # 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 8386901 commit 416e15a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

tools/perf/builtin-ftrace.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -879,17 +879,7 @@ int cmd_ftrace(int argc, const char **argv)
879879
.tracer = DEFAULT_TRACER,
880880
.target = { .uid = UINT_MAX, },
881881
};
882-
const char * const ftrace_usage[] = {
883-
"perf ftrace [<options>] [<command>]",
884-
"perf ftrace [<options>] -- <command> [<options>]",
885-
NULL
886-
};
887-
const struct option ftrace_options[] = {
888-
OPT_STRING('t', "tracer", &ftrace.tracer, "tracer",
889-
"Tracer to use: function_graph(default) or function"),
890-
OPT_CALLBACK_DEFAULT('F', "funcs", NULL, "[FILTER]",
891-
"Show available functions to filter",
892-
opt_list_avail_functions, "*"),
882+
const struct option common_options[] = {
893883
OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
894884
"Trace on existing process id"),
895885
/* TODO: Add short option -t after -t/--tracer can be removed. */
@@ -901,6 +891,14 @@ int cmd_ftrace(int argc, const char **argv)
901891
"System-wide collection from all CPUs"),
902892
OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
903893
"List of cpus to monitor"),
894+
OPT_END()
895+
};
896+
const struct option ftrace_options[] = {
897+
OPT_STRING('t', "tracer", &ftrace.tracer, "tracer",
898+
"Tracer to use: function_graph(default) or function"),
899+
OPT_CALLBACK_DEFAULT('F', "funcs", NULL, "[FILTER]",
900+
"Show available functions to filter",
901+
opt_list_avail_functions, "*"),
904902
OPT_CALLBACK('T', "trace-funcs", &ftrace.filters, "func",
905903
"Trace given functions using function tracer",
906904
parse_filter_func),
@@ -923,7 +921,15 @@ int cmd_ftrace(int argc, const char **argv)
923921
"Trace children processes"),
924922
OPT_UINTEGER('D', "delay", &ftrace.initial_delay,
925923
"Number of milliseconds to wait before starting tracing after program start"),
926-
OPT_END()
924+
OPT_PARENT(common_options),
925+
};
926+
927+
const char * const ftrace_usage[] = {
928+
"perf ftrace [<options>] [<command>]",
929+
"perf ftrace [<options>] -- [<command>] [<options>]",
930+
"perf ftrace trace [<options>] [<command>]",
931+
"perf ftrace trace [<options>] -- [<command>] [<options>]",
932+
NULL
927933
};
928934

929935
INIT_LIST_HEAD(&ftrace.filters);
@@ -935,6 +941,11 @@ int cmd_ftrace(int argc, const char **argv)
935941
if (ret < 0)
936942
return -1;
937943

944+
if (argc > 1 && !strcmp(argv[1], "trace")) {
945+
argc--;
946+
argv++;
947+
}
948+
938949
argc = parse_options(argc, argv, ftrace_options, ftrace_usage,
939950
PARSE_OPT_STOP_AT_NON_OPTION);
940951
if (!argc && target__none(&ftrace.target))

0 commit comments

Comments
 (0)