[PATCH 09/19] perf ftrace: add support for trace option tracing_thresh

From: Changbin Du
Date: Sun May 10 2020 - 11:08:39 EST


This adds an option '--tracing-thresh' to setup trace duration threshold
for funcgraph tracer.

Signed-off-by: Changbin Du <changbin.du@xxxxxxxxx>
---
tools/perf/builtin-ftrace.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index f11f2d3431b0..20bc14d6c5fb 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -43,6 +43,7 @@ struct perf_ftrace {
bool nosleep_time;
bool nofuncgraph_irqs;
bool long_info;
+ unsigned tracing_thresh;
};

struct filter_entry {
@@ -213,6 +214,9 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
if (write_tracing_file("max_graph_depth", "0") < 0)
return -1;

+ if (write_tracing_file("tracing_thresh", "0") < 0)
+ return -1;
+
reset_tracing_filters();
reset_tracing_options(ftrace);
return 0;
@@ -392,6 +396,21 @@ static int set_tracing_long_info(struct perf_ftrace *ftrace)
return 0;
}

+static int set_tracing_thresh(struct perf_ftrace *ftrace)
+{
+ char buf[16];
+
+ if (ftrace->tracing_thresh == 0)
+ return 0;
+
+ snprintf(buf, sizeof(buf), "%d", ftrace->tracing_thresh);
+
+ if (write_tracing_file("tracing_thresh", buf) < 0)
+ return -1;
+
+ return 0;
+}
+
static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
{
char *trace_file;
@@ -475,6 +494,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
goto out_reset;
}

+ if (set_tracing_thresh(ftrace) < 0) {
+ pr_err("failed to set tracing thresh\n");
+ goto out_reset;
+ }
+
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
goto out_reset;
@@ -616,6 +640,8 @@ int cmd_ftrace(int argc, const char **argv)
"Ignore functions that happen inside interrupt (function_graph only)"),
OPT_BOOLEAN('l', "long-info", &ftrace.long_info,
"Show process names, PIDs, timestamps, irq-info if available"),
+ OPT_UINTEGER(0, "tracing-thresh", &ftrace.tracing_thresh,
+ "Only show functions of which the duration is greater than <n>Âs"),
OPT_END()
};

--
2.25.1