Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1727042 > unrolled thread

[PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases

Started byTom Zanussi <tom.zanussi@linux.intel.com>
First post2017-09-06 00:10 +0200
Last post2017-09-08 21:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-09-06 00:10 +0200
    Re: [PATCH v2 33/40] tracing: Add hist trigger support for variable  reference aliases Steven Rostedt <rostedt@goodmis.org> - 2017-09-08 21:20 +0200
      Re: [PATCH v2 33/40] tracing: Add hist trigger support for variable  reference aliases Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-09-08 21:50 +0200

#1727042 — [PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases

FromTom Zanussi <tom.zanussi@linux.intel.com>
Date2017-09-06 00:10 +0200
Subject[PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases
Message-ID<umucH-oz-55@gated-at.bofh.it>
Add support for alias=$somevar where alias can be used as
onmatch($alias).

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
 kernel/trace/trace_events_hist.c | 61 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 0782766..764c5e5 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -227,6 +227,7 @@ enum hist_field_flags {
 	HIST_FIELD_FL_EXPR		= 16384,
 	HIST_FIELD_FL_VAR_REF		= 32768,
 	HIST_FIELD_FL_CPU		= 65536,
+	HIST_FIELD_FL_ALIAS		= 131072,
 };
 
 struct var_defs {
@@ -1525,7 +1526,8 @@ static const char *hist_field_name(struct hist_field *field,
 
 	if (field->field)
 		field_name = field->field->name;
-	else if (field->flags & HIST_FIELD_FL_LOG2)
+	else if (field->flags & HIST_FIELD_FL_LOG2 ||
+		 field->flags & HIST_FIELD_FL_ALIAS)
 		field_name = hist_field_name(field->operands[0], ++level);
 	else if (field->flags & HIST_FIELD_FL_TIMESTAMP)
 		field_name = "$common_timestamp";
@@ -1961,7 +1963,7 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
 
 	hist_field->hist_data = hist_data;
 
-	if (flags & HIST_FIELD_FL_EXPR)
+	if (flags & HIST_FIELD_FL_EXPR || flags & HIST_FIELD_FL_ALIAS)
 		goto out; /* caller will populate */
 
 	if (flags & HIST_FIELD_FL_VAR_REF) {
@@ -2219,6 +2221,29 @@ static struct hist_field *parse_var_ref(struct trace_array *tr,
 	return field;
 }
 
+static struct hist_field *create_alias(struct hist_trigger_data *hist_data,
+				       struct hist_field *var_ref,
+				       char *var_name)
+{
+	struct hist_field *alias = NULL;
+	unsigned long flags = HIST_FIELD_FL_ALIAS | HIST_FIELD_FL_VAR |
+		HIST_FIELD_FL_VAR_ONLY;
+
+	alias = create_hist_field(hist_data, NULL, flags, var_name);
+	if (!alias)
+		return NULL;
+
+	alias->fn = var_ref->fn;
+	alias->operands[0] = var_ref;
+
+	if (init_var_ref(alias, var_ref)) {
+		destroy_hist_field(alias, 0);
+		return NULL;
+	}
+
+	return alias;
+}
+
 struct hist_field *parse_atom(struct hist_trigger_data *hist_data,
 			      struct trace_event_file *file, char *str,
 			      unsigned long *flags, char *var_name)
@@ -2245,6 +2270,13 @@ struct hist_field *parse_atom(struct hist_trigger_data *hist_data,
 		if (hist_field) {
 			hist_data->var_refs[hist_data->n_var_refs] = hist_field;
 			hist_field->var_ref_idx = hist_data->n_var_refs++;
+			if (var_name) {
+				hist_field = create_alias(hist_data, hist_field, var_name);
+				if (!hist_field) {
+					ret = -ENOMEM;
+					goto out;
+				}
+			}
 			return hist_field;
 		}
 	} else
@@ -2346,6 +2378,26 @@ static int check_expr_operands(struct hist_field *operand1,
 	unsigned long operand1_flags = operand1->flags;
 	unsigned long operand2_flags = operand2->flags;
 
+	if ((operand1_flags & HIST_FIELD_FL_VAR_REF) ||
+	    (operand1_flags & HIST_FIELD_FL_ALIAS)) {
+		struct hist_field *var;
+
+		var = find_var_field(operand1->var.hist_data, operand1->name);
+		if (!var)
+			return -EINVAL;
+		operand1_flags = var->flags;
+	}
+
+	if ((operand2_flags & HIST_FIELD_FL_VAR_REF) ||
+	    (operand2_flags & HIST_FIELD_FL_ALIAS)) {
+		struct hist_field *var;
+
+		var = find_var_field(operand2->var.hist_data, operand2->name);
+		if (!var)
+			return -EINVAL;
+		operand2_flags = var->flags;
+	}
+
 	if ((operand1_flags & HIST_FIELD_FL_TIMESTAMP_USECS) !=
 	    (operand2_flags & HIST_FIELD_FL_TIMESTAMP_USECS))
 		return -EINVAL;
@@ -4339,8 +4391,11 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
 		seq_puts(m, "$common_timestamp");
 	else if (hist_field->flags & HIST_FIELD_FL_CPU)
 		seq_puts(m, "cpu");
-	else if (field_name)
+	else if (field_name) {
+		if (hist_field->flags & HIST_FIELD_FL_ALIAS)
+			seq_putc(m, '$');
 		seq_printf(m, "%s", field_name);
+	}
 
 	if (hist_field->flags) {
 		const char *flags_str = get_hist_field_flags(hist_field);
-- 
1.9.3

[toc] | [next] | [standalone]


#1729215 — Re: [PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-09-08 21:20 +0200
SubjectRe: [PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases
Message-ID<unwYN-2QU-1@gated-at.bofh.it>
In reply to#1727042
On Tue,  5 Sep 2017 16:57:45 -0500
Tom Zanussi <tom.zanussi@linux.intel.com> wrote:

> Add support for alias=$somevar where alias can be used as
> onmatch($alias).

This change log is very lacking. What exactly is the purpose of alias?

Sounds like the variable is going undercover.

-- Steve

> 
> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>

[toc] | [prev] | [next] | [standalone]


#1729235 — Re: [PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases

FromTom Zanussi <tom.zanussi@linux.intel.com>
Date2017-09-08 21:50 +0200
SubjectRe: [PATCH v2 33/40] tracing: Add hist trigger support for variable reference aliases
Message-ID<unxrS-36G-35@gated-at.bofh.it>
In reply to#1729215
On Fri, 2017-09-08 at 15:09 -0400, Steven Rostedt wrote:
> On Tue,  5 Sep 2017 16:57:45 -0500
> Tom Zanussi <tom.zanussi@linux.intel.com> wrote:
> 
> > Add support for alias=$somevar where alias can be used as
> > onmatch($alias).
> 
> This change log is very lacking. What exactly is the purpose of alias?
> 
> Sounds like the variable is going undercover.
> 

This was a feature added at the request of a user, who wanted more
flexibility in making naming clearer in certain cases e.g.:

# echo 'hist:keys=next_pid:new_lat=$common_timestamp.usecs' > /sys/kernel/debug/tracing/events/sched/sched_switch/trigger

# echo 'hist:keys=pid:latency=$new_lat:onmatch(sched.sched_switch).wake2($latency,pid)' > /sys/kernel/debug/tracing/events/synthetic/wake1/trigger

I'll add a better description and exampe to the change log for this.

Tom 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web