From patchwork Sat Nov 12 03:22:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 19087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1089384wru; Fri, 11 Nov 2022 19:23:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf6MvfLUe93W6gWXjlV8VG8NEonhanDqSKsGtTVH1575jBVG2fj/e30MP8aTibQPXwl/P5K3 X-Received: by 2002:a17:906:6d4:b0:7ad:bd02:f491 with SMTP id v20-20020a17090606d400b007adbd02f491mr4226226ejb.703.1668223422347; Fri, 11 Nov 2022 19:23:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668223422; cv=none; d=google.com; s=arc-20160816; b=HjT0JHeEuRnXHItRml192c7e2IItTEIDGgKhHdYNobNBflR3m2MchCldhJYndYEQtf MbLOgIC1aMbwB349j0AXbRUrANvImdiXgts1uS6kSfAexNLGrKAkZnfAwT6Zv4ab3+X8 efLo54Rra8IHSkg9GCyldZdpPwGep00Edoh4NHWkl9WOfqoV5W5WKgLS68pQFp84Gj27 UHjZ9kl/2EuoK01s42pJusbafbQwRTKpUG047YalLgFgJz3NUE2OQ4P9uGBdApypEt7Q 98HeT6lfZz3y8/mA/dxiELg1ic46QpzC1u/hC1YwFY8snR8ck/6r+qI2JjcFuYvo6cVZ +0ZA== 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:sender :dkim-signature; bh=UcoM9akctXagDD4pJeclGlmLvOUIRQorPmWBAJ2dUvo=; b=aTy76VBojMlgYsttwElODG/MaLo0Dsn2E0sOwsvOgyE9TYxpLx9vezhEdJS+OyGdAm 46C5JmXvGicXbc4He3TbSjLsjfPDHvy6eFhO+Emj71MP67SbkNJKR7RgC5BoIpqFDWDA ZpWRF4v1kXgdTDybq6IWQ1K7J7YR47M0/iFvCIE0xv0vGzwCLt2sDtTrCMY15xP6Yp6i PmRnAmFtpOQ7NDRlfHBU18jCuki69DwxCE2Xqsz0ZqJ107MmOpgAYd+Oj+OncAcwf+GH Cu0ZvqXeqx3SsRrJoc3ccueZjv/7OGE+VGiAPhD/T7Iv59JMxN2debd4d1gjQE887KY4 XiQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NYGDRsGb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb17-20020a170907785100b007ae1e519db0si2755114ejc.220.2022.11.11.19.23.17; Fri, 11 Nov 2022 19:23:42 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=NYGDRsGb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234311AbiKLDW4 (ORCPT + 99 others); Fri, 11 Nov 2022 22:22:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbiKLDWw (ORCPT ); Fri, 11 Nov 2022 22:22:52 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A37BF6A747; Fri, 11 Nov 2022 19:22:51 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id c2so5666325plz.11; Fri, 11 Nov 2022 19:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=UcoM9akctXagDD4pJeclGlmLvOUIRQorPmWBAJ2dUvo=; b=NYGDRsGbezN7aCIRSJJau2ba0Fvlx5Y2SsEQH/7FJLRpyZrqRbuvEBaAyVtRaRlN5D EbwIOV4v+EdwQvy/CbAzTS86jTv+Bb2F52Ez0MPM1l5w1VJR7vlOOyqp0VZrhhBls2RP XafUHId5pxu7VsHQESMceuyRL32Bc4pmzgv43BrU8aKYBplRT1vIVEM3hRiitsmrDyX6 EJr7/ONsFtZBEgXCIuQ3YO6z0gCZGZGcFb5GS4+QKf0Q/IbJUc6yGnMXkLNfbmAs4xn4 +jEnPPdt0o/qh4EmFOpfWLKv+l72QT2IZ+qoAA3Bk+oaX05m/1kfyL2uRvXvqBqrnJAW wKuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UcoM9akctXagDD4pJeclGlmLvOUIRQorPmWBAJ2dUvo=; b=SfZBP6s6X66lLIgqWEWTurld6VCmOVNL+tifpyAuIHVrmxny8Hca5iSGz9gj9JgXOj 0wEk2+JQXyIgdyQnAUfdZ+f/nqfp7lwolXFHf0TgUnqsvg9bwwtVxMKpB3W/Ua9GQAqn G/KDIoO+xqOXx/GLGNHI9aZVxBMBLdFPGVZwRl6h8T9OREZsro7PFdyM8LPKMxLW+uN6 5utLGUNgmeE+blD6dgZsQ2yMFepTPmH9K/WiD8TfXfGaWH09qFdg4ecqpcVVu7pEoYsM Dd9OJNj4V4jyCLe+pttlqrSrmt11kQx+N08PAckgdPw2NxdJYMytPq3w1ABRgFJqtJ98 sVCw== X-Gm-Message-State: ANoB5pm/fBDpPtFV0cEnGkrKfirTCWKT1Jg55b2cvjZYpfC/0rzJFQKq NXywUpOveSojg/fzzU5XLhI= X-Received: by 2002:a17:902:d191:b0:186:c483:f017 with SMTP id m17-20020a170902d19100b00186c483f017mr5332657plb.136.1668223371117; Fri, 11 Nov 2022 19:22:51 -0800 (PST) Received: from balhae.roam.corp.google.com ([2607:fb90:27dc:8408:33d7:3b01:eee1:84b]) by smtp.gmail.com with ESMTPSA id ij25-20020a170902ab5900b00186f0f59d1esm2434552plb.192.2022.11.11.19.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 19:22:50 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 02/11] perf stat: Move common code in print_metric_headers() Date: Fri, 11 Nov 2022 19:22:35 -0800 Message-Id: <20221112032244.1077370-3-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog In-Reply-To: <20221112032244.1077370-1-namhyung@kernel.org> References: <20221112032244.1077370-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749259043330116297?= X-GMAIL-MSGID: =?utf-8?q?1749259043330116297?= The struct perf_stat_output_ctx is set in a loop with the same values. Move the code out of the loop and keep the loop minimal. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ea41e6308c50..c7b3a1e10263 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -837,11 +837,16 @@ static void print_metric_headers(struct perf_stat_config *config, struct evlist *evlist, const char *prefix, bool no_indent) { - struct perf_stat_output_ctx out; struct evsel *counter; struct outstate os = { .fh = config->output }; + struct perf_stat_output_ctx out = { + .ctx = &os, + .print_metric = print_metric_header, + .new_line = new_line_metric, + .force_header = true, + }; bool first = true; if (config->json_output && !config->interval) @@ -865,13 +870,11 @@ static void print_metric_headers(struct perf_stat_config *config, /* Print metrics headers only */ evlist__for_each_entry(evlist, counter) { os.evsel = counter; - out.ctx = &os; - out.print_metric = print_metric_header; + if (!first && config->json_output) fprintf(config->output, ", "); first = false; - out.new_line = new_line_metric; - out.force_header = true; + perf_stat__print_shadow_stats(config, counter, 0, 0, &out,