Received: by 10.192.165.156 with SMTP id m28csp230413imm; Thu, 12 Apr 2018 20:47:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx48YF68qfF29NNd6rlYXu03DPaYq5ZdHvu9mattYO4AfcDYFyvToiL1Z11HLXBHuPiMoxabM X-Received: by 10.98.13.23 with SMTP id v23mr10010874pfi.202.1523591226389; Thu, 12 Apr 2018 20:47:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523591226; cv=none; d=google.com; s=arc-20160816; b=pvSwB5cJAMcvPq6H3j/yvoV5fyHMRnfbgwplDBH+e0YBM2a/hOxCjmTSGmhPM11dnH XNSw963brDpxqk97NIVfSNFjEI2AkW5ZGNc6ct1LWebNWJFKXw7lndW9yutLGmPekjeM xWmMhc7DkLtiv4c1wzGmBABAqM1BG5Kd3TuVdr7JGxthikZGFPz8EjUefQSRPFwAvkBF tM8XqTLe8oDwEuCmBOGM1eOVN5LbV/iU5bu4cRFfXF999lceM8IccXeSRy8J6MHrcigs PW0nIOTQpOyE0hRrSWIqCohcwdl1tObmPG27H/tITxmYzTbwd8j0qKeeZB8E2rNycW/X EOlQ== 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=83n5piYmrDNIMG0ikXRntRS9tbvMKJzZboqF7mlApD4=; b=Wq6AkF0pxRJ3VupwUgwYqdfzGcmjeKIbREWxt8wGc2fSOI6Umc97DgJ6tP86uq5SER 2+Zew5saqt1b8Ic4LQJY+HH3ClI1E22I/y6rtzCpqqbf5IDD+WouiL3jF0a9ibOnR9kN o37hwYBoH76oxzrmWa5uZFVveci4YnXVae2BxsuyzQCDbu5zihXjPsEcka0s9emt6QGG HERf+9JqfO0XEKgndDBjxZYS9XgjiDBAxPy+7v+4AbYQZJo8mBrb0CKIsQ0c/x+q7icQ 2uDm4NIziO7ZSBgW+RVTfRxJHwiLWD0dBSitf0MBFUgpHsGXOCNLomGyUs+Yt8txOywD Q5Qg== 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 c3-v6si4727599pld.545.2018.04.12.20.46.52; Thu, 12 Apr 2018 20:47:06 -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 S1753454AbeDMDhn (ORCPT + 99 others); Thu, 12 Apr 2018 23:37:43 -0400 Received: from mga06.intel.com ([134.134.136.31]:44687 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752594AbeDMDhl (ORCPT ); Thu, 12 Apr 2018 23:37:41 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Apr 2018 20:37:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,444,1517904000"; d="scan'208";a="33938052" Received: from yu-chen.sh.intel.com ([10.239.160.138]) by orsmga006.jf.intel.com with ESMTP; 12 Apr 2018 20:37:39 -0700 From: Yu Chen To: Len Brown Cc: Chen Yu , Rafael J Wysocki , Artem Bityutskiy , Doug Smythies , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][v4] tools/power turbostat: if --iterations, print for specific time of iterations Date: Fri, 13 Apr 2018 11:40:47 +0800 Message-Id: <20180413034047.1240-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 iterations if --iterations is specified, for example, with this patch applied: turbostat -i 5 -I 4 will capture 4 samples with 5 seconds interval. Cc: Len Brown Cc: Rafael J Wysocki Cc: Artem Bityutskiy Cc: Doug Smythies Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Chen Yu --- tools/power/x86/turbostat/turbostat.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index bd9c6b31a504..a2fe96f038f0 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 count Number of measurement iterations(requires '--interval'\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 done_iters = 0; restart: restarted++; @@ -2581,6 +2584,7 @@ void turbostat_loop() goto restart; } restarted = 0; + done_iters = 0; gettimeofday(&tv_even, (struct timezone *)NULL); while (1) { @@ -2607,6 +2611,10 @@ void turbostat_loop() compute_average(EVEN_COUNTERS); format_all_counters(EVEN_COUNTERS); flush_output_stdout(); + + if (iterations && (++done_iters >= 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 && (++done_iters >= 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, 'I'}, {"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:i:JM:m:o:qST:v", long_options, &option_index)) != -1) { switch (opt) { case 'a': @@ -5036,6 +5048,15 @@ void cmdline(int argc, char **argv) default: help(); exit(1); + case 'I': + iterations = strtod(optarg, NULL); + + if (iterations <= 0) { + fprintf(outf, "iterations %d should be positive number\n", + iterations); + exit(2); + } + break; case 'i': { double interval = strtod(optarg, NULL); -- 2.13.6