From nobody Thu Dec 18 22:29:59 2025 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 A4DCEC19F20 for ; Tue, 2 May 2023 22:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230186AbjEBWmO (ORCPT ); Tue, 2 May 2023 18:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230188AbjEBWl4 (ORCPT ); Tue, 2 May 2023 18:41:56 -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 8B4473A85 for ; Tue, 2 May 2023 15:41:28 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b9a7d92d0f7so7691262276.1 for ; Tue, 02 May 2023 15:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683067282; x=1685659282; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iSuig3L8R5UEDXeqP0djSS5EgyFufZhQb0rbIBIx5wU=; b=tDLYa0DQagvJ/QEPb9MjF/kNyIbrftWOqww62OA+GLPcY0iPlzA9ULd7zv3ROY9sar WqJIcorOzUgc626O10s3jw3jAjVb1lhnelGHisy/AzS9YiQbhGWMILCDsNslA7qu/XE+ B3f9unZkl+ue2Q5QZSr/nNdXW2Tx0mwZeBKtc2NjkDCz1vQVctEpZSRnQykEZnJHmVAq kDdug1BZcy8lT5cOtr2dGNG1+MixqjPC36LVFwhnWLzOgMc739di1qwHBtxtOoc1s8uG edlsXphPdjdnMdCQIY2LUJWLvwQ9xlXP3JQcelH0gfLNcg6Dq8H83iG9gwDRfVQjapaL cSjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683067282; x=1685659282; 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=iSuig3L8R5UEDXeqP0djSS5EgyFufZhQb0rbIBIx5wU=; b=j2rXOHZggmX5vt/Ofk4yzOOB/c6yOjvtYiT+8HccPVFIh48w5P8088azA8y/equ2GV DYU3mF2mRBRYDGYjysSM9gMObJJynqN7G+3EEasQM+pNnC2RsPGWSw8Q+eTJalgdr0j4 om5Y68jUXPJ6DPRCwcDQVDDo0Kv8iTxUpjez2PQSfI6CGLN+SRR4TIoccdFwTka2CQhq 96CeMRNlrOlfrvLbLBDCRfshtpFMo61xtEYRaMdMueUjuh7mqwwIZSCOEZiYArue3iRD JJnGAQhCvBblq7q5UT+mDjJDCKKwEY2Pg+q1hUAPqOhxOa/Ks5IoVCJR2UvAODKvqwBS xuWg== X-Gm-Message-State: AC+VfDxNMPiSd0m1gvVftsFTrGPOVp6oMjplko577euNq6vWdMtM5w7J OsNN5SCj+tdXQzvo7QVtmKcMfwElgWXj X-Google-Smtp-Source: ACHHUZ4Sq05iGbzmiRWZnqfkmEkdK/S23O3fX4bTPuRLUM7P1GSv/HY6a7FCp6laKk36EZyzo5FJl5vK7p6I X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:e70c:446b:d23b:982e]) (user=irogers job=sendgmr) by 2002:a25:4245:0:b0:b97:8207:443b with SMTP id p66-20020a254245000000b00b978207443bmr6892574yba.5.1683067282203; Tue, 02 May 2023 15:41:22 -0700 (PDT) Date: Tue, 2 May 2023 15:38:24 -0700 In-Reply-To: <20230502223851.2234828-1-irogers@google.com> Message-Id: <20230502223851.2234828-18-irogers@google.com> Mime-Version: 1.0 References: <20230502223851.2234828-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v4 17/44] 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 ee145cec42c0..89ac34a922c9 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -230,58 +230,60 @@ void print_sdt_events(const struct print_callbacks *p= rint_cb, void *print_state) =20 int print_hwcache_events(const struct print_callbacks *print_cb, void *pri= nt_state) { - struct strlist *evt_name_list =3D strlist__new(NULL, NULL); - struct str_node *nd; + const char *event_type_descriptor =3D event_type_descriptors[PERF_TYPE_HW= _CACHE]; =20 - if (!evt_name_list) { - pr_debug("Failed to allocate new strlist for hwcache events\n"); - return -ENOMEM; - } for (int type =3D 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { for (int op =3D 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { /* skip invalid cache type */ if (!evsel__is_cache_op_valid(type, op)) continue; =20 - for (int i =3D 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { + for (int res =3D 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) { struct perf_pmu *pmu =3D NULL; char name[64]; =20 - __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=3D*/NULL, + name, + /*event_alias=3D*/NULL, + /*scale_unit=3D*/NULL, + /*deprecated=3D*/false, + event_type_descriptor, + /*desc=3D*/NULL, + /*long_desc=3D*/NULL, + /*encoding_desc=3D*/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=3D*/NULL, + /*deprecated=3D*/false, + event_type_descriptor, + /*desc=3D*/NULL, + /*long_desc=3D*/NULL, + /*encoding_desc=3D*/NULL); } } } } } - - strlist__for_each_entry(nd, evt_name_list) { - print_cb->print_event(print_state, - "cache", - /*pmu_name=3D*/NULL, - nd->s, - /*event_alias=3D*/NULL, - /*scale_unit=3D*/NULL, - /*deprecated=3D*/false, - event_type_descriptors[PERF_TYPE_HW_CACHE], - /*desc=3D*/NULL, - /*long_desc=3D*/NULL, - /*encoding_desc=3D*/NULL); - } - strlist__delete(evt_name_list); return 0; } =20 --=20 2.40.1.495.gc816e09b53d-goog