diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-01-19 11:07:23 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-01-24 16:46:48 -0500 |
commit | 9ae7d3351aac238eef9646479693105688fd9cc9 (patch) | |
tree | 549c3231d2279023786ad1205eecff94a755230e /tools/perf | |
parent | 172d1b0b73256551f100fc00c69e356d047103f5 (diff) |
perf tools: Add fprintf methods for thread_map and cpu_map classes
For helping with debugging.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
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-m06n4rp7pwr6dlzwoq89cl69@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/cpumap.c | 11 | ||||
-rw-r--r-- | tools/perf/util/cpumap.h | 4 | ||||
-rw-r--r-- | tools/perf/util/thread_map.c | 11 | ||||
-rw-r--r-- | tools/perf/util/thread_map.h | 4 |
4 files changed, 30 insertions, 0 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 6893eec693ab..adc72f09914d 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
@@ -166,6 +166,17 @@ out: | |||
166 | return cpus; | 166 | return cpus; |
167 | } | 167 | } |
168 | 168 | ||
169 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp) | ||
170 | { | ||
171 | int i; | ||
172 | size_t printed = fprintf(fp, "%d cpu%s: ", | ||
173 | map->nr, map->nr > 1 ? "s" : ""); | ||
174 | for (i = 0; i < map->nr; ++i) | ||
175 | printed += fprintf(fp, "%s%d", i ? ", " : "", map->map[i]); | ||
176 | |||
177 | return printed + fprintf(fp, "\n"); | ||
178 | } | ||
179 | |||
169 | struct cpu_map *cpu_map__dummy_new(void) | 180 | struct cpu_map *cpu_map__dummy_new(void) |
170 | { | 181 | { |
171 | struct cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int)); | 182 | struct cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int)); |
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 072c0a374794..c41518573c6a 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h | |||
@@ -1,6 +1,8 @@ | |||
1 | #ifndef __PERF_CPUMAP_H | 1 | #ifndef __PERF_CPUMAP_H |
2 | #define __PERF_CPUMAP_H | 2 | #define __PERF_CPUMAP_H |
3 | 3 | ||
4 | #include <stdio.h> | ||
5 | |||
4 | struct cpu_map { | 6 | struct cpu_map { |
5 | int nr; | 7 | int nr; |
6 | int map[]; | 8 | int map[]; |
@@ -10,4 +12,6 @@ struct cpu_map *cpu_map__new(const char *cpu_list); | |||
10 | struct cpu_map *cpu_map__dummy_new(void); | 12 | struct cpu_map *cpu_map__dummy_new(void); |
11 | void cpu_map__delete(struct cpu_map *map); | 13 | void cpu_map__delete(struct cpu_map *map); |
12 | 14 | ||
15 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); | ||
16 | |||
13 | #endif /* __PERF_CPUMAP_H */ | 17 | #endif /* __PERF_CPUMAP_H */ |
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index a5df131b77c3..894d52f65166 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c | |||
@@ -62,3 +62,14 @@ void thread_map__delete(struct thread_map *threads) | |||
62 | { | 62 | { |
63 | free(threads); | 63 | free(threads); |
64 | } | 64 | } |
65 | |||
66 | size_t thread_map__fprintf(struct thread_map *threads, FILE *fp) | ||
67 | { | ||
68 | int i; | ||
69 | size_t printed = fprintf(fp, "%d thread%s: ", | ||
70 | threads->nr, threads->nr > 1 ? "s" : ""); | ||
71 | for (i = 0; i < threads->nr; ++i) | ||
72 | printed += fprintf(fp, "%s%d", i ? ", " : "", threads->map[i]); | ||
73 | |||
74 | return printed + fprintf(fp, "\n"); | ||
75 | } | ||
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index 3cb907311409..736ab4a26210 100644 --- a/tools/perf/util/thread_map.h +++ b/tools/perf/util/thread_map.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define __PERF_THREAD_MAP_H | 2 | #define __PERF_THREAD_MAP_H |
3 | 3 | ||
4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
5 | #include <stdio.h> | ||
5 | 6 | ||
6 | struct thread_map { | 7 | struct thread_map { |
7 | int nr; | 8 | int nr; |
@@ -12,4 +13,7 @@ struct thread_map *thread_map__new_by_pid(pid_t pid); | |||
12 | struct thread_map *thread_map__new_by_tid(pid_t tid); | 13 | struct thread_map *thread_map__new_by_tid(pid_t tid); |
13 | struct thread_map *thread_map__new(pid_t pid, pid_t tid); | 14 | struct thread_map *thread_map__new(pid_t pid, pid_t tid); |
14 | void thread_map__delete(struct thread_map *threads); | 15 | void thread_map__delete(struct thread_map *threads); |
16 | |||
17 | size_t thread_map__fprintf(struct thread_map *threads, FILE *fp); | ||
18 | |||
15 | #endif /* __PERF_THREAD_MAP_H */ | 19 | #endif /* __PERF_THREAD_MAP_H */ |