Re: [RFC][PATCH 13/21] tracing: Add simple expression support to hist triggers
From: Tom Zanussi
Date: Tue Feb 14 2017 - 10:30:04 EST
Hi Namhyung,
On Tue, 2017-02-14 at 11:37 +0900, Namhyung Kim wrote:
> On Wed, Feb 08, 2017 at 11:25:09AM -0600, Tom Zanussi wrote:
> > Add support for simple addition, subtraction, and unary expressions
> > (-(expr) and expr, where expr = b-a, a+b, a+b+c) to hist triggers, in
> > order to support a minimal set of useful inter-event calculations.
> >
> > These operations are needed for calculating latencies between events
> > (timestamp1-timestamp0) and for combined latencies (latencies over 3
> > or more events).
> >
> > In the process, factor out some common code from key and value
> > parsing.
> >
> > Signed-off-by: Tom Zanussi <tom.zanussi@xxxxxxxxxxxxxxx>
> > ---
>
> [SNIP]
> > +static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
> > + struct trace_event_file *file,
> > + char *str, unsigned long flags,
> > + char *var_name);
> > +
> > +static struct hist_field *parse_unary(struct hist_trigger_data *hist_data,
> > + struct trace_event_file *file,
> > + char *str, unsigned long flags,
> > + char *var_name)
> > +{
> > + struct hist_field *operand1, *expr = NULL;
> > + struct ftrace_event_field *field = NULL;
> > + unsigned long operand_flags;
> > + char *operand1_str;
> > + int ret = 0;
> > + char *s;
> > +
> > + // we support only -(xxx) i.e. explicit parens required
> > +
> > + str++; // skip leading '-'
> > +
> > + s = strchr(str, '(');
> > + if (s)
> > + str++;
> > + else {
> > + ret = -EINVAL;
> > + goto free;
> > + }
> > +
> > + s = strchr(str, ')');
> > + if (s)
> > + *s = '\0';
> > + else {
> > + ret = -EINVAL; // no closing ')'
> > + goto free;
> > + }
> > +
> > + operand1_str = strsep(&str, "(");
> > + if (!operand1_str)
> > + goto free;
> > +
> > + flags |= HIST_FIELD_FL_EXPR;
> > + expr = create_hist_field(NULL, flags, var_name);
> > + if (!expr) {
> > + ret = -ENOMEM;
> > + goto free;
> > + }
> > +
> > + operand_flags = 0;
> > + operand1 = parse_expr(hist_data, file, str, operand_flags, NULL);
>
> Doesn't it create an unbounded recursion?
>
Yeah, Steve asked the same thing about some similar code - I'll either
get rid of the recursion or make sure it's unbounded.
Thanks,
Tom