Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 1 | #ifndef __PERF_THREAD_MAP_H |
| 2 | #define __PERF_THREAD_MAP_H |
| 3 | |
| 4 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | 9ae7d33 | 2012-01-19 14:07:23 -0200 | [diff] [blame] | 5 | #include <stdio.h> |
Jiri Olsa | 186fbb7 | 2015-06-23 00:36:05 +0200 | [diff] [blame] | 6 | #include <linux/atomic.h> |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 7 | |
Jiri Olsa | 38e89d2 | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 8 | struct thread_map_data { |
| 9 | pid_t pid; |
Jiri Olsa | 792402f | 2015-06-26 11:29:07 +0200 | [diff] [blame] | 10 | char *comm; |
Jiri Olsa | 38e89d2 | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 11 | }; |
| 12 | |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 13 | struct thread_map { |
Jiri Olsa | 186fbb7 | 2015-06-23 00:36:05 +0200 | [diff] [blame] | 14 | atomic_t refcnt; |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 15 | int nr; |
Jiri Olsa | 38e89d2 | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 16 | struct thread_map_data map[]; |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 17 | }; |
| 18 | |
Jiri Olsa | 5966094 | 2015-10-25 15:51:21 +0100 | [diff] [blame] | 19 | struct thread_map_event; |
| 20 | |
Arnaldo Carvalho de Melo | 641556c | 2014-10-10 12:03:46 -0300 | [diff] [blame] | 21 | struct thread_map *thread_map__new_dummy(void); |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 22 | struct thread_map *thread_map__new_by_pid(pid_t pid); |
| 23 | struct thread_map *thread_map__new_by_tid(pid_t tid); |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 24 | struct thread_map *thread_map__new_by_uid(uid_t uid); |
| 25 | struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid); |
Jiri Olsa | 5966094 | 2015-10-25 15:51:21 +0100 | [diff] [blame] | 26 | struct thread_map *thread_map__new_event(struct thread_map_event *event); |
David Ahern | b52956c | 2012-02-08 09:32:52 -0700 | [diff] [blame] | 27 | |
Jiri Olsa | 186fbb7 | 2015-06-23 00:36:05 +0200 | [diff] [blame] | 28 | struct thread_map *thread_map__get(struct thread_map *map); |
| 29 | void thread_map__put(struct thread_map *map); |
| 30 | |
David Ahern | b52956c | 2012-02-08 09:32:52 -0700 | [diff] [blame] | 31 | struct thread_map *thread_map__new_str(const char *pid, |
| 32 | const char *tid, uid_t uid); |
| 33 | |
Jiri Olsa | 097be0f | 2016-04-12 15:29:28 +0200 | [diff] [blame] | 34 | struct thread_map *thread_map__new_by_tid_str(const char *tid_str); |
| 35 | |
Arnaldo Carvalho de Melo | 9ae7d33 | 2012-01-19 14:07:23 -0200 | [diff] [blame] | 36 | size_t thread_map__fprintf(struct thread_map *threads, FILE *fp); |
| 37 | |
Namhyung Kim | b3a319d | 2013-03-11 16:43:14 +0900 | [diff] [blame] | 38 | static inline int thread_map__nr(struct thread_map *threads) |
| 39 | { |
| 40 | return threads ? threads->nr : 1; |
| 41 | } |
| 42 | |
Jiri Olsa | e13798c | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 43 | static inline pid_t thread_map__pid(struct thread_map *map, int thread) |
| 44 | { |
Jiri Olsa | 38e89d2 | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 45 | return map->map[thread].pid; |
Jiri Olsa | e13798c | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static inline void |
| 49 | thread_map__set_pid(struct thread_map *map, int thread, pid_t pid) |
| 50 | { |
Jiri Olsa | 38e89d2 | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 51 | map->map[thread].pid = pid; |
Jiri Olsa | e13798c | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 52 | } |
Jiri Olsa | 792402f | 2015-06-26 11:29:07 +0200 | [diff] [blame] | 53 | |
| 54 | static inline char *thread_map__comm(struct thread_map *map, int thread) |
| 55 | { |
| 56 | return map->map[thread].comm; |
| 57 | } |
| 58 | |
| 59 | void thread_map__read_comms(struct thread_map *threads); |
Jiri Olsa | 3407df8 | 2016-04-12 15:29:24 +0200 | [diff] [blame] | 60 | bool thread_map__has(struct thread_map *threads, pid_t pid); |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 61 | #endif /* __PERF_THREAD_MAP_H */ |