Received: by 10.223.176.46 with SMTP id f43csp1872289wra; Thu, 25 Jan 2018 01:12:44 -0800 (PST) X-Google-Smtp-Source: AH8x227IHFdTjeP8aZWDu9sB1wFnLiyh/Wxl1GWkjv4+mUM+w21+OXahNaO3JgfV8duyXg3b9Z0K X-Received: by 10.98.11.218 with SMTP id 87mr15057573pfl.99.1516871564080; Thu, 25 Jan 2018 01:12:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516871564; cv=none; d=google.com; s=arc-20160816; b=GpRxE0wtAsPbTkbk3ZL6/yZ89jptCdRj2RWHhvHW4uDMMI7WpGb5cSy+fneaF0YCpo /z+FWpdTI2E87tZ6VPN/zVfkwYh3Xn9Raom3kZYHDQfhUeuZJSUiANKn+JZEi4Fk3+J5 EjN7X1KeLgMU3rResg7lmqwE5LfcwterS+iH0cxJQYVoP66h/sBYNlVMrzC3eRsvanaw Tl8rtYUJ/Z6yc0lFL87H46dyl6Zzuy9FkXofDrn9VSPzKYsxGp8clDVq/H9TawiG5KH5 48XUC3WTMXpHFy4iofyoLsMWhAm6Z4D0Qo3UPT39WRNs2EsHjKeUkwgggfD7kNEbadxp F5XQ== 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=BNuR7PIAE86ZlIVqlXl2pwmWg2ClgfvY3FXBAGXIULM=; b=gQ8WTSZsvuyXmAkYRita7NImxgP4k6t7X2OEBpndKJqGIgctSAuaPGNkYs74ymquw2 AcihFKcsOAaLBrNEnKhgYsLdJ33Z8u1yYT6bAaZExJc7Bv7ZAD28KREXBGD5rOv3vdXQ v/VGuCpRkA/+kLb51axn0gkGPVz06ubjgvtFuV3bNtEMYWuErdj8s1bSwk6qq68C2WlO 8PVUZ/iuI6pn1R5gPVwSpYWFjW/a7K83bE6hkScWsz/TuUzOUFbmHzrGByHTwgcAS5WC 3Dio1de3mMB6Dkd0hJGIV9tWSx89385JUbUHNMPmevDwIv+5QaV/mp6k5Kg30HpyLoed 5aJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YujBVc2/; 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 x10-v6si1693970pln.30.2018.01.25.01.12.29; Thu, 25 Jan 2018 01:12:44 -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=YujBVc2/; 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 S1751514AbeAYJLL (ORCPT + 99 others); Thu, 25 Jan 2018 04:11:11 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:39080 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751436AbeAYJKe (ORCPT ); Thu, 25 Jan 2018 04:10:34 -0500 Received: by mail-io0-f195.google.com with SMTP id b198so7911516iof.6; Thu, 25 Jan 2018 01:10:33 -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=BNuR7PIAE86ZlIVqlXl2pwmWg2ClgfvY3FXBAGXIULM=; b=YujBVc2/ziyZ9RS+j8E2W6q9V2BUCEj8S/DocCakKuuVHssaYVjM45mQatTJiypf9Q PKkuShwiWxijpyLNdxksxsc5WA4ODjUKGr4xjaGdu/eQlL+wkT8dhnWrM1mptQBzW+ka j3/K/lbTxYlLNVbjihXbyN9QUwtN9K+F4XQhooOKsqAs29uJZJrOMNU4QVHE7y/sZ+fZ V2R5Lg5Rg0cFyO8mVQV8T3b6nxUTaS+v0D9ifxYCly9buwT4slAUKDdscBXNguthaMzt d3R4uF+v0vW5VbJ+1PLX3zuPFSi1sikNW6Ay02Sc58LjmB4gg6ATy4KnBq0aZA49q08X AYfw== 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=BNuR7PIAE86ZlIVqlXl2pwmWg2ClgfvY3FXBAGXIULM=; b=oOqercKwQuS7VtdMl8rTOJq2/z5e61KHovYQNIS1yt1ErCNsvS0Xmu3hsLKst7PPbn u0FW4Nl79SN+DCyYFu+D2Ts/K5EAQ7Ae1JtTaNUh/JZf+M52TdRsSti95zZhspAEysey BvQV+ubhxen+7nHXY2AqAZWlC7M5qdya+BAR465MNFa10J1NkekMlO9px6Tzyli2z1dz zy3UGXB6uWNfUShcz98oamPFXTvE1AS/vKC/pv1n8wegWPrgTox9Z0hVJp2nOYM8m6i1 zwxIWk/GP4dMo6QDkfBic5CTakRXuAmwij220v1yiGhG+hg5Sxw5NhSJEdoXb1bfp5mn LZBA== X-Gm-Message-State: AKwxytcw7KNdaFMsXdkjgyqI0TD+4BH9NZGJz6+fiY+FmzHGzypTZ7I7 yD/DZ7q55zaQYmxEUs6yKg15oA== X-Received: by 10.107.192.2 with SMTP id q2mr12186889iof.112.1516871433126; Thu, 25 Jan 2018 01:10:33 -0800 (PST) Received: from node3.didichuxing.com ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id n95sm1693917ioo.12.2018.01.25.01.10.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jan 2018 01:10:32 -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 Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, acme@redhat.com Subject: [PATCH v2 2/2] perf stat: Add support to print counts after a period of time Date: Thu, 25 Jan 2018 10:10:04 +0100 Message-Id: <1516871404-31920-3-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516871404-31920-1-git-send-email-ufo19890607@gmail.com> References: <1516871404-31920-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 after N milliseconds and update perf-stat documentation accordingly. Show below is the output of the new option for perf stat. $ perf stat --time 2000 -e cycles -a Performance counter stats for 'system wide': 157,260,423 cycles 2.003060766 seconds time elapsed We can print the count deltas after N milliseconds with this new introduced option. This option is not supported with "-I" option. Changes since v1: - none. Signed-off-by: yuzhoujian --- tools/perf/Documentation/perf-stat.txt | 7 ++++++- tools/perf/builtin-stat.c | 29 ++++++++++++++++++++++++++--- tools/perf/util/stat.h | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 47a21645f60c..8270a0708ea2 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -149,7 +149,12 @@ The overhead percentage could be high in some cases, for instance with small, su --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' + example: 'perf stat -I 1000 --times-print 2 -e cycles -a' + +--time msecs:: +Print count deltas after N milliseconds (minimum: 10 ms). +This option is not supported with "-I" option. + example: 'perf stat --time 2000 -e cycles -a' --metric-only:: Only print computed metrics. Print them in a single line. diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 406f546ad74c..427f06dc35cc 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -573,6 +573,7 @@ static int __run_perf_stat(int argc, const char **argv) { int interval = stat_config.interval; int times = stat_config.times; + int time = stat_config.time; char msg[BUFSIZ]; unsigned long long t0, t1; struct perf_evsel *counter; @@ -586,6 +587,9 @@ static int __run_perf_stat(int argc, const char **argv) if (interval) { ts.tv_sec = interval / USEC_PER_MSEC; ts.tv_nsec = (interval % USEC_PER_MSEC) * NSEC_PER_MSEC; + } else if (time) { + ts.tv_sec = time / USEC_PER_MSEC; + ts.tv_nsec = (time % USEC_PER_MSEC) * NSEC_PER_MSEC; } else { ts.tv_sec = 1; ts.tv_nsec = 0; @@ -698,9 +702,11 @@ static int __run_perf_stat(int argc, const char **argv) perf_evlist__start_workload(evsel_list); enable_counters(); - if (interval) { + if (interval || time) { while (!waitpid(child_pid, &status, WNOHANG)) { nanosleep(&ts, NULL); + if (time) + break; process_interval(); if (interval_count == true) { if (--times == 0) @@ -722,7 +728,9 @@ static int __run_perf_stat(int argc, const char **argv) enable_counters(); while (!done) { nanosleep(&ts, NULL); - if (interval) { + if (interval || time) { + if (time) + break; process_interval(); if (interval_count == true) { if (--times == 0) @@ -1904,6 +1912,8 @@ static const struct option stat_options[] = { "print counts at regular interval in ms (>= 10)"), OPT_INTEGER(0, "interval-count", &stat_config.times, "print counts for fixed number of times"), + OPT_UINTEGER(0, "time", &stat_config.time, + "print counts after a period of time in ms (>= 10)"), 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, @@ -2701,7 +2711,7 @@ int cmd_stat(int argc, const char **argv) int status = -EINVAL, run_idx; const char *mode; FILE *output = stderr; - unsigned int interval; + unsigned int interval, time; int times; const char * const stat_subcommands[] = { "record", "report" }; @@ -2734,6 +2744,7 @@ int cmd_stat(int argc, const char **argv) interval = stat_config.interval; times = stat_config.times; + time = stat_config.time; /* * For record command the -o is already taken care of. @@ -2885,6 +2896,7 @@ int cmd_stat(int argc, const char **argv) "The overhead percentage could be high in some cases. " "Please proceed with caution.\n"); } + if (times && interval) interval_count = true; else if (times && !interval) { @@ -2895,6 +2907,17 @@ int cmd_stat(int argc, const char **argv) goto out; } + if (time && time < 10) { + pr_err("time must be >= 10ms.\n"); + parse_options_usage(stat_usage, stat_options, "time", 0); + goto out; + } else if (time && interval) { + pr_err("time option is not supported with interval-print.\n"); + parse_options_usage(stat_usage, stat_options, "time", 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 b2f8a347d358..6c621951fda8 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; + unsigned int time; int times; struct runtime_stat *stats; int stats_num; -- 2.14.1