aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-stat.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-01-11 17:56:53 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-01-22 16:56:28 -0500
commit361c99a661a78ed22264649440e87fe4fe8da1f2 (patch)
treea60bc86f132608f2d41c800760b41f6f54f8e7af /tools/perf/builtin-stat.c
parent00e99a49f6f3a6b5a84ba8bf8f632c9b974bea7a (diff)
perf evsel: Introduce perf_evlist
Killing two more perf wide global variables: nr_counters and evsel_list as a list_head. There are more operations that will need more fields in perf_evlist, like the pollfd for polling all the fds in a list of evsel instances. Use option->value to pass the evsel_list to parse_{events,filters}. LKML-Reference: <new-submission> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r--tools/perf/builtin-stat.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index a482a191a0ca..da9090245934 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -43,6 +43,7 @@
43#include "util/parse-options.h" 43#include "util/parse-options.h"
44#include "util/parse-events.h" 44#include "util/parse-events.h"
45#include "util/event.h" 45#include "util/event.h"
46#include "util/evlist.h"
46#include "util/evsel.h" 47#include "util/evsel.h"
47#include "util/debug.h" 48#include "util/debug.h"
48#include "util/header.h" 49#include "util/header.h"
@@ -71,6 +72,8 @@ static struct perf_event_attr default_attrs[] = {
71 72
72}; 73};
73 74
75struct perf_evlist *evsel_list;
76
74static bool system_wide = false; 77static bool system_wide = false;
75static struct cpu_map *cpus; 78static struct cpu_map *cpus;
76static int run_idx = 0; 79static int run_idx = 0;
@@ -309,7 +312,7 @@ static int run_perf_stat(int argc __used, const char **argv)
309 close(child_ready_pipe[0]); 312 close(child_ready_pipe[0]);
310 } 313 }
311 314
312 list_for_each_entry(counter, &evsel_list, node) { 315 list_for_each_entry(counter, &evsel_list->entries, node) {
313 if (create_perf_stat_counter(counter) < 0) { 316 if (create_perf_stat_counter(counter) < 0) {
314 if (errno == -EPERM || errno == -EACCES) { 317 if (errno == -EPERM || errno == -EACCES) {
315 error("You may not have permission to collect %sstats.\n" 318 error("You may not have permission to collect %sstats.\n"
@@ -347,12 +350,12 @@ static int run_perf_stat(int argc __used, const char **argv)
347 update_stats(&walltime_nsecs_stats, t1 - t0); 350 update_stats(&walltime_nsecs_stats, t1 - t0);
348 351
349 if (no_aggr) { 352 if (no_aggr) {
350 list_for_each_entry(counter, &evsel_list, node) { 353 list_for_each_entry(counter, &evsel_list->entries, node) {
351 read_counter(counter); 354 read_counter(counter);
352 perf_evsel__close_fd(counter, cpus->nr, 1); 355 perf_evsel__close_fd(counter, cpus->nr, 1);
353 } 356 }
354 } else { 357 } else {
355 list_for_each_entry(counter, &evsel_list, node) { 358 list_for_each_entry(counter, &evsel_list->entries, node) {
356 read_counter_aggr(counter); 359 read_counter_aggr(counter);
357 perf_evsel__close_fd(counter, cpus->nr, threads->nr); 360 perf_evsel__close_fd(counter, cpus->nr, threads->nr);
358 } 361 }
@@ -555,10 +558,10 @@ static void print_stat(int argc, const char **argv)
555 } 558 }
556 559
557 if (no_aggr) { 560 if (no_aggr) {
558 list_for_each_entry(counter, &evsel_list, node) 561 list_for_each_entry(counter, &evsel_list->entries, node)
559 print_counter(counter); 562 print_counter(counter);
560 } else { 563 } else {
561 list_for_each_entry(counter, &evsel_list, node) 564 list_for_each_entry(counter, &evsel_list->entries, node)
562 print_counter_aggr(counter); 565 print_counter_aggr(counter);
563 } 566 }
564 567
@@ -610,7 +613,7 @@ static int stat__set_big_num(const struct option *opt __used,
610} 613}
611 614
612static const struct option options[] = { 615static const struct option options[] = {
613 OPT_CALLBACK('e', "event", NULL, "event", 616 OPT_CALLBACK('e', "event", &evsel_list, "event",
614 "event selector. use 'perf list' to list available events", 617 "event selector. use 'perf list' to list available events",
615 parse_events), 618 parse_events),
616 OPT_BOOLEAN('i', "no-inherit", &no_inherit, 619 OPT_BOOLEAN('i', "no-inherit", &no_inherit,
@@ -648,6 +651,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
648 651
649 setlocale(LC_ALL, ""); 652 setlocale(LC_ALL, "");
650 653
654 evsel_list = perf_evlist__new();
655 if (evsel_list == NULL)
656 return -ENOMEM;
657
651 argc = parse_options(argc, argv, options, stat_usage, 658 argc = parse_options(argc, argv, options, stat_usage,
652 PARSE_OPT_STOP_AT_NON_OPTION); 659 PARSE_OPT_STOP_AT_NON_OPTION);
653 660
@@ -679,17 +686,14 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
679 usage_with_options(stat_usage, options); 686 usage_with_options(stat_usage, options);
680 687
681 /* Set attrs and nr_counters if no event is selected and !null_run */ 688 /* Set attrs and nr_counters if no event is selected and !null_run */
682 if (!null_run && !nr_counters) { 689 if (!null_run && !evsel_list->nr_entries) {
683 size_t c; 690 size_t c;
684 691
685 nr_counters = ARRAY_SIZE(default_attrs);
686
687 for (c = 0; c < ARRAY_SIZE(default_attrs); ++c) { 692 for (c = 0; c < ARRAY_SIZE(default_attrs); ++c) {
688 pos = perf_evsel__new(&default_attrs[c], 693 pos = perf_evsel__new(&default_attrs[c], c);
689 nr_counters);
690 if (pos == NULL) 694 if (pos == NULL)
691 goto out; 695 goto out;
692 list_add(&pos->node, &evsel_list); 696 perf_evlist__add(evsel_list, pos);
693 } 697 }
694 } 698 }
695 699
@@ -713,7 +717,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
713 return -1; 717 return -1;
714 } 718 }
715 719
716 list_for_each_entry(pos, &evsel_list, node) { 720 list_for_each_entry(pos, &evsel_list->entries, node) {
717 if (perf_evsel__alloc_stat_priv(pos) < 0 || 721 if (perf_evsel__alloc_stat_priv(pos) < 0 ||
718 perf_evsel__alloc_counts(pos, cpus->nr) < 0 || 722 perf_evsel__alloc_counts(pos, cpus->nr) < 0 ||
719 perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0) 723 perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0)
@@ -741,9 +745,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
741 if (status != -1) 745 if (status != -1)
742 print_stat(argc, argv); 746 print_stat(argc, argv);
743out_free_fd: 747out_free_fd:
744 list_for_each_entry(pos, &evsel_list, node) 748 list_for_each_entry(pos, &evsel_list->entries, node)
745 perf_evsel__free_stat_priv(pos); 749 perf_evsel__free_stat_priv(pos);
746 perf_evsel_list__delete(); 750 perf_evlist__delete(evsel_list);
747out: 751out:
748 thread_map__delete(threads); 752 thread_map__delete(threads);
749 threads = NULL; 753 threads = NULL;