From patchwork Mon Nov 14 23:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409142wru; Mon, 14 Nov 2022 15:06:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf5hkxb2HsrsRnKyjmqMrok3G036j6tg/nlNSqT2KylhFObdN9A/MNXrLIcZOGheGV8i9S3u X-Received: by 2002:a50:f612:0:b0:458:caec:8f1e with SMTP id c18-20020a50f612000000b00458caec8f1emr12533507edn.280.1668467182804; Mon, 14 Nov 2022 15:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467182; cv=none; d=google.com; s=arc-20160816; b=JSMiqTJVkfWnf9nKxR9+p4PfXOpecSbRBpmwh1+I5m8hn24ejBAKziVpj+p00/yZ81 tdbTN0d9NxZM9wsSxcoG8QDGzFZ9il0BJdGuE4ralCrrogzWVAh1Tm9qEKEGWkUfviX/ NmIZQGVn+WztVFc7BQnnkq2XNSmhDN9lv4gnbgHFN729Jg6RQomWBg2X7j2QwcRYYnpu lfKXDgbI1QHpSTWnebOsNwKG3Qv/P4RO6JSJVVLwy15QczJYBAmwG3TgUfVYrqP5yC4a 2xXJU5lWR65mTXyOYBebOigdLhLlKEEq5DKWpNAqtLy77FK/cV1vNjN3WXI7imVQAwMc TIcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=rt0OZoaxk4oNSiXVua0yf4Wn8zR1kll8hc9QqXyH+pA=; b=JGR3U9xoXTe3E10oi+6If85QnH4uX/12HlX2zEYAN9C9pyueX08B/prkQyo78Sq8JC bmXGjli97kVcpO9I1W25M4tT7WmPyfo3FIqzH6IjBk769fQ6k8WJr3uptyw6jsqgP6hj vMIkkUFTTWgSyvsY1F1jme4P9VGTfABfELYcgwQeT7PmTmkwnfttW8jWHqwwyM8MbZCx 7XjjyAqpF5Hzhcwb7AvUCWG8OQCIhbWbQiC6tWZv/kSpdMajmOmglNJl/pr8HN5I9dxi vdx+vpXpLW9PXmKAbs1Y8G+Cb1OB0lNqaNLLxVQqF6QqsEdOG4CnXlxt+axRyAXdRWYm 9kPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="jcCl/Fyx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u24-20020a50a418000000b0045cca8f9a0asi8971089edb.580.2022.11.14.15.05.58; Mon, 14 Nov 2022 15:06:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="jcCl/Fyx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237853AbiKNXC6 (ORCPT + 99 others); Mon, 14 Nov 2022 18:02:58 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514644588138690?= X-GMAIL-MSGID: =?utf-8?q?1749514644588138690?= 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) } } + 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 = output; /* From patchwork Mon Nov 14 23:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408402wru; Mon, 14 Nov 2022 15:04:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4hjlkqjjf7LLlAItoCbiFsFKDVJ3S/0n/xmwJYR4lBEi6g61jRs4PNX9PB3/suNx1Mk0Q2 X-Received: by 2002:a17:907:a681:b0:78d:3505:6f3e with SMTP id vv1-20020a170907a68100b0078d35056f3emr11397017ejc.611.1668467086564; Mon, 14 Nov 2022 15:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467086; cv=none; d=google.com; s=arc-20160816; b=hUB9GuQ3jTq8Um501zbbgTP/QmxZeDpOfaIGkp2As/QHNxpeA3TkJQGp44Tl2UTp4k K5BqBdo7Min8nmXCHnfk5lE9NosfyUa8lOgogBA2CjxA2rr5kHTEj9p+7oofB1rvx7vO hWaPh6+W9NBXY3yvQy+jHxq4ZAbThD9q96aERy8lA3yVfGeFEAWMf7hpJwBj93INZ0yx UbgT/D3sO/SISd56tx6Z15e4iFGLQIuMT47UlyixGrlMVYAZtoWqmNFC1i7N0hmBIodA AfHb5PicV9w9te4BpM7xTl2eFC3hoSxMZ13+kALaJl9HzCRVhfd89SQHVfYDfqrwFDOt IG0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=g9gVgzaugGBijq/uNgO/XLVSIa4Ghp/O4hPteTZwehU=; b=dz+CmLo/wDMh94il49O8N+vIqu0RNy1GGLSl7IzbfLUeKRZgSw8Yr3egfYjE6Nn0Vo P4gIYUK1vHsivC2UFvmtOHnnj9wREI1vn05xzU7reNqtoqZM5yjT0EJMY+Ge7Ioif65b ukySerZ0Vs4uH6tcU+A5aER5jxc+4iXe9JWrYsOcwFA8ugOYVPBLLPdmjSP2h4YQSndN ScUjmvG1WxmsyZ058688xhXb1dmZhJNho7OGuVszjXHb226xY7v8QGyl+xh6iZOV/g5k bwv4JlBcztBbYivFQ16iM69eW99ieQb2+mNTLizvXkyNu277xzxzW2JU5KEglm3zheeJ mHFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=P8ggZH5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa6-20020a170906fd8600b00730936657d1si4658217ejb.552.2022.11.14.15.04.22; Mon, 14 Nov 2022 15:04:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=P8ggZH5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237977AbiKNXDD (ORCPT + 99 others); Mon, 14 Nov 2022 18:03:03 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514543682222424?= X-GMAIL-MSGID: =?utf-8?q?1749514543682222424?= 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 "" -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, u64 ena) +{ + if (run != ena) + fprintf(config->output, " (%.2f%%)", 100.0 * run / ena); +} + +static void print_running_csv(struct perf_stat_config *config, u64 run, u64 ena) { + double enabled_percent = 100; + + if (run != ena) + enabled_percent = 100 * run / ena; + fprintf(config->output, "%s%" PRIu64 "%s%.2f", + config->csv_sep, run, config->csv_sep, enabled_percent); +} +static void print_running_json(struct perf_stat_config *config, u64 run, u64 ena) +{ double enabled_percent = 100; if (run != ena) enabled_percent = 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 != ena) - fprintf(config->output, " (%.2f%%)", 100.0 * run / ena); + print_running_csv(config, run, ena); + else + print_running_std(config, run, ena); } static void print_noise_pct(struct perf_stat_config *config, From patchwork Mon Nov 14 23:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408413wru; Mon, 14 Nov 2022 15:04:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf5at0NoJ40kvvyo5onk1Gs+l+pYSJelMJ2dLVIMoD17DL5pk1SehaxEMblTVkuMKj7Gpmie X-Received: by 2002:a05:6402:5384:b0:458:4868:814 with SMTP id ew4-20020a056402538400b0045848680814mr12753827edb.190.1668467088222; Mon, 14 Nov 2022 15:04:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467088; cv=none; d=google.com; s=arc-20160816; b=O2QjXOpb38Nh3bvJ/ZTamRWGfzuR889yUbpEhdRCjYtd2Ua722jGxDhwr0d8asn5Mp 5pxiDhqHEvdEr86iqaS4++3fHUoJJk3Kd41o+21qDHrrwRm34SZMDrWyzZWyaGZ0vlHf Z7M01BfuSBnJYEWEvn/KVcE7jiKhGdGbzt7ghIE4bpAOw/lQtsw4KjBGe1BgP+IjUVbP 3BOpWhi4Z4JGaj8EwqbjM2SBnHSqP/IQpDwG4Zevc2qPj6u7zXi07S0xMiQ6y0QAfQIR hFCoXauIERCe6RZRidcKuNcnG+1LoLhrG1F1YIWeYlxQ/kLM7srLlJpNUMhdMqjAOk4S UQ8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=mLjySvlGPKnVQ41FH3ZyjLNiZRwop922hNhTc7oubmw=; b=axycRcxGxehAxw2u8n+jSv81EDpgTtvPyLOrk+PyWyCUsCYlKnb9IJ4l8X1DHOGG8d OD6GA6wgdk5erlCrRTjoP3kHClAc65fliGwQwwkKEJMwVTvvh5UBzEftL+rxoghcCDZ3 5t0QKdQEf8ri/eyEYyeZ0mjXLKC6d36YiccRCpdGhdvlPVJ91AECnRsajhBN3i4Ar06k gGyLi5+RU/tZIolaB0hJWM5jBvYnl0s0b/87YFYFpYfy58dA8uw6fB22TbFBhrd2w+iB 2YxL/8sw12BZDFTyfvV64UTu6dKvh80Nj7d9ERvoObRUIyRG21KAHXVZr4n2W0MI+Ffw NBzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FaZabm5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b44-20020a509f2f000000b004573c1ae3fasi8622476edf.285.2022.11.14.15.04.23; Mon, 14 Nov 2022 15:04:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FaZabm5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237896AbiKNXDH (ORCPT + 99 others); Mon, 14 Nov 2022 18:03:07 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514545267698531?= X-GMAIL-MSGID: =?utf-8?q?1749514545267698531?= 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 *config, print_running_std(config, run, ena); } +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 = rel_stddev_stats(total, avg); 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); } static void print_noise(struct perf_stat_config *config, From patchwork Mon Nov 14 23:02:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408445wru; Mon, 14 Nov 2022 15:04:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf5u+zRofZil0ggM6lm+tEpl/PuGY+toV4MKLn+4/KtIVItyCdNaJnk+v7ZL4onn3W1yvvx0 X-Received: by 2002:a17:906:7e4a:b0:78d:a136:732b with SMTP id z10-20020a1709067e4a00b0078da136732bmr11489446ejr.135.1668467092439; Mon, 14 Nov 2022 15:04:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467092; cv=none; d=google.com; s=arc-20160816; b=wZgp1CJIH7JLQ2ffEoviS8Ybpf7+bv7FJLqkaSU8Kh4zfsKZ0NUMlpEDXcGxOUnNiM 5HZ8RtbTpHUmmBtEGHKX4SbV54GsU7nM7iFdXlO5lXEk7m89AMKPWGK+KQJAWVeb/bAJ IAVPZ52qM2FWfFHKWL0vbD1RIHFq5ZmCwQyczh3WhZTFDTDn0Pd6T3YsY3J67MGqYP90 +gmhL8HExLHyqnz8Q12IFAvC+JkimwSl1X6d0AspqYEgIxFi4lMmQ2lNcf4SEJgtLPK1 xxCoffp8fIxb5Fym/IVdk8TlDG5roa24JTFKF7CanTkp53wqH0e8uzAN7ZpzgMphZaJH h24g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=nd5GkeCeE0yxKOMovgVohdgD8iFx/xVnrv4/oHPrZuI=; b=DRuhTFSiqlu4xuWGGhJ1Svz0EA/tjE6WwLzvx9Hq8MeM9tIJhyInY4d56FXihcA35Q /eGuxIassJnw36wR3EbGvdf+k6kuIhhUGjMM6tqaLTxqvr46Tk+pXIDpguM2FlAMBdtS Y6YlOFuzFUcnylSGNb9SLRFiijh+4zc+Huw7lKxWep3rf7DCEkz3geWo754t6Et4HW7T JXmGcsJTNYMliQaV0kXZ+Knq4faEeKCuzedU11MxYvXqwkcMpHRKCWk1mnNn6EWdZrvg OGHya2ubqgEtJBoUeGeL1CQ25pLhnxRj66rASmfDLHcIjKLEgUGLhepNUzA4HDVz7mEe gpMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R9Jluqc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp17-20020a1709073e1100b007a7d37e4681si9418243ejc.845.2022.11.14.15.04.28; Mon, 14 Nov 2022 15:04:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R9Jluqc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238009AbiKNXDP (ORCPT + 99 others); Mon, 14 Nov 2022 18:03:15 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514549739624237?= X-GMAIL-MSGID: =?utf-8?q?1749514549739624237?= 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 *config, print_noise_pct(config, stddev_stats(&ps->res_stats), avg); } +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 *evsel) { if (nr_cgroups) { const char *cgrp_name = evsel->cgrp ? evsel->cgrp->name : ""; 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); } } From patchwork Mon Nov 14 23:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20073 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408687wru; Mon, 14 Nov 2022 15:05:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7E4zM0XkWkFVhVDBZ+TfBS57PUuVpPpkQ1oYAnYPDfCnOX7Xct75y5VXLHN74ep20wz9be X-Received: by 2002:a05:6402:60a:b0:461:92bd:21cf with SMTP id n10-20020a056402060a00b0046192bd21cfmr12287344edv.405.1668467119882; Mon, 14 Nov 2022 15:05:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467119; cv=none; d=google.com; s=arc-20160816; b=ibJP9ap2yobONXxpONLkYoZzmEXg/pSq7cmaS0GC2swh4PxBfVzUnliohMYdjfwd2M Mm7TXdMoOCE/2detNpNW0JAcmTWpJUxh8MMAEuDBGnvVow1dRF3Ii5RLmofKYhcmserU TgUJYHGTLXe9IV0NMMTaWijbLu+BOV0B0f+QM1FO3U7BZQuKzwFufkwpSgBVTSYP5cdD eij9n6JBK/g5Dx22nh5LzdgJBefOh3SOAw2L+k8jmxfvzEelvP31sm30aCRgBSHv/qMe q3f2FUK/KyPqphLq2+0O7wxlQ8ayo5lqlKeeBTXuAQGP3H2sknyie3VyoCNE9+dCA1yi paEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=YQA2ZacCoh/AZvzO4JvdY6xJYRgMztnwPe0iUU1Auf8=; b=QWhecp+oNVemqLhtx8YFHiTXnE4Wy7Uow2FLyf/5fRwlLbEeR0qlO8/+HbDDLgXKW6 Ey0HjSa8GjLkTmCWsrqQ8Z9+nE+VVLyiL4HiqNww3I0U9XWyhnrDtEzRCz2RBNUx/zB1 8qUJx6YMT4lSRqA3A95d3W1X6XTKa1XJpDfhGVlDkrFlKtv0LG/dJntOw3z9f5x7rj5s acdPEqb9/d/ZrbSYaElZd04qbWkTQmIwELFoDD6tgrw8uHGHWXzBLHUOAvSswD5/r4HW dFCxoty9NhVxe5hsFTTvYBWOXHNkwGyaWuj8jwSYqRTmGhdIldRhNWrWHD1UzwoL9nWG XMfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YkO4x0Bw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n11-20020a05640205cb00b0046830a9c984si897414edx.476.2022.11.14.15.04.55; Mon, 14 Nov 2022 15:05:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YkO4x0Bw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238039AbiKNXD2 (ORCPT + 99 others); Mon, 14 Nov 2022 18:03:28 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514578563881143?= X-GMAIL-MSGID: =?utf-8?q?1749514578563881143?= 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 *config, struct evsel *evsel) } } - -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 = config->output; + 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; + } +} - 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 = config->output; + const char *sep = config->csv_sep; 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 = 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 *config, } } +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; From patchwork Mon Nov 14 23:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408530wru; Mon, 14 Nov 2022 15:05:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf7y+s2M+yL9hUez05Ya6+BVZ+6hWX/ytL/aJk5n+DBn4e5GfnHJf8PlI2t7r/2R+JazlTxi X-Received: by 2002:a17:907:9613:b0:78d:bc56:8f22 with SMTP id gb19-20020a170907961300b0078dbc568f22mr11170857ejc.256.1668467102591; Mon, 14 Nov 2022 15:05:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467102; cv=none; d=google.com; s=arc-20160816; b=IOAkh1iwT8vVYCPFi5XXcgGx6i3TJo28a49H8KpBWoRxQsOeeEXww+o0I+jtdvIN+Q JOObFEjx82sSiSNAnbZZmtz27cuzWeZTAWHaWclc3OXd5iDX1C02IUou2mfFYDq+Yuoc Cslfivj41dEC+xCqTjwpEzZP+2dCZdyPPudkGtqoEmIMk9H59IRjVrMQHZlklxi5NW8/ /amX8nuPPEAMCvkQ5pY38HtWAHsuIGCi+sOxivrUpIWLlZ2OXAfgDc/XW0/k8Nya33qo pg1tHP38WkMtIFkBH17cI2sEaoNuRfPEiWVrnp5D7+Kh8A5ATZzgnHClhK16ANElIm4o loHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=gWTJCUMMuG2d3heYPVKFPEFB7/flVbDDi20CjhO794s=; b=ihOi6GM+uw5rY2idhIqUgFZcbnR8t4B0cpK5Ibnodd/j5NbKonRtUhfAkoLynmefIK 1Qd5UMd7gY451qqAYsFOtnkYg8JBkDnESbD10AKHiCY+e+/Xqb7Xhahr5Rv+m3QZqoCi 6GS5pCCOtMbsC+a+7M6rifie5B+06ZMk9K5kJgaJfo0dvI629Nj0a0fGQKbdyvugW75K DSQiBV6HgDnfqRohGbny+ZhTukDoFo5KGIM90tXrH6PzJ/OZDB+gAdYEnvHkpuAm13SU TsLzay0TDWsQWGxc8u6HXaJPSmFn5EthZv+sJr3zbnRRulio6foka6I38yT7K8lPGksY eCNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R9u8Rjqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs14-20020a0564020c4e00b00462e4cbe815si10846477edb.550.2022.11.14.15.04.37; Mon, 14 Nov 2022 15:05:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R9u8Rjqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237785AbiKNXDe (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514560647839784?= X-GMAIL-MSGID: =?utf-8?q?1749514560647839784?= 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_config *config, fprintf(os->fh, "%*s ", config->metric_only_len, unit); } -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 = config->output; double sc = evsel->scale; const char *fmt; - if (config->csv_output) { - fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s"; - } else { - if (config->big_num) - fmt = floor(sc) != sc ? "%'18.2f%s" : "%'18.0f%s"; - else - fmt = floor(sc) != sc ? "%18.2f%s" : "%18.0f%s"; - } + if (config->big_num) + fmt = floor(sc) != sc ? "%'18.2f " : "%'18.0f "; + else + fmt = floor(sc) != sc ? "%18.2f " : "%18.0f "; - aggr_printout(config, evsel, id, nr); + fprintf(output, fmt, avg); - 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); - 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)); +} +static void print_counter_value_csv(struct perf_stat_config *config, + struct evsel *evsel, double avg) +{ + FILE *output = config->output; + double sc = evsel->scale; + const char *sep = config->csv_sep; + const char *fmt = floor(sc) != 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 = 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); +} +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); } From patchwork Mon Nov 14 23:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408678wru; Mon, 14 Nov 2022 15:05:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf6n926Q6FWR/JNI98KOZA7N14BXVX+Lsz5+nYVz8heA2Q7WcfudosEJo6LaMrTviJEAvCjf X-Received: by 2002:a17:907:d110:b0:78d:9f2f:a661 with SMTP id uy16-20020a170907d11000b0078d9f2fa661mr11507688ejc.555.1668467118580; Mon, 14 Nov 2022 15:05:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467118; cv=none; d=google.com; s=arc-20160816; b=GAZN2eYvvKC0TllPkJwcAMyINjIvOHmaqLccux4Ap1gAySh7AAVI+8CnnBXTaKF6a5 ZFF6HKfd3p2yaHAbr16Yw57dhKJmN874K90owQQuLdVsYQxFqu/Q6k2ZYOkTmaE9RApg kj0hCM2xhz9/p8O7griHH1OlfcxjZqirE7bukjy5CsUgjgD1dRfHK8vxcUA/gFXR+BLZ 1oDLCcQYRLCiDIp4oack/XDLlrix7YT8ofoKa1KYizsTgMIMCI8iFTAzMBindP9KKuvt TkvHhhUKpq5ctvePTlrGRbcrsT2j/pJGqj2dS4NJ6GgY8r0tc1R62DGXWSt4TscZjHfR wm3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=+XtdOOIqcdV1KgiG/01v+Rj8BokEmQ43hQ9dFYU/fNg=; b=EpRnDKq7T6F4QbT0LR5+LUgKum1spxvL213RL3hUlX6HIXdc9/B38OTQ2mHAP25D48 8uNQm2PYFPRcFYavQLBEYBobsKVRY8VfPxk5i6O+YXqiTEfIvoOkd8h89hvrFN7Hm5sL 1qzD3Du4Dr4IMRPAErjKUVE4dEk/cJoRzxTziQtfG3PElmMq5Lkl4St/7xEMV6kAHs07 L/Nf7/tn1E82gUp6qUXABUPwwfVAr9B8fbQMwzNpTdB2Gh6sDj9niyR90sUXSFpYQTXX JnHIYuLXm1UJCSk0cyUNzFhE8OdGdSjN9Kk9cVoo5VKRNvcCL/dduT4uU5umuVSTfVND 5JZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ei84jXWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn17-20020a17090794d100b00797670441desi10094367ejc.911.2022.11.14.15.04.54; Mon, 14 Nov 2022 15:05:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ei84jXWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238020AbiKNXDn (ORCPT + 99 others); Mon, 14 Nov 2022 18:03:43 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514577208970792?= X-GMAIL-MSGID: =?utf-8?q?1749514577208970792?= 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_config *config, } 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 = config->output; double sc = evsel->scale; const char *fmt; + const char *bad_count = evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED; if (config->big_num) fmt = floor(sc) != sc ? "%'18.2f " : "%'18.0f "; else fmt = floor(sc) != sc ? "%18.2f " : "%18.0f "; - fprintf(output, fmt, avg); + if (ok) + fprintf(output, fmt, avg); + else + fprintf(output, "%18s ", bad_count); 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, } 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 = config->output; double sc = evsel->scale; const char *sep = config->csv_sep; const char *fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s"; + const char *bad_count = evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED; - fprintf(output, fmt, avg, sep); + if (ok) + fprintf(output, fmt, avg, sep); + else + fprintf(output, "%s%s", bad_count, sep); 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, } 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 = config->output; + const char *bad_count = evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED; - fprintf(output, "\"counter-value\" : \"%f\", ", avg); + if (ok) + fprintf(output, "\"counter-value\" : \"%f\", ", avg); + else + fprintf(output, "\"counter-value\" : \"%s\", ", bad_count); if (evsel->unit) fprintf(output, "\"unit\" : \"%s\", ", evsel->unit); @@ -567,21 +579,22 @@ static void print_counter_value_json(struct perf_stat_config *config, } 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); } 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); } @@ -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); - 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=*/false); 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 } } - 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, struct aggr_cpu_id id, int } if (!config->metric_only) - abs_printout(config, id, nr, counter, uval); + abs_printout(config, id, nr, counter, uval, /*ok=*/true); out.print_metric = pm; out.new_line = nl; From patchwork Mon Nov 14 23:02:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408695wru; Mon, 14 Nov 2022 15:05:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Xs3vtmWNydcC9FJX9HLT3d6ayZ+90udCFe8xlGeHqLFuMwEr4JIdiTxdN2Ql8Uym1GMhd X-Received: by 2002:a17:906:a2d6:b0:7ae:98fc:aaa3 with SMTP id by22-20020a170906a2d600b007ae98fcaaa3mr12072901ejb.547.1668467120802; Mon, 14 Nov 2022 15:05:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467120; cv=none; d=google.com; s=arc-20160816; b=JeF2azDxJZfkzdP0+UxN1iUXvoU4fUQNJkQ3PEO5FuARLAXS0evJQy4fZmLkCOXLLN DTrR5yfxcW1T2u/Ml6hO/3hxw6doPX13HSXZs4hvAPdpVAqdbVnZ60z6TsOUEqwEgann P1ZipYBBx5rRgRNclv88CCblKoHziYyy6i+AKwJ9khcN/VgNOKtmxnfYrWjS5tlTfIDH DsCxN35Ck2AaV3G4Kudmi7kn478V3XJ6FEEsb1ZY+MgyXFVnI5jVDGv9lpKs5oMqNmm/ 9R81N2/0fnbLprTm+5DzshbMJuJecGvCQuOkYYCMaJlUn/42q2cuQMTMtRkZQDsPE0LI BvIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=uteOdCyPFJuZ4/e8j5gcW2AzjfSkGz9Zxx29RYucpO4=; b=Kipy/Gg180vyHJXahO5pObfxryDU4LRbcp9LgNArgKD0nCD38i/5ubhaposRITYvD9 3Q5ptvWbUwa8Y4P52RE2Odlh2G7jj7PQhsORpfNo25+C25Qr/UCCLGke7v8jq7X0c4Ck a2JB0QPozzvQrFqc/XEnVnF0eoBbVttTJvcppQXPKdFZW8o3X4mBXMcnSGyV+ZE9kGCm pWvRfDQ1MkCn1SPq3bDRkq8PrYdGJYdPWqpAkX4UolM6nKGu0Q16uxTiLRXFs8vSqcUz 6lhlOVXtJ3PYV9h5sr07cwKhxlHR5y7wlkO+K33/hDVcbQ4U3tNXck9Jjsq0SrRtr4fI TNtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HVi8Rv+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o19-20020a170906975300b0072b1964e54esi10798384ejy.1007.2022.11.14.15.04.57; Mon, 14 Nov 2022 15:05:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HVi8Rv+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238101AbiKNXDr (ORCPT + 99 others); Mon, 14 Nov 2022 18:03:47 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514579690514399?= X-GMAIL-MSGID: =?utf-8?q?1749514579690514399?= 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 } 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); + } } static void print_noise_pct_std(struct perf_stat_config *config, @@ -82,20 +86,24 @@ static void print_noise_pct_json(struct perf_stat_config *config, } static void print_noise_pct(struct perf_stat_config *config, - double total, double avg) + double total, double avg, bool before_metric) { double pct = rel_stddev_stats(total, avg); - 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); + } } 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; @@ -103,7 +111,7 @@ static void print_noise(struct perf_stat_config *config, return; ps = evsel->stats; - print_noise_pct(config, stddev_stats(&ps->res_stats), avg); + print_noise_pct(config, stddev_stats(&ps->res_stats), avg, before_metric); } 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, struct aggr_cpu_id id, int }; print_metric_t pm; new_line_t nl; + bool ok = true; if (config->csv_output) { static const int aggr_fields[AGGR_MAX] = { @@ -672,7 +681,7 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int return; } - abs_printout(config, id, nr, counter, uval, /*ok=*/false); + ok = false; 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 = 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; } - if (!config->metric_only) - abs_printout(config, id, nr, counter, uval, /*ok=*/true); - out.print_metric = pm; out.new_line = nl; out.ctx = &os; out.force_header = false; - 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=*/true); + print_running(config, run, ena, /*before_metric=*/true); + } + + if (ok) { + perf_stat__print_shadow_stats(config, counter, uval, map_idx, + &out, &config->metric_events, st); + } else { + pm(config, &os, /*color=*/NULL, /*format=*/NULL, /*unit=*/"", /*val=*/0); } - 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=*/false); + print_running(config, run, ena, /*before_metric=*/false); } } @@ -1151,7 +1153,7 @@ static void print_footer(struct perf_stat_config *config) fprintf(output, " %17.*f +- %.*f seconds time elapsed", precision, avg, precision, sd); - print_noise_pct(config, sd, avg); + print_noise_pct(config, sd, avg, /*before_metric=*/false); } fprintf(output, "\n\n"); From patchwork Mon Nov 14 23:02:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408675wru; Mon, 14 Nov 2022 15:05:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wU2eQvvrKYNC4cw1ZKmdxfLRBwqxBuqeQT8TpZvLc4N9NYGTU80RIr/XMlao+3XDWK/eu X-Received: by 2002:a17:907:cf84:b0:78d:a633:b55 with SMTP id ux4-20020a170907cf8400b0078da6330b55mr12450349ejc.106.1668467118325; Mon, 14 Nov 2022 15:05:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467118; cv=none; d=google.com; s=arc-20160816; b=UnmQt11DoyrARivC/VElyH7JUG2TEx9X+gN5NvkZfkbD121ijM8NWcl7jR983NktkP MfO1IPdiKfcLUHtzuHGPwa18IlTMbOpodyNuKW9KlES403aPBLpCLWta+/H8+B20JjBX ArJselRpxgkqaDMYYGlvsIcF8DFO/AUhpZBf5Q0aEwyKhpdsB9nU7tdBIFp/iI4x66lI VZ0hvNHLJpohl7o6Q2ccU08DV6uqq2lrWVaYN8XUrvqnjALwYBqH3FpAlXs192wz3BWP OkrDKD+v30mq/OhfxU+1v6RhS0hxvNFtMNbvIH4kBrrYSjd5DdYEJd7lXPRA9icVrxMX VjsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=spAtbl47EygOQnxJUoTDwXbnzuvEBdxdVrBu6CoUdfg=; b=xMXWBM4wLcBW/W+4SbTT1+PEYXefO+wDCEspeEePAOu1i8Q/XJlghp1VrHnmMA5I1o 4oIknBE6XRQCCQJwQIfjoBLMv+70+UWMy1nKinA6bXjMKf4u7FWOaZTAHDQfyJAFTGY+ k8O+cpV0uMPQf/jnfb6RHGzCqRaxRLCivjV1UaUbU8SPKxqNWKWu0RK10iqgm3V5KKaj jrmseOwPtRK3AHrdhx7rB38JP27hw5VzGDdGJr03q3q0ereeISU60/haCMOxZQPyMusM w1jBtDHnZ+KuyZrSBLzOGGfb8fl8kKj1l2aY//ufxdUPEsVCIqimaftnpDnUxIQ0iBSC a+6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GBNSrINH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020a50f614000000b004588af9ea19si10288580edn.166.2022.11.14.15.04.52; Mon, 14 Nov 2022 15:05:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GBNSrINH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237904AbiKNXDj (ORCPT + 99 others); Mon, 14 Nov 2022 18:03:39 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514577107407744?= X-GMAIL-MSGID: =?utf-8?q?1749514577107407744?= 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, 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); } static void print_cgroup_csv(struct perf_stat_config *config, const char *cgrp_name) From patchwork Mon Nov 14 23:02:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409593wru; Mon, 14 Nov 2022 15:07:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf420iicwUexB98GFftiIW3hE+2SPIAXiVGkwj/cdShz2a0iKj3QhmUyUhLd76E+gteYBF/t X-Received: by 2002:a63:db13:0:b0:45f:a78b:f905 with SMTP id e19-20020a63db13000000b0045fa78bf905mr13815317pgg.296.1668467246031; Mon, 14 Nov 2022 15:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467246; cv=none; d=google.com; s=arc-20160816; b=Q0O6BHYi3YMfFKyhX7wZyRJcXDFTXtsija8O7iHehL/sKiQHyidE9gUHx8AR5jnTEX FniXjvLIIs1LNYrxDucGYYw+2xJ2we8jyfXob9QndzKuw3VlWjBVnQYcroGrjNm0pWfg L/ZHXfnMpXf7L9WfxwX5siOXhq22RVUQV/qzsgRv+3/sU9p+flC3InLYCcCfuvSfCIzk NKlUEr7EG8FG/Wi4CAx8zIlb7x+cZj4Xu6y6mSM5kBLSD8MZDTjhUMkyXeWKWWco5j9Z WzhZ2tP5YzGVAAVZ5LGedVCploErp/+nVIddLgQh1avpUYEVBuvuIzsuUJPdW80PLRjB HbbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=k7m9PL079tg/puX/nq7Az2YxT2Xrw40LYwiV1eclCi4=; b=XodKn8LtvV5CBsi5KGBXODnNxJTUTXWqAGXqSBwPUuz+b9WckgCDOxknZI50XCPLUz HKD/MYld+yO4Kia6GY3OXb8iamIDV1OgLy3WIQwHCFyU2BIitm/InrNrK96pE6kV2dlV B8nl+B5wTYRpF86oFOqK3GC68uGgK57FBtaUiI3Cte1YQvjDHF2W89wJY8LXVnOc9l3k K6ddB3AHnaUipBhvzwTQ2NuuNHDVnM4KHQ0tbFYexKxLgKqTwAPrZjLIgekwix8aQ39G dgxBX/ImKzLQEAWh0J2Ahomg3TE4cqGu6rqMx8SntadLOgJztqRvkobmGWINRuRJboPY M9lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WcjbZOKx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a170902854b00b0017d6ffda9e3si2525021plo.369.2022.11.14.15.07.10; Mon, 14 Nov 2022 15:07:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WcjbZOKx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238111AbiKNXDw (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514710588037369?= X-GMAIL-MSGID: =?utf-8?q?1749514710588037369?= 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[] = { [AGGR_GLOBAL] = "" }; +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_config *config, .force_header = true, }; - 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); - 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); From patchwork Mon Nov 14 23:02:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409151wru; Mon, 14 Nov 2022 15:06:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cmx3KQ6L/GKgHLXi7vWdJrusK4i1mrwh4P1MmtojtddJfmdvdg9eUQhTGkREAQ/uX74zA X-Received: by 2002:a50:ff04:0:b0:462:709:9f7b with SMTP id a4-20020a50ff04000000b0046207099f7bmr13402402edu.263.1668467183674; Mon, 14 Nov 2022 15:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467183; cv=none; d=google.com; s=arc-20160816; b=ua9cfB7EiyD0WqNSVmbiT25vwToYYtc9B2z9NIWyEY4vgJNcD8j8bJvS+w56Y3VBBO WXg7hMo4/d2ulOAg584NltgeSJlRKMORobsx8kW/Dle6tWf4qDTddR4CyZb/WZesYJ7I EqepHzBXYLupcjJ29wvr/eB9gD8q6xKLIcq8i1rJNSKPV4m+7GH2NELPDuhvGFzSxn9U 22CKRzGuL37DfXZfBAgS498RgwiT/JUWFV5pAA6qYVdfzenRWh5ZBdFEqrQV6g96gA2P mxoITb2peMisTiOT3KM0I8YF2cNFFtsoFTrm6duY6QoRTfvGDUqkO2Z+22D6uA+c3iF0 L7nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=p5Jzh6xalJKHBu39qwvImNFihPE1DfayGCHE+NYMErs=; b=JFcnULfrnLaxwZHv6A+iXrPICw/pr0c+XuZUSsmAtkcvTMlofRU8IbiG+j37njZ3XA q68j/HjTcI/AIra1Eh1EE/Lzkw/TSLdZdGyXQjAOd8do7YNoQpdmdBWQfQcoKQkXgN9O L4uT7z42TzIVSch2yn9i73wptnmCsEcqXIgX2d5MoyNA/5k9c0yC5HeBERnZNoWmG49Q mBUi16vOaB2rlbtc9Umw46trL9fyXqcAtAbwdgycU/iOKi2bBMquucxsXVx3YSr3ZNjO vo6VTOC1Hi2KWa0H3coHTCc6dpbjiyCZyWwCdbKz7HPNaOvroXMEQRbNEvBONw1/LEEy lB4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BQkSJKUw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp27-20020a1709071b1b00b007919dbd3770si11268624ejc.485.2022.11.14.15.05.59; Mon, 14 Nov 2022 15:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BQkSJKUw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238118AbiKNXDz (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514645828700298?= X-GMAIL-MSGID: =?utf-8?q?1749514645828700298?= 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_config *config, fputc('\n', config->output); } +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 = config->metric_only; unsigned int unit_width = 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); - 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 == 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 = evlist__first(evlist); - if (interval) - print_interval(config, evlist, prefix = buf, ts); - else + if (interval) { + prefix = buf; + prepare_interval(config, prefix, ts); + print_interval(config, evlist); + } else { print_header(config, _target, argc, argv); + } if (metric_only) { static int num_print_iv; From patchwork Mon Nov 14 23:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409116wru; Mon, 14 Nov 2022 15:06:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf6zKTqNmL25GjOE9RA8bMW+5DcbYi9hAQBzG8qczaYsRt0JDdgKrBBv+287TRk4ly7kNmlh X-Received: by 2002:aa7:c684:0:b0:462:9bc2:d039 with SMTP id n4-20020aa7c684000000b004629bc2d039mr13000689edq.127.1668467177973; Mon, 14 Nov 2022 15:06:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467177; cv=none; d=google.com; s=arc-20160816; b=VbGU/yo8LffiVaGrg6jLGbfpKp84EH2gevNUyrNZ1LRyofKhCM7eH+7z2wMFSOwOOL g40LCu++cQV4KYEUfymmMthVw3IFHSklLdjdyXPUYwtrQyS3JK8gJnBITHqO7pVw84Gz CvVwkVjOlCxIoGg4ErbQBWNsfseA9PsqjtVVUI34eDtCqFQOWEh0PgXLavrAc32K9Uf0 plE7u2+94bh1Vmfp8QVEQhL7rEmIGGGeFd8JNqKiK6hYrIfssLlJgai+EjHo1sh/MXOA bfw433WRbY+6BPoPeOae1pUwiGBVoG9EvjTAtl0H61qzCyOvUF0m3OrUd5C1aGrQ/q/N kTMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=NdSXH2XNQ9roh/KzmA1z2gWpKkgATPTblDS61GUpaBA=; b=UWwUmqy5WwSPtdTjflAW6i/ReE+lazmYniAzixrGFpyDP+29SoLPyFDCNOTPPM4EMm ZX5ZG5XzyESi5TBdM/msznDzwqJvrQEpABIxza78g5y9WhVPEKblb1X8px1XogxK666T ajjJNUh/YXMExmfgGUPj2isLWE0OK1yTA3BeKNUtyqENjfjrsh5BBHcD8rh12QqZ1iIH K7mvwn5fgxw447vwrZCC59C6k5YL+o8QowBBoYrA4VUzJMROeZOy2aDSH0NEIZbeEp0v zpPldpSCF/WJe2otOwbAhEdpOXR1TUmORgBB2SdG4XbBbbWcyHiGkSzXhiVY1gazcR3w jSsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ZT5M/yam"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id da5-20020a056402176500b004615bae2376si8615293edb.147.2022.11.14.15.05.53; Mon, 14 Nov 2022 15:06:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ZT5M/yam"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238130AbiKNXEU (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:20 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514639581682242?= X-GMAIL-MSGID: =?utf-8?q?1749514639581682242?= 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 "" +#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[] = { + [AGGR_CORE] = 18, + [AGGR_DIE] = 12, + [AGGR_SOCKET] = 6, + [AGGR_NODE] = 6, + [AGGR_NONE] = 6, + [AGGR_THREAD] = 16, + [AGGR_GLOBAL] = 0, +}; + +static const char *aggr_header_csv[] = { + [AGGR_CORE] = "core,cpus,", + [AGGR_DIE] = "die,cpus,", + [AGGR_SOCKET] = "socket,cpus,", + [AGGR_NONE] = "cpu,", + [AGGR_THREAD] = "comm-pid,", + [AGGR_NODE] = "node,", + [AGGR_GLOBAL] = "" +}; + +static const char *aggr_header_std[] = { + [AGGR_CORE] = "core", + [AGGR_DIE] = "die", + [AGGR_SOCKET] = "socket", + [AGGR_NONE] = "cpu", + [AGGR_THREAD] = "comm-pid", + [AGGR_NODE] = "node", + [AGGR_GLOBAL] = "" +}; + static void print_running_std(struct perf_stat_config *config, u64 run, u64 ena) { if (run != ena) @@ -116,7 +155,7 @@ static void print_noise(struct perf_stat_config *config, 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); } 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 = config->output; + int idx = config->aggr_mode; + char buf[128]; 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); } static void print_aggr_id_csv(struct perf_stat_config *config, @@ -301,8 +342,6 @@ struct outstate { struct evsel *evsel; }; -#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 = evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED; if (config->big_num) - fmt = floor(sc) != sc ? "%'18.2f " : "%'18.0f "; + fmt = floor(sc) != sc ? "%'*.2f " : "%'*.0f "; else - fmt = floor(sc) != sc ? "%18.2f " : "%18.0f "; + fmt = floor(sc) != sc ? "%*.2f " : "%*.0f "; 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); if (evsel->unit) fprintf(output, "%-*s ", config->unit_width, evsel->unit); - fprintf(output, "%-*s", 32, evsel__name(evsel)); + fprintf(output, "%-*s", EVNAME_LEN, evsel__name(evsel)); } static void print_counter_value_csv(struct perf_stat_config *config, @@ -904,34 +943,19 @@ static void print_no_aggr_metric(struct perf_stat_config *config, } } -static int aggr_header_lens[] = { - [AGGR_CORE] = 24, - [AGGR_DIE] = 18, - [AGGR_SOCKET] = 12, - [AGGR_NONE] = 6, - [AGGR_THREAD] = 24, - [AGGR_NODE] = 6, - [AGGR_GLOBAL] = 0, -}; - -static const char *aggr_header_csv[] = { - [AGGR_CORE] = "core,cpus,", - [AGGR_DIE] = "die,cpus,", - [AGGR_SOCKET] = "socket,cpus,", - [AGGR_NONE] = "cpu,", - [AGGR_THREAD] = "comm-pid,", - [AGGR_NODE] = "node,", - [AGGR_GLOBAL] = "" -}; - 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 = aggr_header_lens[config->aggr_mode]; + + if (nr_cgroups) + len += CGROUP_LEN + 1; + + fprintf(config->output, "%*s", len, ""); } } @@ -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, "unit"); + 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"); + } } if ((num_print_interval == 0 || config->interval_clear) && metric_only) From patchwork Mon Nov 14 23:02:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409230wru; Mon, 14 Nov 2022 15:06:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf4BKxVfgxBfT6S/A5fPfapSAVNfwPgZ4E3RlycgOnS+dwEFxS029ZnMfRz0sss03qqsXdSr X-Received: by 2002:a17:906:3a55:b0:78d:f2d8:4623 with SMTP id a21-20020a1709063a5500b0078df2d84623mr12147031ejf.274.1668467195103; Mon, 14 Nov 2022 15:06:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467195; cv=none; d=google.com; s=arc-20160816; b=UHSN/x+2uytQvqPJPn5cMHAK5hmLJLYcr81YTVZDwsjinCHxtUCKJNWVnWTCr3ICqg HKwM5ULvwFPIfTevtMHrZ+DtTw2S4Vuexl5jcu/azXja5WcuBZNaPOagdeK0i4KCmD8A H6fAR5+Av2RZQZQZKE37YVQ/Cu8k1GZ3GR3EZlibvJ8SBQpJyt8+tNqYOc0qCP7o4C8I J52geqlx7SaYtwEnxrla5+a+avLBRhgukV9pk064Q9yLG+NhNW/7BAHQ2leRgnAw1Uk0 bxvryxgPEc0/ZQybSojl9slT4+kDS6wyGZlJV+HZnQP8qhNPOpOcQIce/mbL5XgbXRkp 1ZQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=Dj8iIW6Moofk4jxR56ZsoVFULFdU2ag6CE3awXc28Rc=; b=cIL3MH5aJIRnV6V5XFJLoseidIOKRzYbgpPkCoAM6Dpn/5ejaNyzRRaoKn3+IfKn4U sZzTagqWmGU8Zf6LM8WxbJ5d8ih71+s23dpZTHtD/nh4JqqnnRH0I8jJ6m4reqJSpWli uAAJfRRPkyImMlT9W0Zk8mlvDJQ2CRGWi/ipXzLREpFnJ5eI0LK/rpwTg+QQmfmx2pEH 2mU/ywjIWjRU7KVGNKTKP+Tef3tBDeMWt6vfN01pmXwA2v5RqWnORYbyeEzSouoQNher mBhUUYhhu7a5scZdEEXTfNrfiQR9xprYpxu4Isg/2IntqbPF38er+G+yorPtceDvSFxZ Kqkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GlPXquPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa37-20020a17090786a500b00782ece08669si8975851ejc.13.2022.11.14.15.06.09; Mon, 14 Nov 2022 15:06:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GlPXquPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237829AbiKNXEZ (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:25 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514657590623879?= X-GMAIL-MSGID: =?utf-8?q?1749514657590623879?= 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, struct perf_stat_config *conf num_print_iv = 0; if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run) fprintf(config->output, "%s", prefix); - - if (config->json_output && !config->metric_only) - fprintf(config->output, "}"); } switch (config->aggr_mode) { From patchwork Mon Nov 14 23:02:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409327wru; Mon, 14 Nov 2022 15:06:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Idh84/WFBiSqnzMbKp3P9F4raIB6U/w9yRiKlyTArT3DS/OfiqovmI+maMvrVEXyX8g6h X-Received: by 2002:a17:903:445:b0:186:95ca:1e4c with SMTP id iw5-20020a170903044500b0018695ca1e4cmr1431982plb.13.1668467210675; Mon, 14 Nov 2022 15:06:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467210; cv=none; d=google.com; s=arc-20160816; b=A8ekzReDUAwzyq74AKZKNBN3Srt/TLh2Xrx/0KOhDYf0x9yQdK9uOtWpDGhmpHM8tS yLmKBo9y4ZVPkfDEk/F92DMZpTGuW1riRlU1idxORWcr/j0o8vN9qJBtBySOba3NfJM3 403FJh2nK8V07KnuLndEFWiFYaTwCck6oQJsRAEDnEqGF5hVsnBsEXSPsN571xblRepS E2aTtubJrxjlrL25KYxqtquXgNOU7rrd9m9xJqq/qdsPB+k1+sSVdnSfFCAd4qOeNJmh E6C0xRk+wEKtTxtYXz83foS+MBXwwsBdr/gbBcL8bkWdzioZqCDRGU7Mp4bpfs9VYytE /24A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=a1MFej65CJ+NfpSltvQHgaIoZB+GNGl8r1EVGrPKTcw=; b=nhpCQlCxDbMgPHP1enOhkgjuJGhoA0AL+AkVlHSPPy50PwUDJt7UEu1gx6ey5+7g28 OxUDgvGMDazrQJ9OTseaIBcHMAXDdiivq6kZvz8Sh/g5a9RVueJ6oMTRh6q1BqEsJVud iQZM2iK3ZqTn9q39VlUuaXyZriC4LoNOgSLTvN0ngWqVJznT2/KT9SWM5vZjT9az3Ooc qlwbqu86Fu9cGTPlSu1r1O0rZHS94Xa9QIHAaXYmBRe18nTuIguW4ixXenfEqFnUorTf I2pNK8L2kO8qZ8v+9s0p2vOXkLMq5ClDhl9kFob9VkU2mUlXXIW8oersEVXkAO2JVJZv vuSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IW59hFHw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a170902d2cd00b001865c55049dsi12245869plc.570.2022.11.14.15.06.32; Mon, 14 Nov 2022 15:06:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IW59hFHw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238092AbiKNXEa (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238075AbiKNXDb (ORCPT ); Mon, 14 Nov 2022 18:03:31 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C1361CFD7; Mon, 14 Nov 2022 15:02:52 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id m6so12505020pfb.0; Mon, 14 Nov 2022 15:02:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=a1MFej65CJ+NfpSltvQHgaIoZB+GNGl8r1EVGrPKTcw=; b=IW59hFHwqet/9Q/o/UQ0AVw+mr0ZNMfZjssD1fodhAMyVGc2eH+XfTVtKBHHBqJb+/ 1R7WCwgfTFYpGCqd5w2+nLn7cTLdvw6SMoD5w5FIYKfZ6mMXfNliPgBDtjuUCApb+YLC 1eh6rALcUJ+GVOlGsDJ7nzr35xz1QK2ZYFEGEmA6j663ZRW4KsCqjkREJo7UYcPGrZIp b8YoHQzBRCJnYxoWs/7qGzbzcEKUcubEyBVJA/H/2B3+wlZaHeDhZbzXJMSVynlABCWi +8gBiIknECUMF4KRSZRvzdW6k4mWVMWVNWnmF8cFPM0YFHd5U7BawFF/gYJ+ZuqjT72s qeDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=a1MFej65CJ+NfpSltvQHgaIoZB+GNGl8r1EVGrPKTcw=; b=c9Q865EwcUVMMB75CU14xR0t613DzzzFLR06rhTEsftCkVI7zRuM6X1XlxNe6zfR3S 38sA8BGaciHVCOlMROztB34XMauDtr0B8fkGu98TY/mbl2X4zy356m8ZD6yqYrOaoP6N X+0DWoXwp1oDv+b+8Sz3BFe/meDSl/DOy3+/fyawSvfW+V9jAaQb5WvskZVUKeOeApu2 oSlVjlTlsGzU28mIj5EYFAIknxdfEEZVO/x7cAUFVmrV8UttYPz7MDuc5SFAg62UzEOq 5nK2DYVSy2OhXUVXjC29LmaLKSFky2nyKXbRwDZQB0hjFB7xL+7NSZOLKxprfjN1nIQC ZP4Q== X-Gm-Message-State: ANoB5pkPwhqE4L/hmyHthdDIZ/1Kj7Ht1NdH+QJcG8FzwB/Wzl3QeLxJ EWKWFZ+f31r+uVx1Mx7jMmQ= X-Received: by 2002:aa7:956d:0:b0:56e:924e:ee22 with SMTP id x13-20020aa7956d000000b0056e924eee22mr15655339pfq.34.1668466971685; Mon, 14 Nov 2022 15:02:51 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:a80:cf9f:e038:c19b:797e]) by smtp.gmail.com with ESMTPSA id 132-20020a62148a000000b0056c814a501dsm7534724pfu.10.2022.11.14.15.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:51 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark , Athira Jajeev Subject: [PATCH 14/19] perf stat: Rework header display Date: Mon, 14 Nov 2022 15:02:22 -0800 Message-Id: <20221114230227.1255976-15-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog In-Reply-To: <20221114230227.1255976-1-namhyung@kernel.org> References: <20221114230227.1255976-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514673667645499?= X-GMAIL-MSGID: =?utf-8?q?1749514673667645499?= There are print_header() and print_interval() to print header lines before actual counter values. Also print_metric_headers() needs to be called for the metric-only case. Let's move all these logics to a single place including num_print_iv to refresh the headers for interval mode. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 185 +++++++++++++++++++-------------- 1 file changed, 106 insertions(+), 79 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index cc8bb6d07dcb..f97817628478 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1034,94 +1034,129 @@ static void prepare_interval(struct perf_stat_config *config, ts->tv_sec, ts->tv_nsec); } -static void print_interval(struct perf_stat_config *config, - struct evlist *evlist) +static void print_header_interval_std(struct perf_stat_config *config, + struct target *_target __maybe_unused, + struct evlist *evlist, + int argc __maybe_unused, + const char **argv __maybe_unused) { - bool metric_only = config->metric_only; - unsigned int unit_width = config->unit_width; FILE *output = config->output; - static int num_print_interval; - if (config->interval_clear && isatty(fileno(output))) - puts(CONSOLE_CLEAR); + switch (config->aggr_mode) { + case AGGR_NODE: + case AGGR_SOCKET: + case AGGR_DIE: + case AGGR_CORE: + fprintf(output, "#%*s %-*s cpus", + INTERVAL_LEN - 1, "time", + aggr_header_lens[config->aggr_mode], + aggr_header_std[config->aggr_mode]); + break; + case AGGR_NONE: + fprintf(output, "#%*s %-*s", + INTERVAL_LEN - 1, "time", + aggr_header_lens[config->aggr_mode], + aggr_header_std[config->aggr_mode]); + break; + case AGGR_THREAD: + fprintf(output, "#%*s %*s-%-*s", + INTERVAL_LEN - 1, "time", + COMM_LEN, "comm", PID_LEN, "pid"); + break; + case AGGR_GLOBAL: + default: + if (!config->iostat_run) + fprintf(output, "#%*s", + INTERVAL_LEN - 1, "time"); + case AGGR_UNSET: + case AGGR_MAX: + break; + } - if ((num_print_interval == 0 || config->interval_clear) && - !config->csv_output && !config->json_output) { - switch (config->aggr_mode) { - case AGGR_NODE: - case AGGR_SOCKET: - case AGGR_DIE: - case AGGR_CORE: - fprintf(output, "#%*s %-*s cpus", - INTERVAL_LEN - 1, "time", - aggr_header_lens[config->aggr_mode], - aggr_header_std[config->aggr_mode]); - break; - case AGGR_NONE: - fprintf(output, "#%*s %-*s", - INTERVAL_LEN - 1, "time", - aggr_header_lens[config->aggr_mode], - aggr_header_std[config->aggr_mode]); - break; - case AGGR_THREAD: - fprintf(output, "#%*s %*s-%-*s", - INTERVAL_LEN - 1, "time", - COMM_LEN, "comm", PID_LEN, "pid"); - break; - case AGGR_GLOBAL: - default: - if (!config->iostat_run) - fprintf(output, "#%*s", - INTERVAL_LEN - 1, "time"); - case AGGR_UNSET: - case AGGR_MAX: - break; - } + if (config->metric_only) + print_metric_headers(config, evlist, " ", true); + else + fprintf(output, " %*s %*s events\n", + COUNTS_LEN, "counts", config->unit_width, "unit"); +} - if (!metric_only) { - fprintf(output, " %*s %*s events\n", - COUNTS_LEN, "counts", unit_width, "unit"); - } - } +static void print_header_std(struct perf_stat_config *config, + struct target *_target, struct evlist *evlist, + int argc, const char **argv) +{ + FILE *output = config->output; + int i; + + fprintf(output, "\n"); + fprintf(output, " Performance counter stats for "); + if (_target->bpf_str) + fprintf(output, "\'BPF program(s) %s", _target->bpf_str); + else if (_target->system_wide) + fprintf(output, "\'system wide"); + else if (_target->cpu_list) + fprintf(output, "\'CPU(s) %s", _target->cpu_list); + else if (!target__has_task(_target)) { + fprintf(output, "\'%s", argv ? argv[0] : "pipe"); + for (i = 1; argv && (i < argc); i++) + fprintf(output, " %s", argv[i]); + } else if (_target->pid) + fprintf(output, "process id \'%s", _target->pid); + else + fprintf(output, "thread id \'%s", _target->tid); - if ((num_print_interval == 0 || config->interval_clear) && metric_only) + fprintf(output, "\'"); + if (config->run_count > 1) + fprintf(output, " (%d runs)", config->run_count); + fprintf(output, ":\n\n"); + + if (config->metric_only) + print_metric_headers(config, evlist, " ", false); +} + +static void print_header_csv(struct perf_stat_config *config, + struct target *_target __maybe_unused, + struct evlist *evlist, + int argc __maybe_unused, + const char **argv __maybe_unused) +{ + if (config->metric_only) + print_metric_headers(config, evlist, " ", true); +} +static void print_header_json(struct perf_stat_config *config, + struct target *_target __maybe_unused, + struct evlist *evlist, + int argc __maybe_unused, + const char **argv __maybe_unused) +{ + if (config->metric_only) print_metric_headers(config, evlist, " ", true); - if (++num_print_interval == 25) - num_print_interval = 0; } static void print_header(struct perf_stat_config *config, struct target *_target, + struct evlist *evlist, int argc, const char **argv) { - FILE *output = config->output; - int i; + static int num_print_iv; fflush(stdout); - if (!config->csv_output && !config->json_output) { - fprintf(output, "\n"); - fprintf(output, " Performance counter stats for "); - if (_target->bpf_str) - fprintf(output, "\'BPF program(s) %s", _target->bpf_str); - else if (_target->system_wide) - fprintf(output, "\'system wide"); - else if (_target->cpu_list) - fprintf(output, "\'CPU(s) %s", _target->cpu_list); - else if (!target__has_task(_target)) { - fprintf(output, "\'%s", argv ? argv[0] : "pipe"); - for (i = 1; argv && (i < argc); i++) - fprintf(output, " %s", argv[i]); - } else if (_target->pid) - fprintf(output, "process id \'%s", _target->pid); - else - fprintf(output, "thread id \'%s", _target->tid); + if (config->interval_clear) + puts(CONSOLE_CLEAR); - fprintf(output, "\'"); - if (config->run_count > 1) - fprintf(output, " (%d runs)", config->run_count); - fprintf(output, ":\n\n"); + if (num_print_iv == 0 || config->interval_clear) { + if (config->json_output) + print_header_json(config, _target, evlist, argc, argv); + else if (config->csv_output) + print_header_csv(config, _target, evlist, argc, argv); + else if (config->interval) + print_header_interval_std(config, _target, evlist, argc, argv); + else + print_header_std(config, _target, evlist, argc, argv); } + + if (num_print_iv++ == 25) + num_print_iv = 0; } static int get_precision(double num) @@ -1278,18 +1313,10 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf if (interval) { prefix = buf; prepare_interval(config, prefix, ts); - print_interval(config, evlist); - } else { - print_header(config, _target, argc, argv); } + print_header(config, _target, evlist, argc, argv); if (metric_only) { - static int num_print_iv; - - if (num_print_iv == 0 && !interval) - print_metric_headers(config, evlist, prefix, false); - if (num_print_iv++ == 25) - num_print_iv = 0; if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run) fprintf(config->output, "%s", prefix); } From patchwork Mon Nov 14 23:02:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2410536wru; Mon, 14 Nov 2022 15:09:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf5T92OyMIH2BcEsIqVTL9QP/JAQ708yVolucQ3sFfctQGqEWH9TldlLgKQO7gApiMUIBoqE X-Received: by 2002:a17:906:806:b0:73d:7112:4601 with SMTP id e6-20020a170906080600b0073d71124601mr11700170ejd.239.1668467374389; Mon, 14 Nov 2022 15:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467374; cv=none; d=google.com; s=arc-20160816; b=botMv4tMcOW1JdEeMjOBdjH5Br4pfwPoKrLSI0yNFbhWTPNCk2Ahv9msiJbi+/jYLj /GRk3RdxE2ZTDkpHloPbpZD9fqneXs1OBudetpu+72LSv+N/wSwxPXEyhTM/CQ1z1It3 uSYSMrJXSFFEuJK+5GqGGnnM5wA3V9K72lVs7XBY1WhxNRxCTIJ10s8V2WvyczBRbRBv arPTY5v+gYGLFK0MI5VRf4NZ4NLckREpakX3Kd8F2MJaEjjaZsuA66+e77wfWZqkjlU3 7Ef/Q9Rh+LGLGBvnFsiu784KB9OuO7loRVRU9OG/3gU82bm7FbCssXi0dxJ8BrFmZXrX XM2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=CC4R4Flp577u4yBTPLbgmfpC6msSDOQY4vvA3zFzeIk=; b=DEhjvphgpXwO/HNpSUe4SQLW/c3KLPiKFv49zjzk30SA5n6ODvVVERBrxVueY1fZfL NpcxF2qXCAJmOmTnUesHVClOX+v9FSa8mOzrYxMccObqbiWIpWmsX0WbFtXmwcQP0PQ1 q1sP0pCzSKBgpah2U4QUakIprgEIXRDPIPC7Q3jqoCHKTJ+u1bPcsd/MuIKUfPkMxbRO 1s1kQloHA6Alm4OveIy/LpJVTuS8eKHrMUqv3DXt4+tY04JN0lIrWeFr1dowhkcnNxXH 3bI5jE7C6IxuHQI6IlTykAIRnHhi2nOoMjZVjlfHUswyQ+oOBR5rrZQyo4SKsAQoshrj ioXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OpbUbMzr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb36-20020a170907962400b007316ac034a1si10354213ejc.831.2022.11.14.15.09.10; Mon, 14 Nov 2022 15:09:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OpbUbMzr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237814AbiKNXEe (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514845306061704?= X-GMAIL-MSGID: =?utf-8?q?1749514845306061704?= 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 *config) double avg = avg_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC; FILE *output = config->output; + if (config->interval || config->csv_output || config->json_output) + return; + if (!config->null_run) fprintf(output, "\n"); @@ -1359,8 +1362,7 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf break; } - if (!interval && !config->csv_output && !config->json_output) - print_footer(config); + print_footer(config); fflush(config->output); } From patchwork Mon Nov 14 23:02:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409595wru; Mon, 14 Nov 2022 15:07:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Ef8JiVp1AiGxeRZj2zQQ6AU9t38t4L2jYmG/lqf+7SQFXkEIhVFimXkOYScTE6Qwr7amE X-Received: by 2002:a63:4621:0:b0:470:79cb:6c5b with SMTP id t33-20020a634621000000b0047079cb6c5bmr13823197pga.130.1668467246038; Mon, 14 Nov 2022 15:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467246; cv=none; d=google.com; s=arc-20160816; b=bkAIyv07dFl0OcSZtCLyFgcVjm3lUpxLkDPPVzFDt31javRjXF4eorUpqwlfee/o8Q OsULLEHkTy5G6Ieuxf64euo5USlfHaUW/3IlWtr3Ert+hJVrckGh/uCoYW6nlFGwG6XD 6yjoq8w2alx9dsq1zwtGu/8S6+zm1+AOURUjDT4vMmzkM95szB3p3Q26GOvsrBeJHbbB UL7utzkv3vbyrN0GJ4oAinZQJKAZ7yeC45CSs5/M87m5VvScj4oTF+FwMdK80edUb/ok /QQT5j1P7MlUrIo0+yYFMK/h8Ezr6m3tK6Z3CMTLR8ysGk4mSZZErDU0XqQZxWKxpJw1 fgCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=QUGjDewK+aO2x22NgTca81ezePEJqtKcnqIInofdYc0=; b=05zmKEzQBnafWc9qTYMRkM+ziqyhaqOemQxkFBABy3odLrj1LirlSsEGDM/AEy0C/R 9IhyruA69WpREY2e3XkbaRb0hC+dfRnGYK3lk06BOecjxBvsSvpGjXJ5gRU+irGB9WOZ JmX9NoZaU5bLo4Pdxm/nYaBUlCAcHizILk0nvw3JBoW0Xm3rp3r8N5FeCQ5F3bziTU/C YzKuUoV3sgErE0C+3rm1HkUQ4RwtzHMJ5Avn65Bz/xN2lCzh3AqYf5Fcvs2clITrlnQO WW3/IFhPu9okGNdAIGb2+ljfToW2b08bQlTYu08nunGa+x51DyuINh7r78BtnMlVJn8F F4KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Nu1quPwZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a63db0b000000b0046ff4e3a5d4si10185468pgg.260.2022.11.14.15.07.09; Mon, 14 Nov 2022 15:07:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Nu1quPwZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238158AbiKNXEf (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238016AbiKNXDf (ORCPT ); Mon, 14 Nov 2022 18:03:35 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447811D0CD; Mon, 14 Nov 2022 15:02:55 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id p21so11501317plr.7; Mon, 14 Nov 2022 15:02:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=QUGjDewK+aO2x22NgTca81ezePEJqtKcnqIInofdYc0=; b=Nu1quPwZo1yskrgF1eihnt838Q1iJxTsfR0lpStvoCZMAAgPmUIgVkd1k1KcgLgAkr f21vl7mchsZgmLpmX0aduzqWhm4RT+0+VLzULdPpqBDFrNv/BI2jbKD/+klBga6OChVG qCBTd/hkERzdD3v40/UCAxekt5ZTWI2TecbhyDNEumYwGGHG/5+86TZSjF+K02ZHHJmU d1eLy3HMcawQkybqryqw2gwg2Ajd35BoXbWZo84bv2ewx7OPzQfllhVD0tbqB1BxjQY8 jiq2qCq3WmRpFclNN5CApsOjI7BzeLLQMvm3KvBRP1WHu8rerOHZHU4T3/kIXsST9del NuSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=QUGjDewK+aO2x22NgTca81ezePEJqtKcnqIInofdYc0=; b=CM33V1ezY/lifA+gH4la0V7cw1NrRNfHjQP5VUGtbW7f9oRyP8UsxGDpbTSxXmUpqv 7zdeyF9AyFhh+b3cJoYuMiXGwkmRKdZ5P79v9uVCvyBnwTmJ7iM9xhT8HOQFY7e0UVUA OzRME6s4V59F285zpAPGNpn8KUMZacgKV5hs0k+nhNpLt6E38Wtcobdspxcee8/CRo3y ALWY0mk3d9R+ZI7v6YpqUW+rFnUAiDFUUmizfKBOVI9FOluJ58XgCy7n0L2qPSy/UZBC /KYjKxkqyC9bIGXQg2x/5+r4CdJtNVe6n3RkU9woiXzgOS8TVCnLx0ExA6gmCIKO/4t+ QdmQ== X-Gm-Message-State: ANoB5pm0u0BdV3MfP+HAntsVSxlSNn4pNZf3xlP3EsBVXMgB8sD/HoMz yM3un6uHYb/zjmNUMlUq8G5Gpsno8bU= X-Received: by 2002:a17:90a:4003:b0:212:deef:a087 with SMTP id u3-20020a17090a400300b00212deefa087mr15837374pjc.77.1668466974859; Mon, 14 Nov 2022 15:02:54 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:a80:cf9f:e038:c19b:797e]) by smtp.gmail.com with ESMTPSA id 132-20020a62148a000000b0056c814a501dsm7534724pfu.10.2022.11.14.15.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 15:02:54 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Zhengjun Xing , James Clark , Athira Jajeev Subject: [PATCH 16/19] perf stat: Factor out prefix display Date: Mon, 14 Nov 2022 15:02:24 -0800 Message-Id: <20221114230227.1255976-17-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog In-Reply-To: <20221114230227.1255976-1-namhyung@kernel.org> References: <20221114230227.1255976-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514710843168131?= X-GMAIL-MSGID: =?utf-8?q?1749514710843168131?= The prefix is needed for interval mode to print timestamp at the beginning of each line. But the it's tricky for the metric only mode since it doesn't print every evsel and combines the metrics into a single line. So it needed to pass 'first' argument to print_counter_aggrdata() to determine if the current event is being printed at first. This makes the code hard to read. Let's move the logic out of the function and do it in the outer print loop. This would enable further cleanups later. Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 43 ++++++++++++---------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 73cf898060c0..bb40ed29300d 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -805,8 +805,7 @@ static void uniquify_counter(struct perf_stat_config *config, struct evsel *coun static void print_counter_aggrdata(struct perf_stat_config *config, struct evsel *counter, int s, - char *prefix, bool metric_only, - bool *first) + char *prefix, bool metric_only) { FILE *output = config->output; u64 ena, run, val; @@ -825,10 +824,6 @@ static void print_counter_aggrdata(struct perf_stat_config *config, ena = aggr->counts.ena; run = aggr->counts.run; - if (*first && metric_only) { - *first = false; - aggr_printout(config, counter, id, aggr->nr); - } if (prefix && !metric_only) fprintf(output, "%s", prefix); @@ -849,7 +844,6 @@ static void print_aggr(struct perf_stat_config *config, FILE *output = config->output; struct evsel *counter; int s; - bool first; if (!config->aggr_map || !config->aggr_get_id) return; @@ -860,21 +854,23 @@ static void print_aggr(struct perf_stat_config *config, */ for (s = 0; s < config->aggr_map->nr; s++) { if (metric_only) { + struct perf_stat_aggr *aggr; + struct aggr_cpu_id id = config->aggr_map->map[s]; + if (prefix) fprintf(output, "%s", prefix); - else if (config->summary && !config->no_csv_summary && - config->csv_output && !config->interval) - fprintf(output, "%16s%s", "summary", config->csv_sep); + + counter = evlist__first(evlist); + aggr = &counter->stats->aggr[s]; + aggr_printout(config, counter, id, aggr->nr); } - first = true; evlist__for_each_entry(evlist, counter) { if (counter->merged_stat) continue; - print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first); + print_counter_aggrdata(config, counter, s, prefix, + metric_only); } if (metric_only) fputc('\n', output); @@ -885,7 +881,6 @@ static void print_counter(struct perf_stat_config *config, struct evsel *counter, char *prefix) { bool metric_only = config->metric_only; - bool first = false; int s; /* AGGR_THREAD doesn't have config->aggr_get_id */ @@ -896,9 +891,8 @@ static void print_counter(struct perf_stat_config *config, return; for (s = 0; s < config->aggr_map->nr; s++) { - print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first); + print_counter_aggrdata(config, counter, s, prefix, + metric_only); } } @@ -1260,7 +1254,6 @@ static void print_percore(struct perf_stat_config *config, FILE *output = config->output; struct cpu_aggr_map *core_map; int s, c, i; - bool first = true; if (!config->aggr_map || !config->aggr_get_id) return; @@ -1288,11 +1281,7 @@ static void print_percore(struct perf_stat_config *config, if (found) continue; - if (prefix && metric_only) - fprintf(output, "%s", prefix); - - print_counter_aggrdata(config, counter, s, - prefix, metric_only, &first); + print_counter_aggrdata(config, counter, s, prefix, metric_only); core_map->map[c++] = core_id; } @@ -1319,10 +1308,6 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf } print_header(config, _target, evlist, argc, argv); - if (metric_only) { - if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run) - fprintf(config->output, "%s", prefix); - } switch (config->aggr_mode) { case AGGR_CORE: @@ -1337,6 +1322,8 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf iostat_print_counters(evlist, config, ts, prefix = buf, print_counter); else { + if (prefix && metric_only) + fprintf(config->output, "%s", prefix); evlist__for_each_entry(evlist, counter) { print_counter(config, counter, prefix); } From patchwork Mon Nov 14 23:02:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409708wru; Mon, 14 Nov 2022 15:07:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ph77tbKNXOk/j/zxxSupnovK/jahFORRk7aW/Dqvm/Ftzgly5RI4uX0hKLvUjQDmOR3pY X-Received: by 2002:a17:906:f2c3:b0:78d:d762:5457 with SMTP id gz3-20020a170906f2c300b0078dd7625457mr12524720ejb.67.1668467260039; Mon, 14 Nov 2022 15:07:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467260; cv=none; d=google.com; s=arc-20160816; b=QtL+bNWpjUJ34hYVB/43P5xs48nx3XMeTPU+O+f1u3SzvIyP9Twks07/OY1COtfkxN PWKACAyyZC91CZp3nZdZ3ky3bqo5bIYmjw0h7e4OuiWlL14PkpWpKdFo+2bqpfRemp6s HHKgzoEY36Mw2c+75CjfVSLNP80QmKNIcLKsIYAUxVggKUys0KRkuzq7wwKzH0Eqput9 3YXWEN7ATREMVSddMiGHebHl4t/dmsiXY+oWrdRdSMjHZksqgW0FYjeuOQFJMmrgzLZd z4prdotyYCkE9D5BZ64GiLDf0IhEkuq13XaJW0INzkpNdQHLheLhouj8WPJNVEm5cYy0 l2Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=EneTTOLEdeiyFEwMJVIPNECCRgEct82mU8+e7v3Zlys=; b=IRMB1jpwINH821L4fKVByETGhdPr3hVPr/g4Skdj/V8NUmfFV3clFpRC+TeJwLO+JP 0B55sqnAGtSVO0gaz6tPcio07pUBr7aQw9rLev59TsO8CFwlJZFgT+Gja3euhZN2LLTA GraYpvxROyha92h6yLxNyuimQTeCWa3AZFB/WyaM87Jml2vCM1kXLFS8EnK+n09k5eIa +8RXe58sFQmpGrnIajGYp06i42SpEDNPtGUg/qeLibXHEb0x26VL+bSRnbN/KD8i9bb8 01T7AEIN60Uzjqe/Bdok1z59mFrXP1mtsbKzWc7GuVfTy+XYIzOJjbdMxtkoZN8UDTfK EhUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LFq6cFJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb7-20020a0564020d0700b00458cba4c78bsi10326828edb.416.2022.11.14.15.07.13; Mon, 14 Nov 2022 15:07:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LFq6cFJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238176AbiKNXEw (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514725969794619?= X-GMAIL-MSGID: =?utf-8?q?1749514725969794619?= 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_config *config, fputc('\n', output); } +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 = evlist__first(evlist); + id = config->aggr_map->map[aggr_idx]; + aggr = &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 = config->metric_only; - FILE *output = config->output; struct evsel *counter; int s; @@ -853,17 +880,7 @@ static void print_aggr(struct perf_stat_config *config, * Without each counter has its own line. */ for (s = 0; s < config->aggr_map->nr; s++) { - if (metric_only) { - struct perf_stat_aggr *aggr; - struct aggr_cpu_id id = config->aggr_map->map[s]; - - if (prefix) - fprintf(output, "%s", prefix); - - counter = evlist__first(evlist); - aggr = &counter->stats->aggr[s]; - aggr_printout(config, counter, id, aggr->nr); - } + print_metric_begin(config, evlist, prefix, s); 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); } } @@ -919,9 +935,7 @@ static void print_no_aggr_metric(struct perf_stat_config *config, id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); if (first) { - if (prefix) - fputs(prefix, config->output); - aggr_printout(config, counter, id, 0); + print_metric_begin(config, evlist, prefix, counter_idx); first = false; } val = ps->aggr[counter_idx].counts.val; @@ -933,7 +947,7 @@ static void print_no_aggr_metric(struct perf_stat_config *config, run, ena, 1.0, &rt_stat, counter_idx); } if (!first) - fputc('\n', config->output); + print_metric_end(config); } } @@ -1322,13 +1336,11 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf iostat_print_counters(evlist, config, ts, prefix = buf, print_counter); else { - if (prefix && metric_only) - fprintf(config->output, "%s", prefix); + print_metric_begin(config, evlist, prefix, /*aggr_idx=*/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: From patchwork Mon Nov 14 23:02:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2409936wru; Mon, 14 Nov 2022 15:08:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf6rWP7ZDQePS8573Y2lsFOi4wbOv4QOGrOB3S/3wgBVsssY/F0J7pibJnbybvbbCPQLyKu7 X-Received: by 2002:a63:5b65:0:b0:46f:f740:3ff5 with SMTP id l37-20020a635b65000000b0046ff7403ff5mr13579270pgm.70.1668467290115; Mon, 14 Nov 2022 15:08:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467290; cv=none; d=google.com; s=arc-20160816; b=SiQMlMQ0G+Huc6UlZJUb1LaURQLijCogOSUDlLsNRS/Funcj2npl8alrql8eOqzmWU WOoLVLZLA3ZsnLlr39BZLJzPBxxNaW68OdCTJxYjwfMqWv04/ArL0Trhy+py5CMb5Cxg Ic/UIrG2buBo8qBZyIWEQ3Gi/n4lnYA1k3vqg0yN2Kp8CHGABH9Req3N6W9LxtvcRpvM GutUDp9BCVlAB6kz46sv4/DYN085Z+T1cb/T9WAvJW1MyFWl1nMPBCmAjWiRMC6IHH01 TYUwp71rf0JFwzjfPRuQuu0r0wHjZgXFV5EM9UOF7eH06UG5ADTMUj+Pr2o2qii4CunC ztXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=MYDLtl9GSeaGL91h5dtqz1M8wM/Y9pV3tpLuUgjiMtg=; b=tdob49MRfxAoF0MnjZDGlDkTuAJbdPWi1b1DabQIDBHROnrbuMQxrYGdQz0NcnvI9R BLaNItdyKc1+cHgQgATb5AZW1Wl4g8FRZHPu3+A4OPlj9i3aNXG99UqIHk1iI3eOW/mV 0hWLUFS9UqIYvsevlaXP91gkalBotyWIRt7U455eDqKdNE5sxW7EsUUXJyQtTpfSNgBT QgMh3X3HwZ13XtciPqgm1IxLLy+HVauxw4AaCs0hFsxXdEWwdK8faX2Wq9pyUlgYQdq8 2usb8xSwabq6/V8UmBe8FUSIv8W4YPXAlIMs0dYsk2GxRcshnfBStCzFZ7BRyk65/Qdd T9Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ayXvD3Oy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a636c06000000b0046fed3af6c9si9583109pgc.370.2022.11.14.15.07.56; Mon, 14 Nov 2022 15:08:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ayXvD3Oy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238051AbiKNXEz (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:55 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514757187902262?= X-GMAIL-MSGID: =?utf-8?q?1749514757187902262?= 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 sleep 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); } -static void print_cgroup(struct perf_stat_config *config, struct evsel *evsel) +static void print_cgroup(struct perf_stat_config *config, struct cgroup *cgrp) { - if (nr_cgroups) { - const char *cgrp_name = evsel->cgrp ? evsel->cgrp->name : ""; + if (nr_cgroups || config->cgroup_list) { + const char *cgrp_name = cgrp ? cgrp->name : ""; 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; }; 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 != os->evsel->evlist->selected->priv) return; + if (os->evsel->cgrp != os->cgrp) + return; + if (!valid_only_metric(unit)) return; unit = fixunit(tbuf, os->evsel, unit); @@ -642,7 +646,7 @@ static void abs_printout(struct perf_stat_config *config, { aggr_printout(config, evsel, id, nr); print_counter_value(config, evsel, avg, ok); - print_cgroup(config, evsel); + print_cgroup(config, evsel->cgrp); } static bool is_mixed_hw_group(struct evsel *counter) @@ -838,7 +842,8 @@ static void print_counter_aggrdata(struct perf_stat_config *config, 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 = config->aggr_map->map[aggr_idx]; aggr = &evsel->stats->aggr[aggr_idx]; aggr_printout(config, evsel, id, aggr->nr); + + print_cgroup(config, cgrp); } 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 = 0; s < config->aggr_map->nr; s++) { - print_metric_begin(config, evlist, prefix, s); + print_metric_begin(config, evlist, prefix, s, /*cgrp=*/NULL); evlist__for_each_entry(evlist, counter) { if (counter->merged_stat) @@ -935,7 +942,8 @@ static void print_no_aggr_metric(struct perf_stat_config *config, id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); if (first) { - print_metric_begin(config, evlist, prefix, counter_idx); + print_metric_begin(config, evlist, prefix, + counter_idx, /*cgrp=*/NULL); first = false; } val = ps->aggr[counter_idx].counts.val; @@ -960,7 +968,7 @@ static void print_metric_headers_std(struct perf_stat_config *config, if (!no_indent) { int len = aggr_header_lens[config->aggr_mode]; - if (nr_cgroups) + if (nr_cgroups || config->cgroup_list) len += CGROUP_LEN + 1; fprintf(config->output, "%*s", len, ""); @@ -1012,6 +1020,9 @@ static void print_metric_headers(struct perf_stat_config *config, if (config->iostat_run) iostat_print_header_prefix(config); + if (config->cgroup_list) + os.cgrp = evlist__first(evlist)->cgrp; + /* Print metrics headers only */ evlist__for_each_entry(evlist, counter) { os.evsel = counter; @@ -1305,6 +1316,28 @@ static void print_percore(struct perf_stat_config *config, fputc('\n', output); } +static void print_cgroup_counter(struct perf_stat_config *config, struct evlist *evlist, + char *prefix) +{ + struct cgroup *cgrp = NULL; + struct evsel *counter; + + evlist__for_each_entry(evlist, counter) { + if (cgrp != counter->cgrp) { + if (cgrp != NULL) + print_metric_end(config); + + cgrp = counter->cgrp; + print_metric_begin(config, evlist, prefix, + /*aggr_idx=*/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 = buf, print_counter); - else { - print_metric_begin(config, evlist, prefix, /*aggr_idx=*/0); + } else if (config->cgroup_list) { + print_cgroup_counter(config, evlist, prefix); + } else { + print_metric_begin(config, evlist, prefix, + /*aggr_idx=*/0, /*cgrp=*/NULL); evlist__for_each_entry(evlist, counter) { print_counter(config, counter, prefix); } From patchwork Mon Nov 14 23:02:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 20086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2410073wru; Mon, 14 Nov 2022 15:08:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf5fl2lciFkFCz8H/nnmI3cVb4mA4oU6JfPndkZJyivRrAvwgRdH+CzFKRq0TWO0JuwkErSF X-Received: by 2002:a17:902:d716:b0:186:b3cb:3b85 with SMTP id w22-20020a170902d71600b00186b3cb3b85mr1346275ply.96.1668467308033; Mon, 14 Nov 2022 15:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467308; cv=none; d=google.com; s=arc-20160816; b=WWPz7dhYIGb68hnRE28ckRLLp1p3d/8GU6/5bKh90o027WYmQh5o1xVio+S8U7UtZp OuVVXmm6r5YcKt+++Kl+151fIjMVaN6LtfEUJBiT7UzRv7c7LlKJUWycr7jka8LwQ343 +zHDShpGfztLb86XHyeZtIxRifM+a69AmoO68WjtIkPf4KIAQZ/c+UbY7IjNeh1G9g5/ akVDuwGnIYg9H3F+zWrFZ5OrgVJxZ3y+6xRkP1GhSxE9f7kBSAFMtuW63Dr3SJ7LreNF URp592mrgZ15MPNIQrjqRKcwUavHkx8T6ylyvRfy7jFRtOQZsReGbzcOlL7a/zI6pZmh IYrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=V4xN0opfJbQJnUhtmkfw3MqwhSTJXF+vfzMgniki+7E=; b=mAiTDHsvqDGimg+WixGFRhCgMk0glrRi6Qd+jUrYowmXzKXLSDMOBc6EKbbyU2726V 74N1Ib+CR5L0um4urqUjYFc6SKBNhhKjcN1BMdE7Ui+olq7pM5zZg0KBm0pcv0aO2wfL dGjOnrTbZzQr8AOSaI3dDHBFEQwkytN0VgFn0MSh0GXb+yO/pWiXvES7pKTd65mDFN5t 4BelNT7Ni/bX0i9YmkXcSnlpmslupTSldeNTN5watrUCc+COBnfy15S+TohsOlaOl8lD yQEWTS+WOx3ajZ4SJVyHuTRmMRcOZGH1iH5EYSTQ8YKrBFgo6edoxymxJmYTr+SccNet T2FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qp+2rjNM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a17090a8a0e00b002135a4d80d7si10215325pjn.188.2022.11.14.15.08.12; Mon, 14 Nov 2022 15:08:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qp+2rjNM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238038AbiKNXE5 (ORCPT + 99 others); Mon, 14 Nov 2022 18:04:57 -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-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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514775698457991?= X-GMAIL-MSGID: =?utf-8?q?1749514775698457991?= 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 speculation 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, } } +static void print_aggr_cgroup(struct perf_stat_config *config, + struct evlist *evlist, + char *prefix) +{ + bool metric_only = config->metric_only; + struct evsel *counter, *evsel; + struct cgroup *cgrp = NULL; + int s; + + if (!config->aggr_map || !config->aggr_get_id) + return; + + evlist__for_each_entry(evlist, evsel) { + if (cgrp == evsel->cgrp) + continue; + + cgrp = evsel->cgrp; + + for (s = 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 != 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, struct 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: