Skip to content

Commit 38988f2

Browse files
changbinduacmel
authored andcommitted
perf ftrace: Add support for trace option sleep-time
This adds an option '--graph-opts nosleep-time' which allow us only to measure on-CPU time. This option is function_graph tracer only. 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 b1d84af commit 38988f2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tools/perf/Documentation/perf-ftrace.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ OPTIONS
101101
--graph-depth=::
102102
Set max depth for function graph tracer to follow
103103

104+
--graph-opts::
105+
List of options allowed to set:
106+
nosleep-time - Measure on-CPU time only for function_graph tracer.
107+
104108
SEE ALSO
105109
--------
106110
linkperf:perf-record[1], linkperf:perf-trace[1]

tools/perf/builtin-ftrace.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct perf_ftrace {
4444
unsigned long percpu_buffer_size;
4545
bool inherit;
4646
int func_stack_trace;
47+
int graph_nosleep_time;
4748
};
4849

4950
struct filter_entry {
@@ -205,6 +206,7 @@ static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused)
205206
{
206207
write_tracing_option_file("function-fork", "0");
207208
write_tracing_option_file("func_stack_trace", "0");
209+
write_tracing_option_file("sleep-time", "1");
208210
}
209211

210212
static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
@@ -386,6 +388,17 @@ static int set_tracing_trace_inherit(struct perf_ftrace *ftrace)
386388
return 0;
387389
}
388390

391+
static int set_tracing_sleep_time(struct perf_ftrace *ftrace)
392+
{
393+
if (!ftrace->graph_nosleep_time)
394+
return 0;
395+
396+
if (write_tracing_option_file("sleep-time", "0") < 0)
397+
return -1;
398+
399+
return 0;
400+
}
401+
389402
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
390403
{
391404
char *trace_file;
@@ -465,6 +478,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
465478
goto out_reset;
466479
}
467480

481+
if (set_tracing_sleep_time(ftrace) < 0) {
482+
pr_err("failed to set tracing option sleep-time\n");
483+
goto out_reset;
484+
}
485+
468486
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
469487
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
470488
goto out_reset;
@@ -637,6 +655,26 @@ static int parse_func_tracer_opts(const struct option *opt,
637655
return 0;
638656
}
639657

658+
static int parse_graph_tracer_opts(const struct option *opt,
659+
const char *str, int unset)
660+
{
661+
int ret;
662+
struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value;
663+
struct sublevel_option graph_tracer_opts[] = {
664+
{ .name = "nosleep-time", .value_ptr = &ftrace->graph_nosleep_time },
665+
{ .name = NULL, }
666+
};
667+
668+
if (unset)
669+
return 0;
670+
671+
ret = perf_parse_sublevel_options(str, graph_tracer_opts);
672+
if (ret)
673+
return ret;
674+
675+
return 0;
676+
}
677+
640678
static void select_tracer(struct perf_ftrace *ftrace)
641679
{
642680
bool graph = !list_empty(&ftrace->graph_funcs) ||
@@ -694,6 +732,9 @@ int cmd_ftrace(int argc, const char **argv)
694732
"Set nograph filter on given functions", parse_filter_func),
695733
OPT_INTEGER('D', "graph-depth", &ftrace.graph_depth,
696734
"Max depth for function graph tracer"),
735+
OPT_CALLBACK(0, "graph-opts", &ftrace, "options",
736+
"graph tracer options, available options: nosleep-time",
737+
parse_graph_tracer_opts),
697738
OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size",
698739
"size of per cpu buffer", parse_buffer_size),
699740
OPT_BOOLEAN(0, "inherit", &ftrace.inherit,

0 commit comments

Comments
 (0)