From: Namhyung Kim <namhyung@kernel.org>
To: Tom Zanussi <tom.zanussi@linux.intel.com>
Cc: rostedt@goodmis.org, tglx@linutronix.de, mhiramat@kernel.org,
vedang.patel@intel.com, linux-kernel@vger.kernel.org,
linux-rt-users@vger.kernel.org, kernel-team@lge.com
Subject: Re: [PATCH 24/32] tracing: Add 'onmax' hist trigger action support
Date: Wed, 26 Jul 2017 12:04:27 +0900 [thread overview]
Message-ID: <20170726030427.GB32043@sejong> (raw)
In-Reply-To: <eba89c852028b147fe695bb47cfafd690c345e74.1498510759.git.tom.zanussi@linux.intel.com>
On Mon, Jun 26, 2017 at 05:49:25PM -0500, Tom Zanussi wrote:
> Add an 'onmax(var).save(field,...)' hist trigger action which is
> invoked whenever an event exceeds the current maximum.
>
> The end result is that the trace event fields or variables specified
> as the onmax.save() params will be saved if 'var' exceeds the current
> maximum for that hist trigger entry. This allows context from the
> event that exhibited the new maximum to be saved for later reference.
> When the histogram is displayed, additional fields displaying the
> saved values will be printed.
>
> As an example the below defines a couple of hist triggers, one for
> sched_wakeup and another for sched_switch, keyed on pid. Whenever a
> sched_wakeup occurs, the timestamp is saved in the entry corresponding
> to the current pid, and when the scheduler switches back to that pid,
> the timestamp difference is calculated. If the resulting latency
> exceeds the current maximum latency, the specified save() values are
> saved:
>
> # echo 'hist:keys=pid:ts0=common_timestamp.usecs \
> if comm=="cyclictest"' >> \
> /sys/kernel/debug/tracing/events/sched/sched_wakeup/trigger
>
> # echo 'hist:keys=next_pid:\
> wakeup_lat=common_timestamp.usecs-$ts0:\
> onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm) \
> if next_comm=="cyclictest"' >> \
> /sys/kernel/debug/tracing/events/sched/sched_switch/trigger
>
> When the histogram is displayed, the max value and the saved values
> corresponding to the max are displayed following the rest of the
> fields:
>
> # cat /sys/kernel/debug/tracing/events/sched/sched_switch/hist
> { next_pid: 2255 } hitcount: 239 \
> common_timestamp-$ts0: 0
What is this, wakeup_lat? If so, it'd be better showing the variable name.
> max: 27 next_comm: cyclictest \
> prev_pid: 0 prev_prio: 120 prev_comm: swapper/1 \
> { next_pid: 2256 } hitcount: 2355 common_timestamp-$ts0: 0 \
> max: 49 next_comm: cyclictest \
> prev_pid: 0 prev_prio: 120 prev_comm: swapper/0
>
> Totals:
> Hits: 12970
Why total hits is different than the sum of two?
> Entries: 2
> Dropped: 0
>
> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
> ---
> kernel/trace/trace_events_hist.c | 310 ++++++++++++++++++++++++++++++++++-----
> 1 file changed, 276 insertions(+), 34 deletions(-)
>
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index b1f859c..d191f1a 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -282,6 +282,10 @@ struct hist_trigger_data {
> unsigned int n_field_var_str;
> struct field_var_hist *field_var_hists[SYNTH_FIELDS_MAX];
> unsigned int n_field_var_hists;
> +
> + struct field_var *max_vars[SYNTH_FIELDS_MAX];
> + unsigned int n_max_vars;
> + unsigned int n_max_var_str;
> };
>
> struct synth_field {
> @@ -318,6 +322,12 @@ struct action_data {
> char *match_event_system;
> char *synth_event_name;
> struct synth_event *synth_event;
> +
> + char *onmax_var_str;
> + char *onmax_fn_name;
> + unsigned int max_var_ref_idx;
> + struct hist_field *max_var;
> + struct hist_field *onmax_var;
Couldn't it be a union?
> };
[SNIP]
> @@ -2613,6 +2633,222 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data,
> return create_field_var(hist_data, file, var_name);
> }
>
> +static void onmax_print(struct seq_file *m,
> + struct hist_trigger_data *hist_data,
> + struct tracing_map_elt *elt,
> + struct action_data *data)
> +{
> + unsigned int i, save_var_idx, max_idx = data->max_var->var.idx;
> +
> + seq_printf(m, "\n\tmax: %10llu", tracing_map_read_var(elt, max_idx));
> +
> + for (i = 0; i < hist_data->n_max_vars; i++) {
> + struct hist_field *save_val = hist_data->max_vars[i]->val;
> + struct hist_field *save_var = hist_data->max_vars[i]->var;
> + u64 val;
> +
> + save_var_idx = save_var->var.idx;
> +
> + val = tracing_map_read_var(elt, save_var_idx);
> +
> + if (save_val->flags & HIST_FIELD_FL_STRING) {
> + seq_printf(m, " %s: %-50s", save_var->var.name,
It seems TASK_COMM_LEN is enough. Or please define STR_VAR_LEN or
something.
> + (char *)(uintptr_t)(val));
> + } else
> + seq_printf(m, " %s: %10llu", save_var->var.name, val);
> + }
> +}
[SNIP]
> +static struct action_data *onmax_parse(char *str)
> +{
> + char *onmax_fn_name, *onmax_var_str;
> + struct action_data *data;
> + int ret = -EINVAL;
> +
> + data = kzalloc(sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return ERR_PTR(-ENOMEM);
> +
> + onmax_var_str = strsep(&str, ")");
> + if (!onmax_var_str || !str)
> + return ERR_PTR(-EINVAL);
> + data->onmax_var_str = kstrdup(onmax_var_str, GFP_KERNEL);
> +
> + strsep(&str, ".");
> + if (!str)
> + goto free;
> +
> + onmax_fn_name = strsep(&str, "(");
> + if (!onmax_fn_name || !str)
> + goto free;
> +
> + if (strncmp(onmax_fn_name, "save", strlen("save")) == 0) {
> + char *params = strsep(&str, ")");
> +
> + if (!params)
> + goto free;
> +
> + ret = parse_action_params(params, data);
> + if (ret)
> + goto free;
> + }
Hmm.. is it ok to give a function name other than 'save'?
Thanks,
Namhyung
> + data->onmax_fn_name = kstrdup(onmax_fn_name, GFP_KERNEL);
> +
> + if (!data->onmax_var_str || !data->onmax_fn_name) {
> + ret = -ENOMEM;
> + goto free;
> + }
> + out:
> + return data;
> + free:
> + onmax_destroy(data);
> + data = ERR_PTR(ret);
> + goto out;
> +}
next prev parent reply other threads:[~2017-07-26 3:04 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-26 22:49 [PATCH 00/32] tracing: Inter-event (e.g. latency) support Tom Zanussi
2017-06-26 22:49 ` [PATCH 01/32] tracing: Add hist_field_name() accessor Tom Zanussi
2017-07-13 6:49 ` Piotr Gregor
2017-07-13 14:41 ` Tom Zanussi
2017-07-14 2:19 ` Namhyung Kim
2017-06-26 22:49 ` [PATCH 02/32] tracing: Reimplement log2 Tom Zanussi
2017-07-14 2:33 ` Namhyung Kim
2017-07-14 16:13 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 03/32] ring-buffer: Add interface for setting absolute time stamps Tom Zanussi
2017-07-14 5:25 ` Namhyung Kim
2017-07-14 16:14 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 04/32] ring-buffer: Redefine the unimplemented RINGBUF_TIME_TIME_STAMP Tom Zanussi
2017-07-02 8:51 ` Joel Fernandes (Google)
2017-06-26 22:49 ` [PATCH 05/32] tracing: Give event triggers access to ring_buffer_event Tom Zanussi
2017-06-26 22:49 ` [PATCH 06/32] tracing: Add ring buffer event param to hist field functions Tom Zanussi
2017-06-26 22:49 ` [PATCH 07/32] tracing: Increase tracing map KEYS_MAX size Tom Zanussi
2017-06-26 22:49 ` [PATCH 08/32] tracing: Break out hist trigger assignment parsing Tom Zanussi
2017-06-26 22:49 ` [PATCH 09/32] tracing: Make traceprobe parsing code reusable Tom Zanussi
2017-06-26 22:49 ` [PATCH 10/32] tracing: Add NO_DISCARD event file flag Tom Zanussi
2017-06-26 22:49 ` [PATCH 11/32] tracing: Add post-trigger flag to hist trigger command Tom Zanussi
2017-06-26 22:49 ` [PATCH 12/32] tracing: Add hist trigger timestamp support Tom Zanussi
2017-07-17 6:00 ` Namhyung Kim
2017-07-17 16:57 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 13/32] tracing: Add per-element variable support to tracing_map Tom Zanussi
2017-06-26 22:49 ` [PATCH 14/32] tracing: Add hist_data member to hist_field Tom Zanussi
2017-06-26 22:49 ` [PATCH 15/32] tracing: Add usecs modifier for hist trigger timestamps Tom Zanussi
2017-06-26 22:49 ` [PATCH 16/32] tracing: Add variable support to hist triggers Tom Zanussi
2017-07-19 1:07 ` Namhyung Kim
2017-07-19 15:40 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 17/32] tracing: Account for variables in named trigger compatibility Tom Zanussi
2017-06-26 22:49 ` [PATCH 18/32] tracing: Add simple expression support to hist triggers Tom Zanussi
2017-07-21 2:02 ` Namhyung Kim
2017-07-21 16:29 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 19/32] tracing: Add variable reference handling " Tom Zanussi
2017-07-21 3:31 ` Namhyung Kim
2017-07-21 16:41 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 20/32] tracing: Add support for dynamic tracepoints Tom Zanussi
2017-06-26 22:49 ` [PATCH 21/32] tracing: Add hist trigger action hook Tom Zanussi
2017-06-26 22:49 ` [PATCH 22/32] tracing: Add support for 'synthetic' events Tom Zanussi
2017-07-23 12:00 ` Namhyung Kim
2017-07-24 16:11 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 23/32] tracing: Add 'onmatch' hist trigger action support Tom Zanussi
2017-07-23 15:12 ` Namhyung Kim
2017-07-24 16:17 ` Tom Zanussi
2017-07-26 2:40 ` Namhyung Kim
2017-07-26 16:38 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 24/32] tracing: Add 'onmax' " Tom Zanussi
2017-07-26 3:04 ` Namhyung Kim [this message]
2017-07-26 16:45 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 25/32] tracing: Allow whitespace to surround hist trigger filter Tom Zanussi
2017-06-26 22:49 ` [PATCH 26/32] tracing: Make duplicate count from tracing_map available Tom Zanussi
2017-06-26 22:49 ` [PATCH 27/32] tracing: Add cpu field for hist triggers Tom Zanussi
2017-06-26 22:49 ` [PATCH 28/32] tracing: Add hist trigger support for variable reference aliases Tom Zanussi
2017-06-26 22:49 ` [PATCH 29/32] tracing: Add 'last error' error facility for hist triggers Tom Zanussi
2017-07-26 4:39 ` Namhyung Kim
2017-07-26 16:47 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 30/32] tracing: Add inter-event hist trigger Documentation Tom Zanussi
2017-06-26 22:49 ` [PATCH 31/32] tracing: Make tracing_set_clock() non-static Tom Zanussi
2017-06-26 22:49 ` [PATCH 32/32] tracing: Add a clock attribute for hist triggers Tom Zanussi
2017-06-27 14:58 ` [PATCH 00/32] tracing: Inter-event (e.g. latency) support Steven Rostedt
2017-06-28 14:21 ` Masami Hiramatsu
2017-06-28 19:09 ` Tom Zanussi
2017-07-01 7:01 ` Joel Fernandes (Google)
2017-07-12 19:17 ` Tom Zanussi
2017-07-04 16:12 ` Sebastian Andrzej Siewior
2017-07-12 19:20 ` Tom Zanussi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170726030427.GB32043@sejong \
--to=namhyung@kernel.org \
--cc=kernel-team@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tom.zanussi@linux.intel.com \
--cc=vedang.patel@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).