lkml.org 
[lkml]   [2017]   [Nov]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v6 18/37] tracing: Add simple expression support to hist triggers
Hi Tom,

On Fri, Nov 17, 2017 at 02:32:57PM -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@linux.intel.com>
> ---

[SNIP]
> +static char *expr_str(struct hist_field *field, unsigned int level)
> +{
> + char *expr;
> +
> + if (level > 1)
> + return NULL;
> +
> + expr = kzalloc(MAX_FILTER_STR_VAL, GFP_KERNEL);
> + if (!expr)
> + return NULL;
> +
> + if (field->operator == FIELD_OP_UNARY_MINUS) {
> + char *subexpr;
> +
> + strcat(expr, "-(");
> + subexpr = expr_str(field->operands[0], ++level);
> + if (!subexpr) {
> + kfree(expr);
> + return NULL;
> + }
> + strcat(expr, subexpr);
> + strcat(expr, ")");
> +
> + return expr;

The subexpr was leaked.

Thanks,
Namhyung


> + }
> +
> + strcat(expr, hist_field_name(field->operands[0], 0));
> + if (field->operands[0]->flags) {
> + const char *flags_str = get_hist_field_flags(field->operands[0]);
> +
> + if (flags_str) {
> + strcat(expr, ".");
> + strcat(expr, flags_str);
> + }
> + }
> +
> + switch (field->operator) {
> + case FIELD_OP_MINUS:
> + strcat(expr, "-");
> + break;
> + case FIELD_OP_PLUS:
> + strcat(expr, "+");
> + break;
> + default:
> + kfree(expr);
> + return NULL;
> + }
> +
> + strcat(expr, hist_field_name(field->operands[1], 0));
> + if (field->operands[1]->flags) {
> + const char *flags_str = get_hist_field_flags(field->operands[1]);
> +
> + if (flags_str) {
> + strcat(expr, ".");
> + strcat(expr, flags_str);
> + }
> + }
> +
> + return expr;
> +}

\
 
 \ /
  Last update: 2017-11-20 07:05    [W:0.170 / U:2.916 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site