From: Namhyung Kim <namhyung@kernel.org>
To: Tom Zanussi <tom.zanussi@linux.intel.com>
Cc: rostedt@goodmis.org, daniel.wagner@bmw-carit.de,
masami.hiramatsu.pt@hitachi.com, josh@joshtriplett.org,
andi@firstfloor.org, mathieu.desnoyers@efficios.com,
peterz@infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 17/28] tracing: Add hist trigger 'execname' modifier
Date: Mon, 2 Nov 2015 23:10:12 +0900 [thread overview]
Message-ID: <20151102141012.GA31643@danjae.kornet> (raw)
In-Reply-To: <48db482555d15fbedf6e0492b4d7d78712e0f7a0.1445530672.git.tom.zanussi@linux.intel.com>
On Thu, Oct 22, 2015 at 01:14:21PM -0500, Tom Zanussi wrote:
> Allow users to have pid fields displayed as program names in the output
> by appending '.execname' to field names:
>
> # echo hist:keys=aaa.execname ... \
> [ if filter] > event/trigger
So in this case, 'aaa' should be 'common_pid', right?
Also, it's just for display thus tasks which have different pid but
same comm name will be saved in different entries, right? If so, it'd
be better to note that somewhere as it might confuse users..
>
> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
> Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> ---
> kernel/trace/trace.c | 3 +-
> kernel/trace/trace_events_hist.c | 86 +++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 87 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 4f0968e..a143be0 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3822,7 +3822,8 @@ static const char readme_msg[] =
> "\t following modifiers to the field name, as applicable:\n\n"
> "\t .hex display a number as a hex value\n"
> "\t .sym display an address as a symbol\n"
> - "\t .sym-offset display an address as a symbol and offset\n\n"
> + "\t .sym-offset display an address as a symbol and offset\n"
> + "\t .execname display a common_pid as a program name\n\n"
> "\t The 'pause' parameter can be used to pause an existing hist\n"
> "\t trigger or to start a hist trigger but not log any events\n"
> "\t until told to do so. 'continue' can be used to start or\n"
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index e6e5c6e..656973a 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -75,6 +75,7 @@ enum hist_field_flags {
> HIST_FIELD_HEX = 8,
> HIST_FIELD_SYM = 16,
> HIST_FIELD_SYM_OFFSET = 32,
> + HIST_FIELD_EXECNAME = 64,
> };
>
> struct hist_trigger_attrs {
> @@ -218,6 +219,78 @@ static struct hist_trigger_attrs *parse_hist_trigger_attrs(char *trigger_str)
> return ERR_PTR(ret);
> }
>
> +static inline void save_comm(char *comm, struct task_struct *task)
> +{
> + if (!task->pid) {
> + strcpy(comm, "<idle>");
> + return;
> + }
> +
> + if (WARN_ON_ONCE(task->pid < 0)) {
> + strcpy(comm, "<XXX>");
> + return;
> + }
> +
> + if (task->pid > PID_MAX_DEFAULT) {
> + strcpy(comm, "<...>");
> + return;
> + }
I guess this comes from the saved_cmdlines code which uses a fixed
array of PID_MAX_DEFAULT size. But as it doesn't use the array, we
can simply copy the task->comm IMHO.
> +
> + memcpy(comm, task->comm, TASK_COMM_LEN);
> +}
> +
> +static void hist_trigger_elt_free(struct tracing_map_elt *elt)
> +{
> + kfree((char *)elt->private_data);
> +}
> +
> +static int hist_trigger_elt_alloc(struct tracing_map_elt *elt)
> +{
> + struct hist_trigger_data *hist_data = elt->map->private_data;
> + struct hist_field *key_field;
> + unsigned int i;
> +
> + for (i = hist_data->n_vals; i < hist_data->n_fields; i++) {
I think it'd be better to add a list iterator macro like
for_each_key_field() or something since it's easy to miss that the key
fields always follows the value fields IMHO.
> + key_field = hist_data->fields[i];
> +
> + if (key_field->flags & HIST_FIELD_EXECNAME) {
> + unsigned int size = TASK_COMM_LEN + 1;
> +
> + elt->private_data = kzalloc(size, GFP_KERNEL);
> + if (!elt->private_data)
> + return -ENOMEM;
> + break;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static void hist_trigger_elt_copy(struct tracing_map_elt *to,
> + struct tracing_map_elt *from)
> +{
> + char *comm_from = from->private_data;
> + char *comm_to = to->private_data;
> +
> + if (comm_from)
> + memcpy(comm_to, comm_from, TASK_COMM_LEN + 1);
> +}
> +
> +static void hist_trigger_elt_init(struct tracing_map_elt *elt)
> +{
> + char *comm = elt->private_data;
> +
> + if (comm)
> + save_comm(comm, current);
> +}
> +
> +static struct tracing_map_ops hist_trigger_ops = {
> + .elt_alloc = hist_trigger_elt_alloc,
> + .elt_copy = hist_trigger_elt_copy,
> + .elt_free = hist_trigger_elt_free,
> + .elt_init = hist_trigger_elt_init,
> +};
How about making it const?
> +
> static void destroy_hist_field(struct hist_field *hist_field)
> {
> kfree(hist_field);
> @@ -376,6 +449,9 @@ static int create_key_field(struct hist_trigger_data *hist_data,
> flags |= HIST_FIELD_SYM;
> else if (!strcmp(field_str, "sym-offset"))
> flags |= HIST_FIELD_SYM_OFFSET;
> + else if (!strcmp(field_str, "execname") &&
> + !strcmp(field_name, "common_pid"))
> + flags |= HIST_FIELD_EXECNAME;
> else {
> ret = -EINVAL;
> goto out;
> @@ -612,7 +688,7 @@ create_hist_data(unsigned int map_bits,
> goto free;
>
> hist_data->map = tracing_map_create(map_bits, hist_data->key_size,
> - NULL, hist_data);
> + &hist_trigger_ops, hist_data);
Why not using the hist_trigger_ops only if HIST_FIELD_EXECNAME is set
to one of the key fields actually?
Thanks,
Namhyung
> if (IS_ERR(hist_data->map)) {
> ret = PTR_ERR(hist_data->map);
> hist_data->map = NULL;
> @@ -732,6 +808,12 @@ hist_trigger_entry_print(struct seq_file *m,
> sprint_symbol(str, uval);
> seq_printf(m, "%s: [%llx] %-55s",
> key_field->field->name, uval, str);
> + } else if (key_field->flags & HIST_FIELD_EXECNAME) {
> + char *comm = elt->private_data;
> +
> + uval = *(u64 *)(key + key_field->offset);
> + seq_printf(m, "%s: %-16s[%10llu]",
> + key_field->field->name, comm, uval);
> } else if (key_field->flags & HIST_FIELD_STRING) {
> seq_printf(m, "%s: %-50s", key_field->field->name,
> (char *)(key + key_field->offset));
> @@ -851,6 +933,8 @@ static const char *get_hist_field_flags(struct hist_field *hist_field)
> flags_str = "sym";
> else if (hist_field->flags & HIST_FIELD_SYM_OFFSET)
> flags_str = "sym-offset";
> + else if (hist_field->flags & HIST_FIELD_EXECNAME)
> + flags_str = "execname";
>
> return flags_str;
> }
> --
> 1.9.3
>
next prev parent reply other threads:[~2015-11-02 14:10 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-22 18:14 [PATCH 00/28] tracing: 'hist' triggers Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 01/28] tracing: Update cond flag when enabling or disabling a trigger Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 02/28] tracing: Make ftrace_event_field checking functions available Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 03/28] tracing: Make event trigger " Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 04/28] tracing: Add event record param to trigger_ops.func() Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 05/28] tracing: Add get_syscall_name() Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 06/28] tracing: Add a per-event-trigger 'paused' field Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 07/28] tracing: Add needs_rec flag to event triggers Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 08/28] tracing: Add lock-free tracing_map Tom Zanussi
2015-10-29 8:31 ` Namhyung Kim
2015-10-29 18:35 ` Tom Zanussi
2015-11-02 7:08 ` Namhyung Kim
2015-11-04 1:47 ` Tom Zanussi
2015-11-04 2:26 ` Namhyung Kim
2015-11-04 2:56 ` Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 09/28] tracing: Add 'hist' event trigger command Tom Zanussi
2015-10-29 9:11 ` Namhyung Kim
2015-10-29 18:37 ` Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 10/28] tracing: Add hist trigger support for multiple values ('vals=' param) Tom Zanussi
2015-11-02 7:42 ` Namhyung Kim
2015-10-22 18:14 ` [PATCH v11 11/28] tracing: Add hist trigger support for compound keys Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 12/28] tracing: Add hist trigger support for user-defined sorting ('sort=' param) Tom Zanussi
2015-11-02 8:03 ` Namhyung Kim
2015-10-22 18:14 ` [PATCH v11 13/28] tracing: Add hist trigger support for pausing and continuing a trace Tom Zanussi
2015-11-03 8:38 ` Namhyung Kim
2015-11-04 1:53 ` Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 14/28] tracing: Add hist trigger support for clearing " Tom Zanussi
2015-11-03 8:43 ` Namhyung Kim
2015-10-22 18:14 ` [PATCH v11 15/28] tracing: Add hist trigger 'hex' modifier for displaying numeric fields Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 16/28] tracing: Add hist trigger 'sym' and 'sym-offset' modifiers Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 17/28] tracing: Add hist trigger 'execname' modifier Tom Zanussi
2015-11-02 14:10 ` Namhyung Kim [this message]
2015-11-04 2:37 ` Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 18/28] tracing: Add hist trigger 'syscall' modifier Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 19/28] tracing: Add hist trigger support for stacktraces as keys Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 20/28] tracing: Support string type key properly Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 21/28] tracing: Remove restriction on string position in hist trigger keys Tom Zanussi
2015-11-02 14:40 ` Namhyung Kim
2015-10-22 18:14 ` [PATCH v11 22/28] tracing: Add enable_hist/disable_hist triggers Tom Zanussi
2015-11-03 8:55 ` Namhyung Kim
2015-11-04 1:58 ` Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 23/28] tracing: Add 'hist' trigger Documentation Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 24/28] tracing: Add support for multiple hist triggers per event Tom Zanussi
2015-11-03 0:34 ` Namhyung Kim
2015-11-04 1:52 ` Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 25/28] tracing: Add support for named triggers Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 26/28] tracing: Add support for named hist triggers Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 27/28] kselftests/ftrace : Add event trigger testcases Tom Zanussi
2015-10-22 18:14 ` [PATCH v11 28/28] kselftests/ftrace: Add hist " Tom Zanussi
2015-10-22 18:21 ` [PATCH 00/28] tracing: 'hist' triggers Steven Rostedt
2015-10-22 18:31 ` Tom Zanussi
2015-11-05 14:43 ` Namhyung Kim
2015-11-05 14:59 ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-05 22:13 ` Tom Zanussi
2015-11-05 23:18 ` Namhyung Kim
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=20151102141012.GA31643@danjae.kornet \
--to=namhyung@kernel.org \
--cc=andi@firstfloor.org \
--cc=daniel.wagner@bmw-carit.de \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tom.zanussi@linux.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