From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA623C77B61 for ; Fri, 28 Apr 2023 07:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345666AbjD1Hl5 (ORCPT ); Fri, 28 Apr 2023 03:41:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345631AbjD1HlS (ORCPT ); Fri, 28 Apr 2023 03:41:18 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A2B44C18 for ; Fri, 28 Apr 2023 00:40:57 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b9a753ce33cso3285336276.2 for ; Fri, 28 Apr 2023 00:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682667656; x=1685259656; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vS1UrpzSlF6e1IL2Ub99FazCajkEnmAPiwupuP2N/bo=; b=WbeD55FD/AXjfAsTkDotpJL0au7iu5wE0rmKDc9KCwMs0A5eegIalBEGvnrc5duQnq 9jrm8XtiR42DnjVlcEeMIFIraQD183z2RhPsNCipdKheBRHgNQFz8kDQaDBG8TXoNCF0 WYUXeC+MhOdL+K296ehziK0/q+Q24KmsqTwj02CBH7xOREVDKGo1HBaahTqeaP5Hh4ZE ZmCX6UfkMZnSmN1P+lWah0B0fll2UZPFV14lL9e9x5/s3KfSdyfQXFiVwYx5CGE7AL5N nZLOtOsOFnTWoa31T+M6pXCT5/VBaqH26qJdVwn6mlDhj2aIaC5rNnkkcpxgcHYKpwdr Svdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682667656; x=1685259656; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vS1UrpzSlF6e1IL2Ub99FazCajkEnmAPiwupuP2N/bo=; b=aGkfi4hxHBwnENfaCpGgglNiB6Z2ZS2eaOTR/eeYRAYfuuHXk7U2CBdLWWNbSjaT3c mezzM3NQ06q5/IqSZ9v0XaGKEoc8GqH3rf5H3B9OPzepsYXWB6OXtdvL7oPIIPxe77KW xlCB7uuCEsNx0u83Vc+uCj4Wuh9H1VqN2cPSxFRb8aBj4073AZqxHR7AJX//ydrceM4p YIyHMJoE2VlNE63mbGmpQYParNxToxWVaxxxkNDth/uJN8vyvPo6AmjuTzF05bSehHD9 oXsc7nVO7eG5yWVdHMuBi8UN7NcMzfrjp9225jlYg0JD732cuM3eXZ6RMpk84EBQv6qN /76Q== X-Gm-Message-State: AC+VfDw67AKNtiY3kiGufNt8zcJYmyKbmW5zXNt+hzkP6YEaXtfQeVQz 3YR1LdyBJXjg7PJ8cPT56FtM7sIXC37K X-Google-Smtp-Source: ACHHUZ6Za4HfU3R3K1Qb+acJRn4V3kZ7LYaQH7bCLULSJ/cSWM2onAta7gj72f4iYrh9JTJnxp8bxln+moQN X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:24a7:aeb5:5de4:c29b]) (user=irogers job=sendgmr) by 2002:a05:6902:18c3:b0:b95:6b30:9752 with SMTP id ck3-20020a05690218c300b00b956b309752mr2485546ybb.12.1682667656306; Fri, 28 Apr 2023 00:40:56 -0700 (PDT) Date: Fri, 28 Apr 2023 00:37:43 -0700 In-Reply-To: <20230428073809.1803624-1-irogers@google.com> Message-Id: <20230428073809.1803624-18-irogers@google.com> Mime-Version: 1.0 References: <20230428073809.1803624-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v2 17/43] perf print-events: Avoid unnecessary strlist From: Ian Rogers To: Arnaldo Carvalho de Melo , Kan Liang , Ahmad Yasin , Peter Zijlstra , Ingo Molnar , Stephane Eranian , Andi Kleen , Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Florian Fischer , Rob Herring , Zhengjun Xing , John Garry , Kajol Jain , Sumanth Korikkar , Thomas Richter , Tiezhu Yang , Ravi Bangoria , Leo Yan , Yang Jihong , James Clark , Suzuki Poulouse , Kang Minchul , Athira Rajeev , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org The strlist in print_hwcache_events holds the event names as they are generated, and then it is iterated and printed. This is unnecessary and each event can just be printed as it is processed. Rename the variable i to res, to be more intention revealing and consistent with other code. Signed-off-by: Ian Rogers --- tools/perf/util/print-events.c | 60 ++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 386b1ab0b60e..93bbb868d400 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -226,58 +226,60 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state) int print_hwcache_events(const struct print_callbacks *print_cb, void *print_state) { - struct strlist *evt_name_list = strlist__new(NULL, NULL); - struct str_node *nd; + const char *event_type_descriptor = event_type_descriptors[PERF_TYPE_HW_CACHE]; - if (!evt_name_list) { - pr_debug("Failed to allocate new strlist for hwcache events\n"); - return -ENOMEM; - } for (int type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { for (int op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { /* skip invalid cache type */ if (!evsel__is_cache_op_valid(type, op)) continue; - for (int i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { + for (int res = 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) { struct perf_pmu *pmu = NULL; char name[64]; - __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name)); + __evsel__hw_cache_type_op_res_name(type, op, res, + name, sizeof(name)); if (!perf_pmu__has_hybrid()) { if (is_event_supported(PERF_TYPE_HW_CACHE, - type | (op << 8) | (i << 16))) - strlist__add(evt_name_list, name); + type | (op << 8) | (res << 16))) { + print_cb->print_event(print_state, + "cache", + /*pmu_name=*/NULL, + name, + /*event_alias=*/NULL, + /*scale_unit=*/NULL, + /*deprecated=*/false, + event_type_descriptor, + /*desc=*/NULL, + /*long_desc=*/NULL, + /*encoding_desc=*/NULL); + } continue; } perf_pmu__for_each_hybrid_pmu(pmu) { if (is_event_supported(PERF_TYPE_HW_CACHE, - type | (op << 8) | (i << 16) | + type | (op << 8) | (res << 16) | ((__u64)pmu->type << PERF_PMU_TYPE_SHIFT))) { char new_name[128]; - snprintf(new_name, sizeof(new_name), - "%s/%s/", pmu->name, name); - strlist__add(evt_name_list, new_name); + snprintf(new_name, sizeof(new_name), + "%s/%s/", pmu->name, name); + print_cb->print_event(print_state, + "cache", + pmu->name, + name, + new_name, + /*scale_unit=*/NULL, + /*deprecated=*/false, + event_type_descriptor, + /*desc=*/NULL, + /*long_desc=*/NULL, + /*encoding_desc=*/NULL); } } } } } - - strlist__for_each_entry(nd, evt_name_list) { - print_cb->print_event(print_state, - "cache", - /*pmu_name=*/NULL, - nd->s, - /*event_alias=*/NULL, - /*scale_unit=*/NULL, - /*deprecated=*/false, - event_type_descriptors[PERF_TYPE_HW_CACHE], - /*desc=*/NULL, - /*long_desc=*/NULL, - /*encoding_desc=*/NULL); - } - strlist__delete(evt_name_list); return 0; } -- 2.40.1.495.gc816e09b53d-goog