thread.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef __PERF_THREAD_H
  2. #define __PERF_THREAD_H
  3. #include <linux/rbtree.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include "symbol.h"
  7. struct thread {
  8. union {
  9. struct rb_node rb_node;
  10. struct list_head node;
  11. };
  12. struct map_groups mg;
  13. pid_t pid_; /* Not all tools update this */
  14. pid_t tid;
  15. pid_t ppid;
  16. char shortname[3];
  17. bool comm_set;
  18. bool dead; /* if set thread has exited */
  19. char *comm;
  20. int comm_len;
  21. void *priv;
  22. };
  23. struct machine;
  24. struct thread *thread__new(pid_t pid, pid_t tid);
  25. void thread__delete(struct thread *self);
  26. static inline void thread__exited(struct thread *thread)
  27. {
  28. thread->dead = true;
  29. }
  30. int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp);
  31. int thread__comm_len(struct thread *self);
  32. const char *thread__comm_str(const struct thread *thread);
  33. void thread__insert_map(struct thread *self, struct map *map);
  34. int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
  35. size_t thread__fprintf(struct thread *thread, FILE *fp);
  36. static inline struct map *thread__find_map(struct thread *self,
  37. enum map_type type, u64 addr)
  38. {
  39. return self ? map_groups__find(&self->mg, type, addr) : NULL;
  40. }
  41. void thread__find_addr_map(struct thread *thread, struct machine *machine,
  42. u8 cpumode, enum map_type type, u64 addr,
  43. struct addr_location *al);
  44. void thread__find_addr_location(struct thread *thread, struct machine *machine,
  45. u8 cpumode, enum map_type type, u64 addr,
  46. struct addr_location *al);
  47. static inline void *thread__priv(struct thread *thread)
  48. {
  49. return thread->priv;
  50. }
  51. static inline void thread__set_priv(struct thread *thread, void *p)
  52. {
  53. thread->priv = p;
  54. }
  55. #endif /* __PERF_THREAD_H */