summaryrefslogtreecommitdiff
path: root/Documentation/perf_counter/builtin-report.c
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2009-06-04 16:53:49 +0200
committerIngo Molnar <mingo@elte.hu>2009-06-04 17:51:39 +0200
commit62fc44536c14b5787531bac7417580fca54c88b4 (patch)
tree6b43ae4d32a1087f5e1bfa04d323fae8067a8ce4 /Documentation/perf_counter/builtin-report.c
parentd99e9446200c1ffab28cb0e39b76c34a2bfafd06 (diff)
downloadlwn-62fc44536c14b5787531bac7417580fca54c88b4.tar.gz
lwn-62fc44536c14b5787531bac7417580fca54c88b4.zip
perf_counter tools: Use fork and remove munmap events
Use fork events to clone comm and map data and remove everything munmap related Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/builtin-report.c')
-rw-r--r--Documentation/perf_counter/builtin-report.c103
1 files changed, 93 insertions, 10 deletions
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index 389ae2569f49..5d191216c80a 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -43,12 +43,6 @@ static int full_paths;
static unsigned long page_size;
static unsigned long mmap_window = 32;
-const char *perf_event_names[] = {
- [PERF_EVENT_MMAP] = " PERF_EVENT_MMAP",
- [PERF_EVENT_MUNMAP] = " PERF_EVENT_MUNMAP",
- [PERF_EVENT_COMM] = " PERF_EVENT_COMM",
-};
-
struct ip_event {
struct perf_event_header header;
__u64 ip;
@@ -70,11 +64,17 @@ struct comm_event {
char comm[16];
};
+struct fork_event {
+ struct perf_event_header header;
+ __u32 pid, ppid;
+};
+
typedef union event_union {
struct perf_event_header header;
struct ip_event ip;
struct mmap_event mmap;
struct comm_event comm;
+ struct fork_event fork;
} event_t;
static LIST_HEAD(dsos);
@@ -208,7 +208,31 @@ out_delete:
return NULL;
}
-struct thread;
+static struct map *map__clone(struct map *self)
+{
+ struct map *map = malloc(sizeof(*self));
+
+ if (!map)
+ return NULL;
+
+ memcpy(map, self, sizeof(*self));
+
+ return map;
+}
+
+static int map__overlap(struct map *l, struct map *r)
+{
+ if (l->start > r->start) {
+ struct map *t = l;
+ l = r;
+ r = t;
+ }
+
+ if (l->end > r->start)
+ return 1;
+
+ return 0;
+}
struct thread {
struct rb_node rb_node;
@@ -284,9 +308,39 @@ static struct thread *threads__findnew(pid_t pid)
static void thread__insert_map(struct thread *self, struct map *map)
{
+ struct map *pos, *tmp;
+
+ list_for_each_entry_safe(pos, tmp, &self->maps, node) {
+ if (map__overlap(pos, map)) {
+ list_del_init(&pos->node);
+ /* XXX leaks dsos */
+ free(pos);
+ }
+ }
+
list_add_tail(&map->node, &self->maps);
}
+static int thread__fork(struct thread *self, struct thread *parent)
+{
+ struct map *map;
+
+ if (self->comm)
+ free(self->comm);
+ self->comm = strdup(parent->comm);
+ if (!self->comm)
+ return -ENOMEM;
+
+ list_for_each_entry(map, &parent->maps, node) {
+ struct map *new = map__clone(map);
+ if (!new)
+ return -ENOMEM;
+ thread__insert_map(self, new);
+ }
+
+ return 0;
+}
+
static struct map *thread__find_map(struct thread *self, uint64_t ip)
{
struct map *pos;
@@ -784,7 +838,11 @@ static void register_idle_thread(void)
}
}
-static unsigned long total = 0, total_mmap = 0, total_comm = 0, total_unknown = 0;
+static unsigned long total = 0,
+ total_mmap = 0,
+ total_comm = 0,
+ total_fork = 0,
+ total_unknown = 0;
static int
process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
@@ -866,9 +924,10 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
struct thread *thread = threads__findnew(event->mmap.pid);
struct map *map = map__new(&event->mmap);
- dprintf("%p [%p]: PERF_EVENT_MMAP: [%p(%p) @ %p]: %s\n",
+ dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
+ event->mmap.pid,
(void *)(long)event->mmap.start,
(void *)(long)event->mmap.len,
(void *)(long)event->mmap.pgoff,
@@ -906,6 +965,26 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head)
}
static int
+process_fork_event(event_t *event, unsigned long offset, unsigned long head)
+{
+ struct thread *thread = threads__findnew(event->fork.pid);
+ struct thread *parent = threads__findnew(event->fork.ppid);
+
+ dprintf("%p [%p]: PERF_EVENT_FORK: %d:%d\n",
+ (void *)(offset + head),
+ (void *)(long)(event->header.size),
+ event->fork.pid, event->fork.ppid);
+
+ if (!thread || !parent || thread__fork(thread, parent)) {
+ dprintf("problem processing PERF_EVENT_FORK, skipping event.\n");
+ return -1;
+ }
+ total_fork++;
+
+ return 0;
+}
+
+static int
process_event(event_t *event, unsigned long offset, unsigned long head)
{
if (event->header.misc & PERF_EVENT_MISC_OVERFLOW)
@@ -918,10 +997,13 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
case PERF_EVENT_COMM:
return process_comm_event(event, offset, head);
+ case PERF_EVENT_FORK:
+ return process_fork_event(event, offset, head);
+
/*
* We dont process them right now but they are fine:
*/
- case PERF_EVENT_MUNMAP:
+
case PERF_EVENT_PERIOD:
case PERF_EVENT_THROTTLE:
case PERF_EVENT_UNTHROTTLE:
@@ -1038,6 +1120,7 @@ more:
dprintf(" IP events: %10ld\n", total);
dprintf(" mmap events: %10ld\n", total_mmap);
dprintf(" comm events: %10ld\n", total_comm);
+ dprintf(" fork events: %10ld\n", total_fork);
dprintf(" unknown events: %10ld\n", total_unknown);
if (dump_trace)