aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-top.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-top.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-top.c')
-rw-r--r--tools/perf/builtin-top.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 0e426665716d..1e67ab9c7ebc 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -68,8 +68,7 @@ static int print_entries;
68 68
69static int target_pid = -1; 69static int target_pid = -1;
70static int target_tid = -1; 70static int target_tid = -1;
71static pid_t *all_tids = NULL; 71static struct thread_map *threads;
72static int thread_num = 0;
73static bool inherit = false; 72static bool inherit = false;
74static struct cpu_map *cpus; 73static struct cpu_map *cpus;
75static int realtime_prio = 0; 74static int realtime_prio = 0;
@@ -1200,7 +1199,7 @@ static void perf_session__mmap_read(struct perf_session *self)
1200 for (i = 0; i < cpus->nr; i++) { 1199 for (i = 0; i < cpus->nr; i++) {
1201 list_for_each_entry(counter, &evsel_list, node) { 1200 list_for_each_entry(counter, &evsel_list, node) {
1202 for (thread_index = 0; 1201 for (thread_index = 0;
1203 thread_index < thread_num; 1202 thread_index < threads->nr;
1204 thread_index++) { 1203 thread_index++) {
1205 perf_session__mmap_read_counter(self, 1204 perf_session__mmap_read_counter(self,
1206 counter, i, thread_index); 1205 counter, i, thread_index);
@@ -1236,10 +1235,10 @@ static void start_counter(int i, struct perf_evsel *evsel)
1236 attr->inherit = (cpu < 0) && inherit; 1235 attr->inherit = (cpu < 0) && inherit;
1237 attr->mmap = 1; 1236 attr->mmap = 1;
1238 1237
1239 for (thread_index = 0; thread_index < thread_num; thread_index++) { 1238 for (thread_index = 0; thread_index < threads->nr; thread_index++) {
1240try_again: 1239try_again:
1241 FD(evsel, i, thread_index) = sys_perf_event_open(attr, 1240 FD(evsel, i, thread_index) = sys_perf_event_open(attr,
1242 all_tids[thread_index], cpu, group_fd, 0); 1241 threads->map[thread_index], cpu, group_fd, 0);
1243 1242
1244 if (FD(evsel, i, thread_index) < 0) { 1243 if (FD(evsel, i, thread_index) < 0) {
1245 int err = errno; 1244 int err = errno;
@@ -1410,25 +1409,17 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
1410 if (argc) 1409 if (argc)
1411 usage_with_options(top_usage, options); 1410 usage_with_options(top_usage, options);
1412 1411
1413 if (target_pid != -1) { 1412 if (target_pid != -1)
1414 target_tid = target_pid; 1413 target_tid = target_pid;
1415 thread_num = find_all_tid(target_pid, &all_tids);
1416 if (thread_num <= 0) {
1417 fprintf(stderr, "Can't find all threads of pid %d\n",
1418 target_pid);
1419 usage_with_options(top_usage, options);
1420 }
1421 } else {
1422 all_tids=malloc(sizeof(pid_t));
1423 if (!all_tids)
1424 return -ENOMEM;
1425 1414
1426 all_tids[0] = target_tid; 1415 threads = thread_map__new(target_pid, target_tid);
1427 thread_num = 1; 1416 if (threads == NULL) {
1417 pr_err("Problems finding threads of monitor\n");
1418 usage_with_options(top_usage, options);
1428 } 1419 }
1429 1420
1430 event_array = malloc( 1421 event_array = malloc((sizeof(struct pollfd) *
1431 sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); 1422 MAX_NR_CPUS * MAX_COUNTERS * threads->nr));
1432 if (!event_array) 1423 if (!event_array)
1433 return -ENOMEM; 1424 return -ENOMEM;
1434 1425
@@ -1468,8 +1459,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
1468 usage_with_options(top_usage, options); 1459 usage_with_options(top_usage, options);
1469 1460
1470 list_for_each_entry(pos, &evsel_list, node) { 1461 list_for_each_entry(pos, &evsel_list, node) {
1471 if (perf_evsel__alloc_mmap_per_thread(pos, cpus->nr, thread_num) < 0 || 1462 if (perf_evsel__alloc_mmap_per_thread(pos, cpus->nr, threads->nr) < 0 ||
1472 perf_evsel__alloc_fd(pos, cpus->nr, thread_num) < 0) 1463 perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0)
1473 goto out_free_fd; 1464 goto out_free_fd;
1474 /* 1465 /*
1475 * Fill in the ones not specifically initialized via -c: 1466 * Fill in the ones not specifically initialized via -c: