Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp850998ybt; Fri, 26 Jun 2020 13:08:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoE8+ufb/Ax34Y6nirEXt+lq7NOco6tctdvfsEbwU6buC0WP+JMLXtJIQ23DuzL2E+1rmt X-Received: by 2002:a50:f01d:: with SMTP id r29mr5171848edl.158.1593202089956; Fri, 26 Jun 2020 13:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593202089; cv=none; d=google.com; s=arc-20160816; b=G+54HoSab18Fa+5MqUaHF/nsLCMu3Ez+qAs4XQ+hb4mMMLzi7XkvALK5JwnfNEBNmS u9IW5zPaQCgXbHBnygY/EPC7Qe4u20wBCfSdFvYQDxLzQpPkbk7nX1/H8vcz0Qhr3ILi doCU7zv0Lp6RqLo5jUewC+MUsRfg7o75VpU+Dl5rqCGxcQFy4VBjig8cjk/KWeUEAHxD GA8rpSZIVj/NXe1NAMlKWiClQMvNHm5bMUdzhmD/0zlGNU8jx5x69kVA261KFfsgfnbT wlH8Q/Zickt/QiGVtBzx7x50rGFTgWZlS+yShLnOlEjILKuj+vtP+/CvIIHRiSpchuqG xXkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=g0y1yBCUar1RcebjU46sNh4usOJdB5GLaAUIgcV2ggI=; b=sZ0yV1nSCDx9IzO8dTGku3Ic2t5j/nm996SiOvKptQBnW3h6HjAnU65TbfXOOwVjGy RhphCOKKSqOdxRTrVP4S5jlMmNDL3L5+++VFrDTH4l97K6j6HA5JVgoxL8w6JAqbQRB+ hgxOntC9Ojq3X/QzECXG2ocX222Q02C/GJMu3bqArekU4g0Jhy+oe9J14SiU5nEYaHJM tjSmpwN5ByGxkF+SA6vMTWr05CXWfx0ALmNpw8XdNqX9o7pLbRQyEsYsv4XoQ8InWaso D2kn5hb3pQ+ocw6e1kPLA9V9KY5xfxFhjooW3Iae2VwcuGPl7b4MfaFOk2wZS8PQm3ce kUTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="XuzDc5/F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si18284875ejx.161.2020.06.26.13.07.46; Fri, 26 Jun 2020 13:08:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="XuzDc5/F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725861AbgFZUHh (ORCPT + 99 others); Fri, 26 Jun 2020 16:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725806AbgFZUHh (ORCPT ); Fri, 26 Jun 2020 16:07:37 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B595C03E979 for ; Fri, 26 Jun 2020 13:07:37 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id o11so10601230wrv.9 for ; Fri, 26 Jun 2020 13:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=g0y1yBCUar1RcebjU46sNh4usOJdB5GLaAUIgcV2ggI=; b=XuzDc5/FQBS6MzrKTnE+8TXtblP/VKGGTWDP0da2I7mlvPq3wkHUMscELHo4zjRodF INDn0AXf18ttd3kK1yZqX0X1XFLof1FRp/7M86k+XNbVNjBJTiMbYoPhy0G5WyKJdbAh s2Y2h/ORQjSpEPAPMZ191e+qDzj1kPwsydqSUgd+7SxyT9BS1WdfR9uSqzgrkqCrn8od aHrDdoAhd3eHJMiQcjvfws0iS7Zvo9D1F2PnqnsfPAMbUo7G7LdpCkKQRSTkMABEs6XE fM3Hpbh206m/+QjPqdgrJM8rLwZwm3Tu6UP/Fhda5fJtX4TCSSJ7tB+2QwBpXoKNS8ri mvfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=g0y1yBCUar1RcebjU46sNh4usOJdB5GLaAUIgcV2ggI=; b=YsKgIBNxAJpihGIDHtc6fkcJ4FxbcYVr+xPWGW6plaLDsrWJYywMbdvzXen0wCoio9 Hd3/My4dZJc2I5XIYFyFYKmXMrKoRAatwTBhvKymtG3jeA+Krd7Z0pYp3F9B9Lzkwd3I 4pq2sQ7/ukB1dpv6kTaYPC5iJwHma40DhYiaRmg8ANmegfX6SI9pjS1jWpBaDJAGHXTH mLnHPykHSoRKkVY1O01ukf7lAY/VVSXRjWLkpE2E333ydXOcIpLvzuiejABJsZVwumc6 1e2oow1kPAi3LkXjn384EWvMRTRG4kMEkW+GxfLE/eJY4re0y4fdKRurSrguotYBB4sp BB3Q== X-Gm-Message-State: AOAM533UcfyrYxKVdi6rgSO4O5YO712cx/GBwJE5gll8JpJ7wN0hdfVt nUSpc8LFm7b+0uj4bd/JiQypth61YdyN3iCFl4hOUg== X-Received: by 2002:a5d:4bd2:: with SMTP id l18mr5257109wrt.119.1593202055747; Fri, 26 Jun 2020 13:07:35 -0700 (PDT) MIME-Version: 1.0 References: <20200626194720.2915044-1-jolsa@kernel.org> <20200626194720.2915044-4-jolsa@kernel.org> In-Reply-To: <20200626194720.2915044-4-jolsa@kernel.org> From: Ian Rogers Date: Fri, 26 Jun 2020 13:07:24 -0700 Message-ID: Subject: Re: [PATCH 03/10] perf tools: Add expr__add_id function To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Andi Kleen , Kajol Jain , John Garry , "Paul A. Clarke" , Stephane Eranian Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 26, 2020 at 12:47 PM Jiri Olsa wrote: > > Adding expr__add_id function to data for ID > with zero value, which is used when scanning > the expression for IDs. > > Signed-off-by: Jiri Olsa > --- > tools/perf/util/expr.c | 29 +++++++++++++++++++++++------ > tools/perf/util/expr.h | 1 + > tools/perf/util/expr.y | 2 +- > 3 files changed, 25 insertions(+), 7 deletions(-) > > diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c > index 7573b21e73df..0b6d3a6ce88e 100644 > --- a/tools/perf/util/expr.c > +++ b/tools/perf/util/expr.c > @@ -32,6 +32,24 @@ static bool key_equal(const void *key1, const void *key2, > return !strcmp((const char *)key1, (const char *)key2); > } > > +/* Caller must make sure id is allocated */ > +int expr__add_id(struct expr_parse_ctx *ctx, const char *name) Nit, perhaps "id" is more consistent than "name". Perhaps also change add_val below. Acked-by: Ian Rogers > +{ > + struct expr_parse_data *data_ptr = NULL, *old_data = NULL; > + char *old_key = NULL; > + int ret; > + > + data_ptr = malloc(sizeof(*data_ptr)); > + if (!data_ptr) > + return -ENOMEM; > + > + ret = hashmap__set(&ctx->ids, name, data_ptr, > + (const void **)&old_key, (void **)&old_data); > + free(old_key); > + free(old_data); > + return ret; > +} > + > /* Caller must make sure id is allocated */ > int expr__add_val(struct expr_parse_ctx *ctx, const char *name, double val) > { > @@ -39,12 +57,11 @@ int expr__add_val(struct expr_parse_ctx *ctx, const char *name, double val) > char *old_key = NULL; > int ret; > > - if (val != 0.0) { > - data_ptr = malloc(sizeof(*data_ptr)); > - if (!data_ptr) > - return -ENOMEM; > - data_ptr->val = val; > - } > + data_ptr = malloc(sizeof(*data_ptr)); > + if (!data_ptr) > + return -ENOMEM; > + data_ptr->val = val; > + > ret = hashmap__set(&ctx->ids, name, data_ptr, > (const void **)&old_key, (void **)&old_data); > free(old_key); > diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h > index f9f16efe76bc..5452e641acf4 100644 > --- a/tools/perf/util/expr.h > +++ b/tools/perf/util/expr.h > @@ -26,6 +26,7 @@ struct expr_scanner_ctx { > > void expr__ctx_init(struct expr_parse_ctx *ctx); > void expr__ctx_clear(struct expr_parse_ctx *ctx); > +int expr__add_id(struct expr_parse_ctx *ctx, const char *name); > int expr__add_val(struct expr_parse_ctx *ctx, const char *id, double val); > int expr__get_id(struct expr_parse_ctx *ctx, const char *id, double *val_ptr); > int expr__parse(double *final_val, struct expr_parse_ctx *ctx, > diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y > index ff5e5f6e170d..ac4b119877e0 100644 > --- a/tools/perf/util/expr.y > +++ b/tools/perf/util/expr.y > @@ -71,7 +71,7 @@ all_other: all_other other > > other: ID > { > - expr__add_val(ctx, $1, 0.0); > + expr__add_id(ctx, $1); > } > | > MIN | MAX | IF | ELSE | SMT_ON | NUMBER | '|' | '^' | '&' | '-' | '+' | '*' | '/' | '%' | '(' | ')' | ',' > -- > 2.25.4 >