From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Frederik Deweerdt <frederik.deweerdt@xprog.eu>,
Frederik Deweerdt <frederik.deweerdt@gmail.com>,
Ingo Molnar <mingo@redhat.com>, Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 52/54] perf stat: Introduce --repeat forever
Date: Mon, 18 Mar 2013 13:25:37 -0300 [thread overview]
Message-ID: <1363623939-10748-53-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1363623939-10748-1-git-send-email-acme@infradead.org>
From: Frederik Deweerdt <frederik.deweerdt@xprog.eu>
The following patch causes 'perf stat --repeat 0' to be interpreted as
'forever', displaying the stats for every run.
We act as if a single run was asked, and reset the stats in each
iteration. In this mode SIGINT is passed to perf to be able to stop the
loop with Ctrl+C.
Signed-off-by: Frederik Deweerdt <frederik.deweerdt@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20130301180227.GA24385@ks398093.ip-192-95-24.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-stat.txt | 2 +-
tools/perf/builtin-stat.c | 45 ++++++++++++++++++++++++++++---
tools/perf/util/evsel.c | 6 ++++
tools/perf/util/evsel.h | 1 +
4 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index faf4f4f..23e587a 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -52,7 +52,7 @@ OPTIONS
-r::
--repeat=<n>::
- repeat command and print average + stddev (max: 100)
+ repeat command and print average + stddev (max: 100). 0 means forever.
-B::
--big-num::
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 69fe6ed..021783a 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -94,6 +94,7 @@ static const char *pre_cmd = NULL;
static const char *post_cmd = NULL;
static bool sync_run = false;
static unsigned int interval = 0;
+static bool forever = false;
static struct timespec ref_time;
static struct cpu_map *sock_map;
@@ -125,6 +126,11 @@ static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel)
return perf_evsel__cpus(evsel)->nr;
}
+static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
+{
+ memset(evsel->priv, 0, sizeof(struct perf_stat));
+}
+
static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
{
evsel->priv = zalloc(sizeof(struct perf_stat));
@@ -173,6 +179,22 @@ static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];
static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS];
static struct stats walltime_nsecs_stats;
+static void reset_stats(void)
+{
+ memset(runtime_nsecs_stats, 0, sizeof(runtime_nsecs_stats));
+ memset(runtime_cycles_stats, 0, sizeof(runtime_cycles_stats));
+ memset(runtime_stalled_cycles_front_stats, 0, sizeof(runtime_stalled_cycles_front_stats));
+ memset(runtime_stalled_cycles_back_stats, 0, sizeof(runtime_stalled_cycles_back_stats));
+ memset(runtime_branches_stats, 0, sizeof(runtime_branches_stats));
+ memset(runtime_cacherefs_stats, 0, sizeof(runtime_cacherefs_stats));
+ memset(runtime_l1_dcache_stats, 0, sizeof(runtime_l1_dcache_stats));
+ memset(runtime_l1_icache_stats, 0, sizeof(runtime_l1_icache_stats));
+ memset(runtime_ll_cache_stats, 0, sizeof(runtime_ll_cache_stats));
+ memset(runtime_itlb_cache_stats, 0, sizeof(runtime_itlb_cache_stats));
+ memset(runtime_dtlb_cache_stats, 0, sizeof(runtime_dtlb_cache_stats));
+ memset(&walltime_nsecs_stats, 0, sizeof(walltime_nsecs_stats));
+}
+
static int create_perf_stat_counter(struct perf_evsel *evsel)
{
struct perf_event_attr *attr = &evsel->attr;
@@ -1252,7 +1274,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show counter open errors, etc)"),
OPT_INTEGER('r', "repeat", &run_count,
- "repeat command and print average + stddev (max: 100)"),
+ "repeat command and print average + stddev (max: 100, forever: 0)"),
OPT_BOOLEAN('n', "null", &null_run,
"null run - dont start any counters"),
OPT_INCR('d', "detailed", &detailed_run,
@@ -1355,8 +1377,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
if (!argc && !perf_target__has_task(&target))
usage_with_options(stat_usage, options);
- if (run_count <= 0)
+ if (run_count < 0) {
usage_with_options(stat_usage, options);
+ } else if (run_count == 0) {
+ forever = true;
+ run_count = 1;
+ }
/* no_aggr, cgroup are for system-wide only */
if ((no_aggr || nr_cgroups) && !perf_target__has_cpu(&target)) {
@@ -1413,21 +1439,30 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
* task, but being ignored by perf stat itself:
*/
atexit(sig_atexit);
- signal(SIGINT, skip_signal);
+ if (!forever)
+ signal(SIGINT, skip_signal);
signal(SIGCHLD, skip_signal);
signal(SIGALRM, skip_signal);
signal(SIGABRT, skip_signal);
status = 0;
- for (run_idx = 0; run_idx < run_count; run_idx++) {
+ for (run_idx = 0; forever || run_idx < run_count; run_idx++) {
if (run_count != 1 && verbose)
fprintf(output, "[ perf stat: executing run #%d ... ]\n",
run_idx + 1);
status = run_perf_stat(argc, argv);
+ if (forever && status != -1) {
+ print_stat(argc, argv);
+ list_for_each_entry(pos, &evsel_list->entries, node) {
+ perf_evsel__reset_stat_priv(pos);
+ perf_evsel__reset_counts(pos, perf_evsel__nr_cpus(pos));
+ }
+ reset_stats();
+ }
}
- if (status != -1 && !interval)
+ if (!forever && status != -1 && !interval)
print_stat(argc, argv);
out_free_fd:
list_for_each_entry(pos, &evsel_list->entries, node) {
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 7fde9fb..1adb824 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -633,6 +633,12 @@ int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
return 0;
}
+void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus)
+{
+ memset(evsel->counts, 0, (sizeof(*evsel->counts) +
+ (ncpus * sizeof(struct perf_counts_values))));
+}
+
int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus)
{
evsel->counts = zalloc((sizeof(*evsel->counts) +
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index bf758e5..3f156cc 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -121,6 +121,7 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
+void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
void perf_evsel__free_fd(struct perf_evsel *evsel);
void perf_evsel__free_id(struct perf_evsel *evsel);
void perf_evsel__free_counts(struct perf_evsel *evsel);
--
1.7.1
next prev parent reply other threads:[~2013-03-18 16:32 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-18 16:24 [GIT PULL 00/54] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 01/54] perf tools: Fix build on non-glibc systems due to libio.h absence Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 02/54] perf tools: Remove a write-only variable in the debugfs code Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 03/54] perf tools: Honor parallel jobs Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 04/54] perf tools: Correct Makefile.include Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 05/54] perf tools: Sort command-list.txt alphabetically Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 06/54] perf tests: Make attr script verbose friendly Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 07/54] perf tests: Make attr script test event cpu Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 08/54] perf tests: Add attr record -C cpu test Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 09/54] perf tests: Add attr stat " Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 10/54] perf tools: Introduce tools/lib/lk library Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 11/54] perf tools: Extract perf-specific stuff from debugfs.c Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 12/54] tools/vm: Switch to liblk library Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 13/54] tools lib lk: Fix _FORTIFY_SOURCE builds Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 14/54] perf evlist: Remove cpus and threads arguments from perf_evlist__new() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 15/54] perf evlist: Use cpu_map__nr() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 16/54] perf evlist: Add thread_map__nr() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 17/54] perf evlist: Pass struct perf_target to perf_evlist__prepare_workload() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 18/54] perf evlist: Do not pass struct record_opts " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 19/54] perf evlist: Add want_signal parameter " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 20/54] perf stat: Use perf_evlist__prepare/start_workload() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 21/54] perf annotate: Pass evsel instead of evidx on annotation functions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 22/54] perf annotate: Add a comment on the symbol__parse_objdump_line() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 23/54] perf annotate: Factor out disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 24/54] perf annotate: Cleanup disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 25/54] perf annotate: Add basic support to event group view Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 26/54] perf evsel: Introduce perf_evsel__is_group_event() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 27/54] perf annotate: Factor out struct source_line_percent Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 28/54] perf annotate: Support event group view for --print-line Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 29/54] perf annotate browser: Make browser_disasm_line->percent an array Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 30/54] perf annotate browser: Use disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 31/54] perf annotate/gtk: Support event group view on GTK Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 32/54] perf annotate browser: Support event group view on TUI Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 33/54] perf trace: Get rid of a duplicate code Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 34/54] perf tools: Remove unused tracing functions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 35/54] perf session: Remove unused perf_session__remove_thread method Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 36/54] perf machine: Move machine__remove_thread and make static Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 37/54] perf report: Remove duplicated include Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 38/54] perf tools: Remove unused trace_read_data function Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 39/54] perf tools: Remove unused struct definitions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 40/54] perf tools: Remove unnecessary calc_data_size variable Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 41/54] perf tools: Remove unused macro definitions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 42/54] perf tools: Remove duplicated page_size definition Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 43/54] perf tests: Test breakpoint overflow signal handler Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 44/54] perf tests: Test breakpoint overflow signal handler counts Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 45/54] perf evsel: Cleanup perf_evsel__exit() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 46/54] perf evlist: Introduce perf_evlist__close() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 47/54] perf trace: Free evlist resources properly on return path Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 48/54] perf record: Fixup return path of cmd_record() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 49/54] perf tests: Fixup return path of open-syscall-tp-fields test case Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 50/54] perf tests: Fixup return path of perf record " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 51/54] perf test: Add test case for checking number of EXIT events Arnaldo Carvalho de Melo
2013-03-18 16:25 ` Arnaldo Carvalho de Melo [this message]
2013-03-18 16:25 ` [PATCH 53/54] perf stat: Introduce evlist methods to allocate/free the stats Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 54/54] perf tests: Add a test case for checking sw clock event frequency Arnaldo Carvalho de Melo
2013-03-21 10:08 ` [GIT PULL 00/54] perf/core improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1363623939-10748-53-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=frederik.deweerdt@gmail.com \
--cc=frederik.deweerdt@xprog.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®