diff options
author | John Kacur <jkacur@redhat.com> | 2009-11-24 15:35:01 +0100 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-24 16:37:01 +0100 |
commit | e74328d3a17ed75ffdf72b86f289965823a47240 (patch) | |
tree | 03b0db84b69f2cb3dce994db0d058804a8748fb1 /tools/perf/util | |
parent | c9c7ccaf3a2686ed3a44d69bb1f8b55eeead8a4e (diff) | |
download | op-kernel-dev-e74328d3a17ed75ffdf72b86f289965823a47240.zip op-kernel-dev-e74328d3a17ed75ffdf72b86f289965823a47240.tar.gz |
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 0000000..a970789 --- /dev/null +++ b/tools/perf/util/process_event.c @@ -0,0 +1,53 @@ +#include "process_event.h" + +char *cwd; +int cwdlen; + +int +process_mmap_event(event_t *event, unsigned long offset, unsigned long head) +{ + struct map *map = map__new(&event->mmap, cwd, cwdlen); + struct thread *thread = threads__findnew(event->mmap.pid); + + dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", + (void *)(offset + head), + (void *)(long)(event->header.size), + event->mmap.pid, + event->mmap.tid, + (void *)(long)event->mmap.start, + (void *)(long)event->mmap.len, + (void *)(long)event->mmap.pgoff, + event->mmap.filename); + + if (thread == NULL || map == NULL) { + dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); + return 0; + } + + thread__insert_map(thread, map); + total_mmap++; + + return 0; + +} + +int +process_comm_event(event_t *event, unsigned long offset, unsigned long head) +{ + struct thread *thread = threads__findnew(event->comm.pid); + + dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", + (void *)(offset + head), + (void *)(long)(event->header.size), + event->comm.comm, event->comm.pid); + + if (thread == NULL || + thread__set_comm_adjust(thread, event->comm.comm)) { + dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); + return -1; + } + total_comm++; + + return 0; +} + diff --git a/tools/perf/util/process_event.h b/tools/perf/util/process_event.h new file mode 100644 index 0000000..6f68c69 --- /dev/null +++ b/tools/perf/util/process_event.h @@ -0,0 +1,29 @@ +#ifndef __PROCESS_EVENT_H +#define __PROCESS_EVENT_H + +#include "../builtin.h" +#include "util.h" + +#include "color.h" +#include <linux/list.h> +#include "cache.h" +#include <linux/rbtree.h> +#include "symbol.h" +#include "string.h" + +#include "../perf.h" +#include "debug.h" + +#include "parse-options.h" +#include "parse-events.h" + +#include "thread.h" +#include "sort.h" +#include "hist.h" + +extern char *cwd; +extern int cwdlen; +extern int process_mmap_event(event_t *, unsigned long, unsigned long); +extern int process_comm_event(event_t *, unsigned long , unsigned long); + +#endif /* __PROCESS_H */ diff --git a/tools/perf/util/process_events.c b/tools/perf/util/process_events.c new file mode 100644 index 0000000..a920436 --- /dev/null +++ b/tools/perf/util/process_events.c @@ -0,0 +1,64 @@ +#include "process_events.h" + +char *cwd; +int cwdlen; + +int +process_mmap_event(event_t *event, unsigned long offset, unsigned long head) +{ + struct map *map = map__new(&event->mmap, cwd, cwdlen); + struct thread *thread = threads__findnew(event->mmap.pid); + + dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", + (void *)(offset + head), + (void *)(long)(event->header.size), + event->mmap.pid, + event->mmap.tid, + (void *)(long)event->mmap.start, + (void *)(long)event->mmap.len, + (void *)(long)event->mmap.pgoff, + event->mmap.filename); + + if (thread == NULL || map == NULL) { + dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); + return 0; + } + + thread__insert_map(thread, map); + total_mmap++; + + return 0; +} + +int +process_task_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); + + dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n", + (void *)(offset + head), + (void *)(long)(event->header.size), + event->header.type == PERF_RECORD_FORK ? "FORK" : "EXIT", + event->fork.pid, event->fork.tid, + event->fork.ppid, event->fork.ptid); + + /* + * A thread clone will have the same PID for both + * parent and child. + */ + if (thread == parent) + return 0; + + if (event->header.type == PERF_RECORD_EXIT) + return 0; + + if (!thread || !parent || thread__fork(thread, parent)) { + dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); + return -1; + } + total_fork++; + + return 0; +} + diff --git a/tools/perf/util/process_events.h b/tools/perf/util/process_events.h new file mode 100644 index 0000000..73d092f --- /dev/null +++ b/tools/perf/util/process_events.h @@ -0,0 +1,35 @@ +#ifndef __PROCESS_EVENTS_H +#define __PROCESS_EVENTS_H + +#include "../builtin.h" + +#include "util.h" +#include "color.h" +#include <linux/list.h> +#include "cache.h" +#include <linux/rbtree.h> +#include "symbol.h" +#include "string.h" +#include "callchain.h" +#include "strlist.h" +#include "values.h" + +#include "../perf.h" +#include "debug.h" +#include "header.h" + +#include "parse-options.h" +#include "parse-events.h" + +#include "data_map.h" +#include "thread.h" +#include "sort.h" +#include "hist.h" + +extern char *cwd; +extern int cwdlen; + +extern int process_mmap_event(event_t *, unsigned long , unsigned long); +extern int process_task_event(event_t *, unsigned long, unsigned long); + +#endif /* __PROCESS_EVENTS_H */ |