diff options
author | John Kacur <jkacur@redhat.com> | 2009-11-24 09:35:01 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-24 10:37:01 -0500 |
commit | e74328d3a17ed75ffdf72b86f289965823a47240 (patch) | |
tree | 03b0db84b69f2cb3dce994db0d058804a8748fb1 /tools | |
parent | c9c7ccaf3a2686ed3a44d69bb1f8b55eeead8a4e (diff) |
perf tools: Use common process_event functions for annotate and report
Prevent bit-rot in perf-annotate by using common functions where
possible. Here we create process_events.[ch] to hold the common
functions.
Signed-off-by: John Kacur <jkacur@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: acme@redhat.com
LKML-Reference: <1259073301-11506-3-git-send-email-jkacur@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/Makefile | 2 | ||||
-rw-r--r-- | tools/perf/builtin-annotate.c | 56 | ||||
-rw-r--r-- | tools/perf/builtin-report.c | 63 | ||||
-rw-r--r-- | tools/perf/util/process_event.c | 53 | ||||
-rw-r--r-- | tools/perf/util/process_event.h | 29 | ||||
-rw-r--r-- | tools/perf/util/process_events.c | 64 | ||||
-rw-r--r-- | tools/perf/util/process_events.h | 35 |
7 files changed, 186 insertions, 116 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index f1537a94a05f..de37d492e10f 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -369,6 +369,7 @@ LIB_H += util/sort.h | |||
369 | LIB_H += util/hist.h | 369 | LIB_H += util/hist.h |
370 | LIB_H += util/thread.h | 370 | LIB_H += util/thread.h |
371 | LIB_H += util/data_map.h | 371 | LIB_H += util/data_map.h |
372 | LIB_H += util/process_events.h | ||
372 | 373 | ||
373 | LIB_OBJS += util/abspath.o | 374 | LIB_OBJS += util/abspath.o |
374 | LIB_OBJS += util/alias.o | 375 | LIB_OBJS += util/alias.o |
@@ -411,6 +412,7 @@ LIB_OBJS += util/svghelper.o | |||
411 | LIB_OBJS += util/sort.o | 412 | LIB_OBJS += util/sort.o |
412 | LIB_OBJS += util/hist.o | 413 | LIB_OBJS += util/hist.o |
413 | LIB_OBJS += util/data_map.o | 414 | LIB_OBJS += util/data_map.o |
415 | LIB_OBJS += util/process_events.o | ||
414 | 416 | ||
415 | BUILTIN_OBJS += builtin-annotate.o | 417 | BUILTIN_OBJS += builtin-annotate.o |
416 | 418 | ||
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 6b13a1ecf1e7..59b6123abec2 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "util/thread.h" | 24 | #include "util/thread.h" |
25 | #include "util/sort.h" | 25 | #include "util/sort.h" |
26 | #include "util/hist.h" | 26 | #include "util/hist.h" |
27 | #include "util/process_events.h" | ||
27 | 28 | ||
28 | static char const *input_name = "perf.data"; | 29 | static char const *input_name = "perf.data"; |
29 | 30 | ||
@@ -202,32 +203,6 @@ got_map: | |||
202 | } | 203 | } |
203 | 204 | ||
204 | static int | 205 | static int |
205 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | ||
206 | { | ||
207 | struct map *map = map__new(&event->mmap, NULL, 0); | ||
208 | struct thread *thread = threads__findnew(event->mmap.pid); | ||
209 | |||
210 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d: [%p(%p) @ %p]: %s\n", | ||
211 | (void *)(offset + head), | ||
212 | (void *)(long)(event->header.size), | ||
213 | event->mmap.pid, | ||
214 | (void *)(long)event->mmap.start, | ||
215 | (void *)(long)event->mmap.len, | ||
216 | (void *)(long)event->mmap.pgoff, | ||
217 | event->mmap.filename); | ||
218 | |||
219 | if (thread == NULL || map == NULL) { | ||
220 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); | ||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | thread__insert_map(thread, map); | ||
225 | total_mmap++; | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | static int | ||
231 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 206 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) |
232 | { | 207 | { |
233 | struct thread *thread = threads__findnew(event->comm.pid); | 208 | struct thread *thread = threads__findnew(event->comm.pid); |
@@ -248,33 +223,6 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head) | |||
248 | } | 223 | } |
249 | 224 | ||
250 | static int | 225 | static int |
251 | process_fork_event(event_t *event, unsigned long offset, unsigned long head) | ||
252 | { | ||
253 | struct thread *thread = threads__findnew(event->fork.pid); | ||
254 | struct thread *parent = threads__findnew(event->fork.ppid); | ||
255 | |||
256 | dump_printf("%p [%p]: PERF_RECORD_FORK: %d:%d\n", | ||
257 | (void *)(offset + head), | ||
258 | (void *)(long)(event->header.size), | ||
259 | event->fork.pid, event->fork.ppid); | ||
260 | |||
261 | /* | ||
262 | * A thread clone will have the same PID for both | ||
263 | * parent and child. | ||
264 | */ | ||
265 | if (thread == parent) | ||
266 | return 0; | ||
267 | |||
268 | if (!thread || !parent || thread__fork(thread, parent)) { | ||
269 | dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); | ||
270 | return -1; | ||
271 | } | ||
272 | total_fork++; | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | static int | ||
278 | process_event(event_t *event, unsigned long offset, unsigned long head) | 226 | process_event(event_t *event, unsigned long offset, unsigned long head) |
279 | { | 227 | { |
280 | switch (event->header.type) { | 228 | switch (event->header.type) { |
@@ -288,7 +236,7 @@ process_event(event_t *event, unsigned long offset, unsigned long head) | |||
288 | return process_comm_event(event, offset, head); | 236 | return process_comm_event(event, offset, head); |
289 | 237 | ||
290 | case PERF_RECORD_FORK: | 238 | case PERF_RECORD_FORK: |
291 | return process_fork_event(event, offset, head); | 239 | return process_task_event(event, offset, head); |
292 | /* | 240 | /* |
293 | * We dont process them right now but they are fine: | 241 | * We dont process them right now but they are fine: |
294 | */ | 242 | */ |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index fe474b7f8ad0..1826be719b58 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "util/thread.h" | 30 | #include "util/thread.h" |
31 | #include "util/sort.h" | 31 | #include "util/sort.h" |
32 | #include "util/hist.h" | 32 | #include "util/hist.h" |
33 | #include "util/process_events.h" | ||
33 | 34 | ||
34 | static char const *input_name = "perf.data"; | 35 | static char const *input_name = "perf.data"; |
35 | 36 | ||
@@ -54,9 +55,6 @@ static int exclude_other = 1; | |||
54 | static char callchain_default_opt[] = "fractal,0.5"; | 55 | static char callchain_default_opt[] = "fractal,0.5"; |
55 | const char *vmlinux_name; | 56 | const char *vmlinux_name; |
56 | 57 | ||
57 | static char *cwd; | ||
58 | static int cwdlen; | ||
59 | |||
60 | static struct perf_header *header; | 58 | static struct perf_header *header; |
61 | 59 | ||
62 | static u64 sample_type; | 60 | static u64 sample_type; |
@@ -751,33 +749,6 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) | |||
751 | } | 749 | } |
752 | 750 | ||
753 | static int | 751 | static int |
754 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | ||
755 | { | ||
756 | struct map *map = map__new(&event->mmap, cwd, cwdlen); | ||
757 | struct thread *thread = threads__findnew(event->mmap.pid); | ||
758 | |||
759 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", | ||
760 | (void *)(offset + head), | ||
761 | (void *)(long)(event->header.size), | ||
762 | event->mmap.pid, | ||
763 | event->mmap.tid, | ||
764 | (void *)(long)event->mmap.start, | ||
765 | (void *)(long)event->mmap.len, | ||
766 | (void *)(long)event->mmap.pgoff, | ||
767 | event->mmap.filename); | ||
768 | |||
769 | if (thread == NULL || map == NULL) { | ||
770 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); | ||
771 | return 0; | ||
772 | } | ||
773 | |||
774 | thread__insert_map(thread, map); | ||
775 | total_mmap++; | ||
776 | |||
777 | return 0; | ||
778 | } | ||
779 | |||
780 | static int | ||
781 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 752 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) |
782 | { | 753 | { |
783 | struct thread *thread = threads__findnew(event->comm.pid); | 754 | struct thread *thread = threads__findnew(event->comm.pid); |
@@ -798,38 +769,6 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head) | |||
798 | } | 769 | } |
799 | 770 | ||
800 | static int | 771 | static int |
801 | process_task_event(event_t *event, unsigned long offset, unsigned long head) | ||
802 | { | ||
803 | struct thread *thread = threads__findnew(event->fork.pid); | ||
804 | struct thread *parent = threads__findnew(event->fork.ppid); | ||
805 | |||
806 | dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n", | ||
807 | (void *)(offset + head), | ||
808 | (void *)(long)(event->header.size), | ||
809 | event->header.type == PERF_RECORD_FORK ? "FORK" : "EXIT", | ||
810 | event->fork.pid, event->fork.tid, | ||
811 | event->fork.ppid, event->fork.ptid); | ||
812 | |||
813 | /* | ||
814 | * A thread clone will have the same PID for both | ||
815 | * parent and child. | ||
816 | */ | ||
817 | if (thread == parent) | ||
818 | return 0; | ||
819 | |||
820 | if (event->header.type == PERF_RECORD_EXIT) | ||
821 | return 0; | ||
822 | |||
823 | if (!thread || !parent || thread__fork(thread, parent)) { | ||
824 | dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); | ||
825 | return -1; | ||
826 | } | ||
827 | total_fork++; | ||
828 | |||
829 | return 0; | ||
830 | } | ||
831 | |||
832 | static int | ||
833 | process_lost_event(event_t *event, unsigned long offset, unsigned long head) | 772 | process_lost_event(event_t *event, unsigned long offset, unsigned long head) |
834 | { | 773 | { |
835 | dump_printf("%p [%p]: PERF_RECORD_LOST: id:%Ld: lost:%Ld\n", | 774 | dump_printf("%p [%p]: PERF_RECORD_LOST: id:%Ld: lost:%Ld\n", |
diff --git a/tools/perf/util/process_event.c b/tools/perf/util/process_event.c new file mode 100644 index 000000000000..a970789581a2 --- /dev/null +++ b/tools/perf/util/process_event.c | |||
@@ -0,0 +1,53 @@ | |||
1 | #include "process_event.h" | ||
2 | |||
3 | char *cwd; | ||
4 | int cwdlen; | ||
5 | |||
6 | int | ||
7 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | ||
8 | { | ||
9 | struct map *map = map__new(&event->mmap, cwd, cwdlen); | ||
10 | struct thread *thread = threads__findnew(event->mmap.pid); | ||
11 | |||
12 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", | ||
13 | (void *)(offset + head), | ||
14 | (void *)(long)(event->header.size), | ||
15 | event->mmap.pid, | ||
16 | event->mmap.tid, | ||
17 | (void *)(long)event->mmap.start, | ||
18 | (void *)(long)event->mmap.len, | ||
19 | (void *)(long)event->mmap.pgoff, | ||
20 | event->mmap.filename); | ||
21 | |||
22 | if (thread == NULL || map == NULL) { | ||
23 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); | ||
24 | return 0; | ||
25 | } | ||
26 | |||
27 | thread__insert_map(thread, map); | ||
28 | total_mmap++; | ||
29 | |||
30 | return 0; | ||
31 | |||
32 | } | ||
33 | |||
34 | int | ||
35 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | ||
36 | { | ||
37 | struct thread *thread = threads__findnew(event->comm.pid); | ||
38 | |||
39 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", | ||
40 | (void *)(offset + head), | ||
41 | (void *)(long)(event->header.size), | ||
42 | event->comm.comm, event->comm.pid); | ||
43 | |||
44 | if (thread == NULL || | ||
45 | thread__set_comm_adjust(thread, event->comm.comm)) { | ||
46 | dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); | ||
47 | return -1; | ||
48 | } | ||
49 | total_comm++; | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | |||
diff --git a/tools/perf/util/process_event.h b/tools/perf/util/process_event.h new file mode 100644 index 000000000000..6f68c69736cd --- /dev/null +++ b/tools/perf/util/process_event.h | |||
@@ -0,0 +1,29 @@ | |||
1 | #ifndef __PROCESS_EVENT_H | ||
2 | #define __PROCESS_EVENT_H | ||
3 | |||
4 | #include "../builtin.h" | ||
5 | #include "util.h" | ||
6 | |||
7 | #include "color.h" | ||
8 | #include <linux/list.h> | ||
9 | #include "cache.h" | ||
10 | #include <linux/rbtree.h> | ||
11 | #include "symbol.h" | ||
12 | #include "string.h" | ||
13 | |||
14 | #include "../perf.h" | ||
15 | #include "debug.h" | ||
16 | |||
17 | #include "parse-options.h" | ||
18 | #include "parse-events.h" | ||
19 | |||
20 | #include "thread.h" | ||
21 | #include "sort.h" | ||
22 | #include "hist.h" | ||
23 | |||
24 | extern char *cwd; | ||
25 | extern int cwdlen; | ||
26 | extern int process_mmap_event(event_t *, unsigned long, unsigned long); | ||
27 | extern int process_comm_event(event_t *, unsigned long , unsigned long); | ||
28 | |||
29 | #endif /* __PROCESS_H */ | ||
diff --git a/tools/perf/util/process_events.c b/tools/perf/util/process_events.c new file mode 100644 index 000000000000..a9204363efd8 --- /dev/null +++ b/tools/perf/util/process_events.c | |||
@@ -0,0 +1,64 @@ | |||
1 | #include "process_events.h" | ||
2 | |||
3 | char *cwd; | ||
4 | int cwdlen; | ||
5 | |||
6 | int | ||
7 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | ||
8 | { | ||
9 | struct map *map = map__new(&event->mmap, cwd, cwdlen); | ||
10 | struct thread *thread = threads__findnew(event->mmap.pid); | ||
11 | |||
12 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", | ||
13 | (void *)(offset + head), | ||
14 | (void *)(long)(event->header.size), | ||
15 | event->mmap.pid, | ||
16 | event->mmap.tid, | ||
17 | (void *)(long)event->mmap.start, | ||
18 | (void *)(long)event->mmap.len, | ||
19 | (void *)(long)event->mmap.pgoff, | ||
20 | event->mmap.filename); | ||
21 | |||
22 | if (thread == NULL || map == NULL) { | ||
23 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); | ||
24 | return 0; | ||
25 | } | ||
26 | |||
27 | thread__insert_map(thread, map); | ||
28 | total_mmap++; | ||
29 | |||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | int | ||
34 | process_task_event(event_t *event, unsigned long offset, unsigned long head) | ||
35 | { | ||
36 | struct thread *thread = threads__findnew(event->fork.pid); | ||
37 | struct thread *parent = threads__findnew(event->fork.ppid); | ||
38 | |||
39 | dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n", | ||
40 | (void *)(offset + head), | ||
41 | (void *)(long)(event->header.size), | ||
42 | event->header.type == PERF_RECORD_FORK ? "FORK" : "EXIT", | ||
43 | event->fork.pid, event->fork.tid, | ||
44 | event->fork.ppid, event->fork.ptid); | ||
45 | |||
46 | /* | ||
47 | * A thread clone will have the same PID for both | ||
48 | * parent and child. | ||
49 | */ | ||
50 | if (thread == parent) | ||
51 | return 0; | ||
52 | |||
53 | if (event->header.type == PERF_RECORD_EXIT) | ||
54 | return 0; | ||
55 | |||
56 | if (!thread || !parent || thread__fork(thread, parent)) { | ||
57 | dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); | ||
58 | return -1; | ||
59 | } | ||
60 | total_fork++; | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
diff --git a/tools/perf/util/process_events.h b/tools/perf/util/process_events.h new file mode 100644 index 000000000000..73d092f83283 --- /dev/null +++ b/tools/perf/util/process_events.h | |||
@@ -0,0 +1,35 @@ | |||
1 | #ifndef __PROCESS_EVENTS_H | ||
2 | #define __PROCESS_EVENTS_H | ||
3 | |||
4 | #include "../builtin.h" | ||
5 | |||
6 | #include "util.h" | ||
7 | #include "color.h" | ||
8 | #include <linux/list.h> | ||
9 | #include "cache.h" | ||
10 | #include <linux/rbtree.h> | ||
11 | #include "symbol.h" | ||
12 | #include "string.h" | ||
13 | #include "callchain.h" | ||
14 | #include "strlist.h" | ||
15 | #include "values.h" | ||
16 | |||
17 | #include "../perf.h" | ||
18 | #include "debug.h" | ||
19 | #include "header.h" | ||
20 | |||
21 | #include "parse-options.h" | ||
22 | #include "parse-events.h" | ||
23 | |||
24 | #include "data_map.h" | ||
25 | #include "thread.h" | ||
26 | #include "sort.h" | ||
27 | #include "hist.h" | ||
28 | |||
29 | extern char *cwd; | ||
30 | extern int cwdlen; | ||
31 | |||
32 | extern int process_mmap_event(event_t *, unsigned long , unsigned long); | ||
33 | extern int process_task_event(event_t *, unsigned long, unsigned long); | ||
34 | |||
35 | #endif /* __PROCESS_EVENTS_H */ | ||