process_events.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "process_events.h"
  2. char *cwd;
  3. int cwdlen;
  4. int
  5. process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
  6. {
  7. struct map *map = map__new(&event->mmap, MAP__FUNCTION, cwd, cwdlen);
  8. struct thread *thread = threads__findnew(event->mmap.pid);
  9. dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n",
  10. (void *)(offset + head),
  11. (void *)(long)(event->header.size),
  12. event->mmap.pid,
  13. event->mmap.tid,
  14. (void *)(long)event->mmap.start,
  15. (void *)(long)event->mmap.len,
  16. (void *)(long)event->mmap.pgoff,
  17. event->mmap.filename);
  18. if (thread == NULL || map == NULL) {
  19. dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
  20. return 0;
  21. }
  22. thread__insert_map(thread, map);
  23. total_mmap++;
  24. return 0;
  25. }
  26. int
  27. process_task_event(event_t *event, unsigned long offset, unsigned long head)
  28. {
  29. struct thread *thread = threads__findnew(event->fork.pid);
  30. struct thread *parent = threads__findnew(event->fork.ppid);
  31. dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n",
  32. (void *)(offset + head),
  33. (void *)(long)(event->header.size),
  34. event->header.type == PERF_RECORD_FORK ? "FORK" : "EXIT",
  35. event->fork.pid, event->fork.tid,
  36. event->fork.ppid, event->fork.ptid);
  37. /*
  38. * A thread clone will have the same PID for both
  39. * parent and child.
  40. */
  41. if (thread == parent)
  42. return 0;
  43. if (event->header.type == PERF_RECORD_EXIT)
  44. return 0;
  45. if (!thread || !parent || thread__fork(thread, parent)) {
  46. dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
  47. return -1;
  48. }
  49. total_fork++;
  50. return 0;
  51. }