From nobody Mon Apr 13 15:52:28 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 EC902C4332F for ; Mon, 14 Nov 2022 23:03:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237963AbiKNXDA (ORCPT ); Mon, 14 Nov 2022 18:03:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237867AbiKNXCc (ORCPT ); Mon, 14 Nov 2022 18:02:32 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C0EF1B7B5; Mon, 14 Nov 2022 15:02:32 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id io19so11492230plb.8; Mon, 14 Nov 2022 15:02:32 -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=rt0OZoaxk4oNSiXVua0yf4Wn8zR1kll8hc9QqXyH+pA=; b=jcCl/FyxwF3w7YMSk3Qw/Vq3k7ny8Me1VSIXUCAQy0kPHz04yRm68l9gT56RqRB7s3 gK8a7gbS0ZDoygeaAfUqQopGM/82KP1s6SScgdXGARymg+iDxMU5JtpKZOtx5IzkxFjK WfWTQnf88m4QF2Y0pRJQKDWSwwdKvML/JgXrXTz9EikSAav+lDT0ZurpRK37CCWZLzSd lG4GPJCdbdfn+3P5T+cmKS2npifOuuag0uwI4HQHxjjY8iTd0I1MeFcrmWtqDi5ipaNP gPtvdjPcx0L4/5hb6cegUBmRe/6thNB3On6+9C3T84Exn79BE4YEcFRTPyy45tRF6A8B dOHA== 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=rt0OZoaxk4oNSiXVua0yf4Wn8zR1kll8hc9QqXyH+pA=; b=AuQsUcCaWh88OGf31fpw/33a2j2dkGJcC+IyXqBnFMzGGc15Q32X3t4V084fpcCMSe ym6bazRh0CeRpyOptCL64jTsNOTcoW4MCL7u0YrXwb+SI9BLwmjAamvNVypu/kXxdCj3 UluJ4CLnYnjApYJZ5tO5nPF4k/GmldN2v/RWgkra47DT6/mUEP5mnETdowqyG70Jh8Ea X5hkHUy88VHD4u0Pm200DsR9JTZB7T6S0lq7/iVZE7gtRJajvs6AgL2Fw7W984SPIhrU M5qwkKu93ybk3GI4nIkIpkQvCwib8FN4IzAqCzgmJLRy3ULi8uIPbwJ43eYJ09sKZGM+ qTIw== X-Gm-Message-State: ANoB5pkfozXy2LZ/xdcWy/v/AUs1Y4aeeAj1e9n35BJyzRaTGHK1DgEE GyG7jdC5XTqqSNTMUk5kUQs= X-Google-Smtp-Source: AA0mqf7qaTM0zSR6kESEG1Y3F7PoqZE0/2XaKfu/q+kfsI5i/AA12NePc4QMCb/czDt8bGfbFWbhVg== X-Received: by 2002:a17:902:be13:b0:186:748f:e8c5 with SMTP id r19-20020a170902be1300b00186748fe8c5mr1358372pls.73.1668466951601; Mon, 14 Nov 2022 15:02:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:31 -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 01/19] perf stat: Clear screen only if output file is a tty Date: Mon, 14 Nov 2022 15:02:09 -0800 Message-Id: <20221114230227.1255976-2-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" The --interval-clear option makes perf stat to clear the terminal at each interval. But it doesn't need to clear the screen when it saves to a file. Make it fail when it's enabled with the output options. $ perf stat -I 1 --interval-clear -o myfile true --interval-clear does not work with output Usage: perf stat [] [] -o, --output output file name --log-fd log output to fd, instead of stderr --interval-clear clear screen in between new interval Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d5e1670bca20..1d79801f4e84 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2403,6 +2403,14 @@ int cmd_stat(int argc, const char **argv) } } =20 + if (stat_config.interval_clear && !isatty(fileno(output))) { + fprintf(stderr, "--interval-clear does not work with output\n"); + parse_options_usage(stat_usage, stat_options, "o", 1); + parse_options_usage(NULL, stat_options, "log-fd", 0); + parse_options_usage(NULL, stat_options, "interval-clear", 0); + return -1; + } + stat_config.output =3D output; =20 /* --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 85D45C4332F for ; Mon, 14 Nov 2022 23:03:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237983AbiKNXDE (ORCPT ); Mon, 14 Nov 2022 18:03:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237878AbiKNXCg (ORCPT ); Mon, 14 Nov 2022 18:02:36 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96E861B9C0; Mon, 14 Nov 2022 15:02:33 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id w23so5069001ply.12; Mon, 14 Nov 2022 15:02:33 -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=g9gVgzaugGBijq/uNgO/XLVSIa4Ghp/O4hPteTZwehU=; b=P8ggZH5FleD5Kv20TgngyEO98qnMIP+IsgWyIAedDwGn9PltGQOruty/I/EBflF9jY Y9aAWqJGxZ6sYB/SEl+gL4P753EPvL+bZd2ZG2uWnEHn9GSH8nezaQ/1rJJeMjR9T91S K91fp0aQN/6P8jV8qiuaqS6vqfU3ODpplDsCgKJu/3zYjBWxIqa+310hRfF+hDGIYv2E OEMVFoY95QIowZI04HJaFiQ7ixcLAgPKGj1crbjaUUN211lBL0y2ZlJT3ZdaLvqrEM1P HOLZYpkKRhZZLjYY7KuYHKzlcaigqUeDzJzq2xm/VRPvZc5Tsmc0i5nFx74APmrLeRoi KSjQ== 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=g9gVgzaugGBijq/uNgO/XLVSIa4Ghp/O4hPteTZwehU=; b=CdmM80VIuA/zy0NsrWqAnyKenwrBS+ryRwn4E1gshzCkTQRndZeo60R8cn7OkmUW/m CZDHLcMXG9djTtFbmGB2Ex6XAJc4wUMXGSgOkM+RMhgCF8/ynUrcAi4p4pqPcikWFUk7 RQEY6ym1g3hKGpiKeXpa1zLL1WMqxi7kohGnVecNVvMlUsDS9WVLl9HF6O759P1TyywR D/CAheNCkWIP2x5SL683Hi9PLhDcHim3rbT3FoeHaLvIKvQbZAg4Rt2EcvKOPkWe7yu3 utDTLC6VoAHZPLhla14uSkR0ZVBqOG0221rmylxWQ4btwe4tf3PD59k5QmCqaTdgdmME nwHQ== X-Gm-Message-State: ANoB5pksApLHw4rzxGgJ5a5pdU9vD4JAh583bwbHIiDwk+CVhZN7ACXW EplVbBR6P1uXqjiR5CZiivA= X-Google-Smtp-Source: AA0mqf64F2Fj3Bopi8BvuDD2bkX3oy8KcRyoLZlIeOj49Xu6dyfm61qDLkDodFQ9wyIE5xiIRR9jHA== X-Received: by 2002:a17:90a:fa11:b0:212:6a0b:7d55 with SMTP id cm17-20020a17090afa1100b002126a0b7d55mr15484594pjb.16.1668466953078; Mon, 14 Nov 2022 15:02:33 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:32 -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 02/19] perf stat: Split print_running() function Date: Mon, 14 Nov 2022 15:02:10 -0800 Message-Id: <20221114230227.1255976-3-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" To make the code more obvious and hopefully simpler, factor out the code for each output mode - stdio, CSV, JSON. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 37 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 2a3c1e0098b9..281b811f8574 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -25,24 +25,41 @@ #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" =20 -static void print_running(struct perf_stat_config *config, - u64 run, u64 ena) +static void print_running_std(struct perf_stat_config *config, u64 run, u6= 4 ena) +{ + if (run !=3D ena) + fprintf(config->output, " (%.2f%%)", 100.0 * run / ena); +} + +static void print_running_csv(struct perf_stat_config *config, u64 run, u6= 4 ena) { + double enabled_percent =3D 100; + + if (run !=3D ena) + enabled_percent =3D 100 * run / ena; + fprintf(config->output, "%s%" PRIu64 "%s%.2f", + config->csv_sep, run, config->csv_sep, enabled_percent); +} =20 +static void print_running_json(struct perf_stat_config *config, u64 run, u= 64 ena) +{ double enabled_percent =3D 100; =20 if (run !=3D ena) enabled_percent =3D 100 * run / ena; + fprintf(config->output, "\"event-runtime\" : %" PRIu64 ", \"pcnt-running\= " : %.2f, ", + run, enabled_percent); +} + +static void print_running(struct perf_stat_config *config, + u64 run, u64 ena) +{ if (config->json_output) - fprintf(config->output, - "\"event-runtime\" : %" PRIu64 ", \"pcnt-running\" : %.2f, ", - run, enabled_percent); + print_running_json(config, run, ena); else if (config->csv_output) - fprintf(config->output, - "%s%" PRIu64 "%s%.2f", config->csv_sep, - run, config->csv_sep, enabled_percent); - else if (run !=3D ena) - fprintf(config->output, " (%.2f%%)", 100.0 * run / ena); + print_running_csv(config, run, ena); + else + print_running_std(config, run, ena); } =20 static void print_noise_pct(struct perf_stat_config *config, --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 B436DC4332F for ; Mon, 14 Nov 2022 23:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238003AbiKNXDL (ORCPT ); Mon, 14 Nov 2022 18:03:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237885AbiKNXCi (ORCPT ); Mon, 14 Nov 2022 18:02:38 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39E9A1BE88; Mon, 14 Nov 2022 15:02:35 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id 6so11574808pgm.6; Mon, 14 Nov 2022 15:02:35 -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=mLjySvlGPKnVQ41FH3ZyjLNiZRwop922hNhTc7oubmw=; b=FaZabm5DuOJ6hbUuo766RDOgcgo+o1/sjEMrbcLhz4lgO60PfZOSeQsv/uyZZeNGLp EvRuZ2zhPm7Nrcrvl1v6cCUtBw1np5SvUWPBvalBi8pX5RrMI4jORhKZ2z264EvbOqxa EYvnyGHmiVUOTOISIRVqEJ5GqpoauJabnPWNYHVa5o6pj7sbgX0ANgmz60x3I5Z1YPoM 95OnMYnisQii8xJQ5UDcXi7fMBs9L15T83Ri22X77SBThVFJ9q6D9iH3AlJfq80y2s3w 2vttHGPNs+IqEpUHuC3aP5qtINeLHOMRq9ga8tKwyRufIlOJe7Euk+kR2Kr6I1XmFPxh CeDA== 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=mLjySvlGPKnVQ41FH3ZyjLNiZRwop922hNhTc7oubmw=; b=3o0zkLHzcQX2QclwK01TeSUlaHAS2VLXs+dgNU6pzYi5Ajj7bXBhJTLiOJXXrPgPhb Bb5Rnt8jt5M0UlndRFtyK0sakr04fh4f2KG2gABe4QRmY2VQqgosCPTc/rgfM9zxTizF K20eXL+xpY4yTHDj4Zg3fPoH1PnPJy2UiHZvwb475d+YyvbIQjY3gArF5U3bZr3xyvTt Pz7D/GusU5JChaU/UE/Bsw8yrMHAjGW7fZSB2yoyxdYS/+NbF5LiQmHie0PwgVK/bnFa OE4OE9Wmb0ZxWvWyinzKHJYiAVpUGLf2iTtAi5rCxy5hN/ivGdZhoyaElsewRKMnKBGz 7hKA== X-Gm-Message-State: ANoB5plB8TQZCe/4rSV83dVCNqy0mLaKW4RNqOU87d4uDivFREOcVXLQ dTA6535Hd14m5DIpUkZnPm4= X-Google-Smtp-Source: AA0mqf7Bu1Oc5MTf/iTmHgxsalOIz/2Ge//af4EOwZTu0AWWWH3MT1vIpcU2O+zuvhuVFPqJPqDPMA== X-Received: by 2002:a63:2243:0:b0:457:f843:ffcd with SMTP id t3-20020a632243000000b00457f843ffcdmr13400685pgm.101.1668466954619; Mon, 14 Nov 2022 15:02:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:34 -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 03/19] perf stat: Split print_noise_pct() function Date: Mon, 14 Nov 2022 15:02:11 -0800 Message-Id: <20221114230227.1255976-4-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" Likewise, split print_noise_pct() for each output mode. Although it's a tiny function, more logic will be added soon so it'd be better split it and treat it in the same way. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 281b811f8574..a230f65efa62 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -62,17 +62,36 @@ static void print_running(struct perf_stat_config *conf= ig, print_running_std(config, run, ena); } =20 +static void print_noise_pct_std(struct perf_stat_config *config, + double pct) +{ + if (pct) + fprintf(config->output, " ( +-%6.2f%% )", pct); +} + +static void print_noise_pct_csv(struct perf_stat_config *config, + double pct) +{ + fprintf(config->output, "%s%.2f%%", config->csv_sep, pct); +} + +static void print_noise_pct_json(struct perf_stat_config *config, + double pct) +{ + fprintf(config->output, "\"variance\" : %.2f, ", pct); +} + static void print_noise_pct(struct perf_stat_config *config, double total, double avg) { double pct =3D rel_stddev_stats(total, avg); =20 if (config->json_output) - fprintf(config->output, "\"variance\" : %.2f, ", pct); + print_noise_pct_json(config, pct); else if (config->csv_output) - fprintf(config->output, "%s%.2f%%", config->csv_sep, pct); - else if (pct) - fprintf(config->output, " ( +-%6.2f%% )", pct); + print_noise_pct_csv(config, pct); + else + print_noise_pct_std(config, pct); } =20 static void print_noise(struct perf_stat_config *config, --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 7227DC4332F for ; Mon, 14 Nov 2022 23:03:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238012AbiKNXDQ (ORCPT ); Mon, 14 Nov 2022 18:03:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237904AbiKNXCo (ORCPT ); Mon, 14 Nov 2022 18:02:44 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9975519025; Mon, 14 Nov 2022 15:02:36 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id 62so3234502pgb.13; Mon, 14 Nov 2022 15:02:36 -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=nd5GkeCeE0yxKOMovgVohdgD8iFx/xVnrv4/oHPrZuI=; b=R9Jluqc3uYSYzKHR1fx/DQAfhMUewFc9fiC60GFBxnsjXYZkyw27kmZxriO1IPJEyG 4e+CztJ/pkBanz8uQhHc5ZYf3wPQb+H+NfCf5EXu/ZYroj3hs5NM9BaXzsl74zxFuo6P QUEw43FDRea5+HjJG0Jcj4Hvk5D7McLUPVRo9n0t78TfDN3OtQa8DWIetDNZJn5FvqQw z6MjJhqvXl2W4ZG1ORqTp6VDgzllTvfeDP56yHVB09PiL+b57k2cJ31Alr0srHUTCrnZ gdB4DbQYSq3CSECBSNk2MxLkogktK+VOSo8R+zvEQdFIPdPNTOCmcwRTwTFJ+2eBvbr8 gSvA== 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=nd5GkeCeE0yxKOMovgVohdgD8iFx/xVnrv4/oHPrZuI=; b=fz+8AvgpflIzVwencr46DblQV5RF4HKFpBYASRGhNYo45MthjTgnJLyOJ3Imbzxbje Bz1WbDyxIWet23c7xoeNLAPK39g6gT/y8pZ1gAAyUOGKM1qRWjkMyZltX7DfF3bq0Xkb QGjbrr7558MYaTUXVyiGFPlyy2zTzXpIHnEL7wUC3mK4j3lBBD/bReQ6jLs9813ppyU5 hm891Uw+HObcyqO0F121MAn6spW+ch1Ep5id4evubM+mmPpFlusgjz8ii2n6ZTT5RNwS n7+21LmnjYE9rF15nzDBrJ+IDLDr6i9tpHgd1tEXyXLan0bpJ+rvQHXYxX65SPCek+YF G5oQ== X-Gm-Message-State: ANoB5plBcDihdRWkT/sOSDr0pGdyVRVkO08NZ1Ojatk4giaxwJIYB/PT SNT7spFELdJDgkpRRswya1LvC/aZ99g= X-Google-Smtp-Source: AA0mqf7OP9dojr16cGBTHkCZ+Hv6y6Eosc1LsmryTspfVc5G6F5LDBkolGXcJQAgMZoJBnas3JvU9w== X-Received: by 2002:a63:ce04:0:b0:46b:2493:14ad with SMTP id y4-20020a63ce04000000b0046b249314admr13671274pgf.274.1668466956065; Mon, 14 Nov 2022 15:02:36 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:35 -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 04/19] perf stat: Split print_cgroup() function Date: Mon, 14 Nov 2022 15:02:12 -0800 Message-Id: <20221114230227.1255976-5-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" Likewise, split print_cgroup() for each output mode. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index a230f65efa62..af2a561eb20c 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -106,15 +106,32 @@ static void print_noise(struct perf_stat_config *conf= ig, print_noise_pct(config, stddev_stats(&ps->res_stats), avg); } =20 +static void print_cgroup_std(struct perf_stat_config *config, const char *= cgrp_name) +{ + fprintf(config->output, " %s", cgrp_name); +} + +static void print_cgroup_csv(struct perf_stat_config *config, const char *= cgrp_name) +{ + fprintf(config->output, "%s%s", config->csv_sep, cgrp_name); +} + +static void print_cgroup_json(struct perf_stat_config *config, const char = *cgrp_name) +{ + fprintf(config->output, "\"cgroup\" : \"%s\", ", cgrp_name); +} + static void print_cgroup(struct perf_stat_config *config, struct evsel *ev= sel) { if (nr_cgroups) { const char *cgrp_name =3D evsel->cgrp ? evsel->cgrp->name : ""; =20 if (config->json_output) - fprintf(config->output, "\"cgroup\" : \"%s\", ", cgrp_name); + print_cgroup_json(config, cgrp_name); + if (config->csv_output) + print_cgroup_csv(config, cgrp_name); else - fprintf(config->output, "%s%s", config->csv_sep, cgrp_name); + print_cgroup_std(config, cgrp_name); } } =20 --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 184A4C433FE for ; Mon, 14 Nov 2022 23:03:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237976AbiKNXD3 (ORCPT ); Mon, 14 Nov 2022 18:03:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237882AbiKNXDA (ORCPT ); Mon, 14 Nov 2022 18:03:00 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C67D1BEB7; Mon, 14 Nov 2022 15:02:38 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id r18so11564306pgr.12; Mon, 14 Nov 2022 15:02:38 -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=YQA2ZacCoh/AZvzO4JvdY6xJYRgMztnwPe0iUU1Auf8=; b=YkO4x0Bw9IlbNI4xkAxR7I7V+we8MKO3/m8fpQwL+jO7uua/DLgZ71nEjrtOdR4qqW mRsLCi5tU7C3ZtFHyQ86It9WodsRsqljaFIfPbSbZEUxKVXKTSHVpqbC/i5irvrAvpzv rI602hCFVJWBzDVWnUdyf3yesVdSAeu6igM/m6eNgsK3QATy/sRL3ATAkQR+9NiXXkiT oqimadSmxNHbipGIVuCGQCJpIjUmn+0sc1VZJjwxQS8YPbwsj8dlZbuISpf/xAzCHci/ Ydy9n3gD+3FGMmpX5Hbgri/kCAZG88cwOntzENde8WKK+POOKTxTwJ09p7P3hFjqNpBJ X13g== 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=YQA2ZacCoh/AZvzO4JvdY6xJYRgMztnwPe0iUU1Auf8=; b=qLaQ3q1T/BwICn3gC5hdmTSqgb6BTeuqY4Kv7urV7YiNbFPOtvzUMlXBcjF2HVkw3p GMOibQ1pnHnvJlnYtHU4VDNRBllQ3krwyCZ0feLSNJxrzd2WXyrk741dX8iClFGGEfAI XBTGdh2hYkdvz0QL5RF5HBbThO91wRyZW0SwRcQFrdhqraxTJowcWlwr2YQggFWXH0r3 yocyztJvV/pXc/rLFea/yy6iFgodic3wbl6LGn0GVl7spbOuJDQx6tylbZJ+Tz1vCdTn Vkw9+unaEuMtHaBbR9DUIthNkRyKZJ85eEf+zUCrgFrCRb0W8TL5m94dLXGD848B73/t yhXA== X-Gm-Message-State: ANoB5pnirEeo4ftcFUkUNQADu2naMshyUsX2ERqe8aDjJUaCDv3z5PNa lVLJ8HKEZYJfdT6x83pFgLE= X-Google-Smtp-Source: AA0mqf6vLnDzZtFdVVTWyDbkPHKbkW1bMRe3169tDO+quo29tD6Asfa3m4uoCHIPSjbyzSkxS3FfRA== X-Received: by 2002:a63:c51:0:b0:475:7677:fa7f with SMTP id 17-20020a630c51000000b004757677fa7fmr11336058pgm.598.1668466957570; Mon, 14 Nov 2022 15:02:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:37 -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 05/19] perf stat: Split aggr_printout() function Date: Mon, 14 Nov 2022 15:02:13 -0800 Message-Id: <20221114230227.1255976-6-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" The aggr_printout() function is to print aggr_id and count (nr). Split it for each output mode to simplify the code. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 220 ++++++++++++++++++--------------- 1 file changed, 121 insertions(+), 99 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index af2a561eb20c..ed421f6d512f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -135,124 +135,135 @@ static void print_cgroup(struct perf_stat_config *c= onfig, struct evsel *evsel) } } =20 - -static void aggr_printout(struct perf_stat_config *config, - struct evsel *evsel, struct aggr_cpu_id id, int nr) +static void print_aggr_id_std(struct perf_stat_config *config, + struct evsel *evsel, struct aggr_cpu_id id, int nr) { + FILE *output =3D config->output; =20 + switch (config->aggr_mode) { + case AGGR_CORE: + fprintf(output, "S%d-D%d-C%*d %*d ", + id.socket, id.die, -8, id.core, 4, nr); + break; + case AGGR_DIE: + fprintf(output, "S%d-D%*d %*d ", + id.socket, -8, id.die, 4, nr); + break; + case AGGR_SOCKET: + fprintf(output, "S%*d %*d ", + -5, id.socket, 4, nr); + break; + case AGGR_NODE: + fprintf(output, "N%*d %*d ", + -5, id.node, 4, nr); + break; + case AGGR_NONE: + if (evsel->percore && !config->percore_show_thread) { + fprintf(output, "S%d-D%d-C%*d ", + id.socket, id.die, -3, id.core); + } else if (id.cpu.cpu > -1) { + fprintf(output, "CPU%*d ", + -7, id.cpu.cpu); + } + break; + case AGGR_THREAD: + fprintf(output, "%*s-%*d ", + 16, perf_thread_map__comm(evsel->core.threads, id.thread_idx), + -8, perf_thread_map__pid(evsel->core.threads, id.thread_idx)); + break; + case AGGR_GLOBAL: + case AGGR_UNSET: + case AGGR_MAX: + default: + break; + } +} =20 - if (config->json_output && !config->interval) - fprintf(config->output, "{"); +static void print_aggr_id_csv(struct perf_stat_config *config, + struct evsel *evsel, struct aggr_cpu_id id, int nr) +{ + FILE *output =3D config->output; + const char *sep =3D config->csv_sep; =20 switch (config->aggr_mode) { case AGGR_CORE: - if (config->json_output) { - fprintf(config->output, - "\"core\" : \"S%d-D%d-C%d\", \"aggregate-number\" : %d, ", - id.socket, - id.die, - id.core, - nr); - } else { - fprintf(config->output, "S%d-D%d-C%*d%s%*d%s", - id.socket, - id.die, - config->csv_output ? 0 : -8, - id.core, - config->csv_sep, - config->csv_output ? 0 : 4, - nr, - config->csv_sep); - } + fprintf(output, "S%d-D%d-C%d%s%d%s", + id.socket, id.die, id.core, sep, nr, sep); break; case AGGR_DIE: - if (config->json_output) { - fprintf(config->output, - "\"die\" : \"S%d-D%d\", \"aggregate-number\" : %d, ", - id.socket, - id.die, - nr); - } else { - fprintf(config->output, "S%d-D%*d%s%*d%s", - id.socket, - config->csv_output ? 0 : -8, - id.die, - config->csv_sep, - config->csv_output ? 0 : 4, - nr, - config->csv_sep); - } + fprintf(output, "S%d-D%d%s%d%s", + id.socket, id.die, sep, nr, sep); break; case AGGR_SOCKET: - if (config->json_output) { - fprintf(config->output, - "\"socket\" : \"S%d\", \"aggregate-number\" : %d, ", - id.socket, - nr); - } else { - fprintf(config->output, "S%*d%s%*d%s", - config->csv_output ? 0 : -5, - id.socket, - config->csv_sep, - config->csv_output ? 0 : 4, - nr, - config->csv_sep); - } + fprintf(output, "S%d%s%d%s", + id.socket, sep, nr, sep); break; case AGGR_NODE: - if (config->json_output) { - fprintf(config->output, "\"node\" : \"N%d\", \"aggregate-number\" : %d,= ", - id.node, - nr); - } else { - fprintf(config->output, "N%*d%s%*d%s", - config->csv_output ? 0 : -5, - id.node, - config->csv_sep, - config->csv_output ? 0 : 4, - nr, - config->csv_sep); - } + fprintf(output, "N%d%s%d%s", + id.node, sep, nr, sep); break; case AGGR_NONE: - if (config->json_output) { - if (evsel->percore && !config->percore_show_thread) { - fprintf(config->output, "\"core\" : \"S%d-D%d-C%d\"", - id.socket, - id.die, - id.core); - } else if (id.cpu.cpu > -1) { - fprintf(config->output, "\"cpu\" : \"%d\", ", - id.cpu.cpu); - } - } else { - if (evsel->percore && !config->percore_show_thread) { - fprintf(config->output, "S%d-D%d-C%*d%s", - id.socket, - id.die, - config->csv_output ? 0 : -3, - id.core, config->csv_sep); - } else if (id.cpu.cpu > -1) { - fprintf(config->output, "CPU%*d%s", - config->csv_output ? 0 : -7, - id.cpu.cpu, config->csv_sep); - } + if (evsel->percore && !config->percore_show_thread) { + fprintf(output, "S%d-D%d-C%d%s", + id.socket, id.die, id.core, sep); + } else if (id.cpu.cpu > -1) { + fprintf(output, "CPU%d%s", + id.cpu.cpu, sep); } break; case AGGR_THREAD: - if (config->json_output) { - fprintf(config->output, "\"thread\" : \"%s-%d\", ", - perf_thread_map__comm(evsel->core.threads, id.thread_idx), - perf_thread_map__pid(evsel->core.threads, id.thread_idx)); - } else { - fprintf(config->output, "%*s-%*d%s", - config->csv_output ? 0 : 16, - perf_thread_map__comm(evsel->core.threads, id.thread_idx), - config->csv_output ? 0 : -8, - perf_thread_map__pid(evsel->core.threads, id.thread_idx), - config->csv_sep); + fprintf(output, "%s-%d%s", + perf_thread_map__comm(evsel->core.threads, id.thread_idx), + perf_thread_map__pid(evsel->core.threads, id.thread_idx), + sep); + break; + case AGGR_GLOBAL: + case AGGR_UNSET: + case AGGR_MAX: + default: + break; + } +} + +static void print_aggr_id_json(struct perf_stat_config *config, + struct evsel *evsel, struct aggr_cpu_id id, int nr) +{ + FILE *output =3D config->output; + + if (!config->interval) + fputc('{', output); + + switch (config->aggr_mode) { + case AGGR_CORE: + fprintf(output, "\"core\" : \"S%d-D%d-C%d\", \"aggregate-number\" : %d, = ", + id.socket, id.die, id.core, nr); + break; + case AGGR_DIE: + fprintf(output, "\"die\" : \"S%d-D%d\", \"aggregate-number\" : %d, ", + id.socket, id.die, nr); + break; + case AGGR_SOCKET: + fprintf(output, "\"socket\" : \"S%d\", \"aggregate-number\" : %d, ", + id.socket, nr); + break; + case AGGR_NODE: + fprintf(output, "\"node\" : \"N%d\", \"aggregate-number\" : %d, ", + id.node, nr); + break; + case AGGR_NONE: + if (evsel->percore && !config->percore_show_thread) { + fprintf(output, "\"core\" : \"S%d-D%d-C%d\"", + id.socket, id.die, id.core); + } else if (id.cpu.cpu > -1) { + fprintf(output, "\"cpu\" : \"%d\", ", + id.cpu.cpu); } break; + case AGGR_THREAD: + fprintf(output, "\"thread\" : \"%s-%d\", ", + perf_thread_map__comm(evsel->core.threads, id.thread_idx), + perf_thread_map__pid(evsel->core.threads, id.thread_idx)); + break; case AGGR_GLOBAL: case AGGR_UNSET: case AGGR_MAX: @@ -261,6 +272,17 @@ static void aggr_printout(struct perf_stat_config *con= fig, } } =20 +static void aggr_printout(struct perf_stat_config *config, + struct evsel *evsel, struct aggr_cpu_id id, int nr) +{ + if (config->json_output) + print_aggr_id_json(config, evsel, id, nr); + else if (config->csv_output) + print_aggr_id_csv(config, evsel, id, nr); + else + print_aggr_id_std(config, evsel, id, nr); +} + struct outstate { FILE *fh; bool newline; --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 96592C4332F for ; Mon, 14 Nov 2022 23:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238094AbiKNXDe (ORCPT ); Mon, 14 Nov 2022 18:03:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237980AbiKNXDE (ORCPT ); Mon, 14 Nov 2022 18:03:04 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368211C10E; Mon, 14 Nov 2022 15:02:39 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id f3so5166342pgc.2; Mon, 14 Nov 2022 15:02:39 -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=gWTJCUMMuG2d3heYPVKFPEFB7/flVbDDi20CjhO794s=; b=R9u8RjqhVZWOBpKgyOUL5+DiZvnxa6VpfFHjCrqW/mCfnsIqkvsKjce/wZVvuP2p+u 3jAfi4UxZEWCYB8W8t3/3yC7uJFfRz6TBJgiT4Gsu4jfbwfY9AoIxiSk2DDkjBVIKqxn qRpx3N9JHrAwtOKePCTQY3zQX3OzUB/Vj7qPayR1WatwKytaDj/drmvIiF22gSb/KSHt 3mmNMpKiTcc3+g3b4OX5HWCVPPiiiX1FchwDFten3nEjGwPl0EWRkVyjIGaFF1UMK6jn lVlSAe9rYNom0hN2gljFgq7hhAJKgkNZRRLOftUdAPe0Yze98IeODkH6fbRDLFQ+K5a1 1zcA== 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=gWTJCUMMuG2d3heYPVKFPEFB7/flVbDDi20CjhO794s=; b=Q0E/59KShW9MYovlEfkAXGYq9u2pz+C7C2OtTtw27z4jDuAD1VZ1bpqwhsskafHKQT 2DnRiPSz2KWeZ+lFFYb8pkwnsvq3nhSWrM8TlDQe+RhEE6duguLTyWWYu7kXQDzhh50A 4ebOz7llap7CDHb9O9WRlUwfp1nfFjLVcXlgExdpUncNTxSJT3up6JyTcaVzA06t88S2 U+0eFV5Wm5oTpIhjRDUFTW8mgeMX7mg2bc+vmFFFes53ES2F8hXPJ4ebvJxVdNNKbyw+ yF0B0v6RvkmVjCBJtCNU+Z0EQ6QtgEdsbkg8cGJCA56aOiSjwmfR73gjvGLZ+kMdyN8z RXFw== X-Gm-Message-State: ANoB5pl3MECrfCFL1OIMzgCWMlbH8HNT86freVXIwqw8o7qJJAwIiN9o bMUnmYJZn9BWFwWXgOoKtmQ= X-Google-Smtp-Source: AA0mqf7KIRLjR6xF9YgSGRHmvxg7MWHFTFXgYnNLBMSEKgVR8VlWsqPhpMptr2yALWML2G+t1NsyBQ== X-Received: by 2002:a63:1b54:0:b0:476:a08b:b106 with SMTP id b20-20020a631b54000000b00476a08bb106mr2765184pgm.77.1668466959061; Mon, 14 Nov 2022 15:02:39 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:38 -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 06/19] perf stat: Factor out print_counter_value() function Date: Mon, 14 Nov 2022 15:02:14 -0800 Message-Id: <20221114230227.1255976-7-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" And split it for each output mode like others. I believe it makes the code simpler and more intuitive. Now abs_printout() becomes just to call sub-functions. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 81 ++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ed421f6d512f..a72c7442ff3d 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -517,46 +517,71 @@ static void print_metric_header(struct perf_stat_conf= ig *config, fprintf(os->fh, "%*s ", config->metric_only_len, unit); } =20 -static void abs_printout(struct perf_stat_config *config, - struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg) +static void print_counter_value_std(struct perf_stat_config *config, + struct evsel *evsel, double avg) { FILE *output =3D config->output; double sc =3D evsel->scale; const char *fmt; =20 - if (config->csv_output) { - fmt =3D floor(sc) !=3D sc ? "%.2f%s" : "%.0f%s"; - } else { - if (config->big_num) - fmt =3D floor(sc) !=3D sc ? "%'18.2f%s" : "%'18.0f%s"; - else - fmt =3D floor(sc) !=3D sc ? "%18.2f%s" : "%18.0f%s"; - } + if (config->big_num) + fmt =3D floor(sc) !=3D sc ? "%'18.2f " : "%'18.0f "; + else + fmt =3D floor(sc) !=3D sc ? "%18.2f " : "%18.0f "; =20 - aggr_printout(config, evsel, id, nr); + fprintf(output, fmt, avg); =20 - if (config->json_output) - fprintf(output, "\"counter-value\" : \"%f\", ", avg); - else - fprintf(output, fmt, avg, config->csv_sep); + if (evsel->unit) + fprintf(output, "%-*s ", config->unit_width, evsel->unit); =20 - if (config->json_output) { - if (evsel->unit) { - fprintf(output, "\"unit\" : \"%s\", ", - evsel->unit); - } - } else { - if (evsel->unit) - fprintf(output, "%-*s%s", - config->csv_output ? 0 : config->unit_width, - evsel->unit, config->csv_sep); - } + fprintf(output, "%-*s", 32, evsel__name(evsel)); +} =20 +static void print_counter_value_csv(struct perf_stat_config *config, + struct evsel *evsel, double avg) +{ + FILE *output =3D config->output; + double sc =3D evsel->scale; + const char *sep =3D config->csv_sep; + const char *fmt =3D floor(sc) !=3D sc ? "%.2f%s" : "%.0f%s"; + + fprintf(output, fmt, avg, sep); + + if (evsel->unit) + fprintf(output, "%s%s", evsel->unit, sep); + + fprintf(output, "%s", evsel__name(evsel)); +} + +static void print_counter_value_json(struct perf_stat_config *config, + struct evsel *evsel, double avg) +{ + FILE *output =3D config->output; + + fprintf(output, "\"counter-value\" : \"%f\", ", avg); + + if (evsel->unit) + fprintf(output, "\"unit\" : \"%s\", ", evsel->unit); + + fprintf(output, "\"event\" : \"%s\", ", evsel__name(evsel)); +} + +static void print_counter_value(struct perf_stat_config *config, + struct evsel *evsel, double avg) +{ if (config->json_output) - fprintf(output, "\"event\" : \"%s\", ", evsel__name(evsel)); + print_counter_value_json(config, evsel, avg); + else if (config->csv_output) + print_counter_value_csv(config, evsel, avg); else - fprintf(output, "%-*s", config->csv_output ? 0 : 32, evsel__name(evsel)); + print_counter_value_std(config, evsel, avg); +} =20 +static void abs_printout(struct perf_stat_config *config, + struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg) +{ + aggr_printout(config, evsel, id, nr); + print_counter_value(config, evsel, avg); print_cgroup(config, evsel); } =20 --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 8C5D2C433FE for ; Mon, 14 Nov 2022 23:03:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238098AbiKNXDq (ORCPT ); Mon, 14 Nov 2022 18:03:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237991AbiKNXDF (ORCPT ); Mon, 14 Nov 2022 18:03:05 -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 141D01C131; Mon, 14 Nov 2022 15:02:41 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id p21so11500850plr.7; Mon, 14 Nov 2022 15:02:41 -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=+XtdOOIqcdV1KgiG/01v+Rj8BokEmQ43hQ9dFYU/fNg=; b=ei84jXWjNfmnH9OUB1u5al/lYsHMGOntgzm0Q5K+8D47aWFOFNF9PikTTkgU1qzsZD UmRBYU4J1y9wr+QP7oFH3pe5LtCFle0bGq8arql1ouwgtBOFZuJQQFGO6qIWE0SimoK7 iWk3UNLloqElE1gsyRP8Lvh5LAeh9eYRAAht85lQUNulIxTlK45HXq1fZ29aPmjLzuL1 8fNxjaES1Z57CwrUKDd/mnHVrfq0PFeebKgoel3EoUmhdANJ3WdTD9K6RUv/22PN0Yq1 4XyBVZHOJI9Lvp8miDaILeUSiVol+GsO6BO/cj5FKkHFAh0svzNJViRsZVZqHRUVy0ik 9OQg== 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=+XtdOOIqcdV1KgiG/01v+Rj8BokEmQ43hQ9dFYU/fNg=; b=XfHA6lT4G7xWx+rllPBZI0s/lBlzF0PS3gjLtnxGD8djZxOe2uVH6S5QNzAuDgKM3r mJ28KpWoDeUAv7A94B9ndwNrf1c0oVrE+Lk+TqF/HppD8hqAuzk+IOnxQeh0lrHqCDbe mO1pEYKy9xtwFWK/K3Q07gjtMnvqhT4lQvC31mjAEk3d2k4HyYj5/pnOzbMkgqC/tb97 Rb7ytlpipmesnMEsb5WhqDt2l3pjt/7kuK1iF7cWNfkrip2GaHr4A5uB1+asVo2KMmye eZz+oqV8E7EUntG1V9tWgIa/RvlGNhpBXVzx13/8snp+5GxFrkUxUeXcnI83+VC3SLPK LYzg== X-Gm-Message-State: ANoB5pkgr2l88sCAM2hAgUMEwfJR7DA2pkAOKGxbIyD49Qfc/M9ZHL/f 4cxawKeMGR0MI0MuJhIPsGw= X-Google-Smtp-Source: AA0mqf7rdaUq+jdzSbAtikgHm9cnhmYBiObpl+h5pXUJyYLh9rNbSBTQZ4KhUl+TWpkGH/nqBm9wCw== X-Received: by 2002:a17:902:f7c3:b0:176:e414:722 with SMTP id h3-20020a170902f7c300b00176e4140722mr1409144plw.26.1668466960520; Mon, 14 Nov 2022 15:02:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:40 -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 07/19] perf stat: Handle bad events in abs_printout() Date: Mon, 14 Nov 2022 15:02:15 -0800 Message-Id: <20221114230227.1255976-8-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" In the printout() function, it checks if the event is bad (i.e. not counted or not supported) and print the result. But it does the same what abs_printout() is doing. So add an argument to indicate the value is ok or not and use the same function in both cases. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 68 ++++++++++++++-------------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index a72c7442ff3d..fe5483893289 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -518,18 +518,22 @@ static void print_metric_header(struct perf_stat_conf= ig *config, } =20 static void print_counter_value_std(struct perf_stat_config *config, - struct evsel *evsel, double avg) + struct evsel *evsel, double avg, bool ok) { FILE *output =3D config->output; double sc =3D evsel->scale; const char *fmt; + const char *bad_count =3D evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_= SUPPORTED; =20 if (config->big_num) fmt =3D floor(sc) !=3D sc ? "%'18.2f " : "%'18.0f "; else fmt =3D floor(sc) !=3D sc ? "%18.2f " : "%18.0f "; =20 - fprintf(output, fmt, avg); + if (ok) + fprintf(output, fmt, avg); + else + fprintf(output, "%18s ", bad_count); =20 if (evsel->unit) fprintf(output, "%-*s ", config->unit_width, evsel->unit); @@ -538,14 +542,18 @@ static void print_counter_value_std(struct perf_stat_= config *config, } =20 static void print_counter_value_csv(struct perf_stat_config *config, - struct evsel *evsel, double avg) + struct evsel *evsel, double avg, bool ok) { FILE *output =3D config->output; double sc =3D evsel->scale; const char *sep =3D config->csv_sep; const char *fmt =3D floor(sc) !=3D sc ? "%.2f%s" : "%.0f%s"; + const char *bad_count =3D evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_= SUPPORTED; =20 - fprintf(output, fmt, avg, sep); + if (ok) + fprintf(output, fmt, avg, sep); + else + fprintf(output, "%s%s", bad_count, sep); =20 if (evsel->unit) fprintf(output, "%s%s", evsel->unit, sep); @@ -554,11 +562,15 @@ static void print_counter_value_csv(struct perf_stat_= config *config, } =20 static void print_counter_value_json(struct perf_stat_config *config, - struct evsel *evsel, double avg) + struct evsel *evsel, double avg, bool ok) { FILE *output =3D config->output; + const char *bad_count =3D evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_= SUPPORTED; =20 - fprintf(output, "\"counter-value\" : \"%f\", ", avg); + if (ok) + fprintf(output, "\"counter-value\" : \"%f\", ", avg); + else + fprintf(output, "\"counter-value\" : \"%s\", ", bad_count); =20 if (evsel->unit) fprintf(output, "\"unit\" : \"%s\", ", evsel->unit); @@ -567,21 +579,22 @@ static void print_counter_value_json(struct perf_stat= _config *config, } =20 static void print_counter_value(struct perf_stat_config *config, - struct evsel *evsel, double avg) + struct evsel *evsel, double avg, bool ok) { if (config->json_output) - print_counter_value_json(config, evsel, avg); + print_counter_value_json(config, evsel, avg, ok); else if (config->csv_output) - print_counter_value_csv(config, evsel, avg); + print_counter_value_csv(config, evsel, avg, ok); else - print_counter_value_std(config, evsel, avg); + print_counter_value_std(config, evsel, avg, ok); } =20 static void abs_printout(struct perf_stat_config *config, - struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg) + struct aggr_cpu_id id, int nr, + struct evsel *evsel, double avg, bool ok) { aggr_printout(config, evsel, id, nr); - print_counter_value(config, evsel, avg); + print_counter_value(config, evsel, avg, ok); print_cgroup(config, evsel); } =20 @@ -658,17 +671,8 @@ static void printout(struct perf_stat_config *config, = struct aggr_cpu_id id, int pm(config, &os, NULL, "", "", 0); return; } - aggr_printout(config, counter, id, nr); =20 - if (config->json_output) { - fprintf(config->output, "\"counter-value\" : \"%s\", ", - counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED); - } else { - fprintf(config->output, "%*s%s", - config->csv_output ? 0 : 18, - counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, - config->csv_sep); - } + abs_printout(config, id, nr, counter, uval, /*ok=3D*/false); =20 if (counter->supported) { if (!evlist__has_hybrid(counter->evlist)) { @@ -678,24 +682,6 @@ static void printout(struct perf_stat_config *config, = struct aggr_cpu_id id, int } } =20 - if (config->json_output) { - fprintf(config->output, "\"unit\" : \"%s\", ", counter->unit); - } else { - fprintf(config->output, "%-*s%s", - config->csv_output ? 0 : config->unit_width, - counter->unit, config->csv_sep); - } - - if (config->json_output) { - fprintf(config->output, "\"event\" : \"%s\", ", - evsel__name(counter)); - } else { - fprintf(config->output, "%*s", - config->csv_output ? 0 : -25, evsel__name(counter)); - } - - print_cgroup(config, counter); - if (!config->csv_output && !config->json_output) pm(config, &os, NULL, NULL, "", 0); print_noise(config, counter, noise); @@ -706,7 +692,7 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int } =20 if (!config->metric_only) - abs_printout(config, id, nr, counter, uval); + abs_printout(config, id, nr, counter, uval, /*ok=3D*/true); =20 out.print_metric =3D pm; out.new_line =3D nl; --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 192C5C433FE for ; Mon, 14 Nov 2022 23:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238105AbiKNXDs (ORCPT ); Mon, 14 Nov 2022 18:03:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238013AbiKNXDR (ORCPT ); Mon, 14 Nov 2022 18:03:17 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB6F81C404; Mon, 14 Nov 2022 15:02:42 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso15264562pjc.0; Mon, 14 Nov 2022 15:02:42 -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=uteOdCyPFJuZ4/e8j5gcW2AzjfSkGz9Zxx29RYucpO4=; b=HVi8Rv+UWBkOa6K+PUWXuEzMDbI6BtLoh3Oq2fntXUP6ypJC4PvNlE0K/kdltKDsxS fMN7KFT2bvNpKYPcY6ZtsAmU2veGc6xhhVFXmS2sH5mcbMj963Rofu1blZMcseuYSMzN fHSkX+WmS6m/D6OeQBA2LK1Q2rtHWqO80iC0xGdd60cjuyYWDyZqpwd7nDF3qOVS8JET 7ZVSp3hHH1M0SeTe57ZLidj51N8oE3VW0xm3MtsX2N9CpSUEcYyIvWmTbb8neQmLA5NQ i5NO9wwmxvEjFKDi3c3AIPXHclLtW4mZnGppyGJqA5/RdrJwnp5rZmunDsH6pT5QFdiY hw0g== 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=uteOdCyPFJuZ4/e8j5gcW2AzjfSkGz9Zxx29RYucpO4=; b=kkOd6jYkNpS4KCNKlqTzm6TVT43AkziUkCMz4Y3Vu+0bn7ZEUUZ3gaxb5ec4C5q4hn aDeWiuCdV/lgDLCHw7dMjF0i6gv1OpPZ+5eqBrEnTivmuClSUjDt+k36+MGCCfVwqCBF 6za6CsPEHj0zaT3ZUs0OdFXjKF34XQxTEhF3fcAQuUzhAW4wg55cV/hw/GPGqixhc8Vg mqQp/U85lcDRRA/rrTA5erb5WmWLmTA/K2bsQlS6KcW0isgnu9NCXC5Xf6I2uhBOJfLl s3e7StCuOk85yjj0QuIcVhu+eGPSOpAR3GDHH/89GV28TVX46RnXkCI6SS2d/pA9I09G lB6Q== X-Gm-Message-State: ANoB5pmFYydA6i5BBqyEchkT/5OZIjzyLzf2T+YHcvKtnuT8Lw5vFA5H V2QXmNTkDi74pH+PI6Q91ds= X-Google-Smtp-Source: AA0mqf57TdOotLS5/t1jTGV9T0g4kmp/gKY3hikcoESVvD2GMZRvy5XF92B8CBrLxmYOVW0fQJGA1A== X-Received: by 2002:a17:902:8647:b0:17f:63a3:cb48 with SMTP id y7-20020a170902864700b0017f63a3cb48mr1315614plt.123.1668466962130; Mon, 14 Nov 2022 15:02:42 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:41 -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 08/19] perf stat: Add before_metric argument Date: Mon, 14 Nov 2022 15:02:16 -0800 Message-Id: <20221114230227.1255976-9-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" Unfortunately, event running time, percentage and noise data are printed in different positions in normal output than CSV/JSON. I think it's better to put such details in where it actually prints. So add before_metric argument to print_noise() and print_running() and call them twice before and after the metric. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 82 +++++++++++++++++----------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index fe5483893289..bf3f2f9d5dee 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -52,14 +52,18 @@ static void print_running_json(struct perf_stat_config = *config, u64 run, u64 ena } =20 static void print_running(struct perf_stat_config *config, - u64 run, u64 ena) + u64 run, u64 ena, bool before_metric) { - if (config->json_output) - print_running_json(config, run, ena); - else if (config->csv_output) - print_running_csv(config, run, ena); - else - print_running_std(config, run, ena); + if (config->json_output) { + if (before_metric) + print_running_json(config, run, ena); + } else if (config->csv_output) { + if (before_metric) + print_running_csv(config, run, ena); + } else { + if (!before_metric) + print_running_std(config, run, ena); + } } =20 static void print_noise_pct_std(struct perf_stat_config *config, @@ -82,20 +86,24 @@ static void print_noise_pct_json(struct perf_stat_confi= g *config, } =20 static void print_noise_pct(struct perf_stat_config *config, - double total, double avg) + double total, double avg, bool before_metric) { double pct =3D rel_stddev_stats(total, avg); =20 - if (config->json_output) - print_noise_pct_json(config, pct); - else if (config->csv_output) - print_noise_pct_csv(config, pct); - else - print_noise_pct_std(config, pct); + if (config->json_output) { + if (before_metric) + print_noise_pct_json(config, pct); + } else if (config->csv_output) { + if (before_metric) + print_noise_pct_csv(config, pct); + } else { + if (!before_metric) + print_noise_pct_std(config, pct); + } } =20 static void print_noise(struct perf_stat_config *config, - struct evsel *evsel, double avg) + struct evsel *evsel, double avg, bool before_metric) { struct perf_stat_evsel *ps; =20 @@ -103,7 +111,7 @@ static void print_noise(struct perf_stat_config *config, return; =20 ps =3D evsel->stats; - print_noise_pct(config, stddev_stats(&ps->res_stats), avg); + print_noise_pct(config, stddev_stats(&ps->res_stats), avg, before_metric); } =20 static void print_cgroup_std(struct perf_stat_config *config, const char *= cgrp_name) @@ -637,6 +645,7 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int }; print_metric_t pm; new_line_t nl; + bool ok =3D true; =20 if (config->csv_output) { static const int aggr_fields[AGGR_MAX] =3D { @@ -672,7 +681,7 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int return; } =20 - abs_printout(config, id, nr, counter, uval, /*ok=3D*/false); + ok =3D false; =20 if (counter->supported) { if (!evlist__has_hybrid(counter->evlist)) { @@ -681,37 +690,30 @@ static void printout(struct perf_stat_config *config,= struct aggr_cpu_id id, int config->print_mixed_hw_group_error =3D 1; } } - - if (!config->csv_output && !config->json_output) - pm(config, &os, NULL, NULL, "", 0); - print_noise(config, counter, noise); - print_running(config, run, ena); - if (config->csv_output || config->json_output) - pm(config, &os, NULL, NULL, "", 0); - return; } =20 - if (!config->metric_only) - abs_printout(config, id, nr, counter, uval, /*ok=3D*/true); - out.print_metric =3D pm; out.new_line =3D nl; out.ctx =3D &os; out.force_header =3D false; =20 - if (config->csv_output && !config->metric_only) { - print_noise(config, counter, noise); - print_running(config, run, ena); - } else if (config->json_output && !config->metric_only) { - print_noise(config, counter, noise); - print_running(config, run, ena); + if (!config->metric_only) { + abs_printout(config, id, nr, counter, uval, ok); + + print_noise(config, counter, noise, /*before_metric=3D*/true); + print_running(config, run, ena, /*before_metric=3D*/true); + } + + if (ok) { + perf_stat__print_shadow_stats(config, counter, uval, map_idx, + &out, &config->metric_events, st); + } else { + pm(config, &os, /*color=3D*/NULL, /*format=3D*/NULL, /*unit=3D*/"", /*va= l=3D*/0); } =20 - perf_stat__print_shadow_stats(config, counter, uval, map_idx, - &out, &config->metric_events, st); - if (!config->csv_output && !config->metric_only && !config->json_output) { - print_noise(config, counter, noise); - print_running(config, run, ena); + if (!config->metric_only) { + print_noise(config, counter, noise, /*before_metric=3D*/false); + print_running(config, run, ena, /*before_metric=3D*/false); } } =20 @@ -1151,7 +1153,7 @@ static void print_footer(struct perf_stat_config *con= fig) fprintf(output, " %17.*f +- %.*f seconds time elapsed", precision, avg, precision, sd); =20 - print_noise_pct(config, sd, avg); + print_noise_pct(config, sd, avg, /*before_metric=3D*/false); } fprintf(output, "\n\n"); =20 --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 A0785C4332F for ; Mon, 14 Nov 2022 23:03:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237994AbiKNXDl (ORCPT ); Mon, 14 Nov 2022 18:03:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237765AbiKNXDV (ORCPT ); Mon, 14 Nov 2022 18:03:21 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542F91C40F; Mon, 14 Nov 2022 15:02:44 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id o7so11723882pjj.1; Mon, 14 Nov 2022 15:02:44 -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=spAtbl47EygOQnxJUoTDwXbnzuvEBdxdVrBu6CoUdfg=; b=GBNSrINHaYt7YJXAN4zG7nVOyn8d1arFdcIDDx14UM/9uLeOWaKTrmFNQDu+yACf8F fb3luK2ENRMhRIo7wRpHx4gA7eEJ21RF1aJVOSJmvQOUmIWb2f4cqzPb71s8bgmP9ZsF AnFWjzeVeHk9PYl4i0wk+la+pRHQDLt7sGrNKaN9QRoYNXviGiZCtoDF4UCiA/XvW/NU M7KY4SnN6O5nMRowCre/OK5v1CN4LFLwEmHvovme6aJG5v8KR4FexPc2tSlvPbxvekAv HsDTEOAyzC3s+pwqvRQMtlEIy7xDlkPYHPUBMwQGCp60C+bsd2fKJhLF9zc5q3p9hx7t I8IQ== 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=spAtbl47EygOQnxJUoTDwXbnzuvEBdxdVrBu6CoUdfg=; b=gjcvQTwf7Ff5fvI8tstf+dP+mIAUCsIT95GZ9msnq4AHFzLE48aEFxDWM2TZs+VynG /Rkjn3h08qQ6JhSaCaySSNHUkTJ25MbfU/AU5NyBUEFTAOs8ghoOWnSzoxuWL4o9ZQz6 EDF3odJzDrgMLaKL7iONFdFy/LokgAOcGGkSX8jIyScQJ5srpxXspnMD6/1n1Nk2Y/GN zkv7k83ygj9MTS8ke8+7nNTqL9HuhrvmVXyWYnT28XJ/LyibhFKuXzWhmcnYU83+XL81 UJ+ORwLhUfraalP5Y0EwmG0Zt6BXtS6SO/8+ybXIid1CRhQtd4dZS70zgEjaojQQICpn FEjQ== X-Gm-Message-State: ANoB5pnpg89UI+eNrfI/9WrR5RWrk/gagtRktYhvmQVA+bMNHjR6Yk6a +Bx3wb7GC22vFAjMWEFzTN0= X-Google-Smtp-Source: AA0mqf4zJw81epsfXlPYpMayfqaR81tLdkVga3ijGfPj/PA486n3mAYSnbKsWDveoSOo7lHxXgAQAw== X-Received: by 2002:a17:902:f10c:b0:186:cbf1:27e3 with SMTP id e12-20020a170902f10c00b00186cbf127e3mr1216130plb.143.1668466963791; Mon, 14 Nov 2022 15:02:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:43 -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 09/19] perf stat: Align cgroup names Date: Mon, 14 Nov 2022 15:02:17 -0800 Message-Id: <20221114230227.1255976-10-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" We don't know how long cgroup name is, but at least we can align short ones like below. $ perf stat -a --for-each-cgroup system.slice,user.slice true Performance counter stats for 'system wide': 0.13 msec cpu-clock system.slice = # 0.010 CPUs utilized 4 context-switches system.slice = # 31.989 K/sec 1 cpu-migrations system.slice = # 7.997 K/sec 0 page-faults system.slice = # 0.000 /sec 450,673 cycles system.slice = # 3.604 GHz (92.41%) 161,216 instructions system.slice = # 0.36 insn per cycle (92.41%) 32,678 branches system.slice = # 261.332 M/sec (92.41%) 2,628 branch-misses system.slice = # 8.04% of all branches (92.41%) 14.29 msec cpu-clock user.slice = # 1.163 CPUs utilized 35 context-switches user.slice = # 2.449 K/sec 12 cpu-migrations user.slice = # 839.691 /sec 57 page-faults user.slice = # 3.989 K/sec 49,683,026 cycles user.slice = # 3.477 GHz (99.38%) 110,790,266 instructions user.slice = # 2.23 insn per cycle (99.38%) 24,552,255 branches user.slice = # 1.718 G/sec (99.38%) 127,779 branch-misses user.slice = # 0.52% of all branches (99.38%) 0.012289431 seconds time elapsed Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index bf3f2f9d5dee..e66f766a3d78 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -116,7 +116,7 @@ static void print_noise(struct perf_stat_config *config, =20 static void print_cgroup_std(struct perf_stat_config *config, const char *= cgrp_name) { - fprintf(config->output, " %s", cgrp_name); + fprintf(config->output, " %-16s", cgrp_name); } =20 static void print_cgroup_csv(struct perf_stat_config *config, const char *= cgrp_name) --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 8CE51C433FE for ; Mon, 14 Nov 2022 23:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238115AbiKNXDw (ORCPT ); Mon, 14 Nov 2022 18:03:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238019AbiKNXDW (ORCPT ); Mon, 14 Nov 2022 18:03:22 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D9E71C42F; Mon, 14 Nov 2022 15:02:46 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id f5-20020a17090a4a8500b002131bb59d61so245078pjh.1; Mon, 14 Nov 2022 15:02:45 -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=k7m9PL079tg/puX/nq7Az2YxT2Xrw40LYwiV1eclCi4=; b=WcjbZOKxKvBXN4WxmPs2lROepvw+yn3b3+EGv2GpJr9neKf4nzac32FG8OSOcxTa3q 0Trreim1TFPzeWHHQpelNVUVy7+OnRfmVvDx+tOBv2B+jvjPUfN+RB2Z1njxyTLf67y+ gMp1gRvmbJuQ4ScE+LSM1eCN6d8cKq92QAPdpPby2Yz595G0TGyfyBA2TQ4i/6VyR6SN pq5bwQqrHMIO45ziQVcxyJ2eGBePtgQgw5eQOEJaWK/708H6fATL2ZSOTQx5dEmYlwyh Yd9gCjlXDFq1iQGQTx/zA5gtZeDblqbDqdqtqiGck7yRliL/E8C2YDXYYthTDWfcPc7o xOZQ== 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=k7m9PL079tg/puX/nq7Az2YxT2Xrw40LYwiV1eclCi4=; b=ycBGlI+HIDO9m5W+z/SqjpRYCpIT2W7eg07JpOaMbeXhlXT/aaR1pLVIN85nSGd8Jk NRpCS+KEX8eMtalv1r/m2SXAOBe8+Hs2A44wA6mP+MDi51XlViWLMxDPAm7IiN8oZ0Oj n3Hg6klhhrus+Q/E1NMcfjvJNEbo3m6zmkNjFKbAxZWTPZ15CBMJtLy6d99WKSGnPX+m h5AhjkvpAxqWuBsGhzmXi6L2Iy36moK4peI716cZy4l21dlhFh/7XKmOnK0y6IaHCPUT mN7S4t5AHl5x3Lkn3ctf6YCJn/Dj0oXjsowuzAkdcpPgiz2khtW1xHIuCB+/CtBB26se hl7g== X-Gm-Message-State: ANoB5pksEAKts4mkWMFntslxBe9RfnKa0USy2uezgOf4at4kB02XDVvD 4ugiUKDmeSu4VKbEH6wDPGQ= X-Google-Smtp-Source: AA0mqf6CJbvkIe2PJUI9RYlPfMvgnzUQqs4XX3hF/CBeFwAfYEWQ51tEN/5Pmey6DNqig7rxSiHYkg== X-Received: by 2002:a17:90a:14a4:b0:212:d62a:aeb8 with SMTP id k33-20020a17090a14a400b00212d62aaeb8mr15214486pja.221.1668466965385; Mon, 14 Nov 2022 15:02:45 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:44 -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 10/19] perf stat: Split print_metric_headers() function Date: Mon, 14 Nov 2022 15:02:18 -0800 Message-Id: <20221114230227.1255976-11-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" The print_metric_headers() shows metric headers a little bit for each mode. Split it out to make the code clearer. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 52 ++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index e66f766a3d78..bb2791459f5f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -924,6 +924,37 @@ static const char *aggr_header_csv[] =3D { [AGGR_GLOBAL] =3D "" }; =20 +static void print_metric_headers_std(struct perf_stat_config *config, + const char *prefix, bool no_indent) +{ + if (prefix) + fprintf(config->output, "%s", prefix); + if (!no_indent) { + fprintf(config->output, "%*s", + aggr_header_lens[config->aggr_mode], ""); + } +} + +static void print_metric_headers_csv(struct perf_stat_config *config, + const char *prefix, + bool no_indent __maybe_unused) +{ + if (prefix) + fprintf(config->output, "%s", prefix); + if (config->interval) + fputs("time,", config->output); + if (!config->iostat_run) + fputs(aggr_header_csv[config->aggr_mode], config->output); +} + +static void print_metric_headers_json(struct perf_stat_config *config, + const char *prefix __maybe_unused, + bool no_indent __maybe_unused) +{ + if (config->interval) + fputs("{\"unit\" : \"sec\"}", config->output); +} + static void print_metric_headers(struct perf_stat_config *config, struct evlist *evlist, const char *prefix, bool no_indent) @@ -939,22 +970,13 @@ static void print_metric_headers(struct perf_stat_con= fig *config, .force_header =3D true, }; =20 - if (prefix && !config->json_output) - fprintf(config->output, "%s", prefix); + if (config->json_output) + print_metric_headers_json(config, prefix, no_indent); + else if (config->csv_output) + print_metric_headers_csv(config, prefix, no_indent); + else + print_metric_headers_std(config, prefix, no_indent); =20 - if (!config->csv_output && !config->json_output && !no_indent) - fprintf(config->output, "%*s", - aggr_header_lens[config->aggr_mode], ""); - if (config->csv_output) { - if (config->interval) - fputs("time,", config->output); - if (!config->iostat_run) - fputs(aggr_header_csv[config->aggr_mode], config->output); - } - if (config->json_output) { - if (config->interval) - fputs("{\"unit\" : \"sec\"}", config->output); - } if (config->iostat_run) iostat_print_header_prefix(config); =20 --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 E8A59C4332F for ; Mon, 14 Nov 2022 23:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237957AbiKNXDz (ORCPT ); Mon, 14 Nov 2022 18:03:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237955AbiKNXDW (ORCPT ); Mon, 14 Nov 2022 18:03:22 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F7CA1C904; Mon, 14 Nov 2022 15:02:47 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id p12so11509682plq.4; Mon, 14 Nov 2022 15:02:47 -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=p5Jzh6xalJKHBu39qwvImNFihPE1DfayGCHE+NYMErs=; b=BQkSJKUwTi3w4+6vF2KUK9j1JRRPBKnfMOpf4q31cAzr29yOk6gZguFvhDSadkNUhP cDGuNd9lFQpCM9jKDxrUo4txRdOQ0xCylzVfYxevtOROAFYx7/cO/fQKq8mYXRqXM/DG TeImU0q6xxpYr4ti2BgY95DZX81ZztgvZS3Ws+vntjmPMsasyxCcOZe6OcM0T5WgENYs bZ0I4yA9ipVzadswHXhPNy0utjeJ3wa8iu4DvFOyNK1A2Mqz9NCmfLdoGDc4gdZDgAUH TP3D8g+gKcWNkgYvli/4FaO3h26pUdayh0+Q9jQjdpCNv7IFabFxCdM7sqO32fnodgjU egCg== 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=p5Jzh6xalJKHBu39qwvImNFihPE1DfayGCHE+NYMErs=; b=uFKPL1LIbkKd+SSclxe8Md4XRknXoPlXfPFTvkHxBPJcpjJDvqBGQ5jNVta37pfzvC f/RxBFAbHjgqxQwB5EPWHesCP8l2Halg+lB3nJOLYOBMLQyoaR73ij1MVnsA9DRv0Kuv nLg7ZF0qR/5V3pSaYAHNexP9b/nnF/pDVn3UtLn0LKnWpXJ7qjwfR/51ksB479Hp/gPI IiMnC7+dHvnItvNSYNlsy3JIMAIdU2ZI/hBvkMwhS18iP5j1/XMpclWxX3GAmQ0uGRyA /WujRNNUyLDYJvjR2c2LeeDlvbrz/M+DMI6Anu65aC7HyshzaotOfety9mBLLhs1/CAj B3Bw== X-Gm-Message-State: ANoB5pkDN22T8/4/t0OCJpnnAWALqJR3LrBSFDZK0aRG1kn4ot7akU++ CRJ3ZHQeJMonEpXvC7sXAsc= X-Google-Smtp-Source: AA0mqf5gvzG2kf+vWmHVL0H+lmqdGnWDCl8xsQw+SJzii3bk5vanT1jA+zLyR3n22Q3rTP2FkyyXKw== X-Received: by 2002:a17:903:428d:b0:186:a98c:4ab8 with SMTP id ju13-20020a170903428d00b00186a98c4ab8mr1292923plb.118.1668466966879; Mon, 14 Nov 2022 15:02:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:46 -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 11/19] perf stat: Factor out prepare_interval() Date: Mon, 14 Nov 2022 15:02:19 -0800 Message-Id: <20221114230227.1255976-12-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" This logic does not print the time directly, but it just puts the timestamp in the buffer as a prefix. To reduce the confusion, factor out the code into a separate function. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index bb2791459f5f..c234be656db9 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -993,9 +993,25 @@ static void print_metric_headers(struct perf_stat_conf= ig *config, fputc('\n', config->output); } =20 +static void prepare_interval(struct perf_stat_config *config, + char *prefix, struct timespec *ts) +{ + if (config->iostat_run) + return; + + if (!config->json_output) + sprintf(prefix, "%6lu.%09lu%s", (unsigned long) ts->tv_sec, + ts->tv_nsec, config->csv_sep); + else if (!config->metric_only) + sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long) + ts->tv_sec, ts->tv_nsec); + else + sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long) + ts->tv_sec, ts->tv_nsec); +} + static void print_interval(struct perf_stat_config *config, - struct evlist *evlist, - char *prefix, struct timespec *ts) + struct evlist *evlist) { bool metric_only =3D config->metric_only; unsigned int unit_width =3D config->unit_width; @@ -1005,16 +1021,6 @@ static void print_interval(struct perf_stat_config *= config, if (config->interval_clear && isatty(fileno(output))) puts(CONSOLE_CLEAR); =20 - if (!config->iostat_run && !config->json_output) - sprintf(prefix, "%6lu.%09lu%s", (unsigned long) ts->tv_sec, - ts->tv_nsec, config->csv_sep); - if (!config->iostat_run && config->json_output && !config->metric_only) - sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long) - ts->tv_sec, ts->tv_nsec); - if (!config->iostat_run && config->json_output && config->metric_only) - sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long) - ts->tv_sec, ts->tv_nsec); - if ((num_print_interval =3D=3D 0 || config->interval_clear) && !config->csv_output && !config->json_output) { switch (config->aggr_mode) { @@ -1252,10 +1258,13 @@ void evlist__print_counters(struct evlist *evlist, = struct perf_stat_config *conf if (config->iostat_run) evlist->selected =3D evlist__first(evlist); =20 - if (interval) - print_interval(config, evlist, prefix =3D buf, ts); - else + if (interval) { + prefix =3D buf; + prepare_interval(config, prefix, ts); + print_interval(config, evlist); + } else { print_header(config, _target, argc, argv); + } =20 if (metric_only) { static int num_print_iv; --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 0A387C433FE for ; Mon, 14 Nov 2022 23:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237711AbiKNXEW (ORCPT ); Mon, 14 Nov 2022 18:04:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238038AbiKNXD2 (ORCPT ); Mon, 14 Nov 2022 18:03:28 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37FC41CB0A; Mon, 14 Nov 2022 15:02:49 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id k15so12492285pfg.2; Mon, 14 Nov 2022 15:02:49 -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=NdSXH2XNQ9roh/KzmA1z2gWpKkgATPTblDS61GUpaBA=; b=ZT5M/yamNTOk1Rn4OcEY45AtaAUNBZtM/Sgo0tJSRMJZlx5aRes24EQbnklxKvzNEe vbUxlPeCZSvib23VaNatAHR1hKo/7UiHQslWW9n1eNKA4hlNoryFwytlyiNYg/lFiG7L P+f/BgNTA0dyKGGd0GePVy1Ipuhxed4CNMfRbgdGfWRCv5iNiWDig6GdRVcKIzNSFWDQ vCjL//uC77ytjKWfsOPUftbLkArQgt1Ps7P2jXqxdMcbWWauFbWbhWcs9uWrtNwL8ql7 iMG9KfBkPVaUmdJvUJKiE55OobsmepWhpKrxQygs8XPTAd+3SDOG/v02M0xXFEVswt+9 KPhw== 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=NdSXH2XNQ9roh/KzmA1z2gWpKkgATPTblDS61GUpaBA=; b=QZO5XYQtTIONLRjl/sXqJbficyPJYmBTHwA41ckzhsA3JIWFfRg1MlEeXxY8rAxrrq bydPkLjha/i4/diI2kgnRaUHsqpYxVY8rZS+szzP9rhD2Wp67QnSG+CNc5xhUzaqnAQT r2jpib0CIRzcz1tXJCKOqrZ/SVaKfbk69HDwa75A5rgZCW7Q5DnBHyj6tHiHD2X7wVTd yBhpRp55bbcfBACMY9zHUMTahT+L9othtVDTrY4m+pmWJoKgroH6LjWqhZWDbEBcBwd8 G7X2+OLjMCI7Mci4DMmcosIfaugH078JGlmiI9APrp27C/fTygKPOzn6wr8W+o7Z2Lms ETRQ== X-Gm-Message-State: ANoB5pnH0cKeN41bz/yJ8JW021nhg9YWZhZFxO+vIjPi/EtJjSMAHkUy BfmxBAquMsiIhqrQVQoske8= X-Google-Smtp-Source: AA0mqf7zBE/3J/Ok62CY0Mg1NnBPmHFyw8CB9CZewTn6i9C1g5zTU2D02fWdNhAjkeER797wIyqpsQ== X-Received: by 2002:a63:f747:0:b0:434:7885:6adf with SMTP id f7-20020a63f747000000b0043478856adfmr13396224pgk.236.1668466968477; Mon, 14 Nov 2022 15:02:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:48 -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 12/19] perf stat: Cleanup interval print alignment Date: Mon, 14 Nov 2022 15:02:20 -0800 Message-Id: <20221114230227.1255976-13-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" Instead of using magic values, define symbolic constants and use them. Also add aggr_header_std[] array to simplify aggr_mode handling. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 165 ++++++++++++++++++--------------- 1 file changed, 91 insertions(+), 74 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index c234be656db9..f983432aaddd 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -25,6 +25,45 @@ #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" =20 +#define METRIC_LEN 38 +#define EVNAME_LEN 32 +#define COUNTS_LEN 18 +#define INTERVAL_LEN 16 +#define CGROUP_LEN 16 +#define COMM_LEN 16 +#define PID_LEN 7 +#define CPUS_LEN 4 + +static int aggr_header_lens[] =3D { + [AGGR_CORE] =3D 18, + [AGGR_DIE] =3D 12, + [AGGR_SOCKET] =3D 6, + [AGGR_NODE] =3D 6, + [AGGR_NONE] =3D 6, + [AGGR_THREAD] =3D 16, + [AGGR_GLOBAL] =3D 0, +}; + +static const char *aggr_header_csv[] =3D { + [AGGR_CORE] =3D "core,cpus,", + [AGGR_DIE] =3D "die,cpus,", + [AGGR_SOCKET] =3D "socket,cpus,", + [AGGR_NONE] =3D "cpu,", + [AGGR_THREAD] =3D "comm-pid,", + [AGGR_NODE] =3D "node,", + [AGGR_GLOBAL] =3D "" +}; + +static const char *aggr_header_std[] =3D { + [AGGR_CORE] =3D "core", + [AGGR_DIE] =3D "die", + [AGGR_SOCKET] =3D "socket", + [AGGR_NONE] =3D "cpu", + [AGGR_THREAD] =3D "comm-pid", + [AGGR_NODE] =3D "node", + [AGGR_GLOBAL] =3D "" +}; + static void print_running_std(struct perf_stat_config *config, u64 run, u6= 4 ena) { if (run !=3D ena) @@ -116,7 +155,7 @@ static void print_noise(struct perf_stat_config *config, =20 static void print_cgroup_std(struct perf_stat_config *config, const char *= cgrp_name) { - fprintf(config->output, " %-16s", cgrp_name); + fprintf(config->output, " %-*s", CGROUP_LEN, cgrp_name); } =20 static void print_cgroup_csv(struct perf_stat_config *config, const char *= cgrp_name) @@ -147,44 +186,46 @@ static void print_aggr_id_std(struct perf_stat_config= *config, struct evsel *evsel, struct aggr_cpu_id id, int nr) { FILE *output =3D config->output; + int idx =3D config->aggr_mode; + char buf[128]; =20 switch (config->aggr_mode) { case AGGR_CORE: - fprintf(output, "S%d-D%d-C%*d %*d ", - id.socket, id.die, -8, id.core, 4, nr); + snprintf(buf, sizeof(buf), "S%d-D%d-C%d", id.socket, id.die, id.core); break; case AGGR_DIE: - fprintf(output, "S%d-D%*d %*d ", - id.socket, -8, id.die, 4, nr); + snprintf(buf, sizeof(buf), "S%d-D%d", id.socket, id.die); break; case AGGR_SOCKET: - fprintf(output, "S%*d %*d ", - -5, id.socket, 4, nr); + snprintf(buf, sizeof(buf), "S%d", id.socket); break; case AGGR_NODE: - fprintf(output, "N%*d %*d ", - -5, id.node, 4, nr); + snprintf(buf, sizeof(buf), "N%d", id.node); break; case AGGR_NONE: if (evsel->percore && !config->percore_show_thread) { - fprintf(output, "S%d-D%d-C%*d ", - id.socket, id.die, -3, id.core); + snprintf(buf, sizeof(buf), "S%d-D%d-C%d ", + id.socket, id.die, id.core); + fprintf(output, "%-*s ", + aggr_header_lens[AGGR_CORE], buf); } else if (id.cpu.cpu > -1) { - fprintf(output, "CPU%*d ", - -7, id.cpu.cpu); + fprintf(output, "CPU%-*d ", + aggr_header_lens[AGGR_NONE] - 3, id.cpu.cpu); } - break; + return; case AGGR_THREAD: - fprintf(output, "%*s-%*d ", - 16, perf_thread_map__comm(evsel->core.threads, id.thread_idx), - -8, perf_thread_map__pid(evsel->core.threads, id.thread_idx)); - break; + fprintf(output, "%*s-%-*d ", + COMM_LEN, perf_thread_map__comm(evsel->core.threads, id.thread_idx), + PID_LEN, perf_thread_map__pid(evsel->core.threads, id.thread_idx)); + return; case AGGR_GLOBAL: case AGGR_UNSET: case AGGR_MAX: default: - break; + return; } + + fprintf(output, "%-*s %*d ", aggr_header_lens[idx], buf, 4, nr); } =20 static void print_aggr_id_csv(struct perf_stat_config *config, @@ -301,8 +342,6 @@ struct outstate { struct evsel *evsel; }; =20 -#define METRIC_LEN 38 - static void new_line_std(struct perf_stat_config *config __maybe_unused, void *ctx) { @@ -534,19 +573,19 @@ static void print_counter_value_std(struct perf_stat_= config *config, const char *bad_count =3D evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_= SUPPORTED; =20 if (config->big_num) - fmt =3D floor(sc) !=3D sc ? "%'18.2f " : "%'18.0f "; + fmt =3D floor(sc) !=3D sc ? "%'*.2f " : "%'*.0f "; else - fmt =3D floor(sc) !=3D sc ? "%18.2f " : "%18.0f "; + fmt =3D floor(sc) !=3D sc ? "%*.2f " : "%*.0f "; =20 if (ok) - fprintf(output, fmt, avg); + fprintf(output, fmt, COUNTS_LEN, avg); else - fprintf(output, "%18s ", bad_count); + fprintf(output, "%*s ", COUNTS_LEN, bad_count); =20 if (evsel->unit) fprintf(output, "%-*s ", config->unit_width, evsel->unit); =20 - fprintf(output, "%-*s", 32, evsel__name(evsel)); + fprintf(output, "%-*s", EVNAME_LEN, evsel__name(evsel)); } =20 static void print_counter_value_csv(struct perf_stat_config *config, @@ -904,34 +943,19 @@ static void print_no_aggr_metric(struct perf_stat_con= fig *config, } } =20 -static int aggr_header_lens[] =3D { - [AGGR_CORE] =3D 24, - [AGGR_DIE] =3D 18, - [AGGR_SOCKET] =3D 12, - [AGGR_NONE] =3D 6, - [AGGR_THREAD] =3D 24, - [AGGR_NODE] =3D 6, - [AGGR_GLOBAL] =3D 0, -}; - -static const char *aggr_header_csv[] =3D { - [AGGR_CORE] =3D "core,cpus,", - [AGGR_DIE] =3D "die,cpus,", - [AGGR_SOCKET] =3D "socket,cpus,", - [AGGR_NONE] =3D "cpu,", - [AGGR_THREAD] =3D "comm-pid,", - [AGGR_NODE] =3D "node,", - [AGGR_GLOBAL] =3D "" -}; - static void print_metric_headers_std(struct perf_stat_config *config, const char *prefix, bool no_indent) { if (prefix) fprintf(config->output, "%s", prefix); + if (!no_indent) { - fprintf(config->output, "%*s", - aggr_header_lens[config->aggr_mode], ""); + int len =3D aggr_header_lens[config->aggr_mode]; + + if (nr_cgroups) + len +=3D CGROUP_LEN + 1; + + fprintf(config->output, "%*s", len, ""); } } =20 @@ -1025,46 +1049,39 @@ static void print_interval(struct perf_stat_config = *config, !config->csv_output && !config->json_output) { switch (config->aggr_mode) { case AGGR_NODE: - fprintf(output, "# time node cpus"); - if (!metric_only) - fprintf(output, " counts %*s events\n", unit_width, "unit"= ); - break; case AGGR_SOCKET: - fprintf(output, "# time socket cpus"); - if (!metric_only) - fprintf(output, " counts %*s events\n", unit_width, "unit"= ); - break; case AGGR_DIE: - fprintf(output, "# time die cpus"); - if (!metric_only) - fprintf(output, " counts %*s events\n", unit_width, "unit"= ); - break; case AGGR_CORE: - fprintf(output, "# time core cpus"); - if (!metric_only) - fprintf(output, " counts %*s events\n", unit_width, "unit"= ); + 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, "# time CPU "); - if (!metric_only) - fprintf(output, " counts %*s events\n", unit_width, "un= it"); + 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, "# time comm-pid"); - if (!metric_only) - fprintf(output, " counts %*s events\n", unit_width, "= unit"); + 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, "# time"); - if (!metric_only) - fprintf(output, " counts %*s events\n", unit_width, "unit= "); - } + if (!config->iostat_run) + fprintf(output, "#%*s", + INTERVAL_LEN - 1, "time"); case AGGR_UNSET: case AGGR_MAX: break; } + + if (!metric_only) { + fprintf(output, " %*s %*s events\n", + COUNTS_LEN, "counts", unit_width, "unit"); + } } =20 if ((num_print_interval =3D=3D 0 || config->interval_clear) && metric_onl= y) --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 7B4C9C43217 for ; Mon, 14 Nov 2022 23:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238018AbiKNXE0 (ORCPT ); Mon, 14 Nov 2022 18:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238053AbiKNXD3 (ORCPT ); Mon, 14 Nov 2022 18:03:29 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7A51C933; Mon, 14 Nov 2022 15:02:50 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id h14so11705809pjv.4; Mon, 14 Nov 2022 15:02:50 -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=Dj8iIW6Moofk4jxR56ZsoVFULFdU2ag6CE3awXc28Rc=; b=GlPXquPr/Ffvox+CyOypFSRLgTJtFCM69J4Fcnu8bHgNvm8LOdWgtdsBQJfj+4cBDP i7sT51MOc3MVuGENMx5j6UmpuT9CmzahltE3yCcgNaUhAFhYRf6y8zBgL70oBQOZTfCj FIZ/BizgnfXRgvkFFWslH48d0mj4JvM3o8IE65s+tOcij8F0EuVtiSYE8qhVvSWs2hoy 4el0nKkH5j53B5knLlMitO8qKIUXbdMlExlX1w8+2AmMbLMTYeZIdxMF5ziEGi3q2EhD MV1xjF/k98DjcExBb0S7rumweMGwPCS0u/6RM05YvRurZ8giL4phO2QOk/zuvzwMb9ZC u6DA== 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=Dj8iIW6Moofk4jxR56ZsoVFULFdU2ag6CE3awXc28Rc=; b=XFayzyY9EZKyG18EPnpIT3vr6esgFGEDmsaW/+eBDQU0vZmP2pBjWbqbWy+tmfH65H +D8MOe6MFuU3AJpR0vtWu0FhD8zwuZGNVX5DTxIGlmQhaFm0ljFlTETvV/CpzyQC+Ano r2CWIvwRYqVuTOLts0u13ecYkniAjdY+ykC2gsp+D8yM3X2j0utRYD1C9D8jY43dR0rL 7T8IBP4XRscp788HK82tyQyCnoT2GfUobYAi6KncT4qDGD8aXR9dfLnVtRSdBYZWcHt5 CchCoCoQxrFoObqPXH2hlCzvf6uxYxl5MzJpdYS+qBm1MZF0HVdM1m6LpFM+u4R5pZ+7 TxjQ== X-Gm-Message-State: ANoB5plvxxfs19SAMGX93MVF2Ox9yMGRkoywXy93cj7WYUTF2e04d49u h2rFytLzfUsfAhLigLO7t2k= X-Google-Smtp-Source: AA0mqf4KjGcj8maOHGHDnGzpz0rniCOrXm2bPXvBRC4E1kFIRbtVH0/jrvLIfhtKPj2mnuQPdjvtxA== X-Received: by 2002:a17:902:c211:b0:188:a6ea:27a1 with SMTP id 17-20020a170902c21100b00188a6ea27a1mr1234620pll.164.1668466970017; Mon, 14 Nov 2022 15:02:50 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:49 -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 13/19] perf stat: Remove impossible condition Date: Mon, 14 Nov 2022 15:02:21 -0800 Message-Id: <20221114230227.1255976-14-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" The print would run only if metric_only is not set, but it's already in a block that says it's in metric_only case. And there's no place to change the setting. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f983432aaddd..cc8bb6d07dcb 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1292,9 +1292,6 @@ void evlist__print_counters(struct evlist *evlist, st= ruct perf_stat_config *conf num_print_iv =3D 0; if (config->aggr_mode =3D=3D AGGR_GLOBAL && prefix && !config->iostat_ru= n) fprintf(config->output, "%s", prefix); - - if (config->json_output && !config->metric_only) - fprintf(config->output, "}"); } =20 switch (config->aggr_mode) { --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 From nobody Mon Apr 13 15:52:28 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 B34DDC43219 for ; Mon, 14 Nov 2022 23:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238155AbiKNXEe (ORCPT ); Mon, 14 Nov 2022 18:04:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238017AbiKNXDe (ORCPT ); Mon, 14 Nov 2022 18:03:34 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D201CFF7; Mon, 14 Nov 2022 15:02:53 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id 136so11594080pga.1; Mon, 14 Nov 2022 15:02:53 -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=CC4R4Flp577u4yBTPLbgmfpC6msSDOQY4vvA3zFzeIk=; b=OpbUbMzrJ8W7hEVVcarvOE/Z8N5O0xLRBWVksEFDk8w+TmJUJBuN7uh2O91GlRulr9 Y2IWMKcTFhkUJVhxbibOpSAC9wSL+q3XdteqCdY8u8o9aNDbzpwNn+xgkqKMhE6JndJj eOLIaHKCo2mvZiryqz3tOJulC6MyA4FCMFkL3E9SH2uiGApf51qv63f2cZWG13Pe3+QK i+nI4G51mlF6aviVMx2E+auRZwyelGJYQTvR6mROKPlNiGKVqbxki4RHOlSejc+59vAo 1z/22iOILU0/QO6CvQvdtmYQa9FihbnrwI9Hw3RMQssFYVfki/0k3EimJYaukpIJ+Hm2 NVlA== 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=CC4R4Flp577u4yBTPLbgmfpC6msSDOQY4vvA3zFzeIk=; b=FLZ43eGwYjYJgWQKjEzH2VhAcrC6JTFWKfEPmhGDlFEj0e6cmocBThXDIhgjpDrGd3 +ovbKxjhFDHhUMFdpAIAFVQO/AhfRYpZX8xTo/AN+Fmr+CWR+BlUGyKn3XbSAmYyLMac iLXTac3QBTRS2Z4i9Tt+VPnx4aBDwLpCxjSV/v1kae4TEYU42+nBtC/O3lV2px297b7d 1rqTTmvix5eJL+EeRhMU7zp69Ex6g5nx6GtcSI0r8xf5969axUsWbStb+MGbuAJu9NXA Shil0WDqrc7zsgxS2/j/GxhDPOmGDREfNbcztHKnRo7FxfxVmXWb0rv4zvW96KwO14zI bpcw== X-Gm-Message-State: ANoB5plIkkGPXiuMxoS/UcB5Xr4PZSTWtG84bDFEqJbtkkd8CwN2bS++ hchXiUBnz1azcVXL6bR8XhM= X-Google-Smtp-Source: AA0mqf5hzDcsrFIeUhbK0dTdZ8XNjWXv/awUwAeKsZK5xa/ZU7fjI05cMw5hnDlDVLXV/742hiYHLQ== X-Received: by 2002:a63:1b25:0:b0:459:5fef:a491 with SMTP id b37-20020a631b25000000b004595fefa491mr13869341pgb.150.1668466973275; Mon, 14 Nov 2022 15:02:53 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:52 -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 15/19] perf stat: Move condition to print_footer() Date: Mon, 14 Nov 2022 15:02:23 -0800 Message-Id: <20221114230227.1255976-16-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" Likewise, I think it'd better to have the control inside the function, and = keep the higher level function clearer. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f97817628478..73cf898060c0 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1205,6 +1205,9 @@ static void print_footer(struct perf_stat_config *con= fig) double avg =3D avg_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC; FILE *output =3D config->output; =20 + if (config->interval || config->csv_output || config->json_output) + return; + if (!config->null_run) fprintf(output, "\n"); =20 @@ -1359,8 +1362,7 @@ void evlist__print_counters(struct evlist *evlist, st= ruct perf_stat_config *conf break; } =20 - if (!interval && !config->csv_output && !config->json_output) - print_footer(config); + print_footer(config); =20 fflush(config->output); } --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 64316C433FE for ; Mon, 14 Nov 2022 23:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238163AbiKNXEh (ORCPT ); Mon, 14 Nov 2022 18:04:37 -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-Google-Smtp-Source: AA0mqf4TeGPWXbefMuXS+vF94hu7/u9p+O+HDYKF6VxGZlrfDx32liLURHX3wfvph+Psoxl/cvmabg== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 *c= onfig, struct evsel *coun =20 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 =3D config->output; u64 ena, run, val; @@ -825,10 +824,6 @@ static void print_counter_aggrdata(struct perf_stat_co= nfig *config, ena =3D aggr->counts.ena; run =3D aggr->counts.run; =20 - if (*first && metric_only) { - *first =3D false; - aggr_printout(config, counter, id, aggr->nr); - } if (prefix && !metric_only) fprintf(output, "%s", prefix); =20 @@ -849,7 +844,6 @@ static void print_aggr(struct perf_stat_config *config, FILE *output =3D config->output; struct evsel *counter; int s; - bool first; =20 if (!config->aggr_map || !config->aggr_get_id) return; @@ -860,21 +854,23 @@ static void print_aggr(struct perf_stat_config *confi= g, */ for (s =3D 0; s < config->aggr_map->nr; s++) { if (metric_only) { + struct perf_stat_aggr *aggr; + struct aggr_cpu_id id =3D 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 =3D evlist__first(evlist); + aggr =3D &counter->stats->aggr[s]; + aggr_printout(config, counter, id, aggr->nr); } =20 - first =3D true; evlist__for_each_entry(evlist, counter) { if (counter->merged_stat) continue; =20 - 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 *conf= ig, struct evsel *counter, char *prefix) { bool metric_only =3D config->metric_only; - bool first =3D false; int s; =20 /* AGGR_THREAD doesn't have config->aggr_get_id */ @@ -896,9 +891,8 @@ static void print_counter(struct perf_stat_config *conf= ig, return; =20 for (s =3D 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); } } =20 @@ -1260,7 +1254,6 @@ static void print_percore(struct perf_stat_config *co= nfig, FILE *output =3D config->output; struct cpu_aggr_map *core_map; int s, c, i; - bool first =3D true; =20 if (!config->aggr_map || !config->aggr_get_id) return; @@ -1288,11 +1281,7 @@ static void print_percore(struct perf_stat_config *c= onfig, if (found) continue; =20 - 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); =20 core_map->map[c++] =3D core_id; } @@ -1319,10 +1308,6 @@ void evlist__print_counters(struct evlist *evlist, s= truct perf_stat_config *conf } =20 print_header(config, _target, evlist, argc, argv); - if (metric_only) { - if (config->aggr_mode =3D=3D AGGR_GLOBAL && prefix && !config->iostat_ru= n) - fprintf(config->output, "%s", prefix); - } =20 switch (config->aggr_mode) { case AGGR_CORE: @@ -1337,6 +1322,8 @@ void evlist__print_counters(struct evlist *evlist, st= ruct perf_stat_config *conf iostat_print_counters(evlist, config, ts, prefix =3D buf, print_counter); else { + if (prefix && metric_only) + fprintf(config->output, "%s", prefix); evlist__for_each_entry(evlist, counter) { print_counter(config, counter, prefix); } --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 BC529C4332F for ; Mon, 14 Nov 2022 23:04:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238186AbiKNXEw (ORCPT ); Mon, 14 Nov 2022 18:04:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237958AbiKNXEP (ORCPT ); Mon, 14 Nov 2022 18:04:15 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA0111D30B; Mon, 14 Nov 2022 15:02:56 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id q1-20020a17090a750100b002139ec1e999so12198522pjk.1; Mon, 14 Nov 2022 15:02:56 -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=EneTTOLEdeiyFEwMJVIPNECCRgEct82mU8+e7v3Zlys=; b=LFq6cFJtg2P710jiZO6bIVou2ZNEO4AESaORpocvfA/UUJuKdgj6gUyNVdUKvsfhWc 6u+9Q+mw69rIGUy7wcWhROO+I8MsdRv4jW2MfrY27GpqiKs+/UJZ2LcxBWp6SiCCzaT9 3yiQLe3G66UbZ4QuIGFFt8MDRD1uqNLB3mvjDCoQiwXscdQusreG9K1NTHozdj10errI ebbSuNawM/05piAOzulh3DwPSbWw4w+StNuhRs/vttfy3gOKmpbH5SrN9lnStIw6bxZr Wc69w41xMY90eVTxEmGMpsu8uQOyWIU64JxeKi7tVYZUJZIg9osT4Az1RPMFMlMGmvhs hHqw== 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=EneTTOLEdeiyFEwMJVIPNECCRgEct82mU8+e7v3Zlys=; b=BSkagjWqVLwtSncqd8IeunFSQuJ5luwTOZDroipBCt736Np1VPnf0HI09Zh6SjHCkK jdROA0mGMAV/9q0P3JrNrbb0Tku6kP8x8SNYylY7fYXezcsWntoQiWhuBOOKg8ax7Z4X UQ81nXr4GPSX+mAYZZPnMgeii1BARbkBFr+m/hETg5UAk7CqPs1IMs0ud4qGGMtNj28h gzl02R8zIG/+DZ07hnQAyopbd/vUEvVYzn04DHlKPqAgoDiM6oevPq1TiZWhv9ZtiAGf vpxWidP7zqh8bqkq7FZydHAuWpsRa4GK7zIqF/vZoG8nBYQBAN2Hd/bAx8HUWSSMtHpJ fGTQ== X-Gm-Message-State: ANoB5pkk5zxVY7wIXlZuo0II8C+Txp81OyU2FMvPuwoL4Iryrjhz0K3m 9UAhCgqtKHweD5cMoH8iliE= X-Google-Smtp-Source: AA0mqf6ozSfPXQEIVthvBeZL0zRv94HYK17dLhH/hEfRhdmmWqupwglu2Z5lcv1UWLYQqDh7B2kvqg== X-Received: by 2002:a17:90a:d14d:b0:213:36b6:f9ff with SMTP id t13-20020a17090ad14d00b0021336b6f9ffmr15894806pjw.144.1668466976229; Mon, 14 Nov 2022 15:02:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:55 -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 17/19] perf stat: Factor out print_metric_{begin,end}() Date: Mon, 14 Nov 2022 15:02:25 -0800 Message-Id: <20221114230227.1255976-18-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" For the metric-only case, add new functions to handle the start and the end of each metric display. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 56 +++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index bb40ed29300d..7a0673be720b 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -836,12 +836,39 @@ static void print_counter_aggrdata(struct perf_stat_c= onfig *config, fputc('\n', output); } =20 +static void print_metric_begin(struct perf_stat_config *config, + struct evlist *evlist, + char *prefix, int aggr_idx) +{ + struct perf_stat_aggr *aggr; + struct aggr_cpu_id id; + struct evsel *evsel; + + if (!config->metric_only) + return; + + if (prefix) + fprintf(config->output, "%s", prefix); + + evsel =3D evlist__first(evlist); + id =3D config->aggr_map->map[aggr_idx]; + aggr =3D &evsel->stats->aggr[aggr_idx]; + aggr_printout(config, evsel, id, aggr->nr); +} + +static void print_metric_end(struct perf_stat_config *config) +{ + if (!config->metric_only) + return; + + fputc('\n', config->output); +} + static void print_aggr(struct perf_stat_config *config, struct evlist *evlist, char *prefix) { bool metric_only =3D config->metric_only; - FILE *output =3D config->output; struct evsel *counter; int s; =20 @@ -853,17 +880,7 @@ static void print_aggr(struct perf_stat_config *config, * Without each counter has its own line. */ for (s =3D 0; s < config->aggr_map->nr; s++) { - if (metric_only) { - struct perf_stat_aggr *aggr; - struct aggr_cpu_id id =3D config->aggr_map->map[s]; - - if (prefix) - fprintf(output, "%s", prefix); - - counter =3D evlist__first(evlist); - aggr =3D &counter->stats->aggr[s]; - aggr_printout(config, counter, id, aggr->nr); - } + print_metric_begin(config, evlist, prefix, s); =20 evlist__for_each_entry(evlist, counter) { if (counter->merged_stat) @@ -872,8 +889,7 @@ static void print_aggr(struct perf_stat_config *config, print_counter_aggrdata(config, counter, s, prefix, metric_only); } - if (metric_only) - fputc('\n', output); + print_metric_end(config); } } =20 @@ -919,9 +935,7 @@ static void print_no_aggr_metric(struct perf_stat_confi= g *config, =20 id =3D aggr_cpu_id__cpu(cpu, /*data=3D*/NULL); if (first) { - if (prefix) - fputs(prefix, config->output); - aggr_printout(config, counter, id, 0); + print_metric_begin(config, evlist, prefix, counter_idx); first =3D false; } val =3D ps->aggr[counter_idx].counts.val; @@ -933,7 +947,7 @@ static void print_no_aggr_metric(struct perf_stat_confi= g *config, run, ena, 1.0, &rt_stat, counter_idx); } if (!first) - fputc('\n', config->output); + print_metric_end(config); } } =20 @@ -1322,13 +1336,11 @@ void evlist__print_counters(struct evlist *evlist, = struct perf_stat_config *conf iostat_print_counters(evlist, config, ts, prefix =3D buf, print_counter); else { - if (prefix && metric_only) - fprintf(config->output, "%s", prefix); + print_metric_begin(config, evlist, prefix, /*aggr_idx=3D*/0); evlist__for_each_entry(evlist, counter) { print_counter(config, counter, prefix); } - if (metric_only) - fputc('\n', config->output); + print_metric_end(config); } break; case AGGR_NONE: --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 D54FBC4332F for ; Mon, 14 Nov 2022 23:04:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237975AbiKNXE4 (ORCPT ); Mon, 14 Nov 2022 18:04:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238030AbiKNXES (ORCPT ); Mon, 14 Nov 2022 18:04:18 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 656471D0DE; Mon, 14 Nov 2022 15:02:58 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id c2so11482944plz.11; Mon, 14 Nov 2022 15:02:58 -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=MYDLtl9GSeaGL91h5dtqz1M8wM/Y9pV3tpLuUgjiMtg=; b=ayXvD3OygUKKfObtjdGTFVNkWknwH+E13eYvu+k9krCNg5Btvpjz6mVtFwc/8LELoP fbP7RiLe343+ItXzBg1ctFyq2i3RM1J1dz0eWyw/jN7aayLwfGXK0begkf09MRyvWRbu oj91KwJ/gru84rlgl/Ak5ymKbJ+vGmJ4ZVA0XuoyewFHDUuLTpL4bn47/hUWr4VjzVXa 1QAwSMD3SzyV2WiUJvW8CuAO76u0OoQPwfV5NX/Qlrt4lhQWnevME/UymPFsxAMmnNvD hA2l8uHFhIKZRuuSWJ1eaCPsU0YUjTXGhrzApyzdcH6GCC8zouonJ8idHnX0P+OSgFdI HY4A== 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=MYDLtl9GSeaGL91h5dtqz1M8wM/Y9pV3tpLuUgjiMtg=; b=5mCKBWIBgknyix/7S5CwJsMqN/4Z2kJxWvx6JyKoKDJFpNge0/P2x9OO8bA4yIK9TG 8fipPSb7YsWjZ8wMNWafq7sBYFx6OjuWexq1vWYSP7k2Eybprh1gKQT1pS6Su0n33w8J CJsOdtdZb32knyOMm5fqn4wtmZ5QfMg3LqItKlw/t2Vm7Y2lrhssTe5Q2DbfSniuXtIJ 1kBZlI2grfhG0iEKKTCkmqeWNY84cx6Nh1Ada4GK7Lq/hhqKlWzkWnsxeyJ0OYFDqEQe 0+hakE8F8wyQmjwDCl+5YtvAbZgXAFgzTK3W7AjTuvpi0/L5ifSJ64LSpVyWFaUrrebW KpMw== X-Gm-Message-State: ANoB5pkisqhKURRvCCtftYK3kxllhbDLJa/X0U7CwaRyvkg7Zfi4LE/j DBmmfQFV6Cq5d7pBSUAsb0g= X-Google-Smtp-Source: AA0mqf5TVfG64YT3JMmBzjZClMYJK+r+Q5Xn8LxEQndZ1J9jC8jSCVzVFBRAzY6P9SrySuYzGvrL9Q== X-Received: by 2002:a17:90a:9dc5:b0:20b:2c3b:4b79 with SMTP id x5-20020a17090a9dc500b0020b2c3b4b79mr15748935pjv.236.1668466977858; Mon, 14 Nov 2022 15:02:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:57 -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 18/19] perf stat: Support --for-each-cgroup and --metric-only Date: Mon, 14 Nov 2022 15:02:26 -0800 Message-Id: <20221114230227.1255976-19-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" When we have events for each cgroup, the metric should be printed for each cgroup separately. Add print_cgroup_counter() to handle that situation properly. Also change print_metric_headers() not to print duplicate headers by checking cgroups. $ perf stat -a --for-each-cgroup system.slice,user.slice --metric-only sl= eep 1 Performance counter stats for 'system wide': GHz insn per cycle branch-misses= of all branches system.slice 3.792 0.61 = 3.24% user.slice 3.661 2.32 = 0.37% 1.016111516 seconds time elapsed Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 58 +++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 7a0673be720b..cf25ed99b5df 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -168,10 +168,10 @@ static void print_cgroup_json(struct perf_stat_config= *config, const char *cgrp_ fprintf(config->output, "\"cgroup\" : \"%s\", ", cgrp_name); } =20 -static void print_cgroup(struct perf_stat_config *config, struct evsel *ev= sel) +static void print_cgroup(struct perf_stat_config *config, struct cgroup *c= grp) { - if (nr_cgroups) { - const char *cgrp_name =3D evsel->cgrp ? evsel->cgrp->name : ""; + if (nr_cgroups || config->cgroup_list) { + const char *cgrp_name =3D cgrp ? cgrp->name : ""; =20 if (config->json_output) print_cgroup_json(config, cgrp_name); @@ -340,6 +340,7 @@ struct outstate { int nr; struct aggr_cpu_id id; struct evsel *evsel; + struct cgroup *cgrp; }; =20 static void new_line_std(struct perf_stat_config *config __maybe_unused, @@ -552,6 +553,9 @@ static void print_metric_header(struct perf_stat_config= *config, os->evsel->priv !=3D os->evsel->evlist->selected->priv) return; =20 + if (os->evsel->cgrp !=3D os->cgrp) + return; + if (!valid_only_metric(unit)) return; unit =3D fixunit(tbuf, os->evsel, unit); @@ -642,7 +646,7 @@ static void abs_printout(struct perf_stat_config *confi= g, { aggr_printout(config, evsel, id, nr); print_counter_value(config, evsel, avg, ok); - print_cgroup(config, evsel); + print_cgroup(config, evsel->cgrp); } =20 static bool is_mixed_hw_group(struct evsel *counter) @@ -838,7 +842,8 @@ static void print_counter_aggrdata(struct perf_stat_con= fig *config, =20 static void print_metric_begin(struct perf_stat_config *config, struct evlist *evlist, - char *prefix, int aggr_idx) + char *prefix, int aggr_idx, + struct cgroup *cgrp) { struct perf_stat_aggr *aggr; struct aggr_cpu_id id; @@ -854,6 +859,8 @@ static void print_metric_begin(struct perf_stat_config = *config, id =3D config->aggr_map->map[aggr_idx]; aggr =3D &evsel->stats->aggr[aggr_idx]; aggr_printout(config, evsel, id, aggr->nr); + + print_cgroup(config, cgrp); } =20 static void print_metric_end(struct perf_stat_config *config) @@ -880,7 +887,7 @@ static void print_aggr(struct perf_stat_config *config, * Without each counter has its own line. */ for (s =3D 0; s < config->aggr_map->nr; s++) { - print_metric_begin(config, evlist, prefix, s); + print_metric_begin(config, evlist, prefix, s, /*cgrp=3D*/NULL); =20 evlist__for_each_entry(evlist, counter) { if (counter->merged_stat) @@ -935,7 +942,8 @@ static void print_no_aggr_metric(struct perf_stat_confi= g *config, =20 id =3D aggr_cpu_id__cpu(cpu, /*data=3D*/NULL); if (first) { - print_metric_begin(config, evlist, prefix, counter_idx); + print_metric_begin(config, evlist, prefix, + counter_idx, /*cgrp=3D*/NULL); first =3D false; } val =3D ps->aggr[counter_idx].counts.val; @@ -960,7 +968,7 @@ static void print_metric_headers_std(struct perf_stat_c= onfig *config, if (!no_indent) { int len =3D aggr_header_lens[config->aggr_mode]; =20 - if (nr_cgroups) + if (nr_cgroups || config->cgroup_list) len +=3D CGROUP_LEN + 1; =20 fprintf(config->output, "%*s", len, ""); @@ -1012,6 +1020,9 @@ static void print_metric_headers(struct perf_stat_con= fig *config, if (config->iostat_run) iostat_print_header_prefix(config); =20 + if (config->cgroup_list) + os.cgrp =3D evlist__first(evlist)->cgrp; + /* Print metrics headers only */ evlist__for_each_entry(evlist, counter) { os.evsel =3D counter; @@ -1305,6 +1316,28 @@ static void print_percore(struct perf_stat_config *c= onfig, fputc('\n', output); } =20 +static void print_cgroup_counter(struct perf_stat_config *config, struct e= vlist *evlist, + char *prefix) +{ + struct cgroup *cgrp =3D NULL; + struct evsel *counter; + + evlist__for_each_entry(evlist, counter) { + if (cgrp !=3D counter->cgrp) { + if (cgrp !=3D NULL) + print_metric_end(config); + + cgrp =3D counter->cgrp; + print_metric_begin(config, evlist, prefix, + /*aggr_idx=3D*/0, cgrp); + } + + print_counter(config, counter, prefix); + } + if (cgrp) + print_metric_end(config); +} + void evlist__print_counters(struct evlist *evlist, struct perf_stat_config= *config, struct target *_target, struct timespec *ts, int argc, const char *= *argv) { @@ -1332,11 +1365,14 @@ void evlist__print_counters(struct evlist *evlist, = struct perf_stat_config *conf break; case AGGR_THREAD: case AGGR_GLOBAL: - if (config->iostat_run) + if (config->iostat_run) { iostat_print_counters(evlist, config, ts, prefix =3D buf, print_counter); - else { - print_metric_begin(config, evlist, prefix, /*aggr_idx=3D*/0); + } else if (config->cgroup_list) { + print_cgroup_counter(config, evlist, prefix); + } else { + print_metric_begin(config, evlist, prefix, + /*aggr_idx=3D*/0, /*cgrp=3D*/NULL); evlist__for_each_entry(evlist, counter) { print_counter(config, counter, prefix); } --=20 2.38.1.493.g58b659f92b-goog From nobody Mon Apr 13 15:52:28 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 EBB9DC4332F for ; Mon, 14 Nov 2022 23:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237779AbiKNXE7 (ORCPT ); Mon, 14 Nov 2022 18:04:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238122AbiKNXES (ORCPT ); Mon, 14 Nov 2022 18:04:18 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A1F1D31B; Mon, 14 Nov 2022 15:03:00 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id v28so12454107pfi.12; Mon, 14 Nov 2022 15:03:00 -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=V4xN0opfJbQJnUhtmkfw3MqwhSTJXF+vfzMgniki+7E=; b=qp+2rjNM+J44UCbw2i7qNgQQzk43z/lronElv7ycCE0x0q3pB0H01Zu+XInPlr3cmO sdvCIDkGTMiM2xX06ojIfQgY3kfNbDU1fkd02QN1WVppq1OtZcJHbyuy1OoAbN0IUhyJ JxmPVqs1Na39z65j+J5QHOnBoks2WCbahhJP/iwJAB4RJIXbuG1e+9SiahttpSTcxoAL m+xamjwEljBP0Xs67NtjxDaOjH2pWsDh/UrqR0DCbuWdi8eSLj7uDD5OMa68htyWtCHG ipKnF+4OkUzovf81ZtzQ7f4O5AwZN4Q0kvV0trr6pJhrYHGX8aQOGgOgOpmhZjDxHUAV Va3g== 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=V4xN0opfJbQJnUhtmkfw3MqwhSTJXF+vfzMgniki+7E=; b=T9a71s3X6RFabSIv9Vs/sql/o1lj1SXeFznTQzdx4L1S9d7WB74CLh6dKgAYcXNJIK KPFF0nUSl9y20T/OUiNmARkgR0fXpRWWr2PoRQaabk9OWzJ1XuXc+8tMgli1vBQogzzd hK67eL4nleEzjG4p+TN/O6vG7d4Gkq3Cd2gY2l98FkWW3gxfqZo7TR/Ze8tbhekzSrm5 YLjEt9bfEpo+R1fs4AC9Hgnc/oZ3s3thrfYN5SgSs8JwFLx8WmaVbfbYXHeHaOl+Hy7N xYu0hvJ/oBlVNE6ZswcgCHqNJrQY2O5B5axH4K9eoqmq6k9ktOZeK2XOAQhEd+4B4xhb dT0g== X-Gm-Message-State: ANoB5pnCqkfg4hIjUpPy59uuEAIJBaKFy5BvInO5f55rUzEjUzSvsALy M+G6rAKHWS24dZgHwebYYq0= X-Google-Smtp-Source: AA0mqf6chQrISyKGDSM8yTtWqC9coU7avrKK7VK5jxUBz0T8Xx+B1g2Cf8CKhjxGcJxwrPQMrIWkCA== X-Received: by 2002:a63:a504:0:b0:456:4f9a:fbb6 with SMTP id n4-20020a63a504000000b004564f9afbb6mr13599960pgf.318.1668466979496; Mon, 14 Nov 2022 15:02:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:59 -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 19/19] perf stat: Add print_aggr_cgroup() for --for-each-cgroup and --topdown Date: Mon, 14 Nov 2022 15:02:27 -0800 Message-Id: <20221114230227.1255976-20-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" Normally, --for-each-cgroup only works with AGGR_GLOBAL. However the --topdown on some cpu (e.g. Intel Skylake) converts it to the AGGR_CORE internally. To support those machines, add print_aggr_cgroup and handle the events like in print_cgroup_events(). $ perf stat -a --for-each-cgroup system.slice,user.slice --topdown sleep 1 nmi_watchdog enabled with topdown. May give wrong results. Disable with echo 0 > /proc/sys/kernel/nmi_watchdog Performance counter stats for 'system wide': retiring bad specula= tion frontend bound backend bound S0-D0-C0 2 system.slice 49.0% = -46.6% 31.4% S0-D0-C1 2 system.slice 55.5% = 8.0% 45.5% -9.0% S0-D0-C2 2 system.slice 87.8% = 22.1% 30.3% -40.3% S0-D0-C3 2 system.slice 53.3% = -11.9% 45.2% 13.4% S0-D0-C0 2 user.slice 123.5% = 4.0% 48.5% -75.9% S0-D0-C1 2 user.slice 19.9% = 6.5% 89.9% -16.3% S0-D0-C2 2 user.slice 29.9% = 7.9% 71.3% -9.1% S0-D0-C3 2 user.slice 28.0% = 7.2% 43.3% 21.5% 1.004136937 seconds time elapsed Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index cf25ed99b5df..f5501760ff2e 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -900,6 +900,42 @@ static void print_aggr(struct perf_stat_config *config, } } =20 +static void print_aggr_cgroup(struct perf_stat_config *config, + struct evlist *evlist, + char *prefix) +{ + bool metric_only =3D config->metric_only; + struct evsel *counter, *evsel; + struct cgroup *cgrp =3D NULL; + int s; + + if (!config->aggr_map || !config->aggr_get_id) + return; + + evlist__for_each_entry(evlist, evsel) { + if (cgrp =3D=3D evsel->cgrp) + continue; + + cgrp =3D evsel->cgrp; + + for (s =3D 0; s < config->aggr_map->nr; s++) { + print_metric_begin(config, evlist, prefix, s, cgrp); + + evlist__for_each_entry(evlist, counter) { + if (counter->merged_stat) + continue; + + if (counter->cgrp !=3D cgrp) + continue; + + print_counter_aggrdata(config, counter, s, prefix, + metric_only); + } + print_metric_end(config); + } + } +} + static void print_counter(struct perf_stat_config *config, struct evsel *counter, char *prefix) { @@ -1361,7 +1397,10 @@ void evlist__print_counters(struct evlist *evlist, s= truct perf_stat_config *conf case AGGR_DIE: case AGGR_SOCKET: case AGGR_NODE: - print_aggr(config, evlist, prefix); + if (config->cgroup_list) + print_aggr_cgroup(config, evlist, prefix); + else + print_aggr(config, evlist, prefix); break; case AGGR_THREAD: case AGGR_GLOBAL: --=20 2.38.1.493.g58b659f92b-goog