blob: af679d8a50f852ebb3457491f5dc4b96f6520743 [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
Arnaldo Carvalho de Melo641556c2014-10-10 12:03:46 -030019struct thread_map *thread_map__new_dummy(void);
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020020struct thread_map *thread_map__new_by_pid(pid_t pid);
21struct thread_map *thread_map__new_by_tid(pid_t tid);
Arnaldo Carvalho de Melo0d37aa32012-01-19 14:08:15 -020022struct thread_map *thread_map__new_by_uid(uid_t uid);
23struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid);
David Ahernb52956c2012-02-08 09:32:52 -070024
Jiri Olsa186fbb72015-06-23 00:36:05 +020025struct thread_map *thread_map__get(struct thread_map *map);
26void thread_map__put(struct thread_map *map);
27
David Ahernb52956c2012-02-08 09:32:52 -070028struct thread_map *thread_map__new_str(const char *pid,
29 const char *tid, uid_t uid);
30
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020031size_t thread_map__fprintf(struct thread_map *threads, FILE *fp);
32
Namhyung Kimb3a319d2013-03-11 16:43:14 +090033static inline int thread_map__nr(struct thread_map *threads)
34{
35 return threads ? threads->nr : 1;
36}
37
Jiri Olsae13798c2015-06-23 00:36:02 +020038static inline pid_t thread_map__pid(struct thread_map *map, int thread)
39{
Jiri Olsa38e89d22015-06-23 00:36:02 +020040 return map->map[thread].pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020041}
42
43static inline void
44thread_map__set_pid(struct thread_map *map, int thread, pid_t pid)
45{
Jiri Olsa38e89d22015-06-23 00:36:02 +020046 map->map[thread].pid = pid;
Jiri Olsae13798c2015-06-23 00:36:02 +020047}
Jiri Olsa792402f2015-06-26 11:29:07 +020048
49static inline char *thread_map__comm(struct thread_map *map, int thread)
50{
51 return map->map[thread].comm;
52}
53
54void thread_map__read_comms(struct thread_map *threads);
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020055#endif /* __PERF_THREAD_MAP_H */