From patchwork Mon Nov 14 23:02:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409595wru; Mon, 14 Nov 2022 15:07:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Ef8JiVp1AiGxeRZj2zQQ6AU9t38t4L2jYmG/lqf+7SQFXkEIhVFimXkOYScTE6Qwr7amE X-Received: by 2002:a63:4621:0:b0:470:79cb:6c5b with SMTP id t33-20020a634621000000b0047079cb6c5bmr13823197pga.130.1668467246038; Mon, 14 Nov 2022 15:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467246; cv=none; d=google.com; s=arc-20160816; b=bkAIyv07dFl0OcSZtCLyFgcVjm3lUpxLkDPPVzFDt31javRjXF4eorUpqwlfee/o8Q OsULLEHkTy5G6Ieuxf64euo5USlfHaUW/3IlWtr3Ert+hJVrckGh/uCoYW6nlFGwG6XD 6yjoq8w2alx9dsq1zwtGu/8S6+zm1+AOURUjDT4vMmzkM95szB3p3Q26GOvsrBeJHbbB UL7utzkv3vbyrN0GJ4oAinZQJKAZ7yeC45CSs5/M87m5VvScj4oTF+FwMdK80edUb/ok /QQT5j1P7MlUrIo0+yYFMK/h8Ezr6m3tK6Z3CMTLR8ysGk4mSZZErDU0XqQZxWKxpJw1 fgCw== 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=QUGjDewK+aO2x22NgTca81ezePEJqtKcnqIInofdYc0=; b=05zmKEzQBnafWc9qTYMRkM+ziqyhaqOemQxkFBABy3odLrj1LirlSsEGDM/AEy0C/R 9IhyruA69WpREY2e3XkbaRb0hC+dfRnGYK3lk06BOecjxBvsSvpGjXJ5gRU+irGB9WOZ JmX9NoZaU5bLo4Pdxm/nYaBUlCAcHizILk0nvw3JBoW0Xm3rp3r8N5FeCQ5F3bziTU/C YzKuUoV3sgErE0C+3rm1HkUQ4RwtzHMJ5Avn65Bz/xN2lCzh3AqYf5Fcvs2clITrlnQO WW3/IFhPu9okGNdAIGb2+ljfToW2b08bQlTYu08nunGa+x51DyuINh7r78BtnMlVJn8F F4KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Nu1quPwZ; 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 e11-20020a63db0b000000b0046ff4e3a5d4si10185468pgg.260.2022.11.14.15.07.09; Mon, 14 Nov 2022 15:07:26 -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=Nu1quPwZ; 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 S238158AbiKNXEf (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238016AbiKNXDf (ORCPT ); Mon, 14 Nov 2022 18:03:35 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447811D0CD; Mon, 14 Nov 2022 15:02:55 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id p21so11501317plr.7; Mon, 14 Nov 2022 15:02:55 -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=QUGjDewK+aO2x22NgTca81ezePEJqtKcnqIInofdYc0=; b=Nu1quPwZo1yskrgF1eihnt838Q1iJxTsfR0lpStvoCZMAAgPmUIgVkd1k1KcgLgAkr f21vl7mchsZgmLpmX0aduzqWhm4RT+0+VLzULdPpqBDFrNv/BI2jbKD/+klBga6OChVG qCBTd/hkERzdD3v40/UCAxekt5ZTWI2TecbhyDNEumYwGGHG/5+86TZSjF+K02ZHHJmU d1eLy3HMcawQkybqryqw2gwg2Ajd35BoXbWZo84bv2ewx7OPzQfllhVD0tbqB1BxjQY8 jiq2qCq3WmRpFclNN5CApsOjI7BzeLLQMvm3KvBRP1WHu8rerOHZHU4T3/kIXsST9del NuSw== 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=QUGjDewK+aO2x22NgTca81ezePEJqtKcnqIInofdYc0=; b=CM33V1ezY/lifA+gH4la0V7cw1NrRNfHjQP5VUGtbW7f9oRyP8UsxGDpbTSxXmUpqv 7zdeyF9AyFhh+b3cJoYuMiXGwkmRKdZ5P79v9uVCvyBnwTmJ7iM9xhT8HOQFY7e0UVUA OzRME6s4V59F285zpAPGNpn8KUMZacgKV5hs0k+nhNpLt6E38Wtcobdspxcee8/CRo3y ALWY0mk3d9R+ZI7v6YpqUW+rFnUAiDFUUmizfKBOVI9FOluJ58XgCy7n0L2qPSy/UZBC /KYjKxkqyC9bIGXQg2x/5+r4CdJtNVe6n3RkU9woiXzgOS8TVCnLx0ExA6gmCIKO/4t+ QdmQ== X-Gm-Message-State: ANoB5pm0u0BdV3MfP+HAntsVSxlSNn4pNZf3xlP3EsBVXMgB8sD/HoMz yM3un6uHYb/zjmNUMlUq8G5Gpsno8bU= X-Received: by 2002:a17:90a:4003:b0:212:deef:a087 with SMTP id u3-20020a17090a400300b00212deefa087mr15837374pjc.77.1668466974859; Mon, 14 Nov 2022 15:02:54 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:a80:cf9f:e038:c19b:797e]) by smtp.gmail.com with ESMTPSA id 132-20020a62148a000000b0056c814a501dsm7534724pfu.10.2022.11.14.15.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:54 -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 , Athira Jajeev Subject: [PATCH 16/19] perf stat: Factor out prefix display Date: Mon, 14 Nov 2022 15:02:24 -0800 Message-Id: <20221114230227.1255976-17-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog In-Reply-To: <20221114230227.1255976-1-namhyung@kernel.org> References: <20221114230227.1255976-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 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?1749514710843168131?= X-GMAIL-MSGID: =?utf-8?q?1749514710843168131?= The prefix is needed for interval mode to print timestamp at the beginning of each line. But the it's tricky for the metric only mode since it doesn't print every evsel and combines the metrics into a single line. So it needed to pass 'first' argument to print_counter_aggrdata() to determine if the current event is being printed at first. This makes the code hard to read. Let's move the logic out of the function and do it in the outer print loop. This would enable further cleanups later. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 43 ++++++++++++---------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 73cf898060c0..bb40ed29300d 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -805,8 +805,7 @@ static void uniquify_counter(struct perf_stat_config *config, struct evsel *coun static void print_counter_aggrdata(struct perf_stat_config *config, struct evsel *counter, int s, - char *prefix, bool metric_only, - bool *first) + char *prefix, bool metric_only) { FILE *output = config->output; u64 ena, run, val; @@ -825,10 +824,6 @@ static void print_counter_aggrdata(struct perf_stat_config *config, ena = aggr->counts.ena; run = aggr->counts.run; - if (*first && metric_only) { - *first = false; - aggr_printout(config, counter, id, aggr->nr); - } if (prefix && !metric_only) fprintf(output, "%s", prefix); @@ -849,7 +844,6 @@ static void print_aggr(struct perf_stat_config *config, FILE *output = config->output; struct evsel *counter; int s; - bool first; if (!config->aggr_map || !config->aggr_get_id) return; @@ -860,21 +854,23 @@ static void print_aggr(struct perf_stat_config *config, */ for (s = 0; s < config->aggr_map->nr; s++) { if (metric_only) { + struct perf_stat_aggr *aggr; + struct aggr_cpu_id id = config->aggr_map->map[s]; + if (prefix) fprintf(output, "%s", prefix); - else if (config->summary && !config->no_csv_summary && - config->csv_output && !config->interval) - fprintf(output, "%16s%s", "summary", config->csv_sep); + + counter = evlist__first(evlist); + aggr = &counter->stats->aggr[s]; + aggr_printout(config, counter, id, aggr->nr); } - first = true; evlist__for_each_entry(evlist, counter) { if (counter->merged_stat) continue; - print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first); + print_counter_aggrdata(config, counter, s, prefix, + metric_only); } if (metric_only) fputc('\n', output); @@ -885,7 +881,6 @@ static void print_counter(struct perf_stat_config *config, struct evsel *counter, char *prefix) { bool metric_only = config->metric_only; - bool first = false; int s; /* AGGR_THREAD doesn't have config->aggr_get_id */ @@ -896,9 +891,8 @@ static void print_counter(struct perf_stat_config *config, return; for (s = 0; s < config->aggr_map->nr; s++) { - print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first); + print_counter_aggrdata(config, counter, s, prefix, + metric_only); } } @@ -1260,7 +1254,6 @@ static void print_percore(struct perf_stat_config *config, FILE *output = config->output; struct cpu_aggr_map *core_map; int s, c, i; - bool first = true; if (!config->aggr_map || !config->aggr_get_id) return; @@ -1288,11 +1281,7 @@ static void print_percore(struct perf_stat_config *config, if (found) continue; - if (prefix && metric_only) - fprintf(output, "%s", prefix); - - print_counter_aggrdata(config, counter, s, - prefix, metric_only, &first); + print_counter_aggrdata(config, counter, s, prefix, metric_only); core_map->map[c++] = core_id; } @@ -1319,10 +1308,6 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf } print_header(config, _target, evlist, argc, argv); - if (metric_only) { - if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run) - fprintf(config->output, "%s", prefix); - } switch (config->aggr_mode) { case AGGR_CORE: @@ -1337,6 +1322,8 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf iostat_print_counters(evlist, config, ts, prefix = buf, print_counter); else { + if (prefix && metric_only) + fprintf(config->output, "%s", prefix); evlist__for_each_entry(evlist, counter) { print_counter(config, counter, prefix); }