diff options
-rw-r--r-- | Documentation/perf_counter/Makefile | 2 | ||||
-rw-r--r-- | Documentation/perf_counter/builtin-record.c | 56 | ||||
-rw-r--r-- | Documentation/perf_counter/builtin-report.c | 1 | ||||
-rw-r--r-- | Documentation/perf_counter/util/parse-events.c | 27 | ||||
-rw-r--r-- | Documentation/perf_counter/util/symbol.c | 38 |
5 files changed, 54 insertions, 70 deletions
diff --git a/Documentation/perf_counter/Makefile b/Documentation/perf_counter/Makefile index 416ab11e9786..3b8275feb889 100644 --- a/Documentation/perf_counter/Makefile +++ b/Documentation/perf_counter/Makefile | |||
@@ -296,6 +296,7 @@ LIB_H += util/quote.h | |||
296 | LIB_H += util/util.h | 296 | LIB_H += util/util.h |
297 | LIB_H += util/help.h | 297 | LIB_H += util/help.h |
298 | LIB_H += util/strbuf.h | 298 | LIB_H += util/strbuf.h |
299 | LIB_H += util/string.h | ||
299 | LIB_H += util/run-command.h | 300 | LIB_H += util/run-command.h |
300 | LIB_H += util/sigchain.h | 301 | LIB_H += util/sigchain.h |
301 | LIB_H += util/symbol.h | 302 | LIB_H += util/symbol.h |
@@ -315,6 +316,7 @@ LIB_OBJS += util/rbtree.o | |||
315 | LIB_OBJS += util/run-command.o | 316 | LIB_OBJS += util/run-command.o |
316 | LIB_OBJS += util/quote.o | 317 | LIB_OBJS += util/quote.o |
317 | LIB_OBJS += util/strbuf.o | 318 | LIB_OBJS += util/strbuf.o |
319 | LIB_OBJS += util/string.o | ||
318 | LIB_OBJS += util/usage.o | 320 | LIB_OBJS += util/usage.o |
319 | LIB_OBJS += util/wrapper.o | 321 | LIB_OBJS += util/wrapper.o |
320 | LIB_OBJS += util/sigchain.o | 322 | LIB_OBJS += util/sigchain.o |
diff --git a/Documentation/perf_counter/builtin-record.c b/Documentation/perf_counter/builtin-record.c index 96bfb7c5f1e4..9c151ded22fa 100644 --- a/Documentation/perf_counter/builtin-record.c +++ b/Documentation/perf_counter/builtin-record.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "util/util.h" | 5 | #include "util/util.h" |
6 | #include "util/parse-options.h" | 6 | #include "util/parse-options.h" |
7 | #include "util/parse-events.h" | 7 | #include "util/parse-events.h" |
8 | #include "util/string.h" | ||
8 | 9 | ||
9 | #include <sched.h> | 10 | #include <sched.h> |
10 | 11 | ||
@@ -165,12 +166,10 @@ static pid_t pid_synthesize_comm_event(pid_t pid) | |||
165 | { | 166 | { |
166 | struct comm_event comm_ev; | 167 | struct comm_event comm_ev; |
167 | char filename[PATH_MAX]; | 168 | char filename[PATH_MAX]; |
168 | pid_t spid, ppid; | ||
169 | char bf[BUFSIZ]; | 169 | char bf[BUFSIZ]; |
170 | int fd, nr, ret; | 170 | int fd, ret; |
171 | char comm[18]; | ||
172 | size_t size; | 171 | size_t size; |
173 | char state; | 172 | char *field, *sep; |
174 | 173 | ||
175 | snprintf(filename, sizeof(filename), "/proc/%d/stat", pid); | 174 | snprintf(filename, sizeof(filename), "/proc/%d/stat", pid); |
176 | 175 | ||
@@ -185,20 +184,22 @@ static pid_t pid_synthesize_comm_event(pid_t pid) | |||
185 | } | 184 | } |
186 | close(fd); | 185 | close(fd); |
187 | 186 | ||
187 | /* 9027 (cat) R 6747 9027 6747 34816 9027 ... */ | ||
188 | memset(&comm_ev, 0, sizeof(comm_ev)); | 188 | memset(&comm_ev, 0, sizeof(comm_ev)); |
189 | nr = sscanf(bf, "%d %s %c %d %d ", | 189 | field = strchr(bf, '('); |
190 | &spid, comm, &state, &ppid, &comm_ev.pid); | 190 | if (field == NULL) |
191 | if (nr != 5) { | 191 | goto out_failure; |
192 | fprintf(stderr, "couldn't get COMM and pgid, malformed %s\n", | 192 | sep = strchr(++field, ')'); |
193 | filename); | 193 | if (sep == NULL) |
194 | exit(EXIT_FAILURE); | 194 | goto out_failure; |
195 | } | 195 | size = sep - field; |
196 | memcpy(comm_ev.comm, field, size++); | ||
197 | field = strchr(sep + 4, ' '); | ||
198 | if (field == NULL) | ||
199 | goto out_failure; | ||
200 | comm_ev.pid = atoi(++field); | ||
196 | comm_ev.header.type = PERF_EVENT_COMM; | 201 | comm_ev.header.type = PERF_EVENT_COMM; |
197 | comm_ev.tid = pid; | 202 | comm_ev.tid = pid; |
198 | size = strlen(comm); | ||
199 | comm[--size] = '\0'; /* Remove the ')' at the end */ | ||
200 | --size; /* Remove the '(' at the begin */ | ||
201 | memcpy(comm_ev.comm, comm + 1, size); | ||
202 | size = ALIGN(size, sizeof(uint64_t)); | 203 | size = ALIGN(size, sizeof(uint64_t)); |
203 | comm_ev.header.size = sizeof(comm_ev) - (sizeof(comm_ev.comm) - size); | 204 | comm_ev.header.size = sizeof(comm_ev) - (sizeof(comm_ev.comm) - size); |
204 | 205 | ||
@@ -208,6 +209,11 @@ static pid_t pid_synthesize_comm_event(pid_t pid) | |||
208 | exit(-1); | 209 | exit(-1); |
209 | } | 210 | } |
210 | return comm_ev.pid; | 211 | return comm_ev.pid; |
212 | out_failure: | ||
213 | fprintf(stderr, "couldn't get COMM and pgid, malformed %s\n", | ||
214 | filename); | ||
215 | exit(EXIT_FAILURE); | ||
216 | return -1; | ||
211 | } | 217 | } |
212 | 218 | ||
213 | static void pid_synthesize_mmap_events(pid_t pid, pid_t pgid) | 219 | static void pid_synthesize_mmap_events(pid_t pid, pid_t pgid) |
@@ -223,23 +229,25 @@ static void pid_synthesize_mmap_events(pid_t pid, pid_t pgid) | |||
223 | exit(EXIT_FAILURE); | 229 | exit(EXIT_FAILURE); |
224 | } | 230 | } |
225 | while (1) { | 231 | while (1) { |
226 | char bf[BUFSIZ]; | 232 | char bf[BUFSIZ], *pbf = bf; |
227 | unsigned char vm_read, vm_write, vm_exec, vm_mayshare; | ||
228 | struct mmap_event mmap_ev = { | 233 | struct mmap_event mmap_ev = { |
229 | .header.type = PERF_EVENT_MMAP, | 234 | .header.type = PERF_EVENT_MMAP, |
230 | }; | 235 | }; |
231 | unsigned long ino; | 236 | int n; |
232 | int major, minor; | ||
233 | size_t size; | 237 | size_t size; |
234 | if (fgets(bf, sizeof(bf), fp) == NULL) | 238 | if (fgets(bf, sizeof(bf), fp) == NULL) |
235 | break; | 239 | break; |
236 | 240 | ||
237 | /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ | 241 | /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ |
238 | sscanf(bf, "%llx-%llx %c%c%c%c %llx %x:%x %lu", | 242 | n = hex2u64(pbf, &mmap_ev.start); |
239 | &mmap_ev.start, &mmap_ev.len, | 243 | if (n < 0) |
240 | &vm_read, &vm_write, &vm_exec, &vm_mayshare, | 244 | continue; |
241 | &mmap_ev.pgoff, &major, &minor, &ino); | 245 | pbf += n + 1; |
242 | if (vm_exec == 'x') { | 246 | n = hex2u64(pbf, &mmap_ev.len); |
247 | if (n < 0) | ||
248 | continue; | ||
249 | pbf += n + 3; | ||
250 | if (*pbf == 'x') { /* vm_exec */ | ||
243 | char *execname = strrchr(bf, ' '); | 251 | char *execname = strrchr(bf, ' '); |
244 | 252 | ||
245 | if (execname == NULL || execname[1] != '/') | 253 | if (execname == NULL || execname[1] != '/') |
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c index 4705679debae..7973092094e1 100644 --- a/Documentation/perf_counter/builtin-report.c +++ b/Documentation/perf_counter/builtin-report.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "util/cache.h" | 5 | #include "util/cache.h" |
6 | #include "util/rbtree.h" | 6 | #include "util/rbtree.h" |
7 | #include "util/symbol.h" | 7 | #include "util/symbol.h" |
8 | #include "util/string.h" | ||
8 | 9 | ||
9 | #include "perf.h" | 10 | #include "perf.h" |
10 | 11 | ||
diff --git a/Documentation/perf_counter/util/parse-events.c b/Documentation/perf_counter/util/parse-events.c index 88c903eb260a..2fdfd1d923f2 100644 --- a/Documentation/perf_counter/util/parse-events.c +++ b/Documentation/perf_counter/util/parse-events.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include "parse-options.h" | 4 | #include "parse-options.h" |
5 | #include "parse-events.h" | 5 | #include "parse-events.h" |
6 | #include "exec_cmd.h" | 6 | #include "exec_cmd.h" |
7 | #include "string.h" | ||
7 | 8 | ||
8 | int nr_counters; | 9 | int nr_counters; |
9 | 10 | ||
@@ -105,22 +106,26 @@ static __u64 match_event_symbols(const char *str) | |||
105 | __u64 config, id; | 106 | __u64 config, id; |
106 | int type; | 107 | int type; |
107 | unsigned int i; | 108 | unsigned int i; |
108 | char mask_str[4]; | 109 | const char *sep, *pstr; |
109 | 110 | ||
110 | if (sscanf(str, "r%llx", &config) == 1) | 111 | if (str[0] == 'r' && hex2u64(str + 1, &config) > 0) |
111 | return config | PERF_COUNTER_RAW_MASK; | 112 | return config | PERF_COUNTER_RAW_MASK; |
112 | 113 | ||
113 | switch (sscanf(str, "%d:%llu:%2s", &type, &id, mask_str)) { | 114 | pstr = str; |
114 | case 3: | 115 | sep = strchr(pstr, ':'); |
115 | if (strchr(mask_str, 'k')) | 116 | if (sep) { |
117 | type = atoi(pstr); | ||
118 | pstr = sep + 1; | ||
119 | id = atoi(pstr); | ||
120 | sep = strchr(pstr, ':'); | ||
121 | if (sep) { | ||
122 | pstr = sep + 1; | ||
123 | if (strchr(pstr, 'k')) | ||
116 | event_mask[nr_counters] |= EVENT_MASK_USER; | 124 | event_mask[nr_counters] |= EVENT_MASK_USER; |
117 | if (strchr(mask_str, 'u')) | 125 | if (strchr(pstr, 'u')) |
118 | event_mask[nr_counters] |= EVENT_MASK_KERNEL; | 126 | event_mask[nr_counters] |= EVENT_MASK_KERNEL; |
119 | case 2: | 127 | } |
120 | return EID(type, id); | 128 | return EID(type, id); |
121 | |||
122 | default: | ||
123 | break; | ||
124 | } | 129 | } |
125 | 130 | ||
126 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { | 131 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { |
diff --git a/Documentation/perf_counter/util/symbol.c b/Documentation/perf_counter/util/symbol.c index 47281210443d..31e8fae58426 100644 --- a/Documentation/perf_counter/util/symbol.c +++ b/Documentation/perf_counter/util/symbol.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "../perf.h" | 2 | #include "../perf.h" |
3 | #include "string.h" | ||
3 | #include "symbol.h" | 4 | #include "symbol.h" |
4 | 5 | ||
5 | #include <libelf.h> | 6 | #include <libelf.h> |
@@ -122,39 +123,6 @@ size_t dso__fprintf(struct dso *self, FILE *fp) | |||
122 | return ret; | 123 | return ret; |
123 | } | 124 | } |
124 | 125 | ||
125 | static int hex(char ch) | ||
126 | { | ||
127 | if ((ch >= '0') && (ch <= '9')) | ||
128 | return ch - '0'; | ||
129 | if ((ch >= 'a') && (ch <= 'f')) | ||
130 | return ch - 'a' + 10; | ||
131 | if ((ch >= 'A') && (ch <= 'F')) | ||
132 | return ch - 'A' + 10; | ||
133 | return -1; | ||
134 | } | ||
135 | |||
136 | /* | ||
137 | * While we find nice hex chars, build a long_val. | ||
138 | * Return number of chars processed. | ||
139 | */ | ||
140 | static int hex2long(char *ptr, unsigned long *long_val) | ||
141 | { | ||
142 | const char *p = ptr; | ||
143 | *long_val = 0; | ||
144 | |||
145 | while (*p) { | ||
146 | const int hex_val = hex(*p); | ||
147 | |||
148 | if (hex_val < 0) | ||
149 | break; | ||
150 | |||
151 | *long_val = (*long_val << 4) | hex_val; | ||
152 | p++; | ||
153 | } | ||
154 | |||
155 | return p - ptr; | ||
156 | } | ||
157 | |||
158 | static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) | 126 | static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) |
159 | { | 127 | { |
160 | struct rb_node *nd, *prevnd; | 128 | struct rb_node *nd, *prevnd; |
@@ -166,7 +134,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) | |||
166 | goto out_failure; | 134 | goto out_failure; |
167 | 135 | ||
168 | while (!feof(file)) { | 136 | while (!feof(file)) { |
169 | unsigned long start; | 137 | __u64 start; |
170 | struct symbol *sym; | 138 | struct symbol *sym; |
171 | int line_len, len; | 139 | int line_len, len; |
172 | char symbol_type; | 140 | char symbol_type; |
@@ -180,7 +148,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) | |||
180 | 148 | ||
181 | line[--line_len] = '\0'; /* \n */ | 149 | line[--line_len] = '\0'; /* \n */ |
182 | 150 | ||
183 | len = hex2long(line, &start); | 151 | len = hex2u64(line, &start); |
184 | 152 | ||
185 | len++; | 153 | len++; |
186 | if (len + 2 >= line_len) | 154 | if (len + 2 >= line_len) |