Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp70116imm; Wed, 5 Sep 2018 15:09:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZw02zjODfq5UV1mIUiGqFDuMUAp2qzKnjfSHf+zFggpyPn1TvcpoJ5o9WCvQ73fgcjsEgu X-Received: by 2002:a63:524e:: with SMTP id s14-v6mr38081062pgl.35.1536185393769; Wed, 05 Sep 2018 15:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536185393; cv=none; d=google.com; s=arc-20160816; b=weYmmcKBxzbCKnPX98ln/J68mkUheXA8mel8rxt4MUf85Fv6FtKRuvd6JmEWUmdq5v Sd9QWdaoe18kOPLsXdgFk3O+DvYQQQknYi9dRKX7lwNf6tn1kovudZ4a+1PVDSZH8pJx lpcI9xycZIs6bVJiR0+rGA/l5q9mOKgPQOSGJR4B6J6kLUOg9VUF2br6HIgF5ZErB9A5 Zdf+YkISU6PrS+ecDzIk6LY0gTbilarzWSamu25f5ZqDNbsUeUyjwBH5vW+/OthdML/u a+If+UxuKwMHx8MS2c4lUsa5gsgykhKr/zlgHvnKS7Glmr9U7DbR9wtglKx2CzTuM1Go irTg== 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; bh=Ikf5z0Pun2sPsfeia3JFUfi/jYugevXhzCoYIbee4xg=; b=OrKgMiYy5v0hrp88E1DZ7zo9Z/0gOUW6gHHN1ib46fYD3aFR1CNGZnXOdao4PfUBZi O2UfXCIbSZJtCCJnhVbqSmU5RSsMgr2WiQHs0u3fHa2EPHM7bQE4XAvhR+PnafiFRre9 C0cCN3ulBnLofZTeVFksHqiQNHwTLaXLjMf9rrRgpOjZMIPsxh5C4OleLq+pMqmDlUwA 12cLLk2h/Zi8VcYHB5KTB+HXP2FA/vYGal4o/dCZZHMvX+TFvarzgbilqVhHin3cna39 Yeek5+IR83yqcGa1YjtJM8DOGVj5is/Fy1k5orDQDVKD28duytXB234ixx3RUvoV/gCG xveg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rGloEJrp; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15-v6si3359039pgl.321.2018.09.05.15.09.38; Wed, 05 Sep 2018 15:09:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=rGloEJrp; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728826AbeIFCj1 (ORCPT + 99 others); Wed, 5 Sep 2018 22:39:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:54236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727593AbeIFCj0 (ORCPT ); Wed, 5 Sep 2018 22:39:26 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 85F2820839; Wed, 5 Sep 2018 22:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1536185234; bh=caGea0ilusLwd0Ig8CVaTWwS0CY8uL+vmfwNny2hkZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rGloEJrp5bd3MXYnJEincR1kbCDqM41cJIyh5YCt7Yl3tBWhwueAiDxe+0CGvFHUE JUovyGVmRGKcQaKz9gIx1oS4/FFQc4JUe6Tjb2CgxUY0Xuu4ex8tHUgXwRoezXW0YJ kd6uW+d0sJq4bCHisHdS0wWqdQeruUjxWy0RISTA= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Jiri Olsa , Alexander Shishkin , Andi Kleen , David Ahern , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 52/77] perf stat: Move 'run_count' to 'struct perf_stat_config' Date: Wed, 5 Sep 2018 19:04:15 -0300 Message-Id: <20180905220440.20256-53-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180905220440.20256-1-acme@kernel.org> References: <20180905220440.20256-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Olsa Move the static 'run_count' variable to 'struct perf_stat_config', so that it can be passed around and used outside the 'perf stat' command. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20180830063252.23729-28-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 39 ++++++++++++++++++++------------------- tools/perf/util/stat.h | 1 + 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 11741f3a8342..1276596840c9 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -147,7 +147,6 @@ typedef int (*aggr_get_id_t)(struct cpu_map *m, int cpu); #define METRIC_ONLY_LEN 20 -static int run_count = 1; static volatile pid_t child_pid = -1; static bool null_run = false; static int detailed_run = 0; @@ -200,6 +199,7 @@ static struct perf_stat_config stat_config = { .aggr_mode = AGGR_GLOBAL, .scale = true, .unit_width = 4, /* strlen("unit") */ + .run_count = 1, }; static bool is_duration_time(struct perf_evsel *evsel) @@ -686,7 +686,7 @@ static void print_noise(struct perf_stat_config *config, { struct perf_stat_evsel *ps; - if (run_count == 1) + if (config->run_count == 1) return; ps = evsel->stats; @@ -1620,8 +1620,8 @@ static void print_header(struct perf_stat_config *config, fprintf(output, "thread id \'%s", _target->tid); fprintf(output, "\'"); - if (run_count > 1) - fprintf(output, " (%d runs)", run_count); + if (config->run_count > 1) + fprintf(output, " (%d runs)", config->run_count); fprintf(output, ":\n\n"); } } @@ -1634,7 +1634,8 @@ static int get_precision(double num) return lround(ceil(-log10(num))); } -static void print_table(FILE *output, int precision, double avg) +static void print_table(struct perf_stat_config *config, + FILE *output, int precision, double avg) { char tmp[64]; int idx, indent = 0; @@ -1645,7 +1646,7 @@ static void print_table(FILE *output, int precision, double avg) fprintf(output, "%*s# Table of individual measurements:\n", indent, ""); - for (idx = 0; idx < run_count; idx++) { + for (idx = 0; idx < config->run_count; idx++) { double run = (double) walltime_run[idx] / NSEC_PER_SEC; int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5); @@ -1675,7 +1676,7 @@ static void print_footer(struct perf_stat_config *config) if (!null_run) fprintf(output, "\n"); - if (run_count == 1) { + if (config->run_count == 1) { fprintf(output, " %17.9f seconds time elapsed", avg); if (ru_display) { @@ -1695,7 +1696,7 @@ static void print_footer(struct perf_stat_config *config) int precision = get_precision(sd) + 2; if (walltime_run_table) - print_table(output, precision, avg); + print_table(config, output, precision, avg); fprintf(output, " %17.*f +- %.*f seconds time elapsed", precision, avg, precision, sd); @@ -1886,7 +1887,7 @@ static const struct option stat_options[] = { OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"), - OPT_INTEGER('r', "repeat", &run_count, + OPT_INTEGER('r', "repeat", &stat_config.run_count, "repeat command and print average + stddev (max: 100, forever: 0)"), OPT_BOOLEAN(0, "table", &walltime_run_table, "display details about each run (only with -r option)"), @@ -2484,7 +2485,7 @@ static int __cmd_record(int argc, const char **argv) if (output_name) data->file.path = output_name; - if (run_count != 1 || forever) { + if (stat_config.run_count != 1 || forever) { pr_err("Cannot use -r option with perf stat record.\n"); return -1; } @@ -2792,12 +2793,12 @@ int cmd_stat(int argc, const char **argv) goto out; } - if (stat_config.metric_only && run_count > 1) { + if (stat_config.metric_only && stat_config.run_count > 1) { fprintf(stderr, "--metric-only is not supported with -r\n"); goto out; } - if (walltime_run_table && run_count <= 1) { + if (walltime_run_table && stat_config.run_count <= 1) { fprintf(stderr, "--table is only supported with -r\n"); parse_options_usage(stat_usage, stat_options, "r", 1); parse_options_usage(NULL, stat_options, "table", 0); @@ -2853,20 +2854,20 @@ int cmd_stat(int argc, const char **argv) * Display user/system times only for single * run and when there's specified tracee. */ - if ((run_count == 1) && target__none(&target)) + if ((stat_config.run_count == 1) && target__none(&target)) ru_display = true; - if (run_count < 0) { + if (stat_config.run_count < 0) { pr_err("Run count must be a positive number\n"); parse_options_usage(stat_usage, stat_options, "r", 1); goto out; - } else if (run_count == 0) { + } else if (stat_config.run_count == 0) { forever = true; - run_count = 1; + stat_config.run_count = 1; } if (walltime_run_table) { - walltime_run = zalloc(run_count * sizeof(walltime_run[0])); + walltime_run = zalloc(stat_config.run_count * sizeof(walltime_run[0])); if (!walltime_run) { pr_err("failed to setup -r option"); goto out; @@ -2994,8 +2995,8 @@ int cmd_stat(int argc, const char **argv) signal(SIGABRT, skip_signal); status = 0; - for (run_idx = 0; forever || run_idx < run_count; run_idx++) { - if (run_count != 1 && verbose > 0) + for (run_idx = 0; forever || run_idx < stat_config.run_count; run_idx++) { + if (stat_config.run_count != 1 && verbose > 0) fprintf(output, "[ perf stat: executing run #%d ... ]\n", run_idx + 1); diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 2dc66e0ba4b8..351a36f5f5b0 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -100,6 +100,7 @@ struct perf_stat_config { unsigned int initial_delay; unsigned int unit_width; int times; + int run_count; struct runtime_stat *stats; int stats_num; const char *csv_sep; -- 2.14.4