From nobody Sat Apr 11 12:42:51 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 E4442C4332F for ; Mon, 7 Nov 2022 21:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233413AbiKGVd0 (ORCPT ); Mon, 7 Nov 2022 16:33:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232943AbiKGVdV (ORCPT ); Mon, 7 Nov 2022 16:33:21 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DFAB2EF69; Mon, 7 Nov 2022 13:33:20 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso15944550pjg.5; Mon, 07 Nov 2022 13:33:20 -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=P/+ttTXlN3qSbb6UdL+RVJy8YHaKz6aK11BAwI0KhZk=; b=bT85bhI6QB9lAe+cK/rigjb/ajLGDmXBUw0hdSD22wbGr/UQY/Mminlke55bRAebf7 0+IuVaLVLgYwYqGGpeBn0Tv1LbZ8F04Cs8ihKMzCoi6Uk9YWxKvPweSbFSjOUGe4k1/L BfzY1VyP5MLjC2fwDRYhYiDHNnwboMZEe7+bI2nY9xKPzWJjwMterMehmFHve1RYabZl V1SylFJDb6sXgEBSdkOBwZf0CFxMwxKPCHUGMa4sZJKch/D/tOHGoY3nZkm9Spd4bsy7 z28nkpTYHByNuIxG8vQ+lBb4oe2JzIBHfk7emsPRTkroltTHnR0UPE/W9QjlPA0Y6yNx /fwA== 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=P/+ttTXlN3qSbb6UdL+RVJy8YHaKz6aK11BAwI0KhZk=; b=rBINTWAlOFLhyq/HfW2K1DagS+fEIVV7o5qQsPWuTU4ZZzuCSYvasH0r5Ciopw0BsQ Ov2OjKmFMphkgRZMCP8MBoypy1VGHG71nFJCbSqV3a+WaZE85tGN3cWHksyScZrgJbk6 a9XxRR+Z6qLVmBm1fYLgR3yK51sfDselwT/3GMS26FBVWBTkiltG/FiLtEWQTOJ3txIP HhEFPpB7HihZs+7d2kkSiALlMp/A/OdYsa0ChGgAbODhj2gXfRj3lG0f3Gm9rNqEqW2h v9sHlrNh0YfCd6U3QL2mLW1S6wcLzO/PqRAa/NuxKDBjZEt+rx9wRo9BYhpkaU6iK+RM 5HbQ== X-Gm-Message-State: ACrzQf0TVjtW2XBIENEn6W3aeK9LBH2wOhnBWsQWMphaN7Sf2uVt8XzK ckXMAMfA2Xv++ycIBRZsAq8= X-Google-Smtp-Source: AMsMyM7t6jdCbHFngz6P451f81KbVjyB8yzw1r0FD0YXCKbFAuyxzS8wxkgsrpqunc0bq0s/cCp9pQ== X-Received: by 2002:a17:902:d38d:b0:186:9fc5:6c13 with SMTP id e13-20020a170902d38d00b001869fc56c13mr52726184pld.73.1667856799881; Mon, 07 Nov 2022 13:33:19 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:19 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 1/9] perf stat: Fix crash with --per-node --metric-only in CSV mode Date: Mon, 7 Nov 2022 13:33:06 -0800 Message-Id: <20221107213314.3239159-2-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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 following command will get segfault due to missing aggr_header_csv for AGGR_NODE: $ sudo perf stat -a --per-node -x, --metric-only true Fixes: 86895b480a2f ("perf stat: Add --per-node agregation support") Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 657434cd29ee..ea41e6308c50 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -534,7 +534,7 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int [AGGR_CORE] =3D 2, [AGGR_THREAD] =3D 1, [AGGR_UNSET] =3D 0, - [AGGR_NODE] =3D 0, + [AGGR_NODE] =3D 1, }; =20 pm =3D config->metric_only ? print_metric_only_csv : print_metric_csv; @@ -819,6 +819,7 @@ static int aggr_header_lens[] =3D { [AGGR_SOCKET] =3D 12, [AGGR_NONE] =3D 6, [AGGR_THREAD] =3D 24, + [AGGR_NODE] =3D 6, [AGGR_GLOBAL] =3D 0, }; =20 @@ -828,6 +829,7 @@ static const char *aggr_header_csv[] =3D { [AGGR_SOCKET] =3D "socket,cpus", [AGGR_NONE] =3D "cpu,", [AGGR_THREAD] =3D "comm-pid,", + [AGGR_NODE] =3D "node,", [AGGR_GLOBAL] =3D "" }; =20 --=20 2.38.1.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 A2F1DC4332F for ; Mon, 7 Nov 2022 21:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233441AbiKGVdb (ORCPT ); Mon, 7 Nov 2022 16:33:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233403AbiKGVdY (ORCPT ); Mon, 7 Nov 2022 16:33:24 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8372129; Mon, 7 Nov 2022 13:33:21 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id gw22so11860952pjb.3; Mon, 07 Nov 2022 13:33:21 -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=Qv3hf1ICDXb7Hn+sXBgVCZ+pZTQGoTEBZluThFFWAXw=; b=kE7vmIC0fkdEnNFfXn/JmPMCk/jZwZAJ6eYmSAC8mz5l/evGA37v3qWxC93WNPk1jy 7ofPD7Di5xAfJ5Ijg7llqyLpaCaGx80X0RQC3pEooX8V8F6u05/7CW6Ir25lwiiGjxBj Pd7QeBQsGrkpIfs0HO0Rt09XlchaC3p9XDIcwMWt9xPYORlsA756Sxs3S0OUShd/nrDb DfCrnzUQaLAtZREo+D5NPT9T0tOd235pwhvEzXJ1mq+exXCyyVS2H2jDLcAsO90m7jx8 Fsxpin/f+NLxS10ZEi5SPi/un+LGGAzEeADUq8rcUi/5NLVyQoUy7Xo2VLrVoAZrTkp6 9G2g== 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=Qv3hf1ICDXb7Hn+sXBgVCZ+pZTQGoTEBZluThFFWAXw=; b=ZTPplWGM4aN+EbEw/4IE6c5Pl4JMSYS2QT78mPTOLRbm4EJdRI4mhf0eZlu/BGmCD+ yvNzpeSVF0hxnD5w4PpNq3MV2FuqXE4R4mXFlYdJhIwnHJUcqeizG3kTw32JirtZGjgY UoFyvCDpm3aRySWwiOqRpdXrbRhLioNlzki52juHR4p6FV0n97FMpEcgn3lNSYPENBax pFV80pJVqCpNszqIa70nQb7reBiE7/O4yK280mp4KlAi0nh5YY1NsDGcNP3ZmCqJ+WmE 4zTHIKloPciWrlpxOMVNV5PmADmEywvgoYkiYr9eurkvNGa05H50XN60EeSzqmp4L+Zl Wung== X-Gm-Message-State: ACrzQf0u9eBlPwE9CytADiWGrLPbkDYE+pZBl9ekRbYr6K96uI7zG9GD LdRqDuTw1so98G8M+cnTygk= X-Google-Smtp-Source: AMsMyM5b+kXSahQnt+NHp0RhIwOQmjbsO+cwH3vdxHPABBxOBC/mMZ4NI4AMs6aLQqqdjOSfOEJSIg== X-Received: by 2002:a17:90a:9dc5:b0:213:c885:bc06 with SMTP id x5-20020a17090a9dc500b00213c885bc06mr48829260pjv.223.1667856801287; Mon, 07 Nov 2022 13:33:21 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:20 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 2/9] perf stat: Increase metric length to align outputs Date: Mon, 7 Nov 2022 13:33:07 -0800 Message-Id: <20221107213314.3239159-3-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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 perf stat is called with very detailed events, the output doesn't align well like below: $ sudo perf stat -a -ddd sleep 1 Performance counter stats for 'system wide': 8,020.23 msec cpu-clock # 7.997 CPUs ut= ilized 3,970 context-switches # 494.998 /sec 169 cpu-migrations # 21.072 /sec 586 page-faults # 73.065 /sec 649,568,060 cycles # 0.081 GHz = (30.42%) 304,044,345 instructions # 0.47 insn pe= r cycle (38.40%) 60,313,022 branches # 7.520 M/sec = (38.89%) 2,766,919 branch-misses # 4.59% of all = branches (39.26%) 74,422,951 L1-dcache-loads # 9.279 M/sec = (39.39%) 8,025,568 L1-dcache-load-misses # 10.78% of all = L1-dcache accesses (39.22%) 3,314,995 LLC-loads # 413.329 K/sec = (30.83%) 1,225,619 LLC-load-misses # 36.97% of all = LL-cache accesses (30.45%) L1-icache-loads 20,420,493 L1-icache-load-misses # 0.00% of all = L1-icache accesses (30.29%) 58,017,947 dTLB-loads # 7.234 M/sec = (30.37%) 704,677 dTLB-load-misses # 1.21% of all = dTLB cache accesses (30.27%) 234,225 iTLB-loads # 29.204 K/sec = (30.29%) 417,166 iTLB-load-misses # 178.10% of all = iTLB cache accesses (30.32%) L1-dcache-prefetches L1-dcache-prefetch-misses 1.002947355 seconds time elapsed Increase the METRIC_LEN by 3 so that it can align properly. Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- 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 ea41e6308c50..17d656566cd9 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -218,7 +218,7 @@ struct outstate { struct evsel *evsel; }; =20 -#define METRIC_LEN 35 +#define METRIC_LEN 38 =20 static void new_line_std(struct perf_stat_config *config __maybe_unused, void *ctx) --=20 2.38.1.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 92BADC4332F for ; Mon, 7 Nov 2022 21:33:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233482AbiKGVdh (ORCPT ); Mon, 7 Nov 2022 16:33:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233405AbiKGVdY (ORCPT ); Mon, 7 Nov 2022 16:33:24 -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 1FD79328; Mon, 7 Nov 2022 13:33:23 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id k22so11912408pfd.3; Mon, 07 Nov 2022 13:33:23 -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=7OYL7vpqm8L3ADcCJc6hKNFYnwJB/S0aPLCXr3zst78=; b=CESh0/ZbpAqv78rvTm8npz/mdldte6JqrpQpXmkhJ2wRVcw0OaAFcL7610kd1GdKl8 AZCMrJ9+Fs+7tIV9NG0S4KQq/FViPJ+GxPNZg5ErU7py8WNJmC716PJCcJ3NKBDpkVC0 xTzO6S6hKRmmYXSM5FtGZYrsRN6DufyRAY9noU6V7TwryqQRIz7PAiORUIAZwdCOGtRG TQZE32AFfYDUYjXo5n+KUygsPtM/N/UdLqjpylqsmJqrf7h0JP3WScHuthqjjoywNV5i GG2fqxjkgycjEBQsNbmHSCwgfzuhZYojwxUFKW94EHDJAjtXmLofBafb/AdjMS5CfY+m /D/w== 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=7OYL7vpqm8L3ADcCJc6hKNFYnwJB/S0aPLCXr3zst78=; b=Gsk8NJHsaKlyseXSHVyi43sTCcqumycHxBkRHw55Dj7H7zF0hr1dXbzXx2xFzG+dwA aR9BwCA1noYhTuiTqIBqtlkC6HqUDyFSbdemfNVL3wCNztLM27imDn8vwJVbaXsCAVfj Ul8KlujcZkT3hb330FYjWm1jqcUsrFjRanVL70M7QWMTiVyTFtwQlQOdF89GM8RBlOOc Cm5BCPMRCH7MEUYvWFIulfn/5MJaaRM5eGifBz+VJypjhXpj9tFsMeCEaVNiSKZhAJC+ yHKGnsijxjN/mEht8tKyKQL5qLXCz4lo10GxFDk6lp4+rmbLlgesAwcyxueEidAmCWXa vUzw== X-Gm-Message-State: ACrzQf2pj+rdmyjVSS5yGMXW6hKeUqWXliPXxlozkPb/bTnsybCkTAn5 PlUTxi332PrXWA5EEI6u/lU= X-Google-Smtp-Source: AMsMyM4u9NO1JFKWbXomkYIi87uIFh6amlEwYP336vQAVT1rKngy/BkfKMLL3jc/+8xl8wSXW1Ii1A== X-Received: by 2002:a65:6950:0:b0:439:51cd:8b8b with SMTP id w16-20020a656950000000b0043951cd8b8bmr45185677pgq.230.1667856802573; Mon, 07 Nov 2022 13:33:22 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:22 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 3/9] perf stat: Clear screen only if output file is a tty Date: Mon, 7 Nov 2022 13:33:08 -0800 Message-Id: <20221107213314.3239159-4-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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. 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 17d656566cd9..d4936a502560 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -892,7 +892,7 @@ static void print_interval(struct perf_stat_config *con= fig, FILE *output =3D config->output; static int num_print_interval; =20 - if (config->interval_clear) + if (config->interval_clear && isatty(fileno(output))) puts(CONSOLE_CLEAR); =20 if (!config->iostat_run && !config->json_output) --=20 2.38.1.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 05A04C433FE for ; Mon, 7 Nov 2022 21:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233536AbiKGVdv (ORCPT ); Mon, 7 Nov 2022 16:33:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233477AbiKGVd3 (ORCPT ); Mon, 7 Nov 2022 16:33:29 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A39FDA2; Mon, 7 Nov 2022 13:33:24 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id v3so11629342pgh.4; Mon, 07 Nov 2022 13:33:24 -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=AIzOeW4bqFAI0ZH2XjiJS5dG7CBesFCQCZcY4ffv/5k=; b=Rdq9AtpQ8XqcN3B/WunTUwRM/esIVOLGUjjW0IkrxsTEQDcHBwSY2wQIXEWg/sdJS5 rarfpDM9YCvt5+LMJohUnxBSQXo6pgGP2kxUFXcwA0cj408Z5u2TR9GedsgRndqnO79I 9REV/ya38OwppOAY5PKuKzVk4GTzrm1DTfk07FRrzUeKtLqaV8kS3aY31LXl3O3Ik8a/ E1y0DdGllTSXmnh/wit5D7kyii3XanD79Voxw+NqwLlGvlRrF9it3SKKBOJ3NWl8vvGd vQc8upcdNm8xB9fdsed8VEbpGlDKGHtjeFC8p8nM0b7mlHivMZfn9G1F0QpPektOlTsn 59lA== 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=AIzOeW4bqFAI0ZH2XjiJS5dG7CBesFCQCZcY4ffv/5k=; b=QBWJISr+Etq3HBF+F6pMPoC7gBY4Gy13pTJ3Mo4e6ynOJPD094G/DIq2K3pE+X57dZ sYTzfPwqdBtz87wZrpjfjdCn01J3CXEq93HA1gcmrgpqrzBeRlYeVTjoh54uR/1s0e9n +nhAzI2zlLRXTFdWs0ZiruGJJLSxrAFUFRkaOcNB0CyYUQjtDxaDiZBwUFASogKEyQ3N K3fYiXJUYQqzmgm5hLpo9xv/G/8wwyA+kR1jrX2a6+i5QSOJFzrl8YgXWSo+CS9Hps7a RWC5oS1JzZVG/HWb1UZ7HxR7WSvZH7X5ECoeGLfY312nec3r9yDjI+yMX2YDUKcgNzMg 2Abw== X-Gm-Message-State: ACrzQf1kv48I5JoI21YX8J+ZFM9b0N4iaLiXT63UEnPoWnEu6jjwE5Ug cNSoev++4WxzDssYtp2a6ySrLdxMsqE= X-Google-Smtp-Source: AMsMyM4Ryq09UYPfCZ5YqDppNoZLZOICO2oqCN2VSHAs0RRj9xSG3jBA1+bYKUeEOYeVLMZR3osqdA== X-Received: by 2002:a05:6a00:240b:b0:56c:f55a:65b4 with SMTP id z11-20020a056a00240b00b0056cf55a65b4mr887433pfh.35.1667856803802; Mon, 07 Nov 2022 13:33:23 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:23 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 4/9] perf stat: Move common code in print_metric_headers() Date: Mon, 7 Nov 2022 13:33:09 -0800 Message-Id: <20221107213314.3239159-5-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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 struct perf_stat_output_ctx is set in a loop with the same values. Move the code out of the loop and keep the loop minimal. Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/stat-display.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index d4936a502560..115477461224 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -837,11 +837,16 @@ static void print_metric_headers(struct perf_stat_con= fig *config, struct evlist *evlist, const char *prefix, bool no_indent) { - struct perf_stat_output_ctx out; struct evsel *counter; struct outstate os =3D { .fh =3D config->output }; + struct perf_stat_output_ctx out =3D { + .ctx =3D &os, + .print_metric =3D print_metric_header, + .new_line =3D new_line_metric, + .force_header =3D true, + }; bool first =3D true; =20 if (config->json_output && !config->interval) @@ -865,13 +870,11 @@ static void print_metric_headers(struct perf_stat_con= fig *config, /* Print metrics headers only */ evlist__for_each_entry(evlist, counter) { os.evsel =3D counter; - out.ctx =3D &os; - out.print_metric =3D print_metric_header; + if (!first && config->json_output) fprintf(config->output, ", "); first =3D false; - out.new_line =3D new_line_metric; - out.force_header =3D true; + perf_stat__print_shadow_stats(config, counter, 0, 0, &out, --=20 2.38.1.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 58FCCC433FE for ; Mon, 7 Nov 2022 21:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233500AbiKGVdo (ORCPT ); Mon, 7 Nov 2022 16:33:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233404AbiKGVd2 (ORCPT ); Mon, 7 Nov 2022 16:33:28 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B065B1087; Mon, 7 Nov 2022 13:33:25 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so11115477pjs.4; Mon, 07 Nov 2022 13:33:25 -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=lU4ETOkJBeJhSBeHInOj845NFGd1yJAeswjzuBLmc/c=; b=eungdUUVcH+EwVUeFD1iyPkNP2trdMfx+ha6MJtTRKbg6VneXkw/DV6FfYrf4HNAOO tUvqDOlNAvv2e5ABQRxmLd0WtI2bgfiDFXkb6kOneau3LHHlYpZeF7zVPZsHlUQjMAXn PthKxHaNQkSv14q/YIfOYaZLXnTVUNieDSHXGJc7/9T5WLC0jBVatr1hQs4bKYkFj3D7 l7bv5cH8jljFLkx4RhWF9Q4GWrHD0gVwgVv7TcMV5Zm+gWSC8t8ve5AW7wGZnL1eA4iE VPHZbj3IfngL/oIuUtrUhBzFWTw9Nu1plH8lQTojWe3zx1soCPLaONdqF8YPRjODAma1 Vabw== 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=lU4ETOkJBeJhSBeHInOj845NFGd1yJAeswjzuBLmc/c=; b=TjKiW+Ee6b7OMrWgtoTJE6qDK4mCGBR7S2T78jnncOjio3nrM3T5mf/Ty7zjXLXNaV Bh0aNGNBGHf1WMJ9H3BZTocPkCZtzwBR4bEbAIOZXuzPgR32p//29ef1aioFLGbsRBYE CctsusO/qO0IIEMk6wDfbPpbdc9bWEd+CGPo/BnxX0her2mng4anb/+8Dk8mLfAAqCqE QhycyV6itYwZxNS4DRdfS4M4WaxwrBh4RkZY9ajqP+9531HuuiqwQu6S2TimcuMp0iq0 xanVuWfbo6TOkKif6jc2ysfVuU+bAxs+jOa3OUPyoVEGTyNe849iw79Z9lTd+QxkrdQK +jjw== X-Gm-Message-State: ACrzQf3ABlK5kvklOQJY6obzZQJnHA4iaXfIAsw5gml80yi3QlssbXy2 68ADqJPYzJEawG6y9jnwr+c= X-Google-Smtp-Source: AMsMyM7V4g1CyinSyzdAcspGEGvDKGdkE0oCuY7985o01F0tIozbAzksldNDaVTGEchyLZnH9kJSFw== X-Received: by 2002:a17:902:ebc5:b0:186:b848:c6a with SMTP id p5-20020a170902ebc500b00186b8480c6amr52209955plg.46.1667856805071; Mon, 07 Nov 2022 13:33:25 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:24 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 5/9] perf stat: Fix --metric-only --json output Date: Mon, 7 Nov 2022 13:33:10 -0800 Message-Id: <20221107213314.3239159-6-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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" Currently it prints all metric headers for JSON output. But actually it skips some metrics with valid_only_metric(). So the output looks like: $ perf stat --metric-only --json true {"unit" : "CPUs utilized", "unit" : "/sec", "unit" : "/sec", "unit" : "/s= ec", "unit" : "GHz", "unit" : "insn per cycle", "unit" : "/sec", "unit" : "= branch-misses of all branches"} {"metric-value" : "3.861"}{"metric-value" : "0.79"}{"metric-value" : "3.0= 4"} As you can see there are 8 units in the header but only 3 metric-values are there. It should skip the unused headers as well. Also each unit should be printed as a separate object like metric values. With this patch: $ perf stat --metric-only --json true {"unit" : "GHz"}{"unit" : "insn per cycle"}{"unit" : "branch-misses of al= l branches"} {"metric-value" : "4.166"}{"metric-value" : "0.73"}{"metric-value" : "2.9= 6"} Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 115477461224..515fb6db3d67 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -430,12 +430,12 @@ static void print_metric_header(struct perf_stat_conf= ig *config, os->evsel->priv !=3D os->evsel->evlist->selected->priv) return; =20 - if (!valid_only_metric(unit) && !config->json_output) + if (!valid_only_metric(unit)) return; unit =3D fixunit(tbuf, os->evsel, unit); =20 if (config->json_output) - fprintf(os->fh, "\"unit\" : \"%s\"", unit); + fprintf(os->fh, "{\"unit\" : \"%s\"}", unit); else if (config->csv_output) fprintf(os->fh, "%s%s", unit, config->csv_sep); else @@ -847,10 +847,6 @@ static void print_metric_headers(struct perf_stat_conf= ig *config, .new_line =3D new_line_metric, .force_header =3D true, }; - bool first =3D true; - - if (config->json_output && !config->interval) - fprintf(config->output, "{"); =20 if (prefix && !config->json_output) fprintf(config->output, "%s", prefix); @@ -871,18 +867,12 @@ static void print_metric_headers(struct perf_stat_con= fig *config, evlist__for_each_entry(evlist, counter) { os.evsel =3D counter; =20 - if (!first && config->json_output) - fprintf(config->output, ", "); - first =3D false; - perf_stat__print_shadow_stats(config, counter, 0, 0, &out, &config->metric_events, &rt_stat); } - if (config->json_output) - fprintf(config->output, "}"); fputc('\n', config->output); } =20 @@ -954,14 +944,8 @@ static void print_interval(struct perf_stat_config *co= nfig, } } =20 - if ((num_print_interval =3D=3D 0 || config->interval_clear) - && metric_only && !config->json_output) + if ((num_print_interval =3D=3D 0 || config->interval_clear) && metric_onl= y) print_metric_headers(config, evlist, " ", true); - if ((num_print_interval =3D=3D 0 || config->interval_clear) - && metric_only && config->json_output) { - fprintf(output, "{"); - print_metric_headers(config, evlist, " ", true); - } if (++num_print_interval =3D=3D 25) num_print_interval =3D 0; } --=20 2.38.1.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 2E1ACC4332F for ; Mon, 7 Nov 2022 21:33:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233437AbiKGVds (ORCPT ); Mon, 7 Nov 2022 16:33:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233400AbiKGVd2 (ORCPT ); Mon, 7 Nov 2022 16:33:28 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E59BAB1B; Mon, 7 Nov 2022 13:33:26 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id b21so12303325plc.9; Mon, 07 Nov 2022 13:33:26 -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=uEwG62U2ocTRAE+zcAm5Rx1np9/Wr63UQVaH+5ioR9I=; b=Hc+KCEIHI0yjOOxQWtJwjkjcfiZXxl/jTVZifw/Fon9yqTKXtKv5u4DbvdbdDg7b0G kG8o1emeN56chtVXqrb982qGiSNzp6P3NbXfUnbckq0ANeuDN0wppNwD3xQ8hwOtMNNP jwLuRjW0Jab1wVy26+mMwtVkZWLgj8c/5rtJ2OB2wJc/HT7E/JOe9wAXDm3ZTXd7mZKC kATtnMx12FaYWV0jgws7UYZWrWyxSZNjbVW6m3EaXFE+58au9jrY1kz0hkdR+tDplIDh 4kKLsAadGt7rZXfbu1QFAbgkvLbeUVLIFa1aHcdq9aDMZmqGE9m+/XC6BMp2PlomTXff Bwxw== 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=uEwG62U2ocTRAE+zcAm5Rx1np9/Wr63UQVaH+5ioR9I=; b=VwnpDz7gviu5bMT5MQ4ANzsk1SfuyKfqbWY0UeZ5ZX5TyT9b9ArFhMBnRTPXkjXoe6 xdVnCafIM4ozPsp63rXmVvKUL44hEBWMEY+uYYWLWEMJpxpxYnIZLL4wg7ktH36lFV+f Deprk4l3OKl0NYw8TtevbSxrFJxmvs/YjUjQbrIRDCH4B353GMvb0zz5me9bVgtCT1fd k+5onsCND3m/UNLeJx8Iue8HnKexYjIVmH0LixKPANRh182no98OAGAyx0WKUnj4GvSZ qNnzkf9BLNR+Jw8cCG0WR4seh2wgyJz35DPIu0AzS3jUqRT4Hx6TK6E/1olrYHP8Wi6p l6wA== X-Gm-Message-State: ACrzQf3I52dlikkKv/1pbCAfnYH4KYGpY69szDPERkuMWyZiMbXPTdXj JkrXneT6dtkvC+fuqoevOro= X-Google-Smtp-Source: AMsMyM5n/dzXkOfJeTpeQ97B/T0IHKk094vL/ofETPkyF4jUeyUS3qx/VwbZwR6AO8iNAdaFHXqQvg== X-Received: by 2002:a17:902:9a41:b0:188:50c2:89cf with SMTP id x1-20020a1709029a4100b0018850c289cfmr27538355plv.34.1667856806361; Mon, 07 Nov 2022 13:33:26 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:26 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 6/9] perf stat: Do not indent headers for JSON Date: Mon, 7 Nov 2022 13:33:11 -0800 Message-Id: <20221107213314.3239159-7-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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" Currently --metric-only with --json indents header lines. This is not needed for JSON. $ perf stat -aA --metric-only -j true {"unit" : "GHz"}{"unit" : "insn per cycle"}{"unit" : "branch-misses= of all branches"} {"cpu" : "0", {"metric-value" : "0.101"}{"metric-value" : "0.86"}{"metric= -value" : "1.91"} {"cpu" : "1", {"metric-value" : "0.102"}{"metric-value" : "0.87"}{"metric= -value" : "2.02"} {"cpu" : "2", {"metric-value" : "0.085"}{"metric-value" : "1.02"}{"metric= -value" : "1.69"} ... Note that the other lines are broken JSON, but it will be handled later. Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- 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 515fb6db3d67..25f67fb37f6d 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -851,7 +851,7 @@ static void print_metric_headers(struct perf_stat_confi= g *config, if (prefix && !config->json_output) fprintf(config->output, "%s", prefix); =20 - if (!config->csv_output && !no_indent) + if (!config->csv_output && !config->json_output && !no_indent) fprintf(config->output, "%*s", aggr_header_lens[config->aggr_mode], ""); if (config->csv_output) { --=20 2.38.1.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 52838C43219 for ; Mon, 7 Nov 2022 21:34:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233517AbiKGVeD (ORCPT ); Mon, 7 Nov 2022 16:34:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233510AbiKGVdp (ORCPT ); Mon, 7 Nov 2022 16:33:45 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35EAACFC; Mon, 7 Nov 2022 13:33:28 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id y203so11915803pfb.4; Mon, 07 Nov 2022 13:33:28 -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=mWSDNfZ2wImW4xPzQ9jDtU6vpg7XH7BhaLU95Jwpr2Y=; b=BqNGbFdHwFQxBhVekowAdOUNERDGn2+AWTAyyiZCzt5B/9GCH0SUZ66R7ZrHk9eGZf BfkM9JDgUIkojWuYTxAGCA0Lpd4t21URmF/n/ybGbQaCggsJgy6F7/EbwPflwodxtq9Q 8queCZb++T6Aqvi9QoVSdlpoua1q/gjjTpRJuVuq8M4f6JO5KPxJboIil3/T0bbZ3imc 7M6KNqczmjl/QRcX3jMKvHFQA+rtlEsdd+LMI59y49ANRrEv3Wdswe6XfrUQku825XaL PPObpYYXhLJE3ocialaJlNqBvAnxLpmAkDSRCqva3pCXPoviaatiREdqAAsJK1/FLa08 yq+g== 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=mWSDNfZ2wImW4xPzQ9jDtU6vpg7XH7BhaLU95Jwpr2Y=; b=qYiBIrbG+w+dSjXp3xiEsesSVaNlwoEU32EtRqdQMyWRwFtN5accz9nlui58vssFJM qQB3a9l/0Eakq9r4UvIey2nCDWuSnoNv6HesZNhb1urN3lSB7qek3ooNBdXO54byxZkq f0hG9TNo6h1Y9k0ofQtY7aCsXYsjZYrck8ur345gglh3rdg1kLjA8PnXfk00KeMq8h8q ypGmX4GVXOjZu1F81oCXVEVXQe68j5mDhz+ZRJlI2TQTBO/itaQgRTmjGzxuJMOlTQzq XpuWeO3ewE0ibObd6t8bO9SbuPkyZyqNz355OenoRE9BJPND6bIFg2roOKvtgs7Fwzlp A2hw== X-Gm-Message-State: ACrzQf0mbs/Dl82bhzwvLopK6HzJ6RMAT3pzODQ2sNqbqo6KqeyjOPsj 11LLWGqi9AsriLERay+ExJ8= X-Google-Smtp-Source: AMsMyM4UMw5+jK5rXwMAVsrZfuKsU/79gy9ULlxBwiDvQnSFIwfSmVlXu/h/0M+nmXPBq3RQki89eQ== X-Received: by 2002:a62:860b:0:b0:56d:a2be:ebe4 with SMTP id x11-20020a62860b000000b0056da2beebe4mr873244pfd.28.1667856807633; Mon, 07 Nov 2022 13:33:27 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:27 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 7/9] perf stat: Add header for interval in JSON output Date: Mon, 7 Nov 2022 13:33:12 -0800 Message-Id: <20221107213314.3239159-8-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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" It missed to print a matching header line for intervals. Before: # perf stat -a -e cycles,instructions --metric-only -j -I 500 {"unit" : "insn per cycle"} {"interval" : 0.500544283}{"metric-value" : "1.96"} ^C After: # perf stat -a -e cycles,instructions --metric-only -j -I 500 {"unit" : "sec"}{"unit" : "insn per cycle"} {"interval" : 0.500515681}{"metric-value" : "2.31"} ^C Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/stat-display.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 25f67fb37f6d..aab2576bd40f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -860,6 +860,10 @@ static void print_metric_headers(struct perf_stat_conf= ig *config, 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.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 78A88C433FE for ; Mon, 7 Nov 2022 21:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232832AbiKGVeH (ORCPT ); Mon, 7 Nov 2022 16:34:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233514AbiKGVdq (ORCPT ); Mon, 7 Nov 2022 16:33:46 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCD1F2195; Mon, 7 Nov 2022 13:33:29 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id z5-20020a17090a8b8500b00210a3a2364fso182795pjn.0; Mon, 07 Nov 2022 13:33:29 -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=F3kWpBC1NLbl49EVyM6kuTlOZ/tQuDbS9uiyiK9Bcd8=; b=FcSbzoNLCo8OoQLRTy1AojjTte1miTZf2JSnw5QprLwVDsrGsELCcwIEOdIuBoGpuI v5+QS0SkLzYXJtsLG8JJ19RCg1oSgUJNg6OMEKclucZVbPXotCqihsfZWk9GZfFgIqWG 0Tl69ccf++bhhstTYh68opUzCqfz0nKNORwqH72toYynd+9Jvq6gLdU+gMo7f7qyAQuh 5G+CqBcYQ/S6LR6b0mn8ceudSUEWwh0AXmK31d4feFd0YjHjQpivKkBuzRUyNhc4EFiv wCaAwr6Q2pvBvaNONSW5yJSEmo4bYtd8WrOoqJLnYK/xo4Z/eGoOTlgvZa8MJpV7pZu9 HUxA== 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=F3kWpBC1NLbl49EVyM6kuTlOZ/tQuDbS9uiyiK9Bcd8=; b=x4KYb1PdRWFTJFwHweqkRg2bJdPCyxNasrfpt8O8tTyvHeoi6n5JOiPNMnsjfVlLbV G8uiFLTnhPMQlufccdSENX4Z+1kUQeqsg2W96qtfR3UZ/WJ9nApnyTNXU5Qge13mYk6N 2OhkxzedUVuuqiP0Ije5l9SfcWkiO5ylRyz91VYjo2Li0t1InFsCdd2Rsn9meL90t1Kp 3E72IveYcUFRIqPanYGUEpZgNfjaWrkFiWQh2M1DjLkjnT5R7lx0HrWkJDPuel3SDEzB Ykc/KhlZ8uG9IMwcL7ZWtTOSKJ3Owso+1JfPIMPo/85mc4Zeiq8QjWZKygEg3R0LRTo4 rYEQ== X-Gm-Message-State: ACrzQf1/Fwohts8nM9NW4IcMleU+elBHttkM3z9HpsiqbtnPUbFa0eBz eBcPoblCH/eMIGPuExFthQM= X-Google-Smtp-Source: AMsMyM5fLV37+O7kmaviYn3MmW+LUXgk4eB5+qxKrSreo0uaQHUHcCC7GfzhORwSE+ongdf/sXPXUA== X-Received: by 2002:a17:902:e846:b0:187:2127:cbb with SMTP id t6-20020a170902e84600b0018721270cbbmr44249969plg.125.1667856808976; Mon, 07 Nov 2022 13:33:28 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:28 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 8/9] perf stat: Fix condition in print_interval() Date: Mon, 7 Nov 2022 13:33:13 -0800 Message-Id: <20221107213314.3239159-9-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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 num_print_interval and config->interval_clear should be checked together like other places like later in the function. Otherwise, the --interval-clear option could print the headers for the CSV or JSON output unnecessarily. Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index aab2576bd40f..a10af26c26ab 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -902,8 +902,8 @@ static void print_interval(struct perf_stat_config *con= fig, sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long) ts->tv_sec, ts->tv_nsec); =20 - if ((num_print_interval =3D=3D 0 && !config->csv_output && !config->json_= output) - || config->interval_clear) { + if ((num_print_interval =3D=3D 0 || config->interval_clear) && + !config->csv_output && !config->json_output) { switch (config->aggr_mode) { case AGGR_NODE: fprintf(output, "# time node cpus"); --=20 2.38.1.431.g37b22c650d-goog From nobody Sat Apr 11 12:42:51 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 A8B55C43217 for ; Mon, 7 Nov 2022 21:33:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233546AbiKGVdx (ORCPT ); Mon, 7 Nov 2022 16:33:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233483AbiKGVdk (ORCPT ); Mon, 7 Nov 2022 16:33:40 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D567DD2DE; Mon, 7 Nov 2022 13:33:30 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id gw22so11861576pjb.3; Mon, 07 Nov 2022 13:33:30 -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=tWKNNag4dwKiJExBOGweLXLb/8nFtKqU9STsZaykkGI=; b=nGjJh+u1cT5OcLzNsc5z5NXn3K+ih9o0FvHL2x/uWnazjn2jGmuuTlQD3O1KmcteJm UygjpYZP8GJ+VoNgshCb4dvhzIir2Je/de7WZhyGFrQyAIEE9M6Jr+G7IxwS8kVsgE2U 3CGxv/94tzRcBIgMzedh6NJctPvssF7nWKmVLVecWLC3HiPSpLMG+VDinxKsId/26+KK 5OG5//yDxHa507fdLJo7f9lHIZpl5/dPWVy5Id9vnAC+8IRRjFKnJyMqqS7O/LcU2oTY HumI4hF0T6ie/juL1fKJVCJ9R36t8HNl8I7vfyKEjGhiWLRt4szY+KnbANh1IL3pn4Ew aDzA== 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=tWKNNag4dwKiJExBOGweLXLb/8nFtKqU9STsZaykkGI=; b=kUB09Y9nXnBqTv8Hx+TZY2gl39BbaKWXm6ptpTtUFhKJXy+Yw3BvBRLA4uXzRgV/S8 YNNavW2sUHcxq0LYS/G7GJufJmN++WluXO1xKBq+Y1NGhkSMDIOnqy0i8AC8AjCpeBcd mpGItqNbJfIe+XNP8DhGKz7tL4Gg2glpi5Dd0uExvNrrbq0+TWGOPLV2wYQ14kefjQl4 YB2VUkPYEwrjhJHVWXNQqMXaq69dfLYjwh2cRZL4VU35nkw+8MBnoS8Vn7+/3fmkaR4g xHPHd6Jc3GywxtXpI0e5JDodrUCPLVH8EQHYFUYsb875qkxZif3ZkT4lB67J7+D75jn2 GWAg== X-Gm-Message-State: ACrzQf20+4OvLtXvMVpKeeHcRwwtrTwj3BjiXE5s9vsWcUVf2+NukjfZ hJRDKP5ATo5KgipkA/z1Zjo= X-Google-Smtp-Source: AMsMyM41ctb7Hr22501NqnEn20K0yT4jjisnCMVEgyoJZpBbz/PcJV1E1aUzzIdC6tnWR8ZB8l0bIg== X-Received: by 2002:a17:90b:84:b0:213:de0c:1253 with SMTP id bb4-20020a17090b008400b00213de0c1253mr45777292pjb.74.1667856810221; Mon, 07 Nov 2022 13:33:30 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:5850:5958:9c77:f623]) by smtp.gmail.com with ESMTPSA id a1-20020a1709027e4100b0017f5ba1fffasm5366413pln.297.2022.11.07.13.33.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 13:33:29 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark Subject: [PATCH 9/9] perf stat: Consolidate condition to print metrics Date: Mon, 7 Nov 2022 13:33:14 -0800 Message-Id: <20221107213314.3239159-10-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221107213314.3239159-1-namhyung@kernel.org> References: <20221107213314.3239159-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 pm variable holds an appropriate function to print metrics for CSV anf JSON already. So we can combine the if statement to simplify the code a little bit. This also matches to the above condition for non-CSV and non-JSON case. Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/stat-display.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index a10af26c26ab..4d3999673dde 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -600,9 +600,7 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int pm(config, &os, NULL, NULL, "", 0); print_noise(config, counter, noise); print_running(config, run, ena); - if (config->csv_output) - pm(config, &os, NULL, NULL, "", 0); - else if (config->json_output) + if (config->csv_output || config->json_output) pm(config, &os, NULL, NULL, "", 0); return; } --=20 2.38.1.431.g37b22c650d-goog