Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4367252rdh; Tue, 28 Nov 2023 22:03:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpn5idhJ2TKke1ARhyVcs1iwZBrw/rvkTaQAngXHlQirEeJFQLdhaFOBqrN19V2YAVw/So X-Received: by 2002:a05:6870:f14c:b0:1fa:a78b:cfd2 with SMTP id l12-20020a056870f14c00b001faa78bcfd2mr375886oac.50.1701237812661; Tue, 28 Nov 2023 22:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701237812; cv=none; d=google.com; s=arc-20160816; b=XO/DfxHeP8krnyCUaniGraZWCZFQUBOMgXiRvaZLImT8P+Eb3VjkzBQeKAV9MzV+UR znxjZpgaVm/pmGwjufto3M6GJ+AR4ghZATdBtxaPjb8ePPHQyI7VOsMBfkQuM6Y/4jcN YxOWtayzCqLRVRT9oW0g7IN+UQUM2W/reQbrjzzF3YLnLQJcolMw6cPo5XYLCMnrKHVj XhBwySaA4YIBJSGvS7kuyT6B2AXvEJmFOHLJZH/+VJXGM3MM7Bxnr1exVucYj1Yvcax6 qHMiIE/53GSH2CuA5r0+dx7vEeH4xdszTl6dHRDODCQ9beUd8K3FEkIB3jurLFaRyvtT Etkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=LT6pUkq6nOZyulqCEeWY4llreF+FWbGDdI1GlLo0K+Y=; fh=uYKNI4aCUAMYZ/8oQVBIse94GgoxWIIZr1zaTbrWG7c=; b=P+K2oGY1r1JmCOoTcBrjHDcPhnAThlO892/mMEkH1SZBtyW44OyOgSagRmwRg+AXG8 M6mxgRqpW2G7RSlbTR9GcBh+MCqKTkN8GT/Vsbf2/Kjwn2cA6UM28l1GpFt7PmNLN429 PXqBuaEtl27BZXT7KkruNRWKk8YUiJACfdlAeU70GyU3/66P9hndpbvQCbKWEuHhWzsy zANxz9KWjeq9Kkw9mNM9g8DNYp65Zq6ViCHZSlV5jOAc8LnK7nUsb6PnMD9kriguVtsP WDv2OyzzdqRm0ROKtmF4cgRx1iIdUWHk0oHSx/lr3+VoKvDVQqj1WDKOS/bEPxuh/lCl tlfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3sI5pIGv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id fj6-20020a056a003a0600b006cb8abd39d3si13881404pfb.180.2023.11.28.22.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 22:03:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3sI5pIGv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id F008080481BA; Tue, 28 Nov 2023 22:03:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377083AbjK2GC4 (ORCPT + 99 others); Wed, 29 Nov 2023 01:02:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376999AbjK2GCf (ORCPT ); Wed, 29 Nov 2023 01:02:35 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B363C19B0 for ; Tue, 28 Nov 2023 22:02:39 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d0c4ba7081so38045587b3.0 for ; Tue, 28 Nov 2023 22:02:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701237759; x=1701842559; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LT6pUkq6nOZyulqCEeWY4llreF+FWbGDdI1GlLo0K+Y=; b=3sI5pIGvs/fAI6Opb6EAFgnk3xrzuTRPcS9vxNKmuSZNIyPTDZC0jOo3c14GBriIXC Q2RnZlK7OaUe1ia7sa3p1SNKl3gSeuMuWPsaDE9xjqcGmD3OwrHAdkM+yhzhWNCMvmkR 9gpQWR6Z+ESxHMpgRoxvi+XFHtqQsCZXpPKGdxoBbDMZGf6BBCaJHa5bL57ZVbO8tcY0 D7OfQgQbecbOXAbOwEmskBN9GUiVn04u50jx44iSqT+yt8+p1/Uvqh+dlwlc20AgS3SE /Kr6+ObDr7si897Ss5wEV6AE1jvv6y7YPJLoUHq7vfkGvjB9nhRPcT2ljWrRsjl05tRN SjKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701237759; x=1701842559; h=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=LT6pUkq6nOZyulqCEeWY4llreF+FWbGDdI1GlLo0K+Y=; b=Ac7lAWER3YLvdz0NJSVi9hpyiQpSmXOnKOsOMa1JHGbywRhq7f/zHTzsackp3zTFqk byj+44b49MsrKwQYBOEKA6V5uGmlIB2T9+Oytqg1G+9wMfoprucFMtdIEL8b5Z8+KtoA r863AeT/WoHyiIR+L2WTBUe/D8xaS7bmRWhHbWD1JNI7BUcVDcOTlTFSkK9oZI7LgTx+ yVt56U7q+zAKxdnvCkcCVK7BqvztC9RSAL0E9BJzDnabS7wvsfWT/A9wITRzO+qD+fCg DuyR5qy6LGiiBfuhPtmEHhlENQHbDhaIYj0cCRjhMXTv6thNZyghGb2PPuuMVaPVo+s7 CJ6Q== X-Gm-Message-State: AOJu0YycuRKUpSlA1FyxSx9lANsMnA3iee/XLq1UIZkKshJ0lnpdhv1O dSsvsNxXNBfr+e072D1uRizb6MRzPXmm X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:763b:80fa:23ca:96f8]) (user=irogers job=sendgmr) by 2002:a81:9b10:0:b0:5ca:5fcd:7063 with SMTP id s16-20020a819b10000000b005ca5fcd7063mr598732ywg.3.1701237758929; Tue, 28 Nov 2023 22:02:38 -0800 (PST) Date: Tue, 28 Nov 2023 22:02:07 -0800 In-Reply-To: <20231129060211.1890454-1-irogers@google.com> Message-Id: <20231129060211.1890454-11-irogers@google.com> Mime-Version: 1.0 References: <20231129060211.1890454-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v1 10/14] perf top: Avoid repeated function calls From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 28 Nov 2023 22:03:30 -0800 (PST) Add a local variable to avoid repeated calls to perf_cpu_map__nr. Signed-off-by: Ian Rogers --- tools/perf/util/top.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c index be7157de0451..4db3d1bd686c 100644 --- a/tools/perf/util/top.c +++ b/tools/perf/util/top.c @@ -28,6 +28,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) struct record_opts *opts = &top->record_opts; struct target *target = &opts->target; size_t ret = 0; + int nr_cpus; if (top->samples) { samples_per_sec = top->samples / top->delay_secs; @@ -93,19 +94,17 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) else ret += SNPRINTF(bf + ret, size - ret, " (all"); + nr_cpus = perf_cpu_map__nr(top->evlist->core.user_requested_cpus); if (target->cpu_list) ret += SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)", - perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 - ? "s" : "", + nr_cpus > 1 ? "s" : "", target->cpu_list); else { if (target->tid) ret += SNPRINTF(bf + ret, size - ret, ")"); else ret += SNPRINTF(bf + ret, size - ret, ", %d CPU%s)", - perf_cpu_map__nr(top->evlist->core.user_requested_cpus), - perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 - ? "s" : ""); + nr_cpus, nr_cpus > 1 ? "s" : ""); } perf_top__reset_sample_counters(top); -- 2.43.0.rc1.413.gea7ed67945-goog