aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2013-03-18 10:24:21 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-03-18 10:34:09 -0400
commitd134ffb919ab142b2359ae45a0cf4a5bfa1ff283 (patch)
tree1f9268d69ec3b43294b782e7a7521bc06fc14001 /tools/perf
parenta7e191c376fad084d9f3c7ac89a1f7c47462ebc8 (diff)
perf stat: Introduce evlist methods to allocate/free the stats
Reducing the noise in the main logic. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-o219lnci04hlilxi6711wtcr@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-stat.c67
1 files changed, 43 insertions, 24 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 021783ae2bfa..ba0bdd87c279 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -166,6 +166,35 @@ static void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
166 evsel->prev_raw_counts = NULL; 166 evsel->prev_raw_counts = NULL;
167} 167}
168 168
169static void perf_evlist__free_stats(struct perf_evlist *evlist)
170{
171 struct perf_evsel *evsel;
172
173 list_for_each_entry(evsel, &evlist->entries, node) {
174 perf_evsel__free_stat_priv(evsel);
175 perf_evsel__free_counts(evsel);
176 perf_evsel__free_prev_raw_counts(evsel);
177 }
178}
179
180static int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw)
181{
182 struct perf_evsel *evsel;
183
184 list_for_each_entry(evsel, &evlist->entries, node) {
185 if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
186 perf_evsel__alloc_counts(evsel, perf_evsel__nr_cpus(evsel)) < 0 ||
187 (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel) < 0))
188 goto out_free;
189 }
190
191 return 0;
192
193out_free:
194 perf_evlist__free_stats(evlist);
195 return -1;
196}
197
169static struct stats runtime_nsecs_stats[MAX_NR_CPUS]; 198static struct stats runtime_nsecs_stats[MAX_NR_CPUS];
170static struct stats runtime_cycles_stats[MAX_NR_CPUS]; 199static struct stats runtime_cycles_stats[MAX_NR_CPUS];
171static struct stats runtime_stalled_cycles_front_stats[MAX_NR_CPUS]; 200static struct stats runtime_stalled_cycles_front_stats[MAX_NR_CPUS];
@@ -179,8 +208,15 @@ static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];
179static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS]; 208static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS];
180static struct stats walltime_nsecs_stats; 209static struct stats walltime_nsecs_stats;
181 210
182static void reset_stats(void) 211static void perf_stat__reset_stats(struct perf_evlist *evlist)
183{ 212{
213 struct perf_evsel *evsel;
214
215 list_for_each_entry(evsel, &evlist->entries, node) {
216 perf_evsel__reset_stat_priv(evsel);
217 perf_evsel__reset_counts(evsel, perf_evsel__nr_cpus(evsel));
218 }
219
184 memset(runtime_nsecs_stats, 0, sizeof(runtime_nsecs_stats)); 220 memset(runtime_nsecs_stats, 0, sizeof(runtime_nsecs_stats));
185 memset(runtime_cycles_stats, 0, sizeof(runtime_cycles_stats)); 221 memset(runtime_cycles_stats, 0, sizeof(runtime_cycles_stats));
186 memset(runtime_stalled_cycles_front_stats, 0, sizeof(runtime_stalled_cycles_front_stats)); 222 memset(runtime_stalled_cycles_front_stats, 0, sizeof(runtime_stalled_cycles_front_stats));
@@ -1308,7 +1344,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1308 "perf stat [<options>] [<command>]", 1344 "perf stat [<options>] [<command>]",
1309 NULL 1345 NULL
1310 }; 1346 };
1311 struct perf_evsel *pos;
1312 int status = -ENOMEM, run_idx; 1347 int status = -ENOMEM, run_idx;
1313 const char *mode; 1348 const char *mode;
1314 1349
@@ -1420,17 +1455,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1420 return -1; 1455 return -1;
1421 } 1456 }
1422 1457
1423 list_for_each_entry(pos, &evsel_list->entries, node) { 1458 if (perf_evlist__alloc_stats(evsel_list, interval))
1424 if (perf_evsel__alloc_stat_priv(pos) < 0 || 1459 goto out_free_maps;
1425 perf_evsel__alloc_counts(pos, perf_evsel__nr_cpus(pos)) < 0)
1426 goto out_free_fd;
1427 }
1428 if (interval) {
1429 list_for_each_entry(pos, &evsel_list->entries, node) {
1430 if (perf_evsel__alloc_prev_raw_counts(pos) < 0)
1431 goto out_free_fd;
1432 }
1433 }
1434 1460
1435 /* 1461 /*
1436 * We dont want to block the signals - that would cause 1462 * We dont want to block the signals - that would cause
@@ -1454,22 +1480,15 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1454 status = run_perf_stat(argc, argv); 1480 status = run_perf_stat(argc, argv);
1455 if (forever && status != -1) { 1481 if (forever && status != -1) {
1456 print_stat(argc, argv); 1482 print_stat(argc, argv);
1457 list_for_each_entry(pos, &evsel_list->entries, node) { 1483 perf_stat__reset_stats(evsel_list);
1458 perf_evsel__reset_stat_priv(pos);
1459 perf_evsel__reset_counts(pos, perf_evsel__nr_cpus(pos));
1460 }
1461 reset_stats();
1462 } 1484 }
1463 } 1485 }
1464 1486
1465 if (!forever && status != -1 && !interval) 1487 if (!forever && status != -1 && !interval)
1466 print_stat(argc, argv); 1488 print_stat(argc, argv);
1467out_free_fd: 1489
1468 list_for_each_entry(pos, &evsel_list->entries, node) { 1490 perf_evlist__free_stats(evsel_list);
1469 perf_evsel__free_stat_priv(pos); 1491out_free_maps:
1470 perf_evsel__free_counts(pos);
1471 perf_evsel__free_prev_raw_counts(pos);
1472 }
1473 perf_evlist__delete_maps(evsel_list); 1492 perf_evlist__delete_maps(evsel_list);
1474out: 1493out:
1475 perf_evlist__delete(evsel_list); 1494 perf_evlist__delete(evsel_list);