aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-06-30 18:01:20 -0400
committerIngo Molnar <mingo@elte.hu>2009-06-30 18:07:09 -0400
commit25903407da21552419e0955705d6d8c8e601cb2e (patch)
tree5270f2817f367d9f4930983f7395612621b0b0c8 /tools/perf
parentf5812a7a336fb952d819e4427b9a2dce02368e82 (diff)
perf report: Add --dsos parameter
So that we can filter by dso. Symbols in other dsos won't be accounted for. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1246399282-20934-2-git-send-email-acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Documentation/perf-report.txt4
-rw-r--r--tools/perf/Makefile2
-rw-r--r--tools/perf/builtin-report.c16
-rw-r--r--tools/perf/util/strlist.c184
-rw-r--r--tools/perf/util/strlist.h32
5 files changed, 238 insertions, 0 deletions
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 40c1db83a16..13d85ca8c91 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -20,6 +20,10 @@ OPTIONS
20-i:: 20-i::
21--input=:: 21--input=::
22 Input file name. (default: perf.data) 22 Input file name. (default: perf.data)
23-d::
24--dsos=::
25 Only consider symbols in these dsos. CSV that understands
26 file://filename entries.
23 27
24SEE ALSO 28SEE ALSO
25-------- 29--------
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 1c1296d8a64..9c6d0ae3708 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -301,6 +301,7 @@ LIB_H += util/util.h
301LIB_H += util/help.h 301LIB_H += util/help.h
302LIB_H += util/strbuf.h 302LIB_H += util/strbuf.h
303LIB_H += util/string.h 303LIB_H += util/string.h
304LIB_H += util/strlist.h
304LIB_H += util/run-command.h 305LIB_H += util/run-command.h
305LIB_H += util/sigchain.h 306LIB_H += util/sigchain.h
306LIB_H += util/symbol.h 307LIB_H += util/symbol.h
@@ -322,6 +323,7 @@ LIB_OBJS += util/run-command.o
322LIB_OBJS += util/quote.o 323LIB_OBJS += util/quote.o
323LIB_OBJS += util/strbuf.o 324LIB_OBJS += util/strbuf.o
324LIB_OBJS += util/string.o 325LIB_OBJS += util/string.o
326LIB_OBJS += util/strlist.o
325LIB_OBJS += util/usage.o 327LIB_OBJS += util/usage.o
326LIB_OBJS += util/wrapper.o 328LIB_OBJS += util/wrapper.o
327LIB_OBJS += util/sigchain.o 329LIB_OBJS += util/sigchain.o
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index ed391db9e0f..7c6b6e77671 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -16,6 +16,7 @@
16#include "util/symbol.h" 16#include "util/symbol.h"
17#include "util/string.h" 17#include "util/string.h"
18#include "util/callchain.h" 18#include "util/callchain.h"
19#include "util/strlist.h"
19 20
20#include "perf.h" 21#include "perf.h"
21#include "util/header.h" 22#include "util/header.h"
@@ -32,6 +33,8 @@ static char *vmlinux = NULL;
32 33
33static char default_sort_order[] = "comm,dso"; 34static char default_sort_order[] = "comm,dso";
34static char *sort_order = default_sort_order; 35static char *sort_order = default_sort_order;
36static char *dso_list_str;
37static struct strlist *dso_list;
35 38
36static int input; 39static int input;
37static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; 40static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
@@ -1272,6 +1275,9 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
1272 if (show & show_mask) { 1275 if (show & show_mask) {
1273 struct symbol *sym = resolve_symbol(thread, &map, &dso, &ip); 1276 struct symbol *sym = resolve_symbol(thread, &map, &dso, &ip);
1274 1277
1278 if (dso_list && dso && dso->name && !strlist__has_entry(dso_list, dso->name))
1279 return 0;
1280
1275 if (hist_entry__add(thread, map, dso, sym, ip, chain, level, period)) { 1281 if (hist_entry__add(thread, map, dso, sym, ip, chain, level, period)) {
1276 eprintf("problem incrementing symbol count, skipping event\n"); 1282 eprintf("problem incrementing symbol count, skipping event\n");
1277 return -1; 1283 return -1;
@@ -1659,6 +1665,8 @@ static const struct option options[] = {
1659 OPT_BOOLEAN('x', "exclude-other", &exclude_other, 1665 OPT_BOOLEAN('x', "exclude-other", &exclude_other,
1660 "Only display entries with parent-match"), 1666 "Only display entries with parent-match"),
1661 OPT_BOOLEAN('c', "callchain", &callchain, "Display callchains"), 1667 OPT_BOOLEAN('c', "callchain", &callchain, "Display callchains"),
1668 OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]",
1669 "only consider symbols in these dsos"),
1662 OPT_END() 1670 OPT_END()
1663}; 1671};
1664 1672
@@ -1698,6 +1706,14 @@ int cmd_report(int argc, const char **argv, const char *prefix)
1698 if (argc) 1706 if (argc)
1699 usage_with_options(report_usage, options); 1707 usage_with_options(report_usage, options);
1700 1708
1709 if (dso_list_str) {
1710 dso_list = strlist__new(true, dso_list_str);
1711 if (!dso_list) {
1712 fprintf(stderr, "problems parsing dso list\n");
1713 exit(129);
1714 }
1715 }
1716
1701 setup_pager(); 1717 setup_pager();
1702 1718
1703 return __cmd_report(); 1719 return __cmd_report();
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
new file mode 100644
index 00000000000..025a78edfff
--- /dev/null
+++ b/tools/perf/util/strlist.c
@@ -0,0 +1,184 @@
1/*
2 * (c) 2009 Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Licensed under the GPLv2.
5 */
6
7#include "strlist.h"
8#include <errno.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13static struct str_node *str_node__new(const char *s, bool dupstr)
14{
15 struct str_node *self = malloc(sizeof(*self));
16
17 if (self != NULL) {
18 if (dupstr) {
19 s = strdup(s);
20 if (s == NULL)
21 goto out_delete;
22 }
23 self->s = s;
24 }
25
26 return self;
27
28out_delete:
29 free(self);
30 return NULL;
31}
32
33static void str_node__delete(struct str_node *self, bool dupstr)
34{
35 if (dupstr)
36 free((void *)self->s);
37 free(self);
38}
39
40int strlist__add(struct strlist *self, const char *new_entry)
41{
42 struct rb_node **p = &self->entries.rb_node;
43 struct rb_node *parent = NULL;
44 struct str_node *sn;
45
46 while (*p != NULL) {
47 int rc;
48
49 parent = *p;
50 sn = rb_entry(parent, struct str_node, rb_node);
51 rc = strcmp(sn->s, new_entry);
52
53 if (rc > 0)
54 p = &(*p)->rb_left;
55 else if (rc < 0)
56 p = &(*p)->rb_right;
57 else
58 return -EEXIST;
59 }
60
61 sn = str_node__new(new_entry, self->dupstr);
62 if (sn == NULL)
63 return -ENOMEM;
64
65 rb_link_node(&sn->rb_node, parent, p);
66 rb_insert_color(&sn->rb_node, &self->entries);
67
68 return 0;
69}
70
71int strlist__load(struct strlist *self, const char *filename)
72{
73 char entry[1024];
74 int err;
75 FILE *fp = fopen(filename, "r");
76
77 if (fp == NULL)
78 return errno;
79
80 while (fgets(entry, sizeof(entry), fp) != NULL) {
81 const size_t len = strlen(entry);
82
83 if (len == 0)
84 continue;
85 entry[len - 1] = '\0';
86
87 err = strlist__add(self, entry);
88 if (err != 0)
89 goto out;
90 }
91
92 err = 0;
93out:
94 fclose(fp);
95 return err;
96}
97
98void strlist__remove(struct strlist *self, struct str_node *sn)
99{
100 rb_erase(&sn->rb_node, &self->entries);
101 str_node__delete(sn, self->dupstr);
102}
103
104bool strlist__has_entry(struct strlist *self, const char *entry)
105{
106 struct rb_node **p = &self->entries.rb_node;
107 struct rb_node *parent = NULL;
108
109 while (*p != NULL) {
110 struct str_node *sn;
111 int rc;
112
113 parent = *p;
114 sn = rb_entry(parent, struct str_node, rb_node);
115 rc = strcmp(sn->s, entry);
116
117 if (rc > 0)
118 p = &(*p)->rb_left;
119 else if (rc < 0)
120 p = &(*p)->rb_right;
121 else
122 return true;
123 }
124
125 return false;
126}
127
128static int strlist__parse_list_entry(struct strlist *self, const char *s)
129{
130 if (strncmp(s, "file://", 7) == 0)
131 return strlist__load(self, s + 7);
132
133 return strlist__add(self, s);
134}
135
136int strlist__parse_list(struct strlist *self, const char *s)
137{
138 char *sep;
139 int err;
140
141 while ((sep = strchr(s, ',')) != NULL) {
142 *sep = '\0';
143 err = strlist__parse_list_entry(self, s);
144 *sep = ',';
145 if (err != 0)
146 return err;
147 s = sep + 1;
148 }
149
150 return *s ? strlist__parse_list_entry(self, s) : 0;
151}
152
153struct strlist *strlist__new(bool dupstr, const char *slist)
154{
155 struct strlist *self = malloc(sizeof(*self));
156
157 if (self != NULL) {
158 self->entries = RB_ROOT;
159 self->dupstr = dupstr;
160 if (slist && strlist__parse_list(self, slist) != 0)
161 goto out_error;
162 }
163
164 return self;
165out_error:
166 free(self);
167 return NULL;
168}
169
170void strlist__delete(struct strlist *self)
171{
172 if (self != NULL) {
173 struct str_node *pos;
174 struct rb_node *next = rb_first(&self->entries);
175
176 while (next) {
177 pos = rb_entry(next, struct str_node, rb_node);
178 next = rb_next(&pos->rb_node);
179 strlist__remove(self, pos);
180 }
181 self->entries = RB_ROOT;
182 free(self);
183 }
184}
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
new file mode 100644
index 00000000000..2fb117fb4b6
--- /dev/null
+++ b/tools/perf/util/strlist.h
@@ -0,0 +1,32 @@
1#ifndef STRLIST_H_
2#define STRLIST_H_
3
4#include "rbtree.h"
5#include <stdbool.h>
6
7struct str_node {
8 struct rb_node rb_node;
9 const char *s;
10};
11
12struct strlist {
13 struct rb_root entries;
14 bool dupstr;
15};
16
17struct strlist *strlist__new(bool dupstr, const char *slist);
18void strlist__delete(struct strlist *self);
19
20void strlist__remove(struct strlist *self, struct str_node *sn);
21int strlist__load(struct strlist *self, const char *filename);
22int strlist__add(struct strlist *self, const char *str);
23
24bool strlist__has_entry(struct strlist *self, const char *entry);
25
26static inline bool strlist__empty(const struct strlist *self)
27{
28 return rb_first(&self->entries) == NULL;
29}
30
31int strlist__parse_list(struct strlist *self, const char *s);
32#endif /* STRLIST_H_ */