From nobody Mon Apr 13 17:13:48 2026 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 959A1C433FE for ; Mon, 14 Nov 2022 23:04:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238147AbiKNXEb (ORCPT ); Mon, 14 Nov 2022 18:04:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238075AbiKNXDb (ORCPT ); Mon, 14 Nov 2022 18:03:31 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C1361CFD7; Mon, 14 Nov 2022 15:02:52 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id m6so12505020pfb.0; Mon, 14 Nov 2022 15:02:52 -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=a1MFej65CJ+NfpSltvQHgaIoZB+GNGl8r1EVGrPKTcw=; b=IW59hFHwqet/9Q/o/UQ0AVw+mr0ZNMfZjssD1fodhAMyVGc2eH+XfTVtKBHHBqJb+/ 1R7WCwgfTFYpGCqd5w2+nLn7cTLdvw6SMoD5w5FIYKfZ6mMXfNliPgBDtjuUCApb+YLC 1eh6rALcUJ+GVOlGsDJ7nzr35xz1QK2ZYFEGEmA6j663ZRW4KsCqjkREJo7UYcPGrZIp b8YoHQzBRCJnYxoWs/7qGzbzcEKUcubEyBVJA/H/2B3+wlZaHeDhZbzXJMSVynlABCWi +8gBiIknECUMF4KRSZRvzdW6k4mWVMWVNWnmF8cFPM0YFHd5U7BawFF/gYJ+ZuqjT72s qeDw== 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=a1MFej65CJ+NfpSltvQHgaIoZB+GNGl8r1EVGrPKTcw=; b=c9Q865EwcUVMMB75CU14xR0t613DzzzFLR06rhTEsftCkVI7zRuM6X1XlxNe6zfR3S 38sA8BGaciHVCOlMROztB34XMauDtr0B8fkGu98TY/mbl2X4zy356m8ZD6yqYrOaoP6N X+0DWoXwp1oDv+b+8Sz3BFe/meDSl/DOy3+/fyawSvfW+V9jAaQb5WvskZVUKeOeApu2 oSlVjlTlsGzU28mIj5EYFAIknxdfEEZVO/x7cAUFVmrV8UttYPz7MDuc5SFAg62UzEOq 5nK2DYVSy2OhXUVXjC29LmaLKSFky2nyKXbRwDZQB0hjFB7xL+7NSZOLKxprfjN1nIQC ZP4Q== X-Gm-Message-State: ANoB5pkPwhqE4L/hmyHthdDIZ/1Kj7Ht1NdH+QJcG8FzwB/Wzl3QeLxJ EWKWFZ+f31r+uVx1Mx7jMmQ= X-Google-Smtp-Source: AA0mqf7AbQUxfLKKrIeLSw2aMRv8qsVKLl7ikB9tyPzfvE7g5pkbFbbjgarBMx0+lJafOWK3cUNwmw== X-Received: by 2002:aa7:956d:0:b0:56e:924e:ee22 with SMTP id x13-20020aa7956d000000b0056e924eee22mr15655339pfq.34.1668466971685; Mon, 14 Nov 2022 15:02:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:51 -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 14/19] perf stat: Rework header display Date: Mon, 14 Nov 2022 15:02:22 -0800 Message-Id: <20221114230227.1255976-15-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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There are print_header() and print_interval() to print header lines before actual counter values. Also print_metric_headers() needs to be called for the metric-only case. Let's move all these logics to a single place including num_print_iv to refresh the headers for interval mode. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 185 +++++++++++++++++++-------------- 1 file changed, 106 insertions(+), 79 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index cc8bb6d07dcb..f97817628478 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1034,94 +1034,129 @@ static void prepare_interval(struct perf_stat_conf= ig *config, ts->tv_sec, ts->tv_nsec); } =20 -static void print_interval(struct perf_stat_config *config, - struct evlist *evlist) +static void print_header_interval_std(struct perf_stat_config *config, + struct target *_target __maybe_unused, + struct evlist *evlist, + int argc __maybe_unused, + const char **argv __maybe_unused) { - bool metric_only =3D config->metric_only; - unsigned int unit_width =3D config->unit_width; FILE *output =3D config->output; - static int num_print_interval; =20 - if (config->interval_clear && isatty(fileno(output))) - puts(CONSOLE_CLEAR); + switch (config->aggr_mode) { + case AGGR_NODE: + case AGGR_SOCKET: + case AGGR_DIE: + case AGGR_CORE: + fprintf(output, "#%*s %-*s cpus", + INTERVAL_LEN - 1, "time", + aggr_header_lens[config->aggr_mode], + aggr_header_std[config->aggr_mode]); + break; + case AGGR_NONE: + fprintf(output, "#%*s %-*s", + INTERVAL_LEN - 1, "time", + aggr_header_lens[config->aggr_mode], + aggr_header_std[config->aggr_mode]); + break; + case AGGR_THREAD: + fprintf(output, "#%*s %*s-%-*s", + INTERVAL_LEN - 1, "time", + COMM_LEN, "comm", PID_LEN, "pid"); + break; + case AGGR_GLOBAL: + default: + if (!config->iostat_run) + fprintf(output, "#%*s", + INTERVAL_LEN - 1, "time"); + case AGGR_UNSET: + case AGGR_MAX: + break; + } =20 - if ((num_print_interval =3D=3D 0 || config->interval_clear) && - !config->csv_output && !config->json_output) { - switch (config->aggr_mode) { - case AGGR_NODE: - case AGGR_SOCKET: - case AGGR_DIE: - case AGGR_CORE: - fprintf(output, "#%*s %-*s cpus", - INTERVAL_LEN - 1, "time", - aggr_header_lens[config->aggr_mode], - aggr_header_std[config->aggr_mode]); - break; - case AGGR_NONE: - fprintf(output, "#%*s %-*s", - INTERVAL_LEN - 1, "time", - aggr_header_lens[config->aggr_mode], - aggr_header_std[config->aggr_mode]); - break; - case AGGR_THREAD: - fprintf(output, "#%*s %*s-%-*s", - INTERVAL_LEN - 1, "time", - COMM_LEN, "comm", PID_LEN, "pid"); - break; - case AGGR_GLOBAL: - default: - if (!config->iostat_run) - fprintf(output, "#%*s", - INTERVAL_LEN - 1, "time"); - case AGGR_UNSET: - case AGGR_MAX: - break; - } + if (config->metric_only) + print_metric_headers(config, evlist, " ", true); + else + fprintf(output, " %*s %*s events\n", + COUNTS_LEN, "counts", config->unit_width, "unit"); +} =20 - if (!metric_only) { - fprintf(output, " %*s %*s events\n", - COUNTS_LEN, "counts", unit_width, "unit"); - } - } +static void print_header_std(struct perf_stat_config *config, + struct target *_target, struct evlist *evlist, + int argc, const char **argv) +{ + FILE *output =3D config->output; + int i; + + fprintf(output, "\n"); + fprintf(output, " Performance counter stats for "); + if (_target->bpf_str) + fprintf(output, "\'BPF program(s) %s", _target->bpf_str); + else if (_target->system_wide) + fprintf(output, "\'system wide"); + else if (_target->cpu_list) + fprintf(output, "\'CPU(s) %s", _target->cpu_list); + else if (!target__has_task(_target)) { + fprintf(output, "\'%s", argv ? argv[0] : "pipe"); + for (i =3D 1; argv && (i < argc); i++) + fprintf(output, " %s", argv[i]); + } else if (_target->pid) + fprintf(output, "process id \'%s", _target->pid); + else + fprintf(output, "thread id \'%s", _target->tid); =20 - if ((num_print_interval =3D=3D 0 || config->interval_clear) && metric_onl= y) + fprintf(output, "\'"); + if (config->run_count > 1) + fprintf(output, " (%d runs)", config->run_count); + fprintf(output, ":\n\n"); + + if (config->metric_only) + print_metric_headers(config, evlist, " ", false); +} + +static void print_header_csv(struct perf_stat_config *config, + struct target *_target __maybe_unused, + struct evlist *evlist, + int argc __maybe_unused, + const char **argv __maybe_unused) +{ + if (config->metric_only) + print_metric_headers(config, evlist, " ", true); +} +static void print_header_json(struct perf_stat_config *config, + struct target *_target __maybe_unused, + struct evlist *evlist, + int argc __maybe_unused, + const char **argv __maybe_unused) +{ + if (config->metric_only) print_metric_headers(config, evlist, " ", true); - if (++num_print_interval =3D=3D 25) - num_print_interval =3D 0; } =20 static void print_header(struct perf_stat_config *config, struct target *_target, + struct evlist *evlist, int argc, const char **argv) { - FILE *output =3D config->output; - int i; + static int num_print_iv; =20 fflush(stdout); =20 - if (!config->csv_output && !config->json_output) { - fprintf(output, "\n"); - fprintf(output, " Performance counter stats for "); - if (_target->bpf_str) - fprintf(output, "\'BPF program(s) %s", _target->bpf_str); - else if (_target->system_wide) - fprintf(output, "\'system wide"); - else if (_target->cpu_list) - fprintf(output, "\'CPU(s) %s", _target->cpu_list); - else if (!target__has_task(_target)) { - fprintf(output, "\'%s", argv ? argv[0] : "pipe"); - for (i =3D 1; argv && (i < argc); i++) - fprintf(output, " %s", argv[i]); - } else if (_target->pid) - fprintf(output, "process id \'%s", _target->pid); - else - fprintf(output, "thread id \'%s", _target->tid); + if (config->interval_clear) + puts(CONSOLE_CLEAR); =20 - fprintf(output, "\'"); - if (config->run_count > 1) - fprintf(output, " (%d runs)", config->run_count); - fprintf(output, ":\n\n"); + if (num_print_iv =3D=3D 0 || config->interval_clear) { + if (config->json_output) + print_header_json(config, _target, evlist, argc, argv); + else if (config->csv_output) + print_header_csv(config, _target, evlist, argc, argv); + else if (config->interval) + print_header_interval_std(config, _target, evlist, argc, argv); + else + print_header_std(config, _target, evlist, argc, argv); } + + if (num_print_iv++ =3D=3D 25) + num_print_iv =3D 0; } =20 static int get_precision(double num) @@ -1278,18 +1313,10 @@ void evlist__print_counters(struct evlist *evlist, = struct perf_stat_config *conf if (interval) { prefix =3D buf; prepare_interval(config, prefix, ts); - print_interval(config, evlist); - } else { - print_header(config, _target, argc, argv); } =20 + print_header(config, _target, evlist, argc, argv); if (metric_only) { - static int num_print_iv; - - if (num_print_iv =3D=3D 0 && !interval) - print_metric_headers(config, evlist, prefix, false); - if (num_print_iv++ =3D=3D 25) - num_print_iv =3D 0; if (config->aggr_mode =3D=3D AGGR_GLOBAL && prefix && !config->iostat_ru= n) fprintf(config->output, "%s", prefix); } --=20 2.38.1.493.g58b659f92b-goog