aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/data_map.c4
-rw-r--r--tools/perf/util/event.c18
-rw-r--r--tools/perf/util/event.h4
-rw-r--r--tools/perf/util/session.c4
-rw-r--r--tools/perf/util/session.h5
-rw-r--r--tools/perf/util/thread.c22
-rw-r--r--tools/perf/util/thread.h4
7 files changed, 33 insertions, 28 deletions
diff --git a/tools/perf/util/data_map.c b/tools/perf/util/data_map.c
index ba2eb2ce018a..44dea211cc65 100644
--- a/tools/perf/util/data_map.c
+++ b/tools/perf/util/data_map.c
@@ -125,9 +125,9 @@ out:
125 return err; 125 return err;
126} 126}
127 127
128static struct thread *perf_session__register_idle_thread(struct perf_session *self __used) 128static struct thread *perf_session__register_idle_thread(struct perf_session *self)
129{ 129{
130 struct thread *thread = threads__findnew(0); 130 struct thread *thread = perf_session__findnew(self, 0);
131 131
132 if (!thread || thread__set_comm(thread, "swapper")) { 132 if (!thread || thread__set_comm(thread, "swapper")) {
133 pr_err("problem inserting idle task.\n"); 133 pr_err("problem inserting idle task.\n");
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 40d8d842a21f..2d09c29b3a6c 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -189,9 +189,9 @@ void event__synthesize_threads(int (*process)(event_t *event,
189 189
190struct events_stats event__stats; 190struct events_stats event__stats;
191 191
192int event__process_comm(event_t *self, struct perf_session *session __used) 192int event__process_comm(event_t *self, struct perf_session *session)
193{ 193{
194 struct thread *thread = threads__findnew(self->comm.pid); 194 struct thread *thread = perf_session__findnew(session, self->comm.pid);
195 195
196 dump_printf(": %s:%d\n", self->comm.comm, self->comm.pid); 196 dump_printf(": %s:%d\n", self->comm.comm, self->comm.pid);
197 197
@@ -212,7 +212,7 @@ int event__process_lost(event_t *self, struct perf_session *session __used)
212 212
213int event__process_mmap(event_t *self, struct perf_session *session) 213int event__process_mmap(event_t *self, struct perf_session *session)
214{ 214{
215 struct thread *thread = threads__findnew(self->mmap.pid); 215 struct thread *thread = perf_session__findnew(session, self->mmap.pid);
216 struct map *map = map__new(&self->mmap, MAP__FUNCTION, 216 struct map *map = map__new(&self->mmap, MAP__FUNCTION,
217 session->cwd, session->cwdlen); 217 session->cwd, session->cwdlen);
218 218
@@ -231,10 +231,10 @@ int event__process_mmap(event_t *self, struct perf_session *session)
231 return 0; 231 return 0;
232} 232}
233 233
234int event__process_task(event_t *self, struct perf_session *session __used) 234int event__process_task(event_t *self, struct perf_session *session)
235{ 235{
236 struct thread *thread = threads__findnew(self->fork.pid); 236 struct thread *thread = perf_session__findnew(session, self->fork.pid);
237 struct thread *parent = threads__findnew(self->fork.ppid); 237 struct thread *parent = perf_session__findnew(session, self->fork.ppid);
238 238
239 dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid, 239 dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid,
240 self->fork.ppid, self->fork.ptid); 240 self->fork.ppid, self->fork.ptid);
@@ -300,11 +300,11 @@ try_again:
300 } 300 }
301} 301}
302 302
303int event__preprocess_sample(const event_t *self, struct addr_location *al, 303int event__preprocess_sample(const event_t *self, struct perf_session *session,
304 symbol_filter_t filter) 304 struct addr_location *al, symbol_filter_t filter)
305{ 305{
306 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 306 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
307 struct thread *thread = threads__findnew(self->ip.pid); 307 struct thread *thread = perf_session__findnew(session, self->ip.pid);
308 308
309 if (thread == NULL) 309 if (thread == NULL)
310 return -1; 310 return -1;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 6b6429b63da3..bb090257570e 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -177,8 +177,8 @@ int event__process_mmap(event_t *self, struct perf_session *session);
177int event__process_task(event_t *self, struct perf_session *session); 177int event__process_task(event_t *self, struct perf_session *session);
178 178
179struct addr_location; 179struct addr_location;
180int event__preprocess_sample(const event_t *self, struct addr_location *al, 180int event__preprocess_sample(const event_t *self, struct perf_session *session,
181 symbol_filter_t filter); 181 struct addr_location *al, symbol_filter_t filter);
182int event__parse_sample(event_t *event, u64 type, struct sample_data *data); 182int event__parse_sample(event_t *event, u64 type, struct sample_data *data);
183 183
184#endif /* __PERF_RECORD_H */ 184#endif /* __PERF_RECORD_H */
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 534a8770ee7f..09836a537fc5 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -51,7 +51,7 @@ out_close:
51struct perf_session *perf_session__new(const char *filename, int mode, 51struct perf_session *perf_session__new(const char *filename, int mode,
52 bool force) 52 bool force)
53{ 53{
54 size_t len = strlen(filename) + 1; 54 size_t len = filename ? strlen(filename) + 1 : 0;
55 struct perf_session *self = zalloc(sizeof(*self) + len); 55 struct perf_session *self = zalloc(sizeof(*self) + len);
56 56
57 if (self == NULL) 57 if (self == NULL)
@@ -61,6 +61,8 @@ struct perf_session *perf_session__new(const char *filename, int mode,
61 goto out_delete; 61 goto out_delete;
62 62
63 memcpy(self->filename, filename, len); 63 memcpy(self->filename, filename, len);
64 self->threads = RB_ROOT;
65 self->last_match = NULL;
64 self->mmap_window = 32; 66 self->mmap_window = 32;
65 self->cwd = NULL; 67 self->cwd = NULL;
66 self->cwdlen = 0; 68 self->cwdlen = 0;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 1e0da9ca31aa..1dbef7cdd489 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -3,11 +3,16 @@
3 3
4#include "event.h" 4#include "event.h"
5#include "header.h" 5#include "header.h"
6#include <linux/rbtree.h>
7
8struct thread;
6 9
7struct perf_session { 10struct perf_session {
8 struct perf_header header; 11 struct perf_header header;
9 unsigned long size; 12 unsigned long size;
10 unsigned long mmap_window; 13 unsigned long mmap_window;
14 struct rb_root threads;
15 struct thread *last_match;
11 int fd; 16 int fd;
12 int cwdlen; 17 int cwdlen;
13 char *cwd; 18 char *cwd;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 5c0ab14f3dba..634b7f7140d5 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -2,13 +2,11 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <string.h> 4#include <string.h>
5#include "session.h"
5#include "thread.h" 6#include "thread.h"
6#include "util.h" 7#include "util.h"
7#include "debug.h" 8#include "debug.h"
8 9
9static struct rb_root threads;
10static struct thread *last_match;
11
12void map_groups__init(struct map_groups *self) 10void map_groups__init(struct map_groups *self)
13{ 11{
14 int i; 12 int i;
@@ -122,9 +120,9 @@ static size_t thread__fprintf(struct thread *self, FILE *fp)
122 map_groups__fprintf(&self->mg, fp); 120 map_groups__fprintf(&self->mg, fp);
123} 121}
124 122
125struct thread *threads__findnew(pid_t pid) 123struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
126{ 124{
127 struct rb_node **p = &threads.rb_node; 125 struct rb_node **p = &self->threads.rb_node;
128 struct rb_node *parent = NULL; 126 struct rb_node *parent = NULL;
129 struct thread *th; 127 struct thread *th;
130 128
@@ -133,15 +131,15 @@ struct thread *threads__findnew(pid_t pid)
133 * so most of the time we dont have to look up 131 * so most of the time we dont have to look up
134 * the full rbtree: 132 * the full rbtree:
135 */ 133 */
136 if (last_match && last_match->pid == pid) 134 if (self->last_match && self->last_match->pid == pid)
137 return last_match; 135 return self->last_match;
138 136
139 while (*p != NULL) { 137 while (*p != NULL) {
140 parent = *p; 138 parent = *p;
141 th = rb_entry(parent, struct thread, rb_node); 139 th = rb_entry(parent, struct thread, rb_node);
142 140
143 if (th->pid == pid) { 141 if (th->pid == pid) {
144 last_match = th; 142 self->last_match = th;
145 return th; 143 return th;
146 } 144 }
147 145
@@ -154,8 +152,8 @@ struct thread *threads__findnew(pid_t pid)
154 th = thread__new(pid); 152 th = thread__new(pid);
155 if (th != NULL) { 153 if (th != NULL) {
156 rb_link_node(&th->rb_node, parent, p); 154 rb_link_node(&th->rb_node, parent, p);
157 rb_insert_color(&th->rb_node, &threads); 155 rb_insert_color(&th->rb_node, &self->threads);
158 last_match = th; 156 self->last_match = th;
159 } 157 }
160 158
161 return th; 159 return th;
@@ -269,12 +267,12 @@ int thread__fork(struct thread *self, struct thread *parent)
269 return 0; 267 return 0;
270} 268}
271 269
272size_t threads__fprintf(FILE *fp) 270size_t perf_session__fprintf(struct perf_session *self, FILE *fp)
273{ 271{
274 size_t ret = 0; 272 size_t ret = 0;
275 struct rb_node *nd; 273 struct rb_node *nd;
276 274
277 for (nd = rb_first(&threads); nd; nd = rb_next(nd)) { 275 for (nd = rb_first(&self->threads); nd; nd = rb_next(nd)) {
278 struct thread *pos = rb_entry(nd, struct thread, rb_node); 276 struct thread *pos = rb_entry(nd, struct thread, rb_node);
279 277
280 ret += thread__fprintf(pos, fp); 278 ret += thread__fprintf(pos, fp);
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 2e35e1f6bb43..e93abf2d9cb6 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -23,11 +23,11 @@ struct thread {
23void map_groups__init(struct map_groups *self); 23void map_groups__init(struct map_groups *self);
24int thread__set_comm(struct thread *self, const char *comm); 24int thread__set_comm(struct thread *self, const char *comm);
25int thread__comm_len(struct thread *self); 25int thread__comm_len(struct thread *self);
26struct thread *threads__findnew(pid_t pid); 26struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
27void thread__insert_map(struct thread *self, struct map *map); 27void thread__insert_map(struct thread *self, struct map *map);
28int thread__fork(struct thread *self, struct thread *parent); 28int thread__fork(struct thread *self, struct thread *parent);
29size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp); 29size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp);
30size_t threads__fprintf(FILE *fp); 30size_t perf_session__fprintf(struct perf_session *self, FILE *fp);
31 31
32void maps__insert(struct rb_root *maps, struct map *map); 32void maps__insert(struct rb_root *maps, struct map *map);
33struct map *maps__find(struct rb_root *maps, u64 addr); 33struct map *maps__find(struct rb_root *maps, u64 addr);