Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp287780ybh; Sun, 12 Jul 2020 06:28:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPbvMW/MK7YdYROKDZvjr3ZLzk+SYwZlYBSqZ7c/525sCg8gRNSSVgTgRfMzkSVF3fWL1x X-Received: by 2002:aa7:c3d7:: with SMTP id l23mr77522260edr.18.1594560505138; Sun, 12 Jul 2020 06:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594560505; cv=none; d=google.com; s=arc-20160816; b=yUNWd1fq428af+7cDUo8ffj+krzfLcqoajZi28U81f14I6rUJAHuUVRrIkDe7HxS39 s5mQCXEKErrnfYTwudONYNfkHtpG3O/DCDINYyFK5a48i1xWC2Gsuj2klN48TDFRyiKs RXbtvvOad9nLjy9NA0to0P3BaeekXgoBwsFG5x/dCYur9uYJqYqwws27XPRV81G2NE6E K18ehhuK5+nXOJQ5z6yuBtLBL71JReZwigXD+8XbRV0YewDYp3n+4fL70Of1xe/u/tKH +0rX74mKs4RFH6Qi4wCrnzCRVph7Kwg9uE015OUkQs4B2F0zSUorLqKeRLReT/g7xJ1Y m9SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lWFeVKMsUfTrw8VdbMHe9UGfvIZDvX5b12uFA4/BLdM=; b=WE2QSAreI9nhKKGwuvN+YCRZkg5IDhqTiWTuleP2IqG6wgyxy2KrP/9wGUuuX5zTP5 /0ypnHaCTeafNAGQ1zc0D5lSCssQVv4ZmGd1C0DQ3P9LvgHnfxIw6P1XLGbHfC5UYLa7 JXi/VHhfgvVohk8kcV0OI8717Db1MDtEGUpxnkW8oEdB+yQKo1NyIV6u756hHYO/Egj6 +phj00Eo+RHjck5jS4TokOxF13xVC0fHqrAxaAMSxNcRIy6Piqm47rucn90nsJFWPMf1 IRLaUntH4qrEjsZ1r1M7Qq/GHzL7ZzKBbZQQ5fkssbvlNuj4pRvX7XAYodqm9dAEeOAs Aiug== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si7735931edq.111.2020.07.12.06.28.03; Sun, 12 Jul 2020 06:28:25 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729002AbgGLN1X convert rfc822-to-8bit (ORCPT + 99 others); Sun, 12 Jul 2020 09:27:23 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:33449 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728995AbgGLN1V (ORCPT ); Sun, 12 Jul 2020 09:27:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-ChX5e8TbOvKI1kElQjJN-g-1; Sun, 12 Jul 2020 09:27:13 -0400 X-MC-Unique: ChX5e8TbOvKI1kElQjJN-g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC7F31800D42; Sun, 12 Jul 2020 13:27:11 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10BA51944D; Sun, 12 Jul 2020 13:27:08 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Andi Kleen , Kajol Jain , John Garry , "Paul A. Clarke" , Stephane Eranian , Ian Rogers Subject: [PATCH 10/18] perf metric: Collect referenced metrics in struct metric_expr Date: Sun, 12 Jul 2020 15:26:26 +0200 Message-Id: <20200712132634.138901-11-jolsa@kernel.org> In-Reply-To: <20200712132634.138901-1-jolsa@kernel.org> References: <20200712132634.138901-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add referenced metrics into struct metric_expr object, so they are accessible when computing the metric. Storing just name and expression itself, so the metric can be resolved and computed. Signed-off-by: Jiri Olsa --- tools/perf/util/metricgroup.c | 26 ++++++++++++++++++++++++++ tools/perf/util/metricgroup.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 9923eef1e2d4..8cbcc5e05fef 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -83,6 +83,7 @@ static void metric_event_delete(struct rblist *rblist __maybe_unused, struct metric_expr *expr, *tmp; list_for_each_entry_safe(expr, tmp, &me->head, nd) { + free(expr->metric_refs); free(expr); } @@ -243,6 +244,7 @@ static int metricgroup__setup_events(struct list_head *groups, list_for_each_entry (eg, groups, nd) { struct evsel **metric_events; + struct metric_ref *metric_refs = NULL; metric_events = calloc(sizeof(void *), hashmap__size(&eg->pctx.ids) + 1); @@ -274,6 +276,30 @@ static int metricgroup__setup_events(struct list_head *groups, free(metric_events); break; } + + /* + * Collect and store collected nested expressions + * for metric processing. + */ + if (eg->refs_cnt) { + struct metric_ref_node *ref; + + metric_refs = zalloc(sizeof(struct metric_ref) * (eg->refs_cnt + 1)); + if (!metric_refs) { + ret = -ENOMEM; + free(metric_events); + break; + } + + i = 0; + list_for_each_entry(ref, &eg->refs, list) { + metric_refs[i].metric_name = ref->metric_name; + metric_refs[i].metric_expr = ref->metric_expr; + i++; + } + }; + + expr->metric_refs = metric_refs; expr->metric_expr = eg->metric_expr; expr->metric_name = eg->metric_name; expr->metric_unit = eg->metric_unit; diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index 8315bd1a7da4..62623a39cbec 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -18,12 +18,18 @@ struct metric_event { struct list_head head; /* list of metric_expr */ }; +struct metric_ref { + const char *metric_name; + const char *metric_expr; +}; + struct metric_expr { struct list_head nd; const char *metric_expr; const char *metric_name; const char *metric_unit; struct evsel **metric_events; + struct metric_ref *metric_refs; int runtime; }; -- 2.25.4