diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-06-22 18:36:02 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-06-23 17:21:44 -0400 |
commit | e13798c77bdfed1da497f5e076b105b2be17b44f (patch) | |
tree | 8d68cd10b5986e5f6fcadd366ddcdcb425ee070b /tools | |
parent | 7c31bb8c95ed269062ff7c7cc4a28b84a2b0f3a6 (diff) |
perf thread_map: Don't access the array entries directly
Instead provide a method to set the array entries, and another to access
the contents.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435012588-9007-2-git-send-email-jolsa@kernel.org
[ Split providing the set/get accessors from transforming the entries structs ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-trace.c | 4 | ||||
-rw-r--r-- | tools/perf/tests/openat-syscall-tp-fields.c | 2 | ||||
-rw-r--r-- | tools/perf/util/auxtrace.c | 4 | ||||
-rw-r--r-- | tools/perf/util/event.c | 6 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 4 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 2 | ||||
-rw-r--r-- | tools/perf/util/thread_map.c | 24 | ||||
-rw-r--r-- | tools/perf/util/thread_map.h | 10 |
8 files changed, 34 insertions, 22 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index de5d277d1ad7..2bf2ca771ca5 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -2325,7 +2325,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) | |||
2325 | */ | 2325 | */ |
2326 | if (trace->filter_pids.nr > 0) | 2326 | if (trace->filter_pids.nr > 0) |
2327 | err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries); | 2327 | err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries); |
2328 | else if (evlist->threads->map[0] == -1) | 2328 | else if (thread_map__pid(evlist->threads, 0) == -1) |
2329 | err = perf_evlist__set_filter_pid(evlist, getpid()); | 2329 | err = perf_evlist__set_filter_pid(evlist, getpid()); |
2330 | 2330 | ||
2331 | if (err < 0) { | 2331 | if (err < 0) { |
@@ -2343,7 +2343,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) | |||
2343 | if (forks) | 2343 | if (forks) |
2344 | perf_evlist__start_workload(evlist); | 2344 | perf_evlist__start_workload(evlist); |
2345 | 2345 | ||
2346 | trace->multiple_threads = evlist->threads->map[0] == -1 || | 2346 | trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 || |
2347 | evlist->threads->nr > 1 || | 2347 | evlist->threads->nr > 1 || |
2348 | perf_evlist__first(evlist)->attr.inherit; | 2348 | perf_evlist__first(evlist)->attr.inherit; |
2349 | again: | 2349 | again: |
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index 6245221479d7..01a19626c846 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c | |||
@@ -45,7 +45,7 @@ int test__syscall_openat_tp_fields(void) | |||
45 | 45 | ||
46 | perf_evsel__config(evsel, &opts); | 46 | perf_evsel__config(evsel, &opts); |
47 | 47 | ||
48 | evlist->threads->map[0] = getpid(); | 48 | thread_map__set_pid(evlist->threads, 0, getpid()); |
49 | 49 | ||
50 | err = perf_evlist__open(evlist); | 50 | err = perf_evlist__open(evlist); |
51 | if (err < 0) { | 51 | if (err < 0) { |
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index df66966cfde7..3dab006b4a03 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c | |||
@@ -119,12 +119,12 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, | |||
119 | if (per_cpu) { | 119 | if (per_cpu) { |
120 | mp->cpu = evlist->cpus->map[idx]; | 120 | mp->cpu = evlist->cpus->map[idx]; |
121 | if (evlist->threads) | 121 | if (evlist->threads) |
122 | mp->tid = evlist->threads->map[0]; | 122 | mp->tid = thread_map__pid(evlist->threads, 0); |
123 | else | 123 | else |
124 | mp->tid = -1; | 124 | mp->tid = -1; |
125 | } else { | 125 | } else { |
126 | mp->cpu = -1; | 126 | mp->cpu = -1; |
127 | mp->tid = evlist->threads->map[idx]; | 127 | mp->tid = thread_map__pid(evlist->threads, idx); |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index d7d986d8f23e..67a977e5d0ab 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -504,7 +504,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, | |||
504 | for (thread = 0; thread < threads->nr; ++thread) { | 504 | for (thread = 0; thread < threads->nr; ++thread) { |
505 | if (__event__synthesize_thread(comm_event, mmap_event, | 505 | if (__event__synthesize_thread(comm_event, mmap_event, |
506 | fork_event, | 506 | fork_event, |
507 | threads->map[thread], 0, | 507 | thread_map__pid(threads, thread), 0, |
508 | process, tool, machine, | 508 | process, tool, machine, |
509 | mmap_data, proc_map_timeout)) { | 509 | mmap_data, proc_map_timeout)) { |
510 | err = -1; | 510 | err = -1; |
@@ -515,12 +515,12 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, | |||
515 | * comm.pid is set to thread group id by | 515 | * comm.pid is set to thread group id by |
516 | * perf_event__synthesize_comm | 516 | * perf_event__synthesize_comm |
517 | */ | 517 | */ |
518 | if ((int) comm_event->comm.pid != threads->map[thread]) { | 518 | if ((int) comm_event->comm.pid != thread_map__pid(threads, thread)) { |
519 | bool need_leader = true; | 519 | bool need_leader = true; |
520 | 520 | ||
521 | /* is thread group leader in thread_map? */ | 521 | /* is thread group leader in thread_map? */ |
522 | for (j = 0; j < threads->nr; ++j) { | 522 | for (j = 0; j < threads->nr; ++j) { |
523 | if ((int) comm_event->comm.pid == threads->map[j]) { | 523 | if ((int) comm_event->comm.pid == thread_map__pid(threads, j)) { |
524 | need_leader = false; | 524 | need_leader = false; |
525 | break; | 525 | break; |
526 | } | 526 | } |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 8366511b45f8..d29df901be3e 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -548,7 +548,7 @@ static void perf_evlist__set_sid_idx(struct perf_evlist *evlist, | |||
548 | else | 548 | else |
549 | sid->cpu = -1; | 549 | sid->cpu = -1; |
550 | if (!evsel->system_wide && evlist->threads && thread >= 0) | 550 | if (!evsel->system_wide && evlist->threads && thread >= 0) |
551 | sid->tid = evlist->threads->map[thread]; | 551 | sid->tid = thread_map__pid(evlist->threads, thread); |
552 | else | 552 | else |
553 | sid->tid = -1; | 553 | sid->tid = -1; |
554 | } | 554 | } |
@@ -1475,7 +1475,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar | |||
1475 | __func__, __LINE__); | 1475 | __func__, __LINE__); |
1476 | goto out_close_pipes; | 1476 | goto out_close_pipes; |
1477 | } | 1477 | } |
1478 | evlist->threads->map[0] = evlist->workload.pid; | 1478 | thread_map__set_pid(evlist->threads, 0, evlist->workload.pid); |
1479 | } | 1479 | } |
1480 | 1480 | ||
1481 | close(child_ready_pipe[1]); | 1481 | close(child_ready_pipe[1]); |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 33449decf7bd..1b56047af96b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -1167,7 +1167,7 @@ retry_sample_id: | |||
1167 | int group_fd; | 1167 | int group_fd; |
1168 | 1168 | ||
1169 | if (!evsel->cgrp && !evsel->system_wide) | 1169 | if (!evsel->cgrp && !evsel->system_wide) |
1170 | pid = threads->map[thread]; | 1170 | pid = thread_map__pid(threads, thread); |
1171 | 1171 | ||
1172 | group_fd = get_group_fd(evsel, cpu, thread); | 1172 | group_fd = get_group_fd(evsel, cpu, thread); |
1173 | retry_open: | 1173 | retry_open: |
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index f4822bd03709..8c3c3a0751bd 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c | |||
@@ -45,7 +45,7 @@ struct thread_map *thread_map__new_by_pid(pid_t pid) | |||
45 | threads = thread_map__alloc(items); | 45 | threads = thread_map__alloc(items); |
46 | if (threads != NULL) { | 46 | if (threads != NULL) { |
47 | for (i = 0; i < items; i++) | 47 | for (i = 0; i < items; i++) |
48 | threads->map[i] = atoi(namelist[i]->d_name); | 48 | thread_map__set_pid(threads, i, atoi(namelist[i]->d_name)); |
49 | threads->nr = items; | 49 | threads->nr = items; |
50 | } | 50 | } |
51 | 51 | ||
@@ -61,8 +61,8 @@ struct thread_map *thread_map__new_by_tid(pid_t tid) | |||
61 | struct thread_map *threads = thread_map__alloc(1); | 61 | struct thread_map *threads = thread_map__alloc(1); |
62 | 62 | ||
63 | if (threads != NULL) { | 63 | if (threads != NULL) { |
64 | threads->map[0] = tid; | 64 | thread_map__set_pid(threads, 0, tid); |
65 | threads->nr = 1; | 65 | threads->nr = 1; |
66 | } | 66 | } |
67 | 67 | ||
68 | return threads; | 68 | return threads; |
@@ -123,8 +123,10 @@ struct thread_map *thread_map__new_by_uid(uid_t uid) | |||
123 | threads = tmp; | 123 | threads = tmp; |
124 | } | 124 | } |
125 | 125 | ||
126 | for (i = 0; i < items; i++) | 126 | for (i = 0; i < items; i++) { |
127 | threads->map[threads->nr + i] = atoi(namelist[i]->d_name); | 127 | thread_map__set_pid(threads, threads->nr + i, |
128 | atoi(namelist[i]->d_name)); | ||
129 | } | ||
128 | 130 | ||
129 | for (i = 0; i < items; i++) | 131 | for (i = 0; i < items; i++) |
130 | zfree(&namelist[i]); | 132 | zfree(&namelist[i]); |
@@ -201,7 +203,7 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str) | |||
201 | threads = nt; | 203 | threads = nt; |
202 | 204 | ||
203 | for (i = 0; i < items; i++) { | 205 | for (i = 0; i < items; i++) { |
204 | threads->map[j++] = atoi(namelist[i]->d_name); | 206 | thread_map__set_pid(threads, j++, atoi(namelist[i]->d_name)); |
205 | zfree(&namelist[i]); | 207 | zfree(&namelist[i]); |
206 | } | 208 | } |
207 | threads->nr = total_tasks; | 209 | threads->nr = total_tasks; |
@@ -227,8 +229,8 @@ struct thread_map *thread_map__new_dummy(void) | |||
227 | struct thread_map *threads = thread_map__alloc(1); | 229 | struct thread_map *threads = thread_map__alloc(1); |
228 | 230 | ||
229 | if (threads != NULL) { | 231 | if (threads != NULL) { |
230 | threads->map[0] = -1; | 232 | thread_map__set_pid(threads, 0, -1); |
231 | threads->nr = 1; | 233 | threads->nr = 1; |
232 | } | 234 | } |
233 | return threads; | 235 | return threads; |
234 | } | 236 | } |
@@ -267,8 +269,8 @@ static struct thread_map *thread_map__new_by_tid_str(const char *tid_str) | |||
267 | goto out_free_threads; | 269 | goto out_free_threads; |
268 | 270 | ||
269 | threads = nt; | 271 | threads = nt; |
270 | threads->map[ntasks - 1] = tid; | 272 | thread_map__set_pid(threads, ntasks - 1, tid); |
271 | threads->nr = ntasks; | 273 | threads->nr = ntasks; |
272 | } | 274 | } |
273 | out: | 275 | out: |
274 | return threads; | 276 | return threads; |
@@ -301,7 +303,7 @@ size_t thread_map__fprintf(struct thread_map *threads, FILE *fp) | |||
301 | size_t printed = fprintf(fp, "%d thread%s: ", | 303 | size_t printed = fprintf(fp, "%d thread%s: ", |
302 | threads->nr, threads->nr > 1 ? "s" : ""); | 304 | threads->nr, threads->nr > 1 ? "s" : ""); |
303 | for (i = 0; i < threads->nr; ++i) | 305 | for (i = 0; i < threads->nr; ++i) |
304 | printed += fprintf(fp, "%s%d", i ? ", " : "", threads->map[i]); | 306 | printed += fprintf(fp, "%s%d", i ? ", " : "", thread_map__pid(threads, i)); |
305 | 307 | ||
306 | return printed + fprintf(fp, "\n"); | 308 | return printed + fprintf(fp, "\n"); |
307 | } | 309 | } |
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index 95313f43cc0f..e22570390470 100644 --- a/tools/perf/util/thread_map.h +++ b/tools/perf/util/thread_map.h | |||
@@ -27,4 +27,14 @@ static inline int thread_map__nr(struct thread_map *threads) | |||
27 | return threads ? threads->nr : 1; | 27 | return threads ? threads->nr : 1; |
28 | } | 28 | } |
29 | 29 | ||
30 | static inline pid_t thread_map__pid(struct thread_map *map, int thread) | ||
31 | { | ||
32 | return map->map[thread]; | ||
33 | } | ||
34 | |||
35 | static inline void | ||
36 | thread_map__set_pid(struct thread_map *map, int thread, pid_t pid) | ||
37 | { | ||
38 | map->map[thread] = pid; | ||
39 | } | ||
30 | #endif /* __PERF_THREAD_MAP_H */ | 40 | #endif /* __PERF_THREAD_MAP_H */ |