John Kacur | e74328d | 2009-11-24 15:35:01 +0100 | [diff] [blame] | 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 | { |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 9 | struct map *map = map__new(&event->mmap, MAP__FUNCTION, cwd, cwdlen); |
John Kacur | e74328d | 2009-11-24 15:35:01 +0100 | [diff] [blame] | 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 | |