blob: 6b0cd2dc006b04e9f02ba851fdb547107f70fd70 [file] [log] [blame]
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -02001#ifndef __PERF_THREAD_MAP_H
2#define __PERF_THREAD_MAP_H
3
4#include <sys/types.h>
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -02005#include <stdio.h>
Jiri Olsa186fbb72015-06-23 00:36:05 +02006#include <linux/atomic.h>
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -02007
Jiri Olsa38e89d22015-06-23 00:36:02 +02008struct thread_map_data {
9 pid_t pid;
10};
11
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020012struct thread_map {
Jiri Olsa186fbb72015-06-23 00:36:05 +020013 atomic_t refcnt;
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020014 int nr;
Jiri Olsa38e89d22015-06-23 00:36:02 +020015 struct thread_map_data map[];
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020016};
17
Arnaldo Carvalho de Melo641556c2014-10-10 12:03:46 -030018struct thread_map *thread_map__new_dummy(void);
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020019struct thread_map *thread_map__new_by_pid(pid_t pid);
20struct thread_map *thread_map__new_by_tid(pid_t tid);
Arnaldo Carvalho de Melo0d37aa32012-01-19 14:08:15 -020021struct thread_map *thread_map__new_by_uid(uid_t uid);
22struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid);
David Ahernb52956c2012-02-08 09:32:52 -070023
Jiri Olsa186fbb72015-06-23 00:36:05 +020024struct thread_map *thread_map__get(struct thread_map *map);
25void thread_map__put(struct thread_map *map);
26
David Ahernb52956c2012-02-08 09:32:52 -070027struct thread_map *thread_map__new_str(const char *pid,
28 const char *tid, uid_t uid);
29
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020030size_t thread_map__fprintf(struct thread_map *threads, FILE *fp);
31
Namhyung Kimb3a319d2013-03-11 16:43:14 +090032static inline int thread_map__nr(struct thread_map *threads)
33{
34 return threads ? threads->nr : 1;
35}
36
Jiri Olsae13798c2015-06-23 00:36:02 +020037static inline pid_t thread_map__pid(struct thread_map *map, int thread)
38{
Jiri Olsa38e89d22015-06-23 00:36:02 +020039 return map->map[thread].pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020040}
41
42static inline void
43thread_map__set_pid(struct thread_map *map, int thread, pid_t pid)
44{
Jiri Olsa38e89d22015-06-23 00:36:02 +020045 map->map[thread].pid = pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020046}
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020047#endif /* __PERF_THREAD_MAP_H */