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/perf/util | |
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/perf/util')
-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 |
4 files changed, 181 insertions, 0 deletions
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 */ | ||