aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-stat.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-01-03 14:53:33 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-01-03 21:24:16 -0500
commit5c98d466e49267a9221f30958d45cd06f794269a (patch)
tree0085e9391dc68d00b8260d9d36e8b0d1baf66098 /tools/perf/builtin-stat.c
parent60d567e2d9187379d642f6aba7c8a52b3fd5d261 (diff)
perf tools: Refactor all_tids to hold nr and the map
So that later, we can pass the thread_map instance instead of (thread_num, thread_map) for things like perf_evsel__open and friends, just like was done with cpu_map. 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> LKML-Reference: <new-submission> 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.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3f4a431fb5a4..6b9146cd1ea9 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -81,8 +81,7 @@ static bool scale = true;
81static bool no_aggr = false; 81static bool no_aggr = false;
82static pid_t target_pid = -1; 82static pid_t target_pid = -1;
83static pid_t target_tid = -1; 83static pid_t target_tid = -1;
84static pid_t *all_tids = NULL; 84static struct thread_map *threads;
85static int thread_num = 0;
86static pid_t child_pid = -1; 85static pid_t child_pid = -1;
87static bool null_run = false; 86static bool null_run = false;
88static bool big_num = true; 87static bool big_num = true;
@@ -175,7 +174,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
175 attr->enable_on_exec = 1; 174 attr->enable_on_exec = 1;
176 } 175 }
177 176
178 return perf_evsel__open_per_thread(evsel, thread_num, all_tids); 177 return perf_evsel__open_per_thread(evsel, threads->nr, threads->map);
179} 178}
180 179
181/* 180/*
@@ -200,7 +199,7 @@ static int read_counter_aggr(struct perf_evsel *counter)
200 u64 *count = counter->counts->aggr.values; 199 u64 *count = counter->counts->aggr.values;
201 int i; 200 int i;
202 201
203 if (__perf_evsel__read(counter, cpus->nr, thread_num, scale) < 0) 202 if (__perf_evsel__read(counter, cpus->nr, threads->nr, scale) < 0)
204 return -1; 203 return -1;
205 204
206 for (i = 0; i < 3; i++) 205 for (i = 0; i < 3; i++)
@@ -298,7 +297,7 @@ static int run_perf_stat(int argc __used, const char **argv)
298 } 297 }
299 298
300 if (target_tid == -1 && target_pid == -1 && !system_wide) 299 if (target_tid == -1 && target_pid == -1 && !system_wide)
301 all_tids[0] = child_pid; 300 threads->map[0] = child_pid;
302 301
303 /* 302 /*
304 * Wait for the child to be ready to exec. 303 * Wait for the child to be ready to exec.
@@ -353,7 +352,7 @@ static int run_perf_stat(int argc __used, const char **argv)
353 } else { 352 } else {
354 list_for_each_entry(counter, &evsel_list, node) { 353 list_for_each_entry(counter, &evsel_list, node) {
355 read_counter_aggr(counter); 354 read_counter_aggr(counter);
356 perf_evsel__close_fd(counter, cpus->nr, thread_num); 355 perf_evsel__close_fd(counter, cpus->nr, threads->nr);
357 } 356 }
358 } 357 }
359 358
@@ -693,6 +692,15 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
693 } 692 }
694 } 693 }
695 694
695 if (target_pid != -1)
696 target_tid = target_pid;
697
698 threads = thread_map__new(target_pid, target_tid);
699 if (threads == NULL) {
700 pr_err("Problems finding threads of monitor\n");
701 usage_with_options(stat_usage, options);
702 }
703
696 if (system_wide) 704 if (system_wide)
697 cpus = cpu_map__new(cpu_list); 705 cpus = cpu_map__new(cpu_list);
698 else 706 else
@@ -704,27 +712,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
704 return -1; 712 return -1;
705 } 713 }
706 714
707 if (target_pid != -1) {
708 target_tid = target_pid;
709 thread_num = find_all_tid(target_pid, &all_tids);
710 if (thread_num <= 0) {
711 fprintf(stderr, "Can't find all threads of pid %d\n",
712 target_pid);
713 usage_with_options(stat_usage, options);
714 }
715 } else {
716 all_tids=malloc(sizeof(pid_t));
717 if (!all_tids)
718 return -ENOMEM;
719
720 all_tids[0] = target_tid;
721 thread_num = 1;
722 }
723
724 list_for_each_entry(pos, &evsel_list, node) { 715 list_for_each_entry(pos, &evsel_list, node) {
725 if (perf_evsel__alloc_stat_priv(pos) < 0 || 716 if (perf_evsel__alloc_stat_priv(pos) < 0 ||
726 perf_evsel__alloc_counts(pos, cpus->nr) < 0 || 717 perf_evsel__alloc_counts(pos, cpus->nr) < 0 ||
727 perf_evsel__alloc_fd(pos, cpus->nr, thread_num) < 0) 718 perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0)
728 goto out_free_fd; 719 goto out_free_fd;
729 } 720 }
730 721
@@ -752,5 +743,7 @@ out_free_fd:
752 list_for_each_entry(pos, &evsel_list, node) 743 list_for_each_entry(pos, &evsel_list, node)
753 perf_evsel__free_stat_priv(pos); 744 perf_evsel__free_stat_priv(pos);
754out: 745out:
746 thread_map__delete(threads);
747 threads = NULL;
755 return status; 748 return status;
756} 749}