blob: bd3b971588da57ce14951df6d0a0870a6def1355 [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
Jiri Olsa097be0f2016-04-12 15:29:28 +020034struct thread_map *thread_map__new_by_tid_str(const char *tid_str);
35
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020036size_t thread_map__fprintf(struct thread_map *threads, FILE *fp);
37
Namhyung Kimb3a319d2013-03-11 16:43:14 +090038static inline int thread_map__nr(struct thread_map *threads)
39{
40 return threads ? threads->nr : 1;
41}
42
Jiri Olsae13798c2015-06-23 00:36:02 +020043static inline pid_t thread_map__pid(struct thread_map *map, int thread)
44{
Jiri Olsa38e89d22015-06-23 00:36:02 +020045 return map->map[thread].pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020046}
47
48static inline void
49thread_map__set_pid(struct thread_map *map, int thread, pid_t pid)
50{
Jiri Olsa38e89d22015-06-23 00:36:02 +020051 map->map[thread].pid = pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020052}
Jiri Olsa792402f2015-06-26 11:29:07 +020053
54static inline char *thread_map__comm(struct thread_map *map, int thread)
55{
56 return map->map[thread].comm;
57}
58
59void thread_map__read_comms(struct thread_map *threads);
Jiri Olsa3407df82016-04-12 15:29:24 +020060bool thread_map__has(struct thread_map *threads, pid_t pid);
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020061#endif /* __PERF_THREAD_MAP_H */