blob: 4ebbb40d46d43e13cc78010601611eb30e5c7498 [file] [log] [blame]
John Kacur8b40f522009-09-24 18:02:18 +02001#ifndef __PERF_THREAD_H
2#define __PERF_THREAD_H
3
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +02004#include <linux/rbtree.h>
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +02005#include <unistd.h>
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -03006#include <sys/types.h>
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +02007#include "symbol.h"
8
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -02009struct thread {
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -030010 union {
11 struct rb_node rb_node;
12 struct list_head node;
13 };
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -020014 struct map_groups mg;
Adrian Hunter99d725f2013-08-26 16:00:19 +030015 pid_t pid_; /* Not all tools update this */
Adrian Hunter38051232013-07-04 16:20:31 +030016 pid_t tid;
David Ahern70c57ef2013-05-25 22:47:10 -060017 pid_t ppid;
Ingo Molnar0ec04e12009-09-16 17:40:48 +020018 char shortname[3];
Arnaldo Carvalho de Melofaa5c5c2010-02-19 23:02:07 -020019 bool comm_set;
David Ahern236a3bb2013-08-14 08:49:27 -060020 bool dead; /* if set thread has exited */
Ingo Molnarb5fae122009-09-11 12:12:54 +020021 char *comm;
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +020022 int comm_len;
Xiao Guangrongbcf6edc2012-09-17 16:31:15 +080023
24 void *priv;
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020025};
26
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020027struct machine;
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -030028
Adrian Hunter99d725f2013-08-26 16:00:19 +030029struct thread *thread__new(pid_t pid, pid_t tid);
Arnaldo Carvalho de Melo591765f2010-07-30 18:28:42 -030030void thread__delete(struct thread *self);
David Ahern236a3bb2013-08-14 08:49:27 -060031static inline void thread__exited(struct thread *thread)
32{
33 thread->dead = true;
34}
Arnaldo Carvalho de Melo591765f2010-07-30 18:28:42 -030035
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020036int thread__set_comm(struct thread *self, const char *comm);
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +020037int thread__comm_len(struct thread *self);
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020038void thread__insert_map(struct thread *self, struct map *map);
39int thread__fork(struct thread *self, struct thread *parent);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -030040size_t thread__fprintf(struct thread *thread, FILE *fp);
John Kacur8b40f522009-09-24 18:02:18 +020041
Arnaldo Carvalho de Melo95011c62009-11-27 16:29:20 -020042static inline struct map *thread__find_map(struct thread *self,
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020043 enum map_type type, u64 addr)
Arnaldo Carvalho de Melo1b46cdd2009-09-28 14:48:46 -030044{
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -020045 return self ? map_groups__find(&self->mg, type, addr) : NULL;
Arnaldo Carvalho de Melo95011c62009-11-27 16:29:20 -020046}
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020047
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020048void thread__find_addr_map(struct thread *thread, struct machine *machine,
49 u8 cpumode, enum map_type type, u64 addr,
Adrian Hunter326f59b2013-08-08 14:32:27 +030050 struct addr_location *al);
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -020051
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020052void thread__find_addr_location(struct thread *thread, struct machine *machine,
53 u8 cpumode, enum map_type type, u64 addr,
Adrian Hunter61710bd2013-08-08 14:32:26 +030054 struct addr_location *al);
David Ahernba580412013-06-07 16:22:12 -060055
56static inline void *thread__priv(struct thread *thread)
57{
58 return thread->priv;
59}
60
61static inline void thread__set_priv(struct thread *thread, void *p)
62{
63 thread->priv = p;
64}
John Kacur8b40f522009-09-24 18:02:18 +020065#endif /* __PERF_THREAD_H */