Received: by 10.223.176.5 with SMTP id f5csp2645066wra; Mon, 29 Jan 2018 01:27:48 -0800 (PST) X-Google-Smtp-Source: AH8x224nSrLM0OahBuxejTSJAAqp8lhVNDHtSwlmRNc1BD3rFkWXqZFr9YEx0tXvbkZj57M2ogcn X-Received: by 10.99.3.71 with SMTP id 68mr21367143pgd.334.1517218068084; Mon, 29 Jan 2018 01:27:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517218068; cv=none; d=google.com; s=arc-20160816; b=qPYm93RfDZw7UxyKn0Ia+WvYx90XHTBRPL24l7hjzA9VycgJTVLjs0YLa9Rm/SOLIn jqWS8lHCjKTMRdu68lgL3Ja+wSiGIUkFO5KBvqPPjzTzVbXDtriKP5dBnytx7HtEh+do 198WsBZ2F1tJer57kARIc+EGtW9qB3Oko2Kj06/NwH+yF1iGGpPPfBgiBr+r88hYb4Hm v/VXqcVvmLCao/8gNKM0ZT75LOnUmTyxJTFRk8U5vONbjWHOtcy5/PGZVGVLdP10IhA0 R5qXfSDyqIT7+I9CRgvb3yMBuW/C+rxUEQDtyZUmj9zFWR0K2WwRJC9QBmdvGDbLsyaP Axeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=SPNK2v9fk8dzqaHQv3bgmTbPLIs/qZxiTLolujzMzpA=; b=vv3bqJSI2tuZSwKupYI2h3CUOUUOXCqlv4dsTB/5cawQ83ZR86B9VNtuMxlRvEVXK4 TCFGW69zIqiVPSQarU2An2rJkdJrg7Zi+uod0X1XZ4G1terCcs45coBpk1a2ViMqbEXC SDY3rT2P4hd8iWu6hnb4zFkMGLKKuivXmmRhY7PiqTZqbT6YypeNld/OQv4ea/NdXmod Omi5X6HAelerYfxoF3Aq3sqx61hLgTxB4VrCiA0mwpgnAPLCrpoLGbMQdQNxwLNyZyTN VNifrWAJT1Z74X3veSbGE+oNfcHI+aGUBK1kBgBl9w18pqwFKbvw+V2t3IVdrPQDDFcN ItXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pbp/14xN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7-v6si2898895plm.123.2018.01.29.01.27.33; Mon, 29 Jan 2018 01:27:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pbp/14xN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751693AbeA2JZv (ORCPT + 99 others); Mon, 29 Jan 2018 04:25:51 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:51933 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599AbeA2JZr (ORCPT ); Mon, 29 Jan 2018 04:25:47 -0500 Received: by mail-it0-f66.google.com with SMTP id p139so7499254itb.1; Mon, 29 Jan 2018 01:25:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SPNK2v9fk8dzqaHQv3bgmTbPLIs/qZxiTLolujzMzpA=; b=Pbp/14xNGLWQHqg3MYQqoRpkBdVHpSLPok3fkhFDLR2EXhhhIbdjVZG3H6iPS5VGHs 3S/b2f20VRrxfXahq4nn+A4baQ2Rt/Tb+ouumW42lpQwn/uMdie9iIABk9PgWb9+xBeN 3u5Ebmwur0YKav72K4TO+tSb5rBghZE3/ygCpXbdTi8bLUqAakiL5Jc70Mi9cprmHhrr H81ln+KuvwVypynOXye2s8jmcnYFK1AV1OieVXaG4/ReQ37iCeTQQHrfYp/Nip4fux7y UBMwMVJEktAe4jGH49CUml2netvbJWdZlnp5pM2FlMpLLBca4CdVmEpwi8cjprBbTje0 Fkjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SPNK2v9fk8dzqaHQv3bgmTbPLIs/qZxiTLolujzMzpA=; b=Qd53urIE1N6gsdawLXZR7RtqQRkbQVAZKdrQwasmoMqxvWYGHk8t9K4FMpOESKfNsV xHyvDY2+DziKY7xC+chF7DucXNvc9qRpCDAB0YbtbVOld1wOOmTWRc9x9itLfXprYfI/ byTF1m4hpEE9PF42WDiXOY2Du7WeK/jthHX08SqV5jkGcaKLv66QeYzJqxU48eNNVBQx FxPQTnGl4y1klevGpKdOv5ru1wZjK5Kw2FugabaDH1LSKQr3nDMP5WiCd+kyrUwln54g wBPyD0NQMh7s3W1dguJZT4yaMNun+kRg0q5abTPPd8WONHaYDxx7T+QbphaedDKHjsLO Ggtw== X-Gm-Message-State: AKwxytfW0vgmQnp8+77IezVqYxwXYjSgNxfoWj5bmnyEZ9VKqaFqEMk1 rG4yvg7cNLUnL5Kn7iOmfKw= X-Received: by 10.36.254.4 with SMTP id w4mr8331424ith.80.1517217945849; Mon, 29 Jan 2018 01:25:45 -0800 (PST) Received: from node3.didichuxing.com ([40.83.124.139]) by smtp.gmail.com with ESMTPSA id j3sm3869448iob.14.2018.01.29.01.25.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jan 2018 01:25:44 -0800 (PST) From: ufo19890607 To: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, dsahern@gmail.com, namhyung@kernel.org, milian.wolff@kdab.com, arnaldo.melo@gmail.com, yuzhoujian@didichuxing.com, adrian.hunter@intel.com, wangnan0@huawei.com, Kan.liang@intel.com Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, acme@redhat.com Subject: [PATCH v4 1/2] perf stat: Add support to print counts for fixed times Date: Mon, 29 Jan 2018 10:25:22 +0100 Message-Id: <1517217923-8302-2-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1517217923-8302-1-git-send-email-ufo19890607@gmail.com> References: <1517217923-8302-1-git-send-email-ufo19890607@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: yuzhoujian Introduce a new option to print counts for fixed number of times and update perf-stat documentation accordingly. Show below is the output of the new option for perf stat. $ perf stat -I 1000 --interval-count 2 -e cycles -a # time counts unit events 1.002827089 93,884,870 cycles 2.004231506 56,573,446 cycles We can just print the counts for several times with this newly introduced option. The usage of it is a little like vmstat, and it should be used together with "-I" option. $ vmstat -n 1 2 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 78270544 547484 51732076 0 0 0 20 1 1 1 0 99 0 0 0 0 0 78270512 547484 51732080 0 0 0 16 477 1555 0 0 100 0 0 Changes since v3: - merge interval_count check and times check to one line. - fix the wrong indent in stat.h - use stat_config.times instead of 'times' in cmd_stat function. Changes since v2: - none. Changes since v1: - change the name of the new option "times-print" to "interval-count". - keep the new option interval specifically. Signed-off-by: yuzhoujian --- tools/perf/Documentation/perf-stat.txt | 5 +++++ tools/perf/builtin-stat.c | 20 +++++++++++++++++++- tools/perf/util/stat.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 823fce7674bb..47a21645f60c 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -146,6 +146,11 @@ Print count deltas every N milliseconds (minimum: 10ms) The overhead percentage could be high in some cases, for instance with small, sub 100ms intervals. Use with caution. example: 'perf stat -I 1000 -e cycles -a sleep 5' +--interval-count times:: +Print count deltas for fixed number of times. +This option should be used together with "-I" option. + example: 'perf stat -I 1000 --interval-count 2 -e cycles -a' + --metric-only:: Only print computed metrics. Print them in a single line. Don't show any raw values. Not supported with --per-thread. diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 98bf9d32f222..7d1d7613bf56 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -168,6 +168,7 @@ static struct timespec ref_time; static struct cpu_map *aggr_map; static aggr_get_id_t aggr_get_id; static bool append_file; +static bool interval_count; static const char *output_name; static int output_fd; static int print_free_counters_hint; @@ -571,6 +572,7 @@ static struct perf_evsel *perf_evsel__reset_weak_group(struct perf_evsel *evsel) static int __run_perf_stat(int argc, const char **argv) { int interval = stat_config.interval; + int times = stat_config.times; char msg[BUFSIZ]; unsigned long long t0, t1; struct perf_evsel *counter; @@ -700,6 +702,8 @@ static int __run_perf_stat(int argc, const char **argv) while (!waitpid(child_pid, &status, WNOHANG)) { nanosleep(&ts, NULL); process_interval(); + if (interval_count && !(--times)) + break; } } waitpid(child_pid, &status, 0); @@ -716,8 +720,11 @@ static int __run_perf_stat(int argc, const char **argv) enable_counters(); while (!done) { nanosleep(&ts, NULL); - if (interval) + if (interval) { process_interval(); + if (interval_count && !(--times)) + break; + } } } @@ -1891,6 +1898,8 @@ static const struct option stat_options[] = { "command to run after to the measured command"), OPT_UINTEGER('I', "interval-print", &stat_config.interval, "print counts at regular interval in ms (>= 10)"), + OPT_INTEGER(0, "interval-count", &stat_config.times, + "print counts for fixed number of times"), OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode, "aggregate counts per processor socket", AGGR_SOCKET), OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode, @@ -2870,6 +2879,15 @@ int cmd_stat(int argc, const char **argv) "The overhead percentage could be high in some cases. " "Please proceed with caution.\n"); } + if (stat_config.times && interval) + interval_count = true; + else if (stat_config.times && !interval) { + pr_err("interval-count option should be used together with " + "interval-print.\n"); + parse_options_usage(stat_usage, stat_options, "interval-count", 0); + parse_options_usage(stat_usage, stat_options, "I", 1); + goto out; + } if (perf_evlist__alloc_stats(evsel_list, interval)) goto out; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index dbc6f7134f61..540fbb350e53 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -90,6 +90,7 @@ struct perf_stat_config { bool scale; FILE *output; unsigned int interval; + int times; struct runtime_stat *stats; int stats_num; }; -- 2.14.1