Re: [PATCH] trace-cmd record: add --max-graph-depth option
From: Steven Rostedt
Date: Thu Jun 16 2016 - 11:14:19 EST
On Wed, 15 Jun 2016 13:18:21 -0700
Omar Sandoval <osandov@xxxxxxxxxxx> wrote:
> From: Omar Sandoval <osandov@xxxxxx>
>
> This is exposed in debugfs but there's no quick way to set it with
> trace-cmd. While we're adding support for this, fix --profile so it sets
> max_graph_depth back to whatever it was before.
>
> Signed-off-by: Omar Sandoval <osandov@xxxxxx>
Hi!
Thanks for the patch. I don't mind the long name, but I would also like
a short cut version. Maybe use 'L'? (as mMgGdD are already used :-p)
I may just pull this patch and add the shortcut myself.
Thanks!
-- Steve
> ---
> Documentation/trace-cmd-record.1.txt | 5 ++++
> trace-record.c | 52 +++++++++++++++++++++++++++---------
> trace-usage.c | 1 +
> 3 files changed, 45 insertions(+), 13 deletions(-)
>
> diff --git a/Documentation/trace-cmd-record.1.txt b/Documentation/trace-cmd-record.1.txt
> index d88050d87558..b80520e5e815 100644
> --- a/Documentation/trace-cmd-record.1.txt
> +++ b/Documentation/trace-cmd-record.1.txt
> @@ -263,6 +263,11 @@ OPTIONS
> timestamp to gettimeofday which will allow wall time output from the
> timestamps reading the created 'trace.dat' file.
>
> +*--max-graph-depth* 'depth'::
> + Set the maximum depth the function_graph tracer will trace into a function.
> + A value of one will only show where userspace enters the kernel but not any
> + functions called in the kernel. The default is zero, which means no limit.
> +
> *--profile*::
> With the *--profile* option, "trace-cmd" will enable tracing that can
> be used with trace-cmd-report(1) --profile option. If a tracer *-p* is
> diff --git a/trace-record.c b/trace-record.c
> index 9f220c9c6330..fc124b7f1e98 100644
> --- a/trace-record.c
> +++ b/trace-record.c
> @@ -2180,6 +2180,20 @@ static void set_clock(struct buffer_instance *instance)
> write_instance_file(instance, "trace_clock", instance->clock, "clock");
> }
>
> +static void set_max_graph_depth(struct buffer_instance *instance, char *max_graph_depth)
> +{
> + char *path;
> + int ret;
> +
> + path = get_instance_file(instance, "max_graph_depth");
> + reset_save_file(path, RESET_DEFAULT_PRIO);
> + tracecmd_put_tracing_file(path);
> + ret = write_instance_file(instance, "max_graph_depth", max_graph_depth,
> + NULL);
> + if (ret < 0)
> + die("could not write to max_graph_depth");
> +}
> +
> static struct event_list *
> create_event(struct buffer_instance *instance, char *path, struct event_list *old_event)
> {
> @@ -3993,7 +4007,6 @@ profile_add_event(struct buffer_instance *instance, const char *event_str, int s
> static void enable_profile(struct buffer_instance *instance)
> {
> int stacktrace = 0;
> - int ret;
> int i;
> char *trigger_events[] = {
> "sched:sched_switch",
> @@ -4015,10 +4028,7 @@ static void enable_profile(struct buffer_instance *instance)
> if (!instance->plugin) {
> if (trace_check_file_exists(instance, "max_graph_depth")) {
> instance->plugin = "function_graph";
> - ret = write_instance_file(instance, "max_graph_depth",
> - "1", NULL);
> - if (ret < 0)
> - die("could not write to max_graph_depth");
> + set_max_graph_depth(instance, "1");
> } else
> warning("Kernel does not support max_graph_depth\n"
> " Skipping user/kernel profiling");
> @@ -4103,14 +4113,16 @@ void update_first_instance(struct buffer_instance *instance, int topt)
> }
>
> enum {
> - OPT_debug = 247,
> - OPT_tsoffset = 249,
> - OPT_bycomm = 250,
> - OPT_stderr = 251,
> - OPT_profile = 252,
> - OPT_nosplice = 253,
> - OPT_funcstack = 254,
> - OPT_date = 255,
> +
> + OPT_debug = 247,
> + OPT_max_graph_depth = 248,
> + OPT_tsoffset = 249,
> + OPT_bycomm = 250,
> + OPT_stderr = 251,
> + OPT_profile = 252,
> + OPT_nosplice = 253,
> + OPT_funcstack = 254,
> + OPT_date = 255,
> };
>
> void trace_record (int argc, char **argv)
> @@ -4140,6 +4152,7 @@ void trace_record (int argc, char **argv)
> int neg_event = 0;
> int date = 0;
> int manual = 0;
> + char *max_graph_depth = NULL;
> int topt = 0;
> int do_child = 0;
> int data_flags = 0;
> @@ -4311,6 +4324,7 @@ void trace_record (int argc, char **argv)
> {"stderr", no_argument, NULL, OPT_stderr},
> {"by-comm", no_argument, NULL, OPT_bycomm},
> {"ts-offset", required_argument, NULL, OPT_tsoffset},
> + {"max-graph-depth", required_argument, NULL, OPT_max_graph_depth},
> {"debug", no_argument, NULL, OPT_debug},
> {"help", no_argument, NULL, '?'},
> {NULL, 0, NULL, 0}
> @@ -4574,6 +4588,12 @@ void trace_record (int argc, char **argv)
> die("Can not use both --date and --ts-offset");
> data_flags |= DATA_FL_OFFSET;
> break;
> + case OPT_max_graph_depth:
> + free(max_graph_depth);
> + max_graph_depth = strdup(optarg);
> + if (!max_graph_depth)
> + die("Could not allocate option");
> + break;
> case OPT_debug:
> debug = 1;
> break;
> @@ -4691,6 +4711,12 @@ void trace_record (int argc, char **argv)
>
> set_options();
>
> + if (max_graph_depth) {
> + for_all_instances(instance)
> + set_max_graph_depth(instance, max_graph_depth);
> + free(max_graph_depth);
> + }
> +
> allocate_seq();
>
> if (type & (TRACE_TYPE_RECORD | TRACE_TYPE_STREAM)) {
> diff --git a/trace-usage.c b/trace-usage.c
> index b5304ef9fda1..5c1a69255581 100644
> --- a/trace-usage.c
> +++ b/trace-usage.c
> @@ -52,6 +52,7 @@ static struct usage_help usage_help[] = {
> " --profile enable tracing options needed for report --profile\n"
> " --func-stack perform a stack trace for function tracer\n"
> " (use with caution)\n"
> + " --max-graph-depth limit function_graph depth\n"
> },
> {
> "start",