aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorJohn Kacur <jkacur@redhat.com>2009-11-24 09:35:01 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-24 10:37:01 -0500
commite74328d3a17ed75ffdf72b86f289965823a47240 (patch)
tree03b0db84b69f2cb3dce994db0d058804a8748fb1 /tools/perf/util
parentc9c7ccaf3a2686ed3a44d69bb1f8b55eeead8a4e (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.c53
-rw-r--r--tools/perf/util/process_event.h29
-rw-r--r--tools/perf/util/process_events.c64
-rw-r--r--tools/perf/util/process_events.h35
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
3char *cwd;
4int cwdlen;
5
6int
7process_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
34int
35process_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
24extern char *cwd;
25extern int cwdlen;
26extern int process_mmap_event(event_t *, unsigned long, unsigned long);
27extern 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
3char *cwd;
4int cwdlen;
5
6int
7process_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
33int
34process_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
29extern char *cwd;
30extern int cwdlen;
31
32extern int process_mmap_event(event_t *, unsigned long , unsigned long);
33extern int process_task_event(event_t *, unsigned long, unsigned long);
34
35#endif /* __PROCESS_EVENTS_H */