diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-30 22:02:59 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-30 22:02:59 -0400 |
commit | 55bcab46955644d5a8149a9b3cc9752a336e02f8 (patch) | |
tree | a45593603de9265cb0624043ab36f4e0f98823fc /tools/perf/util | |
parent | 58580c86450bc09ff101f0d23fd8a162c146bc64 (diff) | |
parent | 7bec7a9134c25cecb0d7029199b59f7b1bef35b8 (diff) |
Merge branch 'perfcounters-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perfcounters-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (47 commits)
perf report: Add --symbols parameter
perf report: Add --comms parameter
perf report: Add --dsos parameter
perf_counter tools: Adjust only prelinked symbol's addresses
perf_counter: Provide a way to enable counters on exec
perf_counter tools: Reduce perf stat measurement overhead/skew
perf stat: Use percentages for scaling output
perf_counter, x86: Update x86_pmu after WARN()
perf stat: Micro-optimize the code: memcpy is only required if no event is selected and !null_run
perf stat: Improve output
perf stat: Fix multi-run stats
perf stat: Add -n/--null option to run without counters
perf_counter tools: Remove dead code
perf_counter: Complete counter swap
perf report: Print sorted callchains per histogram entries
perf_counter tools: Prepare a small callchain framework
perf record: Fix unhandled io return value
perf_counter tools: Add alias for 'l1d' and 'l1i'
perf-report: Add bare minimum PERF_EVENT_READ parsing
perf-report: Add modes for inherited stats and no-samples
...
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/callchain.c | 174 | ||||
-rw-r--r-- | tools/perf/util/callchain.h | 33 | ||||
-rw-r--r-- | tools/perf/util/header.c | 242 | ||||
-rw-r--r-- | tools/perf/util/header.h | 37 | ||||
-rw-r--r-- | tools/perf/util/help.c | 15 | ||||
-rw-r--r-- | tools/perf/util/pager.c | 5 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 153 | ||||
-rw-r--r-- | tools/perf/util/run-command.c | 95 | ||||
-rw-r--r-- | tools/perf/util/run-command.h | 5 | ||||
-rw-r--r-- | tools/perf/util/strbuf.c | 2 | ||||
-rw-r--r-- | tools/perf/util/string.h | 2 | ||||
-rw-r--r-- | tools/perf/util/strlist.c | 184 | ||||
-rw-r--r-- | tools/perf/util/strlist.h | 32 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 16 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 5 | ||||
-rw-r--r-- | tools/perf/util/types.h | 17 | ||||
-rw-r--r-- | tools/perf/util/util.h | 15 |
17 files changed, 845 insertions, 187 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c new file mode 100644 index 000000000000..ad3c28578961 --- /dev/null +++ b/tools/perf/util/callchain.c | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009, Frederic Weisbecker <fweisbec@gmail.com> | ||
3 | * | ||
4 | * Handle the callchains from the stream in an ad-hoc radix tree and then | ||
5 | * sort them in an rbtree. | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include <stdlib.h> | ||
10 | #include <stdio.h> | ||
11 | #include <stdbool.h> | ||
12 | #include <errno.h> | ||
13 | |||
14 | #include "callchain.h" | ||
15 | |||
16 | |||
17 | static void rb_insert_callchain(struct rb_root *root, struct callchain_node *chain) | ||
18 | { | ||
19 | struct rb_node **p = &root->rb_node; | ||
20 | struct rb_node *parent = NULL; | ||
21 | struct callchain_node *rnode; | ||
22 | |||
23 | while (*p) { | ||
24 | parent = *p; | ||
25 | rnode = rb_entry(parent, struct callchain_node, rb_node); | ||
26 | |||
27 | if (rnode->hit < chain->hit) | ||
28 | p = &(*p)->rb_left; | ||
29 | else | ||
30 | p = &(*p)->rb_right; | ||
31 | } | ||
32 | |||
33 | rb_link_node(&chain->rb_node, parent, p); | ||
34 | rb_insert_color(&chain->rb_node, root); | ||
35 | } | ||
36 | |||
37 | /* | ||
38 | * Once we get every callchains from the stream, we can now | ||
39 | * sort them by hit | ||
40 | */ | ||
41 | void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node) | ||
42 | { | ||
43 | struct callchain_node *child; | ||
44 | |||
45 | list_for_each_entry(child, &node->children, brothers) | ||
46 | sort_chain_to_rbtree(rb_root, child); | ||
47 | |||
48 | if (node->hit) | ||
49 | rb_insert_callchain(rb_root, node); | ||
50 | } | ||
51 | |||
52 | static struct callchain_node *create_child(struct callchain_node *parent) | ||
53 | { | ||
54 | struct callchain_node *new; | ||
55 | |||
56 | new = malloc(sizeof(*new)); | ||
57 | if (!new) { | ||
58 | perror("not enough memory to create child for code path tree"); | ||
59 | return NULL; | ||
60 | } | ||
61 | new->parent = parent; | ||
62 | INIT_LIST_HEAD(&new->children); | ||
63 | INIT_LIST_HEAD(&new->val); | ||
64 | list_add_tail(&new->brothers, &parent->children); | ||
65 | |||
66 | return new; | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | fill_node(struct callchain_node *node, struct ip_callchain *chain, int start) | ||
71 | { | ||
72 | int i; | ||
73 | |||
74 | for (i = start; i < chain->nr; i++) { | ||
75 | struct callchain_list *call; | ||
76 | |||
77 | call = malloc(sizeof(*chain)); | ||
78 | if (!call) { | ||
79 | perror("not enough memory for the code path tree"); | ||
80 | return; | ||
81 | } | ||
82 | call->ip = chain->ips[i]; | ||
83 | list_add_tail(&call->list, &node->val); | ||
84 | } | ||
85 | node->val_nr = i - start; | ||
86 | } | ||
87 | |||
88 | static void add_child(struct callchain_node *parent, struct ip_callchain *chain) | ||
89 | { | ||
90 | struct callchain_node *new; | ||
91 | |||
92 | new = create_child(parent); | ||
93 | fill_node(new, chain, parent->val_nr); | ||
94 | |||
95 | new->hit = 1; | ||
96 | } | ||
97 | |||
98 | static void | ||
99 | split_add_child(struct callchain_node *parent, struct ip_callchain *chain, | ||
100 | struct callchain_list *to_split, int idx) | ||
101 | { | ||
102 | struct callchain_node *new; | ||
103 | |||
104 | /* split */ | ||
105 | new = create_child(parent); | ||
106 | list_move_tail(&to_split->list, &new->val); | ||
107 | new->hit = parent->hit; | ||
108 | parent->hit = 0; | ||
109 | parent->val_nr = idx; | ||
110 | |||
111 | /* create the new one */ | ||
112 | add_child(parent, chain); | ||
113 | } | ||
114 | |||
115 | static int | ||
116 | __append_chain(struct callchain_node *root, struct ip_callchain *chain, | ||
117 | int start); | ||
118 | |||
119 | static int | ||
120 | __append_chain_children(struct callchain_node *root, struct ip_callchain *chain) | ||
121 | { | ||
122 | struct callchain_node *rnode; | ||
123 | |||
124 | /* lookup in childrens */ | ||
125 | list_for_each_entry(rnode, &root->children, brothers) { | ||
126 | int ret = __append_chain(rnode, chain, root->val_nr); | ||
127 | if (!ret) | ||
128 | return 0; | ||
129 | } | ||
130 | return -1; | ||
131 | } | ||
132 | |||
133 | static int | ||
134 | __append_chain(struct callchain_node *root, struct ip_callchain *chain, | ||
135 | int start) | ||
136 | { | ||
137 | struct callchain_list *cnode; | ||
138 | int i = start; | ||
139 | bool found = false; | ||
140 | |||
141 | /* lookup in the current node */ | ||
142 | list_for_each_entry(cnode, &root->val, list) { | ||
143 | if (cnode->ip != chain->ips[i++]) | ||
144 | break; | ||
145 | if (!found) | ||
146 | found = true; | ||
147 | if (i == chain->nr) | ||
148 | break; | ||
149 | } | ||
150 | |||
151 | /* matches not, relay on the parent */ | ||
152 | if (!found) | ||
153 | return -1; | ||
154 | |||
155 | /* we match only a part of the node. Split it and add the new chain */ | ||
156 | if (i < root->val_nr) { | ||
157 | split_add_child(root, chain, cnode, i); | ||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | /* we match 100% of the path, increment the hit */ | ||
162 | if (i == root->val_nr) { | ||
163 | root->hit++; | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | return __append_chain_children(root, chain); | ||
168 | } | ||
169 | |||
170 | void append_chain(struct callchain_node *root, struct ip_callchain *chain) | ||
171 | { | ||
172 | if (__append_chain_children(root, chain) == -1) | ||
173 | add_child(root, chain); | ||
174 | } | ||
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h new file mode 100644 index 000000000000..fa1cd2f71fd3 --- /dev/null +++ b/tools/perf/util/callchain.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef __PERF_CALLCHAIN_H | ||
2 | #define __PERF_CALLCHAIN_H | ||
3 | |||
4 | #include "../perf.h" | ||
5 | #include "list.h" | ||
6 | #include "rbtree.h" | ||
7 | |||
8 | |||
9 | struct callchain_node { | ||
10 | struct callchain_node *parent; | ||
11 | struct list_head brothers; | ||
12 | struct list_head children; | ||
13 | struct list_head val; | ||
14 | struct rb_node rb_node; | ||
15 | int val_nr; | ||
16 | int hit; | ||
17 | }; | ||
18 | |||
19 | struct callchain_list { | ||
20 | unsigned long ip; | ||
21 | struct list_head list; | ||
22 | }; | ||
23 | |||
24 | static inline void callchain_init(struct callchain_node *node) | ||
25 | { | ||
26 | INIT_LIST_HEAD(&node->brothers); | ||
27 | INIT_LIST_HEAD(&node->children); | ||
28 | INIT_LIST_HEAD(&node->val); | ||
29 | } | ||
30 | |||
31 | void append_chain(struct callchain_node *root, struct ip_callchain *chain); | ||
32 | void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node); | ||
33 | #endif | ||
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c new file mode 100644 index 000000000000..450384b3bbe5 --- /dev/null +++ b/tools/perf/util/header.c | |||
@@ -0,0 +1,242 @@ | |||
1 | #include <sys/types.h> | ||
2 | #include <unistd.h> | ||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | |||
6 | #include "util.h" | ||
7 | #include "header.h" | ||
8 | |||
9 | /* | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | struct perf_header_attr *perf_header_attr__new(struct perf_counter_attr *attr) | ||
14 | { | ||
15 | struct perf_header_attr *self = malloc(sizeof(*self)); | ||
16 | |||
17 | if (!self) | ||
18 | die("nomem"); | ||
19 | |||
20 | self->attr = *attr; | ||
21 | self->ids = 0; | ||
22 | self->size = 1; | ||
23 | self->id = malloc(sizeof(u64)); | ||
24 | |||
25 | if (!self->id) | ||
26 | die("nomem"); | ||
27 | |||
28 | return self; | ||
29 | } | ||
30 | |||
31 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) | ||
32 | { | ||
33 | int pos = self->ids; | ||
34 | |||
35 | self->ids++; | ||
36 | if (self->ids > self->size) { | ||
37 | self->size *= 2; | ||
38 | self->id = realloc(self->id, self->size * sizeof(u64)); | ||
39 | if (!self->id) | ||
40 | die("nomem"); | ||
41 | } | ||
42 | self->id[pos] = id; | ||
43 | } | ||
44 | |||
45 | /* | ||
46 | * | ||
47 | */ | ||
48 | |||
49 | struct perf_header *perf_header__new(void) | ||
50 | { | ||
51 | struct perf_header *self = malloc(sizeof(*self)); | ||
52 | |||
53 | if (!self) | ||
54 | die("nomem"); | ||
55 | |||
56 | self->frozen = 0; | ||
57 | |||
58 | self->attrs = 0; | ||
59 | self->size = 1; | ||
60 | self->attr = malloc(sizeof(void *)); | ||
61 | |||
62 | if (!self->attr) | ||
63 | die("nomem"); | ||
64 | |||
65 | self->data_offset = 0; | ||
66 | self->data_size = 0; | ||
67 | |||
68 | return self; | ||
69 | } | ||
70 | |||
71 | void perf_header__add_attr(struct perf_header *self, | ||
72 | struct perf_header_attr *attr) | ||
73 | { | ||
74 | int pos = self->attrs; | ||
75 | |||
76 | if (self->frozen) | ||
77 | die("frozen"); | ||
78 | |||
79 | self->attrs++; | ||
80 | if (self->attrs > self->size) { | ||
81 | self->size *= 2; | ||
82 | self->attr = realloc(self->attr, self->size * sizeof(void *)); | ||
83 | if (!self->attr) | ||
84 | die("nomem"); | ||
85 | } | ||
86 | self->attr[pos] = attr; | ||
87 | } | ||
88 | |||
89 | static const char *__perf_magic = "PERFFILE"; | ||
90 | |||
91 | #define PERF_MAGIC (*(u64 *)__perf_magic) | ||
92 | |||
93 | struct perf_file_section { | ||
94 | u64 offset; | ||
95 | u64 size; | ||
96 | }; | ||
97 | |||
98 | struct perf_file_attr { | ||
99 | struct perf_counter_attr attr; | ||
100 | struct perf_file_section ids; | ||
101 | }; | ||
102 | |||
103 | struct perf_file_header { | ||
104 | u64 magic; | ||
105 | u64 size; | ||
106 | u64 attr_size; | ||
107 | struct perf_file_section attrs; | ||
108 | struct perf_file_section data; | ||
109 | }; | ||
110 | |||
111 | static void do_write(int fd, void *buf, size_t size) | ||
112 | { | ||
113 | while (size) { | ||
114 | int ret = write(fd, buf, size); | ||
115 | |||
116 | if (ret < 0) | ||
117 | die("failed to write"); | ||
118 | |||
119 | size -= ret; | ||
120 | buf += ret; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | void perf_header__write(struct perf_header *self, int fd) | ||
125 | { | ||
126 | struct perf_file_header f_header; | ||
127 | struct perf_file_attr f_attr; | ||
128 | struct perf_header_attr *attr; | ||
129 | int i; | ||
130 | |||
131 | lseek(fd, sizeof(f_header), SEEK_SET); | ||
132 | |||
133 | |||
134 | for (i = 0; i < self->attrs; i++) { | ||
135 | attr = self->attr[i]; | ||
136 | |||
137 | attr->id_offset = lseek(fd, 0, SEEK_CUR); | ||
138 | do_write(fd, attr->id, attr->ids * sizeof(u64)); | ||
139 | } | ||
140 | |||
141 | |||
142 | self->attr_offset = lseek(fd, 0, SEEK_CUR); | ||
143 | |||
144 | for (i = 0; i < self->attrs; i++) { | ||
145 | attr = self->attr[i]; | ||
146 | |||
147 | f_attr = (struct perf_file_attr){ | ||
148 | .attr = attr->attr, | ||
149 | .ids = { | ||
150 | .offset = attr->id_offset, | ||
151 | .size = attr->ids * sizeof(u64), | ||
152 | } | ||
153 | }; | ||
154 | do_write(fd, &f_attr, sizeof(f_attr)); | ||
155 | } | ||
156 | |||
157 | |||
158 | self->data_offset = lseek(fd, 0, SEEK_CUR); | ||
159 | |||
160 | f_header = (struct perf_file_header){ | ||
161 | .magic = PERF_MAGIC, | ||
162 | .size = sizeof(f_header), | ||
163 | .attr_size = sizeof(f_attr), | ||
164 | .attrs = { | ||
165 | .offset = self->attr_offset, | ||
166 | .size = self->attrs * sizeof(f_attr), | ||
167 | }, | ||
168 | .data = { | ||
169 | .offset = self->data_offset, | ||
170 | .size = self->data_size, | ||
171 | }, | ||
172 | }; | ||
173 | |||
174 | lseek(fd, 0, SEEK_SET); | ||
175 | do_write(fd, &f_header, sizeof(f_header)); | ||
176 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); | ||
177 | |||
178 | self->frozen = 1; | ||
179 | } | ||
180 | |||
181 | static void do_read(int fd, void *buf, size_t size) | ||
182 | { | ||
183 | while (size) { | ||
184 | int ret = read(fd, buf, size); | ||
185 | |||
186 | if (ret < 0) | ||
187 | die("failed to read"); | ||
188 | |||
189 | size -= ret; | ||
190 | buf += ret; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | struct perf_header *perf_header__read(int fd) | ||
195 | { | ||
196 | struct perf_header *self = perf_header__new(); | ||
197 | struct perf_file_header f_header; | ||
198 | struct perf_file_attr f_attr; | ||
199 | u64 f_id; | ||
200 | |||
201 | int nr_attrs, nr_ids, i, j; | ||
202 | |||
203 | lseek(fd, 0, SEEK_SET); | ||
204 | do_read(fd, &f_header, sizeof(f_header)); | ||
205 | |||
206 | if (f_header.magic != PERF_MAGIC || | ||
207 | f_header.size != sizeof(f_header) || | ||
208 | f_header.attr_size != sizeof(f_attr)) | ||
209 | die("incompatible file format"); | ||
210 | |||
211 | nr_attrs = f_header.attrs.size / sizeof(f_attr); | ||
212 | lseek(fd, f_header.attrs.offset, SEEK_SET); | ||
213 | |||
214 | for (i = 0; i < nr_attrs; i++) { | ||
215 | struct perf_header_attr *attr; | ||
216 | off_t tmp = lseek(fd, 0, SEEK_CUR); | ||
217 | |||
218 | do_read(fd, &f_attr, sizeof(f_attr)); | ||
219 | |||
220 | attr = perf_header_attr__new(&f_attr.attr); | ||
221 | |||
222 | nr_ids = f_attr.ids.size / sizeof(u64); | ||
223 | lseek(fd, f_attr.ids.offset, SEEK_SET); | ||
224 | |||
225 | for (j = 0; j < nr_ids; j++) { | ||
226 | do_read(fd, &f_id, sizeof(f_id)); | ||
227 | |||
228 | perf_header_attr__add_id(attr, f_id); | ||
229 | } | ||
230 | perf_header__add_attr(self, attr); | ||
231 | lseek(fd, tmp, SEEK_SET); | ||
232 | } | ||
233 | |||
234 | self->data_offset = f_header.data.offset; | ||
235 | self->data_size = f_header.data.size; | ||
236 | |||
237 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); | ||
238 | |||
239 | self->frozen = 1; | ||
240 | |||
241 | return self; | ||
242 | } | ||
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h new file mode 100644 index 000000000000..b5ef53ad4c7a --- /dev/null +++ b/tools/perf/util/header.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #ifndef _PERF_HEADER_H | ||
2 | #define _PERF_HEADER_H | ||
3 | |||
4 | #include "../../../include/linux/perf_counter.h" | ||
5 | #include <sys/types.h> | ||
6 | #include "types.h" | ||
7 | |||
8 | struct perf_header_attr { | ||
9 | struct perf_counter_attr attr; | ||
10 | int ids, size; | ||
11 | u64 *id; | ||
12 | off_t id_offset; | ||
13 | }; | ||
14 | |||
15 | struct perf_header { | ||
16 | int frozen; | ||
17 | int attrs, size; | ||
18 | struct perf_header_attr **attr; | ||
19 | off_t attr_offset; | ||
20 | u64 data_offset; | ||
21 | u64 data_size; | ||
22 | }; | ||
23 | |||
24 | struct perf_header *perf_header__read(int fd); | ||
25 | void perf_header__write(struct perf_header *self, int fd); | ||
26 | |||
27 | void perf_header__add_attr(struct perf_header *self, | ||
28 | struct perf_header_attr *attr); | ||
29 | |||
30 | struct perf_header_attr * | ||
31 | perf_header_attr__new(struct perf_counter_attr *attr); | ||
32 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); | ||
33 | |||
34 | |||
35 | struct perf_header *perf_header__new(void); | ||
36 | |||
37 | #endif /* _PERF_HEADER_H */ | ||
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c index 6653f7dd1d78..17a00e0df2c4 100644 --- a/tools/perf/util/help.c +++ b/tools/perf/util/help.c | |||
@@ -126,21 +126,6 @@ static int is_executable(const char *name) | |||
126 | !S_ISREG(st.st_mode)) | 126 | !S_ISREG(st.st_mode)) |
127 | return 0; | 127 | return 0; |
128 | 128 | ||
129 | #ifdef __MINGW32__ | ||
130 | /* cannot trust the executable bit, peek into the file instead */ | ||
131 | char buf[3] = { 0 }; | ||
132 | int n; | ||
133 | int fd = open(name, O_RDONLY); | ||
134 | st.st_mode &= ~S_IXUSR; | ||
135 | if (fd >= 0) { | ||
136 | n = read(fd, buf, 2); | ||
137 | if (n == 2) | ||
138 | /* DOS executables start with "MZ" */ | ||
139 | if (!strcmp(buf, "#!") || !strcmp(buf, "MZ")) | ||
140 | st.st_mode |= S_IXUSR; | ||
141 | close(fd); | ||
142 | } | ||
143 | #endif | ||
144 | return st.st_mode & S_IXUSR; | 129 | return st.st_mode & S_IXUSR; |
145 | } | 130 | } |
146 | 131 | ||
diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c index a28bccae5458..1915de20dcac 100644 --- a/tools/perf/util/pager.c +++ b/tools/perf/util/pager.c | |||
@@ -9,7 +9,6 @@ | |||
9 | 9 | ||
10 | static int spawned_pager; | 10 | static int spawned_pager; |
11 | 11 | ||
12 | #ifndef __MINGW32__ | ||
13 | static void pager_preexec(void) | 12 | static void pager_preexec(void) |
14 | { | 13 | { |
15 | /* | 14 | /* |
@@ -24,7 +23,6 @@ static void pager_preexec(void) | |||
24 | 23 | ||
25 | setenv("LESS", "FRSX", 0); | 24 | setenv("LESS", "FRSX", 0); |
26 | } | 25 | } |
27 | #endif | ||
28 | 26 | ||
29 | static const char *pager_argv[] = { "sh", "-c", NULL, NULL }; | 27 | static const char *pager_argv[] = { "sh", "-c", NULL, NULL }; |
30 | static struct child_process pager_process; | 28 | static struct child_process pager_process; |
@@ -70,9 +68,8 @@ void setup_pager(void) | |||
70 | pager_argv[2] = pager; | 68 | pager_argv[2] = pager; |
71 | pager_process.argv = pager_argv; | 69 | pager_process.argv = pager_argv; |
72 | pager_process.in = -1; | 70 | pager_process.in = -1; |
73 | #ifndef __MINGW32__ | ||
74 | pager_process.preexec_cb = pager_preexec; | 71 | pager_process.preexec_cb = pager_preexec; |
75 | #endif | 72 | |
76 | if (start_command(&pager_process)) | 73 | if (start_command(&pager_process)) |
77 | return; | 74 | return; |
78 | 75 | ||
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 35d04da38d6a..4d042f104cdc 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -16,32 +16,28 @@ struct event_symbol { | |||
16 | u8 type; | 16 | u8 type; |
17 | u64 config; | 17 | u64 config; |
18 | char *symbol; | 18 | char *symbol; |
19 | char *alias; | ||
19 | }; | 20 | }; |
20 | 21 | ||
21 | #define C(x, y) .type = PERF_TYPE_##x, .config = PERF_COUNT_##y | 22 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x |
22 | #define CR(x, y) .type = PERF_TYPE_##x, .config = y | 23 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x |
23 | 24 | ||
24 | static struct event_symbol event_symbols[] = { | 25 | static struct event_symbol event_symbols[] = { |
25 | { C(HARDWARE, HW_CPU_CYCLES), "cpu-cycles", }, | 26 | { CHW(CPU_CYCLES), "cpu-cycles", "cycles" }, |
26 | { C(HARDWARE, HW_CPU_CYCLES), "cycles", }, | 27 | { CHW(INSTRUCTIONS), "instructions", "" }, |
27 | { C(HARDWARE, HW_INSTRUCTIONS), "instructions", }, | 28 | { CHW(CACHE_REFERENCES), "cache-references", "" }, |
28 | { C(HARDWARE, HW_CACHE_REFERENCES), "cache-references", }, | 29 | { CHW(CACHE_MISSES), "cache-misses", "" }, |
29 | { C(HARDWARE, HW_CACHE_MISSES), "cache-misses", }, | 30 | { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" }, |
30 | { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branch-instructions", }, | 31 | { CHW(BRANCH_MISSES), "branch-misses", "" }, |
31 | { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branches", }, | 32 | { CHW(BUS_CYCLES), "bus-cycles", "" }, |
32 | { C(HARDWARE, HW_BRANCH_MISSES), "branch-misses", }, | 33 | |
33 | { C(HARDWARE, HW_BUS_CYCLES), "bus-cycles", }, | 34 | { CSW(CPU_CLOCK), "cpu-clock", "" }, |
34 | 35 | { CSW(TASK_CLOCK), "task-clock", "" }, | |
35 | { C(SOFTWARE, SW_CPU_CLOCK), "cpu-clock", }, | 36 | { CSW(PAGE_FAULTS), "page-faults", "faults" }, |
36 | { C(SOFTWARE, SW_TASK_CLOCK), "task-clock", }, | 37 | { CSW(PAGE_FAULTS_MIN), "minor-faults", "" }, |
37 | { C(SOFTWARE, SW_PAGE_FAULTS), "page-faults", }, | 38 | { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, |
38 | { C(SOFTWARE, SW_PAGE_FAULTS), "faults", }, | 39 | { CSW(CONTEXT_SWITCHES), "context-switches", "cs" }, |
39 | { C(SOFTWARE, SW_PAGE_FAULTS_MIN), "minor-faults", }, | 40 | { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" }, |
40 | { C(SOFTWARE, SW_PAGE_FAULTS_MAJ), "major-faults", }, | ||
41 | { C(SOFTWARE, SW_CONTEXT_SWITCHES), "context-switches", }, | ||
42 | { C(SOFTWARE, SW_CONTEXT_SWITCHES), "cs", }, | ||
43 | { C(SOFTWARE, SW_CPU_MIGRATIONS), "cpu-migrations", }, | ||
44 | { C(SOFTWARE, SW_CPU_MIGRATIONS), "migrations", }, | ||
45 | }; | 41 | }; |
46 | 42 | ||
47 | #define __PERF_COUNTER_FIELD(config, name) \ | 43 | #define __PERF_COUNTER_FIELD(config, name) \ |
@@ -74,26 +70,70 @@ static char *sw_event_names[] = { | |||
74 | 70 | ||
75 | #define MAX_ALIASES 8 | 71 | #define MAX_ALIASES 8 |
76 | 72 | ||
77 | static char *hw_cache [][MAX_ALIASES] = { | 73 | static char *hw_cache[][MAX_ALIASES] = { |
78 | { "L1-data" , "l1-d", "l1d" }, | 74 | { "L1-d$", "l1-d", "l1d", "L1-data", }, |
79 | { "L1-instruction" , "l1-i", "l1i" }, | 75 | { "L1-i$", "l1-i", "l1i", "L1-instruction", }, |
80 | { "L2" , "l2" }, | 76 | { "LLC", "L2" }, |
81 | { "Data-TLB" , "dtlb", "d-tlb" }, | 77 | { "dTLB", "d-tlb", "Data-TLB", }, |
82 | { "Instruction-TLB" , "itlb", "i-tlb" }, | 78 | { "iTLB", "i-tlb", "Instruction-TLB", }, |
83 | { "Branch" , "bpu" , "btb", "bpc" }, | 79 | { "branch", "branches", "bpu", "btb", "bpc", }, |
84 | }; | 80 | }; |
85 | 81 | ||
86 | static char *hw_cache_op [][MAX_ALIASES] = { | 82 | static char *hw_cache_op[][MAX_ALIASES] = { |
87 | { "Load" , "read" }, | 83 | { "load", "loads", "read", }, |
88 | { "Store" , "write" }, | 84 | { "store", "stores", "write", }, |
89 | { "Prefetch" , "speculative-read", "speculative-load" }, | 85 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, |
90 | }; | 86 | }; |
91 | 87 | ||
92 | static char *hw_cache_result [][MAX_ALIASES] = { | 88 | static char *hw_cache_result[][MAX_ALIASES] = { |
93 | { "Reference" , "ops", "access" }, | 89 | { "refs", "Reference", "ops", "access", }, |
94 | { "Miss" }, | 90 | { "misses", "miss", }, |
95 | }; | 91 | }; |
96 | 92 | ||
93 | #define C(x) PERF_COUNT_HW_CACHE_##x | ||
94 | #define CACHE_READ (1 << C(OP_READ)) | ||
95 | #define CACHE_WRITE (1 << C(OP_WRITE)) | ||
96 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) | ||
97 | #define COP(x) (1 << x) | ||
98 | |||
99 | /* | ||
100 | * cache operartion stat | ||
101 | * L1I : Read and prefetch only | ||
102 | * ITLB and BPU : Read-only | ||
103 | */ | ||
104 | static unsigned long hw_cache_stat[C(MAX)] = { | ||
105 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
106 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), | ||
107 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
108 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
109 | [C(ITLB)] = (CACHE_READ), | ||
110 | [C(BPU)] = (CACHE_READ), | ||
111 | }; | ||
112 | |||
113 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) | ||
114 | { | ||
115 | if (hw_cache_stat[cache_type] & COP(cache_op)) | ||
116 | return 1; /* valid */ | ||
117 | else | ||
118 | return 0; /* invalid */ | ||
119 | } | ||
120 | |||
121 | static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) | ||
122 | { | ||
123 | static char name[50]; | ||
124 | |||
125 | if (cache_result) { | ||
126 | sprintf(name, "%s-%s-%s", hw_cache[cache_type][0], | ||
127 | hw_cache_op[cache_op][0], | ||
128 | hw_cache_result[cache_result][0]); | ||
129 | } else { | ||
130 | sprintf(name, "%s-%s", hw_cache[cache_type][0], | ||
131 | hw_cache_op[cache_op][1]); | ||
132 | } | ||
133 | |||
134 | return name; | ||
135 | } | ||
136 | |||
97 | char *event_name(int counter) | 137 | char *event_name(int counter) |
98 | { | 138 | { |
99 | u64 config = attrs[counter].config; | 139 | u64 config = attrs[counter].config; |
@@ -113,7 +153,6 @@ char *event_name(int counter) | |||
113 | 153 | ||
114 | case PERF_TYPE_HW_CACHE: { | 154 | case PERF_TYPE_HW_CACHE: { |
115 | u8 cache_type, cache_op, cache_result; | 155 | u8 cache_type, cache_op, cache_result; |
116 | static char name[100]; | ||
117 | 156 | ||
118 | cache_type = (config >> 0) & 0xff; | 157 | cache_type = (config >> 0) & 0xff; |
119 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) | 158 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) |
@@ -127,12 +166,10 @@ char *event_name(int counter) | |||
127 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) | 166 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) |
128 | return "unknown-ext-hardware-cache-result"; | 167 | return "unknown-ext-hardware-cache-result"; |
129 | 168 | ||
130 | sprintf(name, "%s-Cache-%s-%ses", | 169 | if (!is_cache_op_valid(cache_type, cache_op)) |
131 | hw_cache[cache_type][0], | 170 | return "invalid-cache"; |
132 | hw_cache_op[cache_op][0], | ||
133 | hw_cache_result[cache_result][0]); | ||
134 | 171 | ||
135 | return name; | 172 | return event_cache_name(cache_type, cache_op, cache_result); |
136 | } | 173 | } |
137 | 174 | ||
138 | case PERF_TYPE_SOFTWARE: | 175 | case PERF_TYPE_SOFTWARE: |
@@ -163,7 +200,8 @@ static int parse_aliases(const char *str, char *names[][MAX_ALIASES], int size) | |||
163 | return -1; | 200 | return -1; |
164 | } | 201 | } |
165 | 202 | ||
166 | static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *attr) | 203 | static int |
204 | parse_generic_hw_symbols(const char *str, struct perf_counter_attr *attr) | ||
167 | { | 205 | { |
168 | int cache_type = -1, cache_op = 0, cache_result = 0; | 206 | int cache_type = -1, cache_op = 0, cache_result = 0; |
169 | 207 | ||
@@ -182,6 +220,9 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a | |||
182 | if (cache_op == -1) | 220 | if (cache_op == -1) |
183 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; | 221 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
184 | 222 | ||
223 | if (!is_cache_op_valid(cache_type, cache_op)) | ||
224 | return -EINVAL; | ||
225 | |||
185 | cache_result = parse_aliases(str, hw_cache_result, | 226 | cache_result = parse_aliases(str, hw_cache_result, |
186 | PERF_COUNT_HW_CACHE_RESULT_MAX); | 227 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
187 | /* | 228 | /* |
@@ -196,6 +237,19 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a | |||
196 | return 0; | 237 | return 0; |
197 | } | 238 | } |
198 | 239 | ||
240 | static int check_events(const char *str, unsigned int i) | ||
241 | { | ||
242 | if (!strncmp(str, event_symbols[i].symbol, | ||
243 | strlen(event_symbols[i].symbol))) | ||
244 | return 1; | ||
245 | |||
246 | if (strlen(event_symbols[i].alias)) | ||
247 | if (!strncmp(str, event_symbols[i].alias, | ||
248 | strlen(event_symbols[i].alias))) | ||
249 | return 1; | ||
250 | return 0; | ||
251 | } | ||
252 | |||
199 | /* | 253 | /* |
200 | * Each event can have multiple symbolic names. | 254 | * Each event can have multiple symbolic names. |
201 | * Symbolic names are (almost) exactly matched. | 255 | * Symbolic names are (almost) exactly matched. |
@@ -235,9 +289,7 @@ static int parse_event_symbols(const char *str, struct perf_counter_attr *attr) | |||
235 | } | 289 | } |
236 | 290 | ||
237 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { | 291 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { |
238 | if (!strncmp(str, event_symbols[i].symbol, | 292 | if (check_events(str, i)) { |
239 | strlen(event_symbols[i].symbol))) { | ||
240 | |||
241 | attr->type = event_symbols[i].type; | 293 | attr->type = event_symbols[i].type; |
242 | attr->config = event_symbols[i].config; | 294 | attr->config = event_symbols[i].config; |
243 | 295 | ||
@@ -289,6 +341,7 @@ void print_events(void) | |||
289 | { | 341 | { |
290 | struct event_symbol *syms = event_symbols; | 342 | struct event_symbol *syms = event_symbols; |
291 | unsigned int i, type, prev_type = -1; | 343 | unsigned int i, type, prev_type = -1; |
344 | char name[40]; | ||
292 | 345 | ||
293 | fprintf(stderr, "\n"); | 346 | fprintf(stderr, "\n"); |
294 | fprintf(stderr, "List of pre-defined events (to be used in -e):\n"); | 347 | fprintf(stderr, "List of pre-defined events (to be used in -e):\n"); |
@@ -301,14 +354,18 @@ void print_events(void) | |||
301 | if (type != prev_type) | 354 | if (type != prev_type) |
302 | fprintf(stderr, "\n"); | 355 | fprintf(stderr, "\n"); |
303 | 356 | ||
304 | fprintf(stderr, " %-30s [%s]\n", syms->symbol, | 357 | if (strlen(syms->alias)) |
358 | sprintf(name, "%s OR %s", syms->symbol, syms->alias); | ||
359 | else | ||
360 | strcpy(name, syms->symbol); | ||
361 | fprintf(stderr, " %-40s [%s]\n", name, | ||
305 | event_type_descriptors[type]); | 362 | event_type_descriptors[type]); |
306 | 363 | ||
307 | prev_type = type; | 364 | prev_type = type; |
308 | } | 365 | } |
309 | 366 | ||
310 | fprintf(stderr, "\n"); | 367 | fprintf(stderr, "\n"); |
311 | fprintf(stderr, " %-30s [raw hardware event descriptor]\n", | 368 | fprintf(stderr, " %-40s [raw hardware event descriptor]\n", |
312 | "rNNN"); | 369 | "rNNN"); |
313 | fprintf(stderr, "\n"); | 370 | fprintf(stderr, "\n"); |
314 | 371 | ||
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c index b2f5e854f40a..a3935343091a 100644 --- a/tools/perf/util/run-command.c +++ b/tools/perf/util/run-command.c | |||
@@ -65,7 +65,6 @@ int start_command(struct child_process *cmd) | |||
65 | cmd->err = fderr[0]; | 65 | cmd->err = fderr[0]; |
66 | } | 66 | } |
67 | 67 | ||
68 | #ifndef __MINGW32__ | ||
69 | fflush(NULL); | 68 | fflush(NULL); |
70 | cmd->pid = fork(); | 69 | cmd->pid = fork(); |
71 | if (!cmd->pid) { | 70 | if (!cmd->pid) { |
@@ -118,71 +117,6 @@ int start_command(struct child_process *cmd) | |||
118 | } | 117 | } |
119 | exit(127); | 118 | exit(127); |
120 | } | 119 | } |
121 | #else | ||
122 | int s0 = -1, s1 = -1, s2 = -1; /* backups of stdin, stdout, stderr */ | ||
123 | const char **sargv = cmd->argv; | ||
124 | char **env = environ; | ||
125 | |||
126 | if (cmd->no_stdin) { | ||
127 | s0 = dup(0); | ||
128 | dup_devnull(0); | ||
129 | } else if (need_in) { | ||
130 | s0 = dup(0); | ||
131 | dup2(fdin[0], 0); | ||
132 | } else if (cmd->in) { | ||
133 | s0 = dup(0); | ||
134 | dup2(cmd->in, 0); | ||
135 | } | ||
136 | |||
137 | if (cmd->no_stderr) { | ||
138 | s2 = dup(2); | ||
139 | dup_devnull(2); | ||
140 | } else if (need_err) { | ||
141 | s2 = dup(2); | ||
142 | dup2(fderr[1], 2); | ||
143 | } | ||
144 | |||
145 | if (cmd->no_stdout) { | ||
146 | s1 = dup(1); | ||
147 | dup_devnull(1); | ||
148 | } else if (cmd->stdout_to_stderr) { | ||
149 | s1 = dup(1); | ||
150 | dup2(2, 1); | ||
151 | } else if (need_out) { | ||
152 | s1 = dup(1); | ||
153 | dup2(fdout[1], 1); | ||
154 | } else if (cmd->out > 1) { | ||
155 | s1 = dup(1); | ||
156 | dup2(cmd->out, 1); | ||
157 | } | ||
158 | |||
159 | if (cmd->dir) | ||
160 | die("chdir in start_command() not implemented"); | ||
161 | if (cmd->env) { | ||
162 | env = copy_environ(); | ||
163 | for (; *cmd->env; cmd->env++) | ||
164 | env = env_setenv(env, *cmd->env); | ||
165 | } | ||
166 | |||
167 | if (cmd->perf_cmd) { | ||
168 | cmd->argv = prepare_perf_cmd(cmd->argv); | ||
169 | } | ||
170 | |||
171 | cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env); | ||
172 | |||
173 | if (cmd->env) | ||
174 | free_environ(env); | ||
175 | if (cmd->perf_cmd) | ||
176 | free(cmd->argv); | ||
177 | |||
178 | cmd->argv = sargv; | ||
179 | if (s0 >= 0) | ||
180 | dup2(s0, 0), close(s0); | ||
181 | if (s1 >= 0) | ||
182 | dup2(s1, 1), close(s1); | ||
183 | if (s2 >= 0) | ||
184 | dup2(s2, 2), close(s2); | ||
185 | #endif | ||
186 | 120 | ||
187 | if (cmd->pid < 0) { | 121 | if (cmd->pid < 0) { |
188 | int err = errno; | 122 | int err = errno; |
@@ -288,14 +222,6 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const | |||
288 | return run_command(&cmd); | 222 | return run_command(&cmd); |
289 | } | 223 | } |
290 | 224 | ||
291 | #ifdef __MINGW32__ | ||
292 | static __stdcall unsigned run_thread(void *data) | ||
293 | { | ||
294 | struct async *async = data; | ||
295 | return async->proc(async->fd_for_proc, async->data); | ||
296 | } | ||
297 | #endif | ||
298 | |||
299 | int start_async(struct async *async) | 225 | int start_async(struct async *async) |
300 | { | 226 | { |
301 | int pipe_out[2]; | 227 | int pipe_out[2]; |
@@ -304,7 +230,6 @@ int start_async(struct async *async) | |||
304 | return error("cannot create pipe: %s", strerror(errno)); | 230 | return error("cannot create pipe: %s", strerror(errno)); |
305 | async->out = pipe_out[0]; | 231 | async->out = pipe_out[0]; |
306 | 232 | ||
307 | #ifndef __MINGW32__ | ||
308 | /* Flush stdio before fork() to avoid cloning buffers */ | 233 | /* Flush stdio before fork() to avoid cloning buffers */ |
309 | fflush(NULL); | 234 | fflush(NULL); |
310 | 235 | ||
@@ -319,33 +244,17 @@ int start_async(struct async *async) | |||
319 | exit(!!async->proc(pipe_out[1], async->data)); | 244 | exit(!!async->proc(pipe_out[1], async->data)); |
320 | } | 245 | } |
321 | close(pipe_out[1]); | 246 | close(pipe_out[1]); |
322 | #else | 247 | |
323 | async->fd_for_proc = pipe_out[1]; | ||
324 | async->tid = (HANDLE) _beginthreadex(NULL, 0, run_thread, async, 0, NULL); | ||
325 | if (!async->tid) { | ||
326 | error("cannot create thread: %s", strerror(errno)); | ||
327 | close_pair(pipe_out); | ||
328 | return -1; | ||
329 | } | ||
330 | #endif | ||
331 | return 0; | 248 | return 0; |
332 | } | 249 | } |
333 | 250 | ||
334 | int finish_async(struct async *async) | 251 | int finish_async(struct async *async) |
335 | { | 252 | { |
336 | #ifndef __MINGW32__ | ||
337 | int ret = 0; | 253 | int ret = 0; |
338 | 254 | ||
339 | if (wait_or_whine(async->pid)) | 255 | if (wait_or_whine(async->pid)) |
340 | ret = error("waitpid (async) failed"); | 256 | ret = error("waitpid (async) failed"); |
341 | #else | 257 | |
342 | DWORD ret = 0; | ||
343 | if (WaitForSingleObject(async->tid, INFINITE) != WAIT_OBJECT_0) | ||
344 | ret = error("waiting for thread failed: %lu", GetLastError()); | ||
345 | else if (!GetExitCodeThread(async->tid, &ret)) | ||
346 | ret = error("cannot get thread exit code: %lu", GetLastError()); | ||
347 | CloseHandle(async->tid); | ||
348 | #endif | ||
349 | return ret; | 258 | return ret; |
350 | } | 259 | } |
351 | 260 | ||
diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h index 328289f23669..cc1837deba88 100644 --- a/tools/perf/util/run-command.h +++ b/tools/perf/util/run-command.h | |||
@@ -79,12 +79,7 @@ struct async { | |||
79 | int (*proc)(int fd, void *data); | 79 | int (*proc)(int fd, void *data); |
80 | void *data; | 80 | void *data; |
81 | int out; /* caller reads from here and closes it */ | 81 | int out; /* caller reads from here and closes it */ |
82 | #ifndef __MINGW32__ | ||
83 | pid_t pid; | 82 | pid_t pid; |
84 | #else | ||
85 | HANDLE tid; | ||
86 | int fd_for_proc; | ||
87 | #endif | ||
88 | }; | 83 | }; |
89 | 84 | ||
90 | int start_async(struct async *async); | 85 | int start_async(struct async *async); |
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index eaba09306802..464e7ca898cf 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c | |||
@@ -259,7 +259,7 @@ size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f) | |||
259 | res = fread(sb->buf + sb->len, 1, size, f); | 259 | res = fread(sb->buf + sb->len, 1, size, f); |
260 | if (res > 0) | 260 | if (res > 0) |
261 | strbuf_setlen(sb, sb->len + res); | 261 | strbuf_setlen(sb, sb->len + res); |
262 | else if (res < 0 && oldalloc == 0) | 262 | else if (oldalloc == 0) |
263 | strbuf_release(sb); | 263 | strbuf_release(sb); |
264 | return res; | 264 | return res; |
265 | } | 265 | } |
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h index 37b03255b425..3dca2f654cd0 100644 --- a/tools/perf/util/string.h +++ b/tools/perf/util/string.h | |||
@@ -1,7 +1,7 @@ | |||
1 | #ifndef _PERF_STRING_H_ | 1 | #ifndef _PERF_STRING_H_ |
2 | #define _PERF_STRING_H_ | 2 | #define _PERF_STRING_H_ |
3 | 3 | ||
4 | #include "../types.h" | 4 | #include "types.h" |
5 | 5 | ||
6 | int hex2u64(const char *ptr, u64 *val); | 6 | int hex2u64(const char *ptr, u64 *val); |
7 | 7 | ||
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c new file mode 100644 index 000000000000..025a78edfffe --- /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 | |||
13 | static 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 | |||
28 | out_delete: | ||
29 | free(self); | ||
30 | return NULL; | ||
31 | } | ||
32 | |||
33 | static void str_node__delete(struct str_node *self, bool dupstr) | ||
34 | { | ||
35 | if (dupstr) | ||
36 | free((void *)self->s); | ||
37 | free(self); | ||
38 | } | ||
39 | |||
40 | int 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 | |||
71 | int 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; | ||
93 | out: | ||
94 | fclose(fp); | ||
95 | return err; | ||
96 | } | ||
97 | |||
98 | void 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 | |||
104 | bool 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 | |||
128 | static 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 | |||
136 | int 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 | |||
153 | struct 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; | ||
165 | out_error: | ||
166 | free(self); | ||
167 | return NULL; | ||
168 | } | ||
169 | |||
170 | void 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 000000000000..2fb117fb4b67 --- /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 | |||
7 | struct str_node { | ||
8 | struct rb_node rb_node; | ||
9 | const char *s; | ||
10 | }; | ||
11 | |||
12 | struct strlist { | ||
13 | struct rb_root entries; | ||
14 | bool dupstr; | ||
15 | }; | ||
16 | |||
17 | struct strlist *strlist__new(bool dupstr, const char *slist); | ||
18 | void strlist__delete(struct strlist *self); | ||
19 | |||
20 | void strlist__remove(struct strlist *self, struct str_node *sn); | ||
21 | int strlist__load(struct strlist *self, const char *filename); | ||
22 | int strlist__add(struct strlist *self, const char *str); | ||
23 | |||
24 | bool strlist__has_entry(struct strlist *self, const char *entry); | ||
25 | |||
26 | static inline bool strlist__empty(const struct strlist *self) | ||
27 | { | ||
28 | return rb_first(&self->entries) == NULL; | ||
29 | } | ||
30 | |||
31 | int strlist__parse_list(struct strlist *self, const char *s); | ||
32 | #endif /* STRLIST_H_ */ | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 86e14375e74e..78c2efde01b7 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -520,7 +520,9 @@ static int dso__load_sym(struct dso *self, int fd, const char *name, | |||
520 | nr_syms = shdr.sh_size / shdr.sh_entsize; | 520 | nr_syms = shdr.sh_size / shdr.sh_entsize; |
521 | 521 | ||
522 | memset(&sym, 0, sizeof(sym)); | 522 | memset(&sym, 0, sizeof(sym)); |
523 | 523 | self->prelinked = elf_section_by_name(elf, &ehdr, &shdr, | |
524 | ".gnu.prelink_undo", | ||
525 | NULL) != NULL; | ||
524 | elf_symtab__for_each_symbol(syms, nr_syms, index, sym) { | 526 | elf_symtab__for_each_symbol(syms, nr_syms, index, sym) { |
525 | struct symbol *f; | 527 | struct symbol *f; |
526 | u64 obj_start; | 528 | u64 obj_start; |
@@ -535,7 +537,13 @@ static int dso__load_sym(struct dso *self, int fd, const char *name, | |||
535 | gelf_getshdr(sec, &shdr); | 537 | gelf_getshdr(sec, &shdr); |
536 | obj_start = sym.st_value; | 538 | obj_start = sym.st_value; |
537 | 539 | ||
538 | sym.st_value -= shdr.sh_addr - shdr.sh_offset; | 540 | if (self->prelinked) { |
541 | if (verbose >= 2) | ||
542 | printf("adjusting symbol: st_value: %Lx sh_addr: %Lx sh_offset: %Lx\n", | ||
543 | (u64)sym.st_value, (u64)shdr.sh_addr, (u64)shdr.sh_offset); | ||
544 | |||
545 | sym.st_value -= shdr.sh_addr - shdr.sh_offset; | ||
546 | } | ||
539 | 547 | ||
540 | f = symbol__new(sym.st_value, sym.st_size, | 548 | f = symbol__new(sym.st_value, sym.st_size, |
541 | elf_sym__name(&sym, symstrs), | 549 | elf_sym__name(&sym, symstrs), |
@@ -569,6 +577,8 @@ int dso__load(struct dso *self, symbol_filter_t filter, int verbose) | |||
569 | if (!name) | 577 | if (!name) |
570 | return -1; | 578 | return -1; |
571 | 579 | ||
580 | self->prelinked = 0; | ||
581 | |||
572 | if (strncmp(self->name, "/tmp/perf-", 10) == 0) | 582 | if (strncmp(self->name, "/tmp/perf-", 10) == 0) |
573 | return dso__load_perf_map(self, filter, verbose); | 583 | return dso__load_perf_map(self, filter, verbose); |
574 | 584 | ||
@@ -629,7 +639,7 @@ int dso__load_kernel(struct dso *self, const char *vmlinux, | |||
629 | if (vmlinux) | 639 | if (vmlinux) |
630 | err = dso__load_vmlinux(self, vmlinux, filter, verbose); | 640 | err = dso__load_vmlinux(self, vmlinux, filter, verbose); |
631 | 641 | ||
632 | if (err) | 642 | if (err < 0) |
633 | err = dso__load_kallsyms(self, filter, verbose); | 643 | err = dso__load_kallsyms(self, filter, verbose); |
634 | 644 | ||
635 | return err; | 645 | return err; |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index ea332e56e458..2c48ace8203b 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #define _PERF_SYMBOL_ 1 | 2 | #define _PERF_SYMBOL_ 1 |
3 | 3 | ||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | #include "../types.h" | 5 | #include "types.h" |
6 | #include "list.h" | 6 | #include "list.h" |
7 | #include "rbtree.h" | 7 | #include "rbtree.h" |
8 | 8 | ||
@@ -20,8 +20,9 @@ struct symbol { | |||
20 | struct dso { | 20 | struct dso { |
21 | struct list_head node; | 21 | struct list_head node; |
22 | struct rb_root syms; | 22 | struct rb_root syms; |
23 | unsigned int sym_priv_size; | ||
24 | struct symbol *(*find_symbol)(struct dso *, u64 ip); | 23 | struct symbol *(*find_symbol)(struct dso *, u64 ip); |
24 | unsigned int sym_priv_size; | ||
25 | unsigned char prelinked; | ||
25 | char name[0]; | 26 | char name[0]; |
26 | }; | 27 | }; |
27 | 28 | ||
diff --git a/tools/perf/util/types.h b/tools/perf/util/types.h new file mode 100644 index 000000000000..5e75f9005940 --- /dev/null +++ b/tools/perf/util/types.h | |||
@@ -0,0 +1,17 @@ | |||
1 | #ifndef _PERF_TYPES_H | ||
2 | #define _PERF_TYPES_H | ||
3 | |||
4 | /* | ||
5 | * We define u64 as unsigned long long for every architecture | ||
6 | * so that we can print it with %Lx without getting warnings. | ||
7 | */ | ||
8 | typedef unsigned long long u64; | ||
9 | typedef signed long long s64; | ||
10 | typedef unsigned int u32; | ||
11 | typedef signed int s32; | ||
12 | typedef unsigned short u16; | ||
13 | typedef signed short s16; | ||
14 | typedef unsigned char u8; | ||
15 | typedef signed char s8; | ||
16 | |||
17 | #endif /* _PERF_TYPES_H */ | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index b8cfed776d81..b4be6071c105 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -67,7 +67,6 @@ | |||
67 | #include <assert.h> | 67 | #include <assert.h> |
68 | #include <regex.h> | 68 | #include <regex.h> |
69 | #include <utime.h> | 69 | #include <utime.h> |
70 | #ifndef __MINGW32__ | ||
71 | #include <sys/wait.h> | 70 | #include <sys/wait.h> |
72 | #include <sys/poll.h> | 71 | #include <sys/poll.h> |
73 | #include <sys/socket.h> | 72 | #include <sys/socket.h> |
@@ -81,20 +80,6 @@ | |||
81 | #include <netdb.h> | 80 | #include <netdb.h> |
82 | #include <pwd.h> | 81 | #include <pwd.h> |
83 | #include <inttypes.h> | 82 | #include <inttypes.h> |
84 | #if defined(__CYGWIN__) | ||
85 | #undef _XOPEN_SOURCE | ||
86 | #include <grp.h> | ||
87 | #define _XOPEN_SOURCE 600 | ||
88 | #include "compat/cygwin.h" | ||
89 | #else | ||
90 | #undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */ | ||
91 | #include <grp.h> | ||
92 | #define _ALL_SOURCE 1 | ||
93 | #endif | ||
94 | #else /* __MINGW32__ */ | ||
95 | /* pull in Windows compatibility stuff */ | ||
96 | #include "compat/mingw.h" | ||
97 | #endif /* __MINGW32__ */ | ||
98 | 83 | ||
99 | #ifndef NO_ICONV | 84 | #ifndef NO_ICONV |
100 | #include <iconv.h> | 85 | #include <iconv.h> |