Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1078551rdh; Mon, 25 Sep 2023 02:34:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEaIKAQ0oXnnAIiWwC+8QJ2VG/sQe/J8hiXU4nUBJcTwl+1u9MuN3CcaYuK9g0xKOz+5DTT X-Received: by 2002:a17:902:ec83:b0:1c6:19da:b29f with SMTP id x3-20020a170902ec8300b001c619dab29fmr1722787plg.26.1695634447329; Mon, 25 Sep 2023 02:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695634447; cv=none; d=google.com; s=arc-20160816; b=GbsZ/MJzhJnt9RvxVqbToKMCyNsEL6fmIFiUxgBrgtZQGIVleG6xqEUVbPQqF5LOfo UibcHXEtHY/7+lJCdak6c+RxH20Wpc+pZRrjBiGsex06Vvxr9o2620S+Ap+KJ3OKcur6 jLseaCAVTmWc/3+FIoCfj2FDzKwSm1F2Iuzh1gVOXFpUM1JWxydVoxYjkHj0MU4l4W40 sd91YhFNlDFHZkPWblPc3SB/8u60374j2v9qEvJYU+9vwQhd5S1gL9jBfXtMmkZuCtig zC6me/I2TwTu2jO0s76+BAjfKJmSD1OWjrndKTn+wnKA42SzhTxBOmhRGVpb++5B16MS eXdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WclF+q5Ix6jr6+qn/CQ/Ht8lIciiJAUDT/u/Lelzu1Y=; fh=aicQXd2sVDKynU70/92qv+8AnsPgYK5pq7fTzS41MP4=; b=0WlY3hxd8xIRmoOjG7vYr7ZONwBlY1+Z76V2/+znvp5f4Y9uB0haczjz9pSZ8ScpsA XrRUCCGafnf7k+OYDdOHQVU87UlyJ1oKFwXVtZYPjoX9yPnPmGuzH1Wn7adgR6A4Lkiv q8s/F+UE7nVpil9VOsKyoZrSpRiDvn6uCB7l49HCvTS4cbrro+HWXDvVeD1aN03DSFQx zEgjlXMqJWv20TadBNmKsWz3Z0r57lcslYzPEjF/du6tX2DEYIBNw47w+k7HboR8ga5X 2CfmL106kODR+2+37PXRk2I4dAwz/ZUnMILA3t3w9xDVBcjnUiAHlzT+G9Vl774cSW1g mRUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Dkyf/Uqa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id k8-20020a170902c40800b001bbd0450af8si3847362plk.187.2023.09.25.02.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 02:34:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Dkyf/Uqa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8018182A3994; Sun, 24 Sep 2023 23:20:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232238AbjIYGUn (ORCPT + 99 others); Mon, 25 Sep 2023 02:20:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232134AbjIYGUN (ORCPT ); Mon, 25 Sep 2023 02:20:13 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE498CE2; Sun, 24 Sep 2023 23:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695622800; x=1727158800; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8OgQ64b/TdsjITSk6A0hKAfVN037oU4CWECgJVayCew=; b=Dkyf/Uqa19xX9g7pGnKEIOt1J4Q581fqPMZTjNNXmiaI5ndrHLyF828g D/Df+qSEFvxIDx77heBQTiW4lnghQwIkdpPoxfPHZOl4nT7wBz7gKARBU wqDHdibRrNKibS0y6iC/LP0pCQyv7GwdkFJrwaBTNaDf+oJFUG41bsdq9 l+E+oQApSMH6b3Mf1QA2I+Pqws7ebDhvcLQ1zHqTJow+sPz+z3J/XUWRk Om/30r4GXcDPV+JL0WS0tn8Vv8iNFhU1gBgkE+uhPD/UMufMRaSJDdtuM fTqbU7cfOaj75Ine0JqQwEJh4wBC+bkGztJtVZiy+McqG1tYmInCQvc6+ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="445279472" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="445279472" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2023 23:19:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="818494372" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="818494372" Received: from b49691a75598.jf.intel.com ([10.54.34.22]) by fmsmga004.fm.intel.com with ESMTP; 24 Sep 2023 23:19:18 -0700 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland Subject: [RFC PATCH 13/25] perf stat: Add functions to hardware-grouping method Date: Sun, 24 Sep 2023 23:18:12 -0700 Message-Id: <20230925061824.3818631-14-weilin.wang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230925061824.3818631-1-weilin.wang@intel.com> References: <20230925061824.3818631-1-weilin.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 23:20:56 -0700 (PDT) From: Weilin Wang Add functions to free all the group lists before exit metric grouping Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 39 ++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8d54e71bf..4b1b0470d 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1528,6 +1528,38 @@ static int parse_counter(const char *counter, return 0; } +static void group_event_list_free(struct metricgroup__group *groups) +{ + struct metricgroup__group_events *e, *tmp; + + list_for_each_entry_safe (e, tmp, &groups->event_head, nd) { + list_del_init(&e->nd); + free(e); + } +} + +static void group_list_free(struct metricgroup__pmu_group_list *groups) +{ + struct metricgroup__group *g, *tmp; + + list_for_each_entry_safe (g, tmp, &groups->group_head, nd) { + list_del_init(&g->nd); + group_event_list_free(g); + free(g); + } +} + +static void metricgroup__free_group_list(struct list_head *groups) +{ + struct metricgroup__pmu_group_list *g, *tmp; + + list_for_each_entry_safe (g, tmp, groups, nd) { + list_del_init(&g->nd); + group_list_free(g); + free(g); + } +} + static void metricgroup__free_event_info(struct list_head *event_info_list) { @@ -1845,6 +1877,8 @@ static int assign_event_grouping(struct metricgroup__event_info *e, struct metricgroup__pmu_counters *p; pmu_group_head = malloc(sizeof(struct metricgroup__pmu_group_list)); + if (!pmu_group_head) + return -ENOMEM; INIT_LIST_HEAD(&pmu_group_head->group_head); pr_debug("create new group for event %s in pmu %s\n", e->name, e->pmu_name); pmu_group_head->pmu_name = e->pmu_name; @@ -1886,8 +1920,11 @@ static int create_grouping(struct list_head *pmu_info_list, pr_debug("Event name %s, [pmu]=%s, [counters]=%s\n", e->name, e->pmu_name, bit_buf); ret = assign_event_grouping(e, pmu_info_list, &groups); + if (ret) + goto out; } - +out: + metricgroup__free_group_list(&groups); return ret; }; -- 2.39.3