blob: 85e4c7c4fbde1fd5455ed0fa58375aac3934b445 [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;
Jiri Olsa792402f2015-06-26 11:29:07 +020010 char *comm;
Jiri Olsa38e89d22015-06-23 00:36:02 +020011};
12
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020013struct thread_map {
Jiri Olsa186fbb72015-06-23 00:36:05 +020014 atomic_t refcnt;
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020015 int nr;
Jiri Olsa38e89d22015-06-23 00:36:02 +020016 struct thread_map_data map[];
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020017};
18
Jiri Olsa59660942015-10-25 15:51:21 +010019struct thread_map_event;
20
Arnaldo Carvalho de Melo641556c2014-10-10 12:03:46 -030021struct thread_map *thread_map__new_dummy(void);
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020022struct thread_map *thread_map__new_by_pid(pid_t pid);
23struct thread_map *thread_map__new_by_tid(pid_t tid);
Arnaldo Carvalho de Melo0d37aa32012-01-19 14:08:15 -020024struct thread_map *thread_map__new_by_uid(uid_t uid);
25struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid);
Jiri Olsa59660942015-10-25 15:51:21 +010026struct thread_map *thread_map__new_event(struct thread_map_event *event);
David Ahernb52956c2012-02-08 09:32:52 -070027
Jiri Olsa186fbb72015-06-23 00:36:05 +020028struct thread_map *thread_map__get(struct thread_map *map);
29void thread_map__put(struct thread_map *map);
30
David Ahernb52956c2012-02-08 09:32:52 -070031struct thread_map *thread_map__new_str(const char *pid,
32 const char *tid, uid_t uid);
33
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020034size_t thread_map__fprintf(struct thread_map *threads, FILE *fp);
35
Namhyung Kimb3a319d2013-03-11 16:43:14 +090036static inline int thread_map__nr(struct thread_map *threads)
37{
38 return threads ? threads->nr : 1;
39}
40
Jiri Olsae13798c2015-06-23 00:36:02 +020041static inline pid_t thread_map__pid(struct thread_map *map, int thread)
42{
Jiri Olsa38e89d22015-06-23 00:36:02 +020043 return map->map[thread].pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020044}
45
46static inline void
47thread_map__set_pid(struct thread_map *map, int thread, pid_t pid)
48{
Jiri Olsa38e89d22015-06-23 00:36:02 +020049 map->map[thread].pid = pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020050}
Jiri Olsa792402f2015-06-26 11:29:07 +020051
52static inline char *thread_map__comm(struct thread_map *map, int thread)
53{
54 return map->map[thread].comm;
55}
56
57void thread_map__read_comms(struct thread_map *threads);
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020058#endif /* __PERF_THREAD_MAP_H */