Received: by 10.213.65.68 with SMTP id h4csp4004165imn; Tue, 10 Apr 2018 07:51:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx48eTGCGfkWEyHyHlvm7SQ9CTtunIHP5IcbAbKG0CeWB81FUw8/QqSY0lJ29kHrQEVh+lwTu X-Received: by 10.99.134.193 with SMTP id x184mr554999pgd.324.1523371907341; Tue, 10 Apr 2018 07:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523371907; cv=none; d=google.com; s=arc-20160816; b=uaEieg/byKafkKpEKeyzHF0xIbF2ZWl+i4IjRBNmC3LuDKdiLblNNch6RUvAffrz7f RX826MZKVzUWl3wzPLn8zInEsuS5Ki1ufkG98vsspI+BxdRQfBqhgICeDZeLnY9AF8UU VC7cL4Oi/JY1iLU6yDUTtP7/0HVmJnM+iO6hEOab6LpD6KI2dhQdM8fumZLsLeNp4LMy p63v7Pw5jBOVlKkOUCfRjs+HYjW/U0OJxjAD8IaHb0Kbe6vYyshWuXDWOPLdonn3SlaS OZe6qWVmBMNnkxesqqhdbVLKj1g/IjnEev4lK4b8Qzds/zF33ujMtX4WuOw8BvsZLT2r +JLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=FFF+PiVdh72ULPj5uPwM7R4NMsaBKdVP+V95t2vocA8=; b=Q5qD0fhoLVNW4Rcmc8KglX5e/EySvlvvDQ5Gp5iKneSwSk1f6CKCxdxVFZq+n2R8xh Dae6HlFvxuqrWL6OrpwqgbMxJHI8HH6J2w9+vvm5c+UfkrXGFw55gb5x9jf4hUEiNkeg ARV7//iWuxgae47GA2X9xiUxb2E+UmrrohyKagNXGlOSEqVqJkQ9FYG4eaPI8tYxxgWg bZEvMdzDqpVSzBMicZzcAMDjiI3Rs7oyhiDw3iMYG6pxHbRzEIBXF7Lv7KpmdmCJTU+z WI0elixj/p475tvLUloIRQ59cyLiD3JCTSKAi55ftr5zl0V93AFV9Alutpp/Aw2eekUP 6KDQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7-v6si2713497plq.187.2018.04.10.07.51.10; Tue, 10 Apr 2018 07:51:47 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754213AbeDJOse (ORCPT + 99 others); Tue, 10 Apr 2018 10:48:34 -0400 Received: from mga04.intel.com ([192.55.52.120]:6315 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753468AbeDJOsc (ORCPT ); Tue, 10 Apr 2018 10:48:32 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Apr 2018 07:48:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,432,1517904000"; d="scan'208";a="219272517" Received: from yu-chen.sh.intel.com ([10.239.160.138]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2018 07:48:30 -0700 From: Yu Chen To: Len Brown Cc: "Rafael J . Wysocki" , Artem Bityutskiy , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chen Yu Subject: [PATCH][v2] tools/power turbostat: if --max_loop, print for specific time of loops Date: Tue, 10 Apr 2018 22:51:41 +0800 Message-Id: <20180410145141.31166-1-yu.c.chen@intel.com> X-Mailer: git-send-email 2.13.6 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen Yu There's a use case during test to only print specific round of loops if --iterations is specified, for example, with this patch applied: turbostat -i 5 -t 4 will capture 4 samples with 5 seconds interval. Signed-off-by: Chen Yu --- tools/power/x86/turbostat/turbostat.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index bd9c6b31a504..7a09291765af 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -48,6 +48,7 @@ char *proc_stat = "/proc/stat"; FILE *outf; int *fd_percpu; struct timespec interval_ts = {5, 0}; +int iterations; unsigned int debug; unsigned int quiet; unsigned int sums_need_wide_columns; @@ -470,6 +471,7 @@ void help(void) " {core | package | j,k,l..m,n-p }\n" "--quiet skip decoding system configuration header\n" "--interval sec Override default 5-second measurement interval\n" + "--iterations loops The number of loops if interval is specified\n" "--help print this help message\n" "--list list column headers only\n" "--out file create or truncate \"file\" for all output\n" @@ -2565,6 +2567,7 @@ void turbostat_loop() { int retval; int restarted = 0; + int loops = 0; restart: restarted++; @@ -2583,6 +2586,7 @@ void turbostat_loop() restarted = 0; gettimeofday(&tv_even, (struct timezone *)NULL); + loops = 0; while (1) { if (for_all_proc_cpus(cpu_is_not_present)) { re_initialize(); @@ -2607,6 +2611,10 @@ void turbostat_loop() compute_average(EVEN_COUNTERS); format_all_counters(EVEN_COUNTERS); flush_output_stdout(); + + if (iterations && (++loops >= iterations)) + break; + nanosleep(&interval_ts, NULL); if (snapshot_proc_sysfs_files()) goto restart; @@ -2626,6 +2634,9 @@ void turbostat_loop() compute_average(ODD_COUNTERS); format_all_counters(ODD_COUNTERS); flush_output_stdout(); + + if (iterations && (++loops >= iterations)) + break; } } @@ -4999,6 +5010,7 @@ void cmdline(int argc, char **argv) {"Dump", no_argument, 0, 'D'}, {"debug", no_argument, 0, 'd'}, /* internal, not documented */ {"interval", required_argument, 0, 'i'}, + {"iterations", required_argument, 0, 't'}, {"help", no_argument, 0, 'h'}, {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help {"Joules", no_argument, 0, 'J'}, @@ -5014,7 +5026,7 @@ void cmdline(int argc, char **argv) progname = argv[0]; - while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v", + while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:vt:", long_options, &option_index)) != -1) { switch (opt) { case 'a': @@ -5069,6 +5081,18 @@ void cmdline(int argc, char **argv) case 'S': summary_only++; break; + case 't': + { + int loops = strtod(optarg, NULL); + + if (loops <= 0) { + fprintf(outf, "loops %d should be positive number\n", + iterations); + exit(2); + } + iterations = loops; + } + break; case 'T': tcc_activation_temp_override = atoi(optarg); break; -- 2.13.6