aboutsummaryrefslogtreecommitdiffstats
path: root/tools
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
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')
-rw-r--r--tools/perf/builtin-annotate.c3
-rw-r--r--tools/perf/builtin-kmem.c3
-rw-r--r--tools/perf/builtin-report.c6
-rw-r--r--tools/perf/builtin-sched.c3
-rw-r--r--tools/perf/builtin-timechart.c3
-rw-r--r--tools/perf/builtin-trace.c3
-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
10 files changed, 35 insertions, 37 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 93d765a746f2..a931b133f3ac 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -469,8 +469,7 @@ static int __cmd_annotate(void)
469 if (session == NULL) 469 if (session == NULL)
470 return -ENOMEM; 470 return -ENOMEM;
471 471
472 ret = perf_session__process_events(session, &event_ops, 0, 472 ret = perf_session__process_events(session, &event_ops);
473 &event__cwdlen, &event__cwd);
474 if (ret) 473 if (ret)
475 goto out_delete; 474 goto out_delete;
476 475
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 37a849906afe..237155fa756b 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -372,8 +372,7 @@ static int read_events(void)
372 if (session == NULL) 372 if (session == NULL)
373 return -ENOMEM; 373 return -ENOMEM;
374 374
375 err = perf_session__process_events(session, &event_ops, 0, 375 err = perf_session__process_events(session, &event_ops);
376 &event__cwdlen, &event__cwd);
377 perf_session__delete(session); 376 perf_session__delete(session);
378 return err; 377 return err;
379} 378}
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 4b37ac4f128b..26b947860948 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -39,7 +39,6 @@ static struct strlist *dso_list, *comm_list, *sym_list;
39 39
40static int force; 40static int force;
41 41
42static int full_paths;
43static int show_nr_samples; 42static int show_nr_samples;
44 43
45static int show_threads; 44static int show_threads;
@@ -771,8 +770,7 @@ static int __cmd_report(void)
771 if (show_threads) 770 if (show_threads)
772 perf_read_values_init(&show_threads_values); 771 perf_read_values_init(&show_threads_values);
773 772
774 ret = perf_session__process_events(session, &event_ops, full_paths, 773 ret = perf_session__process_events(session, &event_ops);
775 &event__cwdlen, &event__cwd);
776 if (ret) 774 if (ret)
777 goto out_delete; 775 goto out_delete;
778 776
@@ -877,7 +875,7 @@ static const struct option options[] = {
877 "pretty printing style key: normal raw"), 875 "pretty printing style key: normal raw"),
878 OPT_STRING('s', "sort", &sort_order, "key[,key2...]", 876 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
879 "sort by key(s): pid, comm, dso, symbol, parent"), 877 "sort by key(s): pid, comm, dso, symbol, parent"),
880 OPT_BOOLEAN('P', "full-paths", &full_paths, 878 OPT_BOOLEAN('P', "full-paths", &event_ops.full_paths,
881 "Don't shorten the pathnames taking into account the cwd"), 879 "Don't shorten the pathnames taking into account the cwd"),
882 OPT_STRING('p', "parent", &parent_pattern, "regex", 880 OPT_STRING('p', "parent", &parent_pattern, "regex",
883 "regex filter to identify parent, see: '--sort parent'"), 881 "regex filter to identify parent, see: '--sort parent'"),
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 847ed51248b1..1e4e508339a8 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1670,8 +1670,7 @@ static int read_events(void)
1670 if (session == NULL) 1670 if (session == NULL)
1671 return -ENOMEM; 1671 return -ENOMEM;
1672 1672
1673 err = perf_session__process_events(session, &event_ops, 0, 1673 err = perf_session__process_events(session, &event_ops);
1674 &event__cwdlen, &event__cwd);
1675 perf_session__delete(session); 1674 perf_session__delete(session);
1676 return err; 1675 return err;
1677} 1676}
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 4b95cec6b4c5..b5211facddc6 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1062,8 +1062,7 @@ static int __cmd_timechart(void)
1062 if (session == NULL) 1062 if (session == NULL)
1063 return -ENOMEM; 1063 return -ENOMEM;
1064 1064
1065 ret = perf_session__process_events(session, &event_ops, 0, 1065 ret = perf_session__process_events(session, &event_ops);
1066 &event__cwdlen, &event__cwd);
1067 if (ret) 1066 if (ret)
1068 goto out_delete; 1067 goto out_delete;
1069 1068
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 40cb896581dd..b7eb3fcc224e 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -125,8 +125,7 @@ static struct perf_event_ops event_ops = {
125 125
126static int __cmd_trace(struct perf_session *session) 126static int __cmd_trace(struct perf_session *session)
127{ 127{
128 return perf_session__process_events(session, &event_ops, 0, 128 return perf_session__process_events(session, &event_ops);
129 &event__cwdlen, &event__cwd);
130} 129}
131 130
132struct script_spec { 131struct script_spec {
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