From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757309AbdJKOIX (ORCPT ); Wed, 11 Oct 2017 10:08:23 -0400 Received: from mga05.intel.com ([192.55.52.43]:24227 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751835AbdJKOIW (ORCPT ); Wed, 11 Oct 2017 10:08:22 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,361,1503385200"; d="scan'208";a="322054445" Message-ID: <1507730900.8849.19.camel@tzanussi-mobl.amr.corp.intel.com> Subject: Re: [PATCH v3 15/33] tracing: Add simple expression support to hist triggers From: Tom Zanussi To: Namhyung Kim Cc: rostedt@goodmis.org, tglx@linutronix.de, mhiramat@kernel.org, vedang.patel@intel.com, bigeasy@linutronix.de, joel.opensrc@gmail.com, joelaf@google.com, mathieu.desnoyers@efficios.com, baohong.liu@intel.com, rajvi.jingar@intel.com, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, kernel-team@lge.com Date: Wed, 11 Oct 2017 09:08:20 -0500 In-Reply-To: <20171009125401.GA7788@danjae.aot.lge.com> References: <6a4903ab375ffbf9d76cc2c2193efaec1c751b54.1506105131.git.tom.zanussi@linux.intel.com> <20171009125401.GA7788@danjae.aot.lge.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2017-10-09 at 21:54 +0900, Namhyung Kim wrote: > On Fri, Sep 22, 2017 at 02:59:55PM -0500, 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 > > --- > > [SNIP] > > +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, unsigned int level) > > +{ > > + struct hist_field *operand1, *expr = NULL; > > + unsigned long operand_flags; > > + int ret = 0; > > + char *s; > > + > > + // we support only -(xxx) i.e. explicit parens required > > + > > + if (level > 2) { > > + ret = -EINVAL; > > + goto free; > > + } > > + > > + 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; > > + } > > + > > + strsep(&str, "("); > > + if (!str) { > > + ret = -EINVAL; > > + goto free; > > + } > > + > > + flags |= HIST_FIELD_FL_EXPR; > > + expr = create_hist_field(hist_data, NULL, flags, var_name); > > + if (!expr) { > > + ret = -ENOMEM; > > + goto free; > > + } > > + > > + operand_flags = 0; > > + operand1 = parse_expr(hist_data, file, str, operand_flags, NULL, ++level); > > + if (IS_ERR(operand1)) { > > + ret = PTR_ERR(operand1); > > + goto free; > > + } > > + > > + expr->fn = hist_field_unary_minus; > > + expr->operands[0] = operand1; > > + expr->operator = FIELD_OP_UNARY_MINUS; > > + expr->name = expr_str(expr, 0); > > + > > + return expr; > > + free: > > Missing destroy_hist_field(expr, 0)? > Yep, will add, thanks. Tom