Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp377898rwr; Wed, 26 Apr 2023 00:07:53 -0700 (PDT) X-Google-Smtp-Source: AKy350ZjMMlNoVXe/jeK1UrFer56FgqWIUU4NYOq4EcWO/Fb3g89LdYjXow5V1DG6zz1J9UATtds X-Received: by 2002:a17:90a:6acd:b0:247:1233:9b28 with SMTP id b13-20020a17090a6acd00b0024712339b28mr19071539pjm.17.1682492873439; Wed, 26 Apr 2023 00:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682492873; cv=none; d=google.com; s=arc-20160816; b=kP5AFzPmPH9NKODs0ZDv9Z7sHlNs1FKUCXB/q+7GKqO/6IHvY3kJ0YIeF/4CHT2UEk Yopb3CZOEra58p0H4CZFI5o+/PbfISVdwccm4D1HHXmVQvrTbOykCE+ABqVdzxIWCY6I Di+ZcU7qSwmCW9REe/MDl8ZkFkJZUsapowpcyO8wV4FT4B7usKheee+f4TqQYJqO972y UOZuCciE4Qvvjm1WCKfPwkVLDA4QnWzdLQJ0UR7AF/GiFMO7bxNuT3DbGwPvNdvaeRZk 2ccEJpfj/NrGREj/dFEuFlq7BxgAXv/SBLg+kykqOmcxUpCBlwrwQZQ2fM1OKkFdTo63 0Phw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=vS1UrpzSlF6e1IL2Ub99FazCajkEnmAPiwupuP2N/bo=; b=v26TruLmGhqlwUxFknxGg+6eNxz58QyrrbUQIpx2hBWQifibxHCb1lrqFsYqBq6wm6 Vx4Rr71MiVN8GaGQb9mRB5VmeVxlhWLU5+j9uBbOZbOnFEdZEZ8fRpzJ708ab/W6Ycxh pZAgQwpwSaUIR32WPAFlqwAm2Eh66FMqmDKsL264uxTWoxwIuyBG4q/073nXF6f3Ugc2 Vshf/QT7rNHFwqWQo7/CT1kMeGCF+zB+9bPmeIn4NSjmssGOpaoGhX1U0mOXGo7Yi7dl IkyAHRrU6VpThDKy01VNquXTnKOTOghzjZUnQFv2UA8VI/MUQEKqwCybmEM4ghyMDONc PaZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ejl0TCvV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb18-20020a17090b009200b0024666c4e8d8si17925600pjb.187.2023.04.26.00.07.40; Wed, 26 Apr 2023 00:07:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ejl0TCvV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239808AbjDZHEY (ORCPT + 99 others); Wed, 26 Apr 2023 03:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239816AbjDZHDu (ORCPT ); Wed, 26 Apr 2023 03:03:50 -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 9051B2118 for ; Wed, 26 Apr 2023 00:02:54 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b8f32cc8c31so11548913276.2 for ; Wed, 26 Apr 2023 00:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682492572; x=1685084572; 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=ejl0TCvV5fpMBxQn6WqDGfZmntPZib49H9wwWIPY8XFs7yfIwv8VwQ3QfS9YkPh1Og Px/WsHDSFMAKLq0fu2yxkSXbsUp4Ql4Bl9FVt72SAHbzurVY8/RpHLa+tFankZ3yImQA MPvRtS4fkqN2e47S13HaP2shRTAgERnbtvKla0n97C1iw+1nZsSRGTj4j/dpa+jEh4as q0G3jPvQRXR9OsIYv2fqQyrtAFFsnrTrZQhnIglG925H1VRHYoL+e0a6+xFjhVNPZnLI 1P+ByINBI07ddf4Q5q72dVEANE2KAl7OggePqrQa4MaVuc3Ic12+iGhgY4ldmajnQOIV 3/Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682492572; x=1685084572; 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=Q0mlPz6i0WL8jg8hmnPEiR2ukT7k0yxtWKeoPw/3WGX9vwdbczreB0J3Zl7M78Igzn /kdnkQNl+NBVFRyKXnncY1i6MSzSRr0wTHUwpPBEMZiJsrmFAk+OClnnumhX1YDGOV7s SSpRDsomW7hIfJXRH7AHbBp4/iwvgQffd8QrCzDVWiXpM2pCbdgXHHGE83nY5Tglygi0 LRi0MC5KT5TpqKByN1aIKHGsp/eWwDnF+ejij1tWRZXMhk4pbukZtCZVISta1AV7X3Cd 5Q0IM8Q3yJqXkN7QRiLlXFkeeinPEKxVlzAL2ahvTxEhQNZEkVE/wecRMtI0MaoZsrQy AzQQ== X-Gm-Message-State: AAQBX9eovP8qHiwf5eNMNEjARR+EqBNq2nrKLgahsxJxTCjfQfpSK9B7 Ra8ASR2BkAqRDG5gxaRB5eNOJyFikneL X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:144f:e890:2b29:48d9]) (user=irogers job=sendgmr) by 2002:a25:734e:0:b0:b99:4877:99e4 with SMTP id o75-20020a25734e000000b00b99487799e4mr6072621ybc.11.1682492572229; Wed, 26 Apr 2023 00:02:52 -0700 (PDT) Date: Wed, 26 Apr 2023 00:00:24 -0700 In-Reply-To: <20230426070050.1315519-1-irogers@google.com> Message-Id: <20230426070050.1315519-15-irogers@google.com> Mime-Version: 1.0 References: <20230426070050.1315519-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v1 14/40] 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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 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