aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-12-13 16:50:27 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-14 10:57:16 -0500
commitec913369733923dbfd6bdff5953a918107059701 (patch)
tree4c4397f5de47bb1352bfed874919bb438b6e4816 /tools/perf/util
parent13df45ca1c9a430d5f53862854070fcc324e015c (diff)
perf session: Reduce the number of parms to perf_session__process_events
By having the cwd/cwdlen in the perf_session struct and full_paths in perf_event_ops. Now its just a matter of passing the ops. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1260741029-4430-4-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/data_map.c32
-rw-r--r--tools/perf/util/event.c8
-rw-r--r--tools/perf/util/session.c4
-rw-r--r--tools/perf/util/session.h7
4 files changed, 28 insertions, 23 deletions
diff --git a/tools/perf/util/data_map.c b/tools/perf/util/data_map.c
index 36e3bfe73196..ba2eb2ce018a 100644
--- a/tools/perf/util/data_map.c
+++ b/tools/perf/util/data_map.c
@@ -4,9 +4,6 @@
4#include "thread.h" 4#include "thread.h"
5#include "session.h" 5#include "session.h"
6 6
7static unsigned long mmap_window = 32;
8static char __cwd[PATH_MAX];
9
10static int process_event_stub(event_t *event __used, 7static int process_event_stub(event_t *event __used,
11 struct perf_session *session __used) 8 struct perf_session *session __used)
12{ 9{
@@ -141,8 +138,7 @@ static struct thread *perf_session__register_idle_thread(struct perf_session *se
141} 138}
142 139
143int perf_session__process_events(struct perf_session *self, 140int perf_session__process_events(struct perf_session *self,
144 struct perf_event_ops *ops, 141 struct perf_event_ops *ops)
145 int full_paths, int *cwdlen, char **cwd)
146{ 142{
147 int err; 143 int err;
148 unsigned long head, shift; 144 unsigned long head, shift;
@@ -168,17 +164,21 @@ int perf_session__process_events(struct perf_session *self,
168 ops->sample_type_check(sample_type) < 0) 164 ops->sample_type_check(sample_type) < 0)
169 goto out_err; 165 goto out_err;
170 166
171 if (!full_paths) { 167 if (!ops->full_paths) {
172 if (getcwd(__cwd, sizeof(__cwd)) == NULL) { 168 char bf[PATH_MAX];
173 pr_err("failed to get the current directory\n"); 169
170 if (getcwd(bf, sizeof(bf)) == NULL) {
174 err = -errno; 171 err = -errno;
172out_getcwd_err:
173 pr_err("failed to get the current directory\n");
175 goto out_err; 174 goto out_err;
176 } 175 }
177 *cwd = __cwd; 176 self->cwd = strdup(bf);
178 *cwdlen = strlen(*cwd); 177 if (self->cwd == NULL) {
179 } else { 178 err = -ENOMEM;
180 *cwd = NULL; 179 goto out_getcwd_err;
181 *cwdlen = 0; 180 }
181 self->cwdlen = strlen(self->cwd);
182 } 182 }
183 183
184 shift = page_size * (head / page_size); 184 shift = page_size * (head / page_size);
@@ -186,7 +186,7 @@ int perf_session__process_events(struct perf_session *self,
186 head -= shift; 186 head -= shift;
187 187
188remap: 188remap:
189 buf = mmap(NULL, page_size * mmap_window, PROT_READ, 189 buf = mmap(NULL, page_size * self->mmap_window, PROT_READ,
190 MAP_SHARED, self->fd, offset); 190 MAP_SHARED, self->fd, offset);
191 if (buf == MAP_FAILED) { 191 if (buf == MAP_FAILED) {
192 pr_err("failed to mmap file\n"); 192 pr_err("failed to mmap file\n");
@@ -201,12 +201,12 @@ more:
201 if (!size) 201 if (!size)
202 size = 8; 202 size = 8;
203 203
204 if (head + event->header.size >= page_size * mmap_window) { 204 if (head + event->header.size >= page_size * self->mmap_window) {
205 int munmap_ret; 205 int munmap_ret;
206 206
207 shift = page_size * (head / page_size); 207 shift = page_size * (head / page_size);
208 208
209 munmap_ret = munmap(buf, page_size * mmap_window); 209 munmap_ret = munmap(buf, page_size * self->mmap_window);
210 assert(munmap_ret == 0); 210 assert(munmap_ret == 0);
211 211
212 offset += shift; 212 offset += shift;
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index e2c489533c6d..40d8d842a21f 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1,6 +1,7 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include "event.h" 2#include "event.h"
3#include "debug.h" 3#include "debug.h"
4#include "session.h"
4#include "string.h" 5#include "string.h"
5#include "thread.h" 6#include "thread.h"
6 7
@@ -186,9 +187,6 @@ void event__synthesize_threads(int (*process)(event_t *event,
186 closedir(proc); 187 closedir(proc);
187} 188}
188 189
189char *event__cwd;
190int event__cwdlen;
191
192struct events_stats event__stats; 190struct events_stats event__stats;
193 191
194int event__process_comm(event_t *self, struct perf_session *session __used) 192int event__process_comm(event_t *self, struct perf_session *session __used)
@@ -212,11 +210,11 @@ int event__process_lost(event_t *self, struct perf_session *session __used)
212 return 0; 210 return 0;
213} 211}
214 212
215int event__process_mmap(event_t *self, struct perf_session *session __used) 213int event__process_mmap(event_t *self, struct perf_session *session)
216{ 214{
217 struct thread *thread = threads__findnew(self->mmap.pid); 215 struct thread *thread = threads__findnew(self->mmap.pid);
218 struct map *map = map__new(&self->mmap, MAP__FUNCTION, 216 struct map *map = map__new(&self->mmap, MAP__FUNCTION,
219 event__cwd, event__cwdlen); 217 session->cwd, session->cwdlen);
220 218
221 dump_printf(" %d/%d: [%p(%p) @ %p]: %s\n", 219 dump_printf(" %d/%d: [%p(%p) @ %p]: %s\n",
222 self->mmap.pid, self->mmap.tid, 220 self->mmap.pid, self->mmap.tid,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 39766868d43a..534a8770ee7f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -61,6 +61,9 @@ 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->mmap_window = 32;
65 self->cwd = NULL;
66 self->cwdlen = 0;
64 67
65 if (mode == O_RDONLY && perf_session__open(self, force) < 0) { 68 if (mode == O_RDONLY && perf_session__open(self, force) < 0) {
66 perf_session__delete(self); 69 perf_session__delete(self);
@@ -77,5 +80,6 @@ void perf_session__delete(struct perf_session *self)
77{ 80{
78 perf_header__exit(&self->header); 81 perf_header__exit(&self->header);
79 close(self->fd); 82 close(self->fd);
83 free(self->cwd);
80 free(self); 84 free(self);
81} 85}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 7a4c32c545f4..1e0da9ca31aa 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -7,7 +7,10 @@
7struct perf_session { 7struct perf_session {
8 struct perf_header header; 8 struct perf_header header;
9 unsigned long size; 9 unsigned long size;
10 unsigned long mmap_window;
10 int fd; 11 int fd;
12 int cwdlen;
13 char *cwd;
11 char filename[0]; 14 char filename[0];
12}; 15};
13 16
@@ -25,6 +28,7 @@ struct perf_event_ops {
25 event_op process_unthrottle_event; 28 event_op process_unthrottle_event;
26 int (*sample_type_check)(u64 sample_type); 29 int (*sample_type_check)(u64 sample_type);
27 unsigned long total_unknown; 30 unsigned long total_unknown;
31 bool full_paths;
28}; 32};
29 33
30struct perf_session *perf_session__new(const char *filename, int mode, 34struct perf_session *perf_session__new(const char *filename, int mode,
@@ -32,8 +36,7 @@ struct perf_session *perf_session__new(const char *filename, int mode,
32void perf_session__delete(struct perf_session *self); 36void perf_session__delete(struct perf_session *self);
33 37
34int perf_session__process_events(struct perf_session *self, 38int perf_session__process_events(struct perf_session *self,
35 struct perf_event_ops *event_ops, 39 struct perf_event_ops *event_ops);
36 int full_paths, int *cwdlen, char **cwd);
37 40
38int perf_header__read_build_ids(int input, u64 offset, u64 file_size); 41int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
39 42