John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 1 | #ifndef __PERF_THREAD_H |
| 2 | #define __PERF_THREAD_H |
| 3 | |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 4 | #include <linux/rbtree.h> |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 5 | #include <linux/list.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 6 | #include <unistd.h> |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 7 | #include <sys/types.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 8 | #include "symbol.h" |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame^] | 9 | #include <strlist.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 10 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 11 | struct thread { |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 12 | union { |
| 13 | struct rb_node rb_node; |
| 14 | struct list_head node; |
| 15 | }; |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 16 | struct map_groups mg; |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 17 | pid_t pid_; /* Not all tools update this */ |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 18 | pid_t tid; |
David Ahern | 70c57ef | 2013-05-25 22:47:10 -0600 | [diff] [blame] | 19 | pid_t ppid; |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 20 | char shortname[3]; |
Arnaldo Carvalho de Melo | faa5c5c | 2010-02-19 23:02:07 -0200 | [diff] [blame] | 21 | bool comm_set; |
David Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 22 | bool dead; /* if set thread has exited */ |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 23 | struct list_head comm_list; |
Frederic Weisbecker | a4fb581 | 2009-10-22 23:23:23 +0200 | [diff] [blame] | 24 | int comm_len; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 25 | |
| 26 | void *priv; |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 29 | struct machine; |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 30 | struct comm; |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 31 | |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 32 | struct thread *thread__new(pid_t pid, pid_t tid); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 33 | void thread__delete(struct thread *thread); |
David Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 34 | static inline void thread__exited(struct thread *thread) |
| 35 | { |
| 36 | thread->dead = true; |
| 37 | } |
Arnaldo Carvalho de Melo | 591765f | 2010-07-30 18:28:42 -0300 | [diff] [blame] | 38 | |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 39 | int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 40 | int thread__comm_len(struct thread *thread); |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 41 | struct comm *thread__comm(const struct thread *thread); |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 42 | const char *thread__comm_str(const struct thread *thread); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 43 | void thread__insert_map(struct thread *thread, struct map *map); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 44 | int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp); |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 45 | size_t thread__fprintf(struct thread *thread, FILE *fp); |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 46 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 47 | static inline struct map *thread__find_map(struct thread *thread, |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 48 | enum map_type type, u64 addr) |
Arnaldo Carvalho de Melo | 1b46cdd | 2009-09-28 14:48:46 -0300 | [diff] [blame] | 49 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 50 | return thread ? map_groups__find(&thread->mg, type, addr) : NULL; |
Arnaldo Carvalho de Melo | 95011c6 | 2009-11-27 16:29:20 -0200 | [diff] [blame] | 51 | } |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 52 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 53 | void thread__find_addr_map(struct thread *thread, struct machine *machine, |
| 54 | u8 cpumode, enum map_type type, u64 addr, |
Adrian Hunter | 326f59b | 2013-08-08 14:32:27 +0300 | [diff] [blame] | 55 | struct addr_location *al); |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 56 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 57 | void thread__find_addr_location(struct thread *thread, struct machine *machine, |
| 58 | u8 cpumode, enum map_type type, u64 addr, |
Adrian Hunter | 61710bd | 2013-08-08 14:32:26 +0300 | [diff] [blame] | 59 | struct addr_location *al); |
David Ahern | ba58041 | 2013-06-07 16:22:12 -0600 | [diff] [blame] | 60 | |
| 61 | static inline void *thread__priv(struct thread *thread) |
| 62 | { |
| 63 | return thread->priv; |
| 64 | } |
| 65 | |
| 66 | static inline void thread__set_priv(struct thread *thread, void *p) |
| 67 | { |
| 68 | thread->priv = p; |
| 69 | } |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame^] | 70 | |
| 71 | static inline bool thread__is_filtered(struct thread *thread) |
| 72 | { |
| 73 | if (symbol_conf.comm_list && |
| 74 | !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) { |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 81 | #endif /* __PERF_THREAD_H */ |