From patchwork Mon Nov 14 23:02:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409327wru; Mon, 14 Nov 2022 15:06:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Idh84/WFBiSqnzMbKp3P9F4raIB6U/w9yRiKlyTArT3DS/OfiqovmI+maMvrVEXyX8g6h X-Received: by 2002:a17:903:445:b0:186:95ca:1e4c with SMTP id iw5-20020a170903044500b0018695ca1e4cmr1431982plb.13.1668467210675; Mon, 14 Nov 2022 15:06:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467210; cv=none; d=google.com; s=arc-20160816; b=A8ekzReDUAwzyq74AKZKNBN3Srt/TLh2Xrx/0KOhDYf0x9yQdK9uOtWpDGhmpHM8tS yLmKBo9y4ZVPkfDEk/F92DMZpTGuW1riRlU1idxORWcr/j0o8vN9qJBtBySOba3NfJM3 403FJh2nK8V07KnuLndEFWiFYaTwCck6oQJsRAEDnEqGF5hVsnBsEXSPsN571xblRepS E2aTtubJrxjlrL25KYxqtquXgNOU7rrd9m9xJqq/qdsPB+k1+sSVdnSfFCAd4qOeNJmh E6C0xRk+wEKtTxtYXz83foS+MBXwwsBdr/gbBcL8bkWdzioZqCDRGU7Mp4bpfs9VYytE /24A== 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=a1MFej65CJ+NfpSltvQHgaIoZB+GNGl8r1EVGrPKTcw=; b=nhpCQlCxDbMgPHP1enOhkgjuJGhoA0AL+AkVlHSPPy50PwUDJt7UEu1gx6ey5+7g28 OxUDgvGMDazrQJ9OTseaIBcHMAXDdiivq6kZvz8Sh/g5a9RVueJ6oMTRh6q1BqEsJVud iQZM2iK3ZqTn9q39VlUuaXyZriC4LoNOgSLTvN0ngWqVJznT2/KT9SWM5vZjT9az3Ooc qlwbqu86Fu9cGTPlSu1r1O0rZHS94Xa9QIHAaXYmBRe18nTuIguW4ixXenfEqFnUorTf I2pNK8L2kO8qZ8v+9s0p2vOXkLMq5ClDhl9kFob9VkU2mUlXXIW8oersEVXkAO2JVJZv vuSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IW59hFHw; 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 n13-20020a170902d2cd00b001865c55049dsi12245869plc.570.2022.11.14.15.06.32; Mon, 14 Nov 2022 15:06:50 -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=IW59hFHw; 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 S238092AbiKNXEa (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:30 -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-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 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?1749514673667645499?= X-GMAIL-MSGID: =?utf-8?q?1749514673667645499?= 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_config *config, ts->tv_sec, ts->tv_nsec); } -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 = config->metric_only; - unsigned int unit_width = config->unit_width; FILE *output = config->output; - static int num_print_interval; - 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; + } - if ((num_print_interval == 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"); +} - 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 = 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 = 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 ((num_print_interval == 0 || config->interval_clear) && metric_only) + 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 == 25) - num_print_interval = 0; } static void print_header(struct perf_stat_config *config, struct target *_target, + struct evlist *evlist, int argc, const char **argv) { - FILE *output = config->output; - int i; + static int num_print_iv; fflush(stdout); - 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 = 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); - fprintf(output, "\'"); - if (config->run_count > 1) - fprintf(output, " (%d runs)", config->run_count); - fprintf(output, ":\n\n"); + if (num_print_iv == 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++ == 25) + num_print_iv = 0; } 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 = buf; prepare_interval(config, prefix, ts); - print_interval(config, evlist); - } else { - print_header(config, _target, argc, argv); } + print_header(config, _target, evlist, argc, argv); if (metric_only) { - static int num_print_iv; - - if (num_print_iv == 0 && !interval) - print_metric_headers(config, evlist, prefix, false); - if (num_print_iv++ == 25) - num_print_iv = 0; if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run) fprintf(config->output, "%s", prefix); }