diff options
Diffstat (limited to 'tools')
117 files changed, 8077 insertions, 3241 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c new file mode 100644 index 000000000000..11224eddcdc2 --- /dev/null +++ b/tools/hv/hv_kvp_daemon.c | |||
@@ -0,0 +1,500 @@ | |||
1 | /* | ||
2 | * An implementation of key value pair (KVP) functionality for Linux. | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2010, Novell, Inc. | ||
6 | * Author : K. Y. Srinivasan <ksrinivasan@novell.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License version 2 as published | ||
10 | * by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | ||
15 | * NON INFRINGEMENT. See the GNU General Public License for more | ||
16 | * details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | |||
25 | #include <sys/types.h> | ||
26 | #include <sys/socket.h> | ||
27 | #include <sys/poll.h> | ||
28 | #include <sys/utsname.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <stdio.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <unistd.h> | ||
33 | #include <string.h> | ||
34 | #include <errno.h> | ||
35 | #include <arpa/inet.h> | ||
36 | #include <linux/connector.h> | ||
37 | #include <linux/netlink.h> | ||
38 | #include <ifaddrs.h> | ||
39 | #include <netdb.h> | ||
40 | #include <syslog.h> | ||
41 | |||
42 | /* | ||
43 | * KYS: TODO. Need to register these in the kernel. | ||
44 | * | ||
45 | * The following definitions are shared with the in-kernel component; do not | ||
46 | * change any of this without making the corresponding changes in | ||
47 | * the KVP kernel component. | ||
48 | */ | ||
49 | #define CN_KVP_IDX 0x9 /* MSFT KVP functionality */ | ||
50 | #define CN_KVP_VAL 0x1 /* This supports queries from the kernel */ | ||
51 | #define CN_KVP_USER_VAL 0x2 /* This supports queries from the user */ | ||
52 | |||
53 | /* | ||
54 | * KVP protocol: The user mode component first registers with the | ||
55 | * the kernel component. Subsequently, the kernel component requests, data | ||
56 | * for the specified keys. In response to this message the user mode component | ||
57 | * fills in the value corresponding to the specified key. We overload the | ||
58 | * sequence field in the cn_msg header to define our KVP message types. | ||
59 | * | ||
60 | * We use this infrastructure for also supporting queries from user mode | ||
61 | * application for state that may be maintained in the KVP kernel component. | ||
62 | * | ||
63 | * XXXKYS: Have a shared header file between the user and kernel (TODO) | ||
64 | */ | ||
65 | |||
66 | enum kvp_op { | ||
67 | KVP_REGISTER = 0, /* Register the user mode component*/ | ||
68 | KVP_KERNEL_GET, /*Kernel is requesting the value for the specified key*/ | ||
69 | KVP_KERNEL_SET, /*Kernel is providing the value for the specified key*/ | ||
70 | KVP_USER_GET, /*User is requesting the value for the specified key*/ | ||
71 | KVP_USER_SET /*User is providing the value for the specified key*/ | ||
72 | }; | ||
73 | |||
74 | #define HV_KVP_EXCHANGE_MAX_KEY_SIZE 512 | ||
75 | #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE 2048 | ||
76 | |||
77 | struct hv_ku_msg { | ||
78 | __u32 kvp_index; | ||
79 | __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */ | ||
80 | __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */ | ||
81 | }; | ||
82 | |||
83 | enum key_index { | ||
84 | FullyQualifiedDomainName = 0, | ||
85 | IntegrationServicesVersion, /*This key is serviced in the kernel*/ | ||
86 | NetworkAddressIPv4, | ||
87 | NetworkAddressIPv6, | ||
88 | OSBuildNumber, | ||
89 | OSName, | ||
90 | OSMajorVersion, | ||
91 | OSMinorVersion, | ||
92 | OSVersion, | ||
93 | ProcessorArchitecture | ||
94 | }; | ||
95 | |||
96 | /* | ||
97 | * End of shared definitions. | ||
98 | */ | ||
99 | |||
100 | static char kvp_send_buffer[4096]; | ||
101 | static char kvp_recv_buffer[4096]; | ||
102 | static struct sockaddr_nl addr; | ||
103 | |||
104 | static char *os_name = ""; | ||
105 | static char *os_major = ""; | ||
106 | static char *os_minor = ""; | ||
107 | static char *processor_arch; | ||
108 | static char *os_build; | ||
109 | static char *lic_version; | ||
110 | static struct utsname uts_buf; | ||
111 | |||
112 | void kvp_get_os_info(void) | ||
113 | { | ||
114 | FILE *file; | ||
115 | char *p, buf[512]; | ||
116 | |||
117 | uname(&uts_buf); | ||
118 | os_build = uts_buf.release; | ||
119 | processor_arch = uts_buf.machine; | ||
120 | |||
121 | /* | ||
122 | * The current windows host (win7) expects the build | ||
123 | * string to be of the form: x.y.z | ||
124 | * Strip additional information we may have. | ||
125 | */ | ||
126 | p = strchr(os_build, '-'); | ||
127 | if (p) | ||
128 | *p = '\0'; | ||
129 | |||
130 | file = fopen("/etc/SuSE-release", "r"); | ||
131 | if (file != NULL) | ||
132 | goto kvp_osinfo_found; | ||
133 | file = fopen("/etc/redhat-release", "r"); | ||
134 | if (file != NULL) | ||
135 | goto kvp_osinfo_found; | ||
136 | /* | ||
137 | * Add code for other supported platforms. | ||
138 | */ | ||
139 | |||
140 | /* | ||
141 | * We don't have information about the os. | ||
142 | */ | ||
143 | os_name = uts_buf.sysname; | ||
144 | return; | ||
145 | |||
146 | kvp_osinfo_found: | ||
147 | /* up to three lines */ | ||
148 | p = fgets(buf, sizeof(buf), file); | ||
149 | if (p) { | ||
150 | p = strchr(buf, '\n'); | ||
151 | if (p) | ||
152 | *p = '\0'; | ||
153 | p = strdup(buf); | ||
154 | if (!p) | ||
155 | goto done; | ||
156 | os_name = p; | ||
157 | |||
158 | /* second line */ | ||
159 | p = fgets(buf, sizeof(buf), file); | ||
160 | if (p) { | ||
161 | p = strchr(buf, '\n'); | ||
162 | if (p) | ||
163 | *p = '\0'; | ||
164 | p = strdup(buf); | ||
165 | if (!p) | ||
166 | goto done; | ||
167 | os_major = p; | ||
168 | |||
169 | /* third line */ | ||
170 | p = fgets(buf, sizeof(buf), file); | ||
171 | if (p) { | ||
172 | p = strchr(buf, '\n'); | ||
173 | if (p) | ||
174 | *p = '\0'; | ||
175 | p = strdup(buf); | ||
176 | if (p) | ||
177 | os_minor = p; | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | done: | ||
183 | fclose(file); | ||
184 | return; | ||
185 | } | ||
186 | |||
187 | static int | ||
188 | kvp_get_ip_address(int family, char *buffer, int length) | ||
189 | { | ||
190 | struct ifaddrs *ifap; | ||
191 | struct ifaddrs *curp; | ||
192 | int ipv4_len = strlen("255.255.255.255") + 1; | ||
193 | int ipv6_len = strlen("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")+1; | ||
194 | int offset = 0; | ||
195 | const char *str; | ||
196 | char tmp[50]; | ||
197 | int error = 0; | ||
198 | |||
199 | /* | ||
200 | * On entry into this function, the buffer is capable of holding the | ||
201 | * maximum key value (2048 bytes). | ||
202 | */ | ||
203 | |||
204 | if (getifaddrs(&ifap)) { | ||
205 | strcpy(buffer, "getifaddrs failed\n"); | ||
206 | return 1; | ||
207 | } | ||
208 | |||
209 | curp = ifap; | ||
210 | while (curp != NULL) { | ||
211 | if ((curp->ifa_addr != NULL) && | ||
212 | (curp->ifa_addr->sa_family == family)) { | ||
213 | if (family == AF_INET) { | ||
214 | struct sockaddr_in *addr = | ||
215 | (struct sockaddr_in *) curp->ifa_addr; | ||
216 | |||
217 | str = inet_ntop(family, &addr->sin_addr, | ||
218 | tmp, 50); | ||
219 | if (str == NULL) { | ||
220 | strcpy(buffer, "inet_ntop failed\n"); | ||
221 | error = 1; | ||
222 | goto getaddr_done; | ||
223 | } | ||
224 | if (offset == 0) | ||
225 | strcpy(buffer, tmp); | ||
226 | else | ||
227 | strcat(buffer, tmp); | ||
228 | strcat(buffer, ";"); | ||
229 | |||
230 | offset += strlen(str) + 1; | ||
231 | if ((length - offset) < (ipv4_len + 1)) | ||
232 | goto getaddr_done; | ||
233 | |||
234 | } else { | ||
235 | |||
236 | /* | ||
237 | * We only support AF_INET and AF_INET6 | ||
238 | * and the list of addresses is separated by a ";". | ||
239 | */ | ||
240 | struct sockaddr_in6 *addr = | ||
241 | (struct sockaddr_in6 *) curp->ifa_addr; | ||
242 | |||
243 | str = inet_ntop(family, | ||
244 | &addr->sin6_addr.s6_addr, | ||
245 | tmp, 50); | ||
246 | if (str == NULL) { | ||
247 | strcpy(buffer, "inet_ntop failed\n"); | ||
248 | error = 1; | ||
249 | goto getaddr_done; | ||
250 | } | ||
251 | if (offset == 0) | ||
252 | strcpy(buffer, tmp); | ||
253 | else | ||
254 | strcat(buffer, tmp); | ||
255 | strcat(buffer, ";"); | ||
256 | offset += strlen(str) + 1; | ||
257 | if ((length - offset) < (ipv6_len + 1)) | ||
258 | goto getaddr_done; | ||
259 | |||
260 | } | ||
261 | |||
262 | } | ||
263 | curp = curp->ifa_next; | ||
264 | } | ||
265 | |||
266 | getaddr_done: | ||
267 | freeifaddrs(ifap); | ||
268 | return error; | ||
269 | } | ||
270 | |||
271 | |||
272 | static int | ||
273 | kvp_get_domain_name(char *buffer, int length) | ||
274 | { | ||
275 | struct addrinfo hints, *info ; | ||
276 | int error = 0; | ||
277 | |||
278 | gethostname(buffer, length); | ||
279 | memset(&hints, 0, sizeof(hints)); | ||
280 | hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */ | ||
281 | hints.ai_socktype = SOCK_STREAM; | ||
282 | hints.ai_flags = AI_CANONNAME; | ||
283 | |||
284 | error = getaddrinfo(buffer, NULL, &hints, &info); | ||
285 | if (error != 0) { | ||
286 | strcpy(buffer, "getaddrinfo failed\n"); | ||
287 | return error; | ||
288 | } | ||
289 | strcpy(buffer, info->ai_canonname); | ||
290 | freeaddrinfo(info); | ||
291 | return error; | ||
292 | } | ||
293 | |||
294 | static int | ||
295 | netlink_send(int fd, struct cn_msg *msg) | ||
296 | { | ||
297 | struct nlmsghdr *nlh; | ||
298 | unsigned int size; | ||
299 | struct msghdr message; | ||
300 | char buffer[64]; | ||
301 | struct iovec iov[2]; | ||
302 | |||
303 | size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len); | ||
304 | |||
305 | nlh = (struct nlmsghdr *)buffer; | ||
306 | nlh->nlmsg_seq = 0; | ||
307 | nlh->nlmsg_pid = getpid(); | ||
308 | nlh->nlmsg_type = NLMSG_DONE; | ||
309 | nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh)); | ||
310 | nlh->nlmsg_flags = 0; | ||
311 | |||
312 | iov[0].iov_base = nlh; | ||
313 | iov[0].iov_len = sizeof(*nlh); | ||
314 | |||
315 | iov[1].iov_base = msg; | ||
316 | iov[1].iov_len = size; | ||
317 | |||
318 | memset(&message, 0, sizeof(message)); | ||
319 | message.msg_name = &addr; | ||
320 | message.msg_namelen = sizeof(addr); | ||
321 | message.msg_iov = iov; | ||
322 | message.msg_iovlen = 2; | ||
323 | |||
324 | return sendmsg(fd, &message, 0); | ||
325 | } | ||
326 | |||
327 | int main(void) | ||
328 | { | ||
329 | int fd, len, sock_opt; | ||
330 | int error; | ||
331 | struct cn_msg *message; | ||
332 | struct pollfd pfd; | ||
333 | struct nlmsghdr *incoming_msg; | ||
334 | struct cn_msg *incoming_cn_msg; | ||
335 | struct hv_ku_msg *hv_msg; | ||
336 | char *p; | ||
337 | char *key_value; | ||
338 | char *key_name; | ||
339 | |||
340 | daemon(1, 0); | ||
341 | openlog("KVP", 0, LOG_USER); | ||
342 | syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); | ||
343 | /* | ||
344 | * Retrieve OS release information. | ||
345 | */ | ||
346 | kvp_get_os_info(); | ||
347 | |||
348 | fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); | ||
349 | if (fd < 0) { | ||
350 | syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd); | ||
351 | exit(-1); | ||
352 | } | ||
353 | addr.nl_family = AF_NETLINK; | ||
354 | addr.nl_pad = 0; | ||
355 | addr.nl_pid = 0; | ||
356 | addr.nl_groups = CN_KVP_IDX; | ||
357 | |||
358 | |||
359 | error = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); | ||
360 | if (error < 0) { | ||
361 | syslog(LOG_ERR, "bind failed; error:%d", error); | ||
362 | close(fd); | ||
363 | exit(-1); | ||
364 | } | ||
365 | sock_opt = addr.nl_groups; | ||
366 | setsockopt(fd, 270, 1, &sock_opt, sizeof(sock_opt)); | ||
367 | /* | ||
368 | * Register ourselves with the kernel. | ||
369 | */ | ||
370 | message = (struct cn_msg *)kvp_send_buffer; | ||
371 | message->id.idx = CN_KVP_IDX; | ||
372 | message->id.val = CN_KVP_VAL; | ||
373 | message->seq = KVP_REGISTER; | ||
374 | message->ack = 0; | ||
375 | message->len = 0; | ||
376 | |||
377 | len = netlink_send(fd, message); | ||
378 | if (len < 0) { | ||
379 | syslog(LOG_ERR, "netlink_send failed; error:%d", len); | ||
380 | close(fd); | ||
381 | exit(-1); | ||
382 | } | ||
383 | |||
384 | pfd.fd = fd; | ||
385 | |||
386 | while (1) { | ||
387 | pfd.events = POLLIN; | ||
388 | pfd.revents = 0; | ||
389 | poll(&pfd, 1, -1); | ||
390 | |||
391 | len = recv(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0); | ||
392 | |||
393 | if (len < 0) { | ||
394 | syslog(LOG_ERR, "recv failed; error:%d", len); | ||
395 | close(fd); | ||
396 | return -1; | ||
397 | } | ||
398 | |||
399 | incoming_msg = (struct nlmsghdr *)kvp_recv_buffer; | ||
400 | incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); | ||
401 | |||
402 | switch (incoming_cn_msg->seq) { | ||
403 | case KVP_REGISTER: | ||
404 | /* | ||
405 | * Driver is registering with us; stash away the version | ||
406 | * information. | ||
407 | */ | ||
408 | p = (char *)incoming_cn_msg->data; | ||
409 | lic_version = malloc(strlen(p) + 1); | ||
410 | if (lic_version) { | ||
411 | strcpy(lic_version, p); | ||
412 | syslog(LOG_INFO, "KVP LIC Version: %s", | ||
413 | lic_version); | ||
414 | } else { | ||
415 | syslog(LOG_ERR, "malloc failed"); | ||
416 | } | ||
417 | continue; | ||
418 | |||
419 | case KVP_KERNEL_GET: | ||
420 | break; | ||
421 | default: | ||
422 | continue; | ||
423 | } | ||
424 | |||
425 | hv_msg = (struct hv_ku_msg *)incoming_cn_msg->data; | ||
426 | key_name = (char *)hv_msg->kvp_key; | ||
427 | key_value = (char *)hv_msg->kvp_value; | ||
428 | |||
429 | switch (hv_msg->kvp_index) { | ||
430 | case FullyQualifiedDomainName: | ||
431 | kvp_get_domain_name(key_value, | ||
432 | HV_KVP_EXCHANGE_MAX_VALUE_SIZE); | ||
433 | strcpy(key_name, "FullyQualifiedDomainName"); | ||
434 | break; | ||
435 | case IntegrationServicesVersion: | ||
436 | strcpy(key_name, "IntegrationServicesVersion"); | ||
437 | strcpy(key_value, lic_version); | ||
438 | break; | ||
439 | case NetworkAddressIPv4: | ||
440 | kvp_get_ip_address(AF_INET, key_value, | ||
441 | HV_KVP_EXCHANGE_MAX_VALUE_SIZE); | ||
442 | strcpy(key_name, "NetworkAddressIPv4"); | ||
443 | break; | ||
444 | case NetworkAddressIPv6: | ||
445 | kvp_get_ip_address(AF_INET6, key_value, | ||
446 | HV_KVP_EXCHANGE_MAX_VALUE_SIZE); | ||
447 | strcpy(key_name, "NetworkAddressIPv6"); | ||
448 | break; | ||
449 | case OSBuildNumber: | ||
450 | strcpy(key_value, os_build); | ||
451 | strcpy(key_name, "OSBuildNumber"); | ||
452 | break; | ||
453 | case OSName: | ||
454 | strcpy(key_value, os_name); | ||
455 | strcpy(key_name, "OSName"); | ||
456 | break; | ||
457 | case OSMajorVersion: | ||
458 | strcpy(key_value, os_major); | ||
459 | strcpy(key_name, "OSMajorVersion"); | ||
460 | break; | ||
461 | case OSMinorVersion: | ||
462 | strcpy(key_value, os_minor); | ||
463 | strcpy(key_name, "OSMinorVersion"); | ||
464 | break; | ||
465 | case OSVersion: | ||
466 | strcpy(key_value, os_build); | ||
467 | strcpy(key_name, "OSVersion"); | ||
468 | break; | ||
469 | case ProcessorArchitecture: | ||
470 | strcpy(key_value, processor_arch); | ||
471 | strcpy(key_name, "ProcessorArchitecture"); | ||
472 | break; | ||
473 | default: | ||
474 | strcpy(key_value, "Unknown Key"); | ||
475 | /* | ||
476 | * We use a null key name to terminate enumeration. | ||
477 | */ | ||
478 | strcpy(key_name, ""); | ||
479 | break; | ||
480 | } | ||
481 | /* | ||
482 | * Send the value back to the kernel. The response is | ||
483 | * already in the receive buffer. Update the cn_msg header to | ||
484 | * reflect the key value that has been added to the message | ||
485 | */ | ||
486 | |||
487 | incoming_cn_msg->id.idx = CN_KVP_IDX; | ||
488 | incoming_cn_msg->id.val = CN_KVP_VAL; | ||
489 | incoming_cn_msg->seq = KVP_USER_SET; | ||
490 | incoming_cn_msg->ack = 0; | ||
491 | incoming_cn_msg->len = sizeof(struct hv_ku_msg); | ||
492 | |||
493 | len = netlink_send(fd, incoming_cn_msg); | ||
494 | if (len < 0) { | ||
495 | syslog(LOG_ERR, "net_link send failed; error:%d", len); | ||
496 | exit(-1); | ||
497 | } | ||
498 | } | ||
499 | |||
500 | } | ||
diff --git a/tools/perf/Documentation/examples.txt b/tools/perf/Documentation/examples.txt index 8eb6c489fb15..77f952762426 100644 --- a/tools/perf/Documentation/examples.txt +++ b/tools/perf/Documentation/examples.txt | |||
@@ -17,8 +17,8 @@ titan:~> perf list | |||
17 | kmem:kmem_cache_alloc_node [Tracepoint event] | 17 | kmem:kmem_cache_alloc_node [Tracepoint event] |
18 | kmem:kfree [Tracepoint event] | 18 | kmem:kfree [Tracepoint event] |
19 | kmem:kmem_cache_free [Tracepoint event] | 19 | kmem:kmem_cache_free [Tracepoint event] |
20 | kmem:mm_page_free_direct [Tracepoint event] | 20 | kmem:mm_page_free [Tracepoint event] |
21 | kmem:mm_pagevec_free [Tracepoint event] | 21 | kmem:mm_page_free_batched [Tracepoint event] |
22 | kmem:mm_page_alloc [Tracepoint event] | 22 | kmem:mm_page_alloc [Tracepoint event] |
23 | kmem:mm_page_alloc_zone_locked [Tracepoint event] | 23 | kmem:mm_page_alloc_zone_locked [Tracepoint event] |
24 | kmem:mm_page_pcpu_drain [Tracepoint event] | 24 | kmem:mm_page_pcpu_drain [Tracepoint event] |
@@ -29,15 +29,15 @@ measured. For example the page alloc/free properties of a 'hackbench | |||
29 | run' are: | 29 | run' are: |
30 | 30 | ||
31 | titan:~> perf stat -e kmem:mm_page_pcpu_drain -e kmem:mm_page_alloc | 31 | titan:~> perf stat -e kmem:mm_page_pcpu_drain -e kmem:mm_page_alloc |
32 | -e kmem:mm_pagevec_free -e kmem:mm_page_free_direct ./hackbench 10 | 32 | -e kmem:mm_page_free_batched -e kmem:mm_page_free ./hackbench 10 |
33 | Time: 0.575 | 33 | Time: 0.575 |
34 | 34 | ||
35 | Performance counter stats for './hackbench 10': | 35 | Performance counter stats for './hackbench 10': |
36 | 36 | ||
37 | 13857 kmem:mm_page_pcpu_drain | 37 | 13857 kmem:mm_page_pcpu_drain |
38 | 27576 kmem:mm_page_alloc | 38 | 27576 kmem:mm_page_alloc |
39 | 6025 kmem:mm_pagevec_free | 39 | 6025 kmem:mm_page_free_batched |
40 | 20934 kmem:mm_page_free_direct | 40 | 20934 kmem:mm_page_free |
41 | 41 | ||
42 | 0.613972165 seconds time elapsed | 42 | 0.613972165 seconds time elapsed |
43 | 43 | ||
@@ -45,8 +45,8 @@ You can observe the statistical properties as well, by using the | |||
45 | 'repeat the workload N times' feature of perf stat: | 45 | 'repeat the workload N times' feature of perf stat: |
46 | 46 | ||
47 | titan:~> perf stat --repeat 5 -e kmem:mm_page_pcpu_drain -e | 47 | titan:~> perf stat --repeat 5 -e kmem:mm_page_pcpu_drain -e |
48 | kmem:mm_page_alloc -e kmem:mm_pagevec_free -e | 48 | kmem:mm_page_alloc -e kmem:mm_page_free_batched -e |
49 | kmem:mm_page_free_direct ./hackbench 10 | 49 | kmem:mm_page_free ./hackbench 10 |
50 | Time: 0.627 | 50 | Time: 0.627 |
51 | Time: 0.644 | 51 | Time: 0.644 |
52 | Time: 0.564 | 52 | Time: 0.564 |
@@ -57,8 +57,8 @@ You can observe the statistical properties as well, by using the | |||
57 | 57 | ||
58 | 12920 kmem:mm_page_pcpu_drain ( +- 3.359% ) | 58 | 12920 kmem:mm_page_pcpu_drain ( +- 3.359% ) |
59 | 25035 kmem:mm_page_alloc ( +- 3.783% ) | 59 | 25035 kmem:mm_page_alloc ( +- 3.783% ) |
60 | 6104 kmem:mm_pagevec_free ( +- 0.934% ) | 60 | 6104 kmem:mm_page_free_batched ( +- 0.934% ) |
61 | 18376 kmem:mm_page_free_direct ( +- 4.941% ) | 61 | 18376 kmem:mm_page_free ( +- 4.941% ) |
62 | 62 | ||
63 | 0.643954516 seconds time elapsed ( +- 2.363% ) | 63 | 0.643954516 seconds time elapsed ( +- 2.363% ) |
64 | 64 | ||
@@ -158,15 +158,15 @@ Or you can observe the whole system's page allocations for 10 | |||
158 | seconds: | 158 | seconds: |
159 | 159 | ||
160 | titan:~/git> perf stat -a -e kmem:mm_page_pcpu_drain -e | 160 | titan:~/git> perf stat -a -e kmem:mm_page_pcpu_drain -e |
161 | kmem:mm_page_alloc -e kmem:mm_pagevec_free -e | 161 | kmem:mm_page_alloc -e kmem:mm_page_free_batched -e |
162 | kmem:mm_page_free_direct sleep 10 | 162 | kmem:mm_page_free sleep 10 |
163 | 163 | ||
164 | Performance counter stats for 'sleep 10': | 164 | Performance counter stats for 'sleep 10': |
165 | 165 | ||
166 | 171585 kmem:mm_page_pcpu_drain | 166 | 171585 kmem:mm_page_pcpu_drain |
167 | 322114 kmem:mm_page_alloc | 167 | 322114 kmem:mm_page_alloc |
168 | 73623 kmem:mm_pagevec_free | 168 | 73623 kmem:mm_page_free_batched |
169 | 254115 kmem:mm_page_free_direct | 169 | 254115 kmem:mm_page_free |
170 | 170 | ||
171 | 10.000591410 seconds time elapsed | 171 | 10.000591410 seconds time elapsed |
172 | 172 | ||
@@ -174,15 +174,15 @@ Or observe how fluctuating the page allocations are, via statistical | |||
174 | analysis done over ten 1-second intervals: | 174 | analysis done over ten 1-second intervals: |
175 | 175 | ||
176 | titan:~/git> perf stat --repeat 10 -a -e kmem:mm_page_pcpu_drain -e | 176 | titan:~/git> perf stat --repeat 10 -a -e kmem:mm_page_pcpu_drain -e |
177 | kmem:mm_page_alloc -e kmem:mm_pagevec_free -e | 177 | kmem:mm_page_alloc -e kmem:mm_page_free_batched -e |
178 | kmem:mm_page_free_direct sleep 1 | 178 | kmem:mm_page_free sleep 1 |
179 | 179 | ||
180 | Performance counter stats for 'sleep 1' (10 runs): | 180 | Performance counter stats for 'sleep 1' (10 runs): |
181 | 181 | ||
182 | 17254 kmem:mm_page_pcpu_drain ( +- 3.709% ) | 182 | 17254 kmem:mm_page_pcpu_drain ( +- 3.709% ) |
183 | 34394 kmem:mm_page_alloc ( +- 4.617% ) | 183 | 34394 kmem:mm_page_alloc ( +- 4.617% ) |
184 | 7509 kmem:mm_pagevec_free ( +- 4.820% ) | 184 | 7509 kmem:mm_page_free_batched ( +- 4.820% ) |
185 | 25653 kmem:mm_page_free_direct ( +- 3.672% ) | 185 | 25653 kmem:mm_page_free ( +- 3.672% ) |
186 | 186 | ||
187 | 1.058135029 seconds time elapsed ( +- 3.089% ) | 187 | 1.058135029 seconds time elapsed ( +- 3.089% ) |
188 | 188 | ||
diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt index 85c5f026930d..c89f9e1453f7 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt | |||
@@ -22,7 +22,7 @@ OPTIONS | |||
22 | ------- | 22 | ------- |
23 | -i:: | 23 | -i:: |
24 | --input=:: | 24 | --input=:: |
25 | Input file name. (default: perf.data) | 25 | Input file name. (default: perf.data unless stdin is a fifo) |
26 | 26 | ||
27 | -d:: | 27 | -d:: |
28 | --dsos=<dso[,dso...]>:: | 28 | --dsos=<dso[,dso...]>:: |
@@ -66,12 +66,25 @@ OPTIONS | |||
66 | used. This interfaces starts by centering on the line with more | 66 | used. This interfaces starts by centering on the line with more |
67 | samples, TAB/UNTAB cycles through the lines with more samples. | 67 | samples, TAB/UNTAB cycles through the lines with more samples. |
68 | 68 | ||
69 | -c:: | 69 | -C:: |
70 | --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can | 70 | --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can |
71 | be provided as a comma-separated list with no space: 0,1. Ranges of | 71 | be provided as a comma-separated list with no space: 0,1. Ranges of |
72 | CPUs are specified with -: 0-2. Default is to report samples on all | 72 | CPUs are specified with -: 0-2. Default is to report samples on all |
73 | CPUs. | 73 | CPUs. |
74 | 74 | ||
75 | --asm-raw:: | ||
76 | Show raw instruction encoding of assembly instructions. | ||
77 | |||
78 | --source:: | ||
79 | Interleave source code with assembly code. Enabled by default, | ||
80 | disable with --no-source. | ||
81 | |||
82 | --symfs=<directory>:: | ||
83 | Look for files with symbols relative to this directory. | ||
84 | |||
85 | -M:: | ||
86 | --disassembler-style=:: Set disassembler style for objdump. | ||
87 | |||
75 | SEE ALSO | 88 | SEE ALSO |
76 | -------- | 89 | -------- |
77 | linkperf:perf-record[1], linkperf:perf-report[1] | 90 | linkperf:perf-record[1], linkperf:perf-report[1] |
diff --git a/tools/perf/Documentation/perf-buildid-list.txt b/tools/perf/Documentation/perf-buildid-list.txt index 5eaac6f26d51..25c52efcc7f0 100644 --- a/tools/perf/Documentation/perf-buildid-list.txt +++ b/tools/perf/Documentation/perf-buildid-list.txt | |||
@@ -16,6 +16,9 @@ This command displays the buildids found in a perf.data file, so that other | |||
16 | tools can be used to fetch packages with matching symbol tables for use by | 16 | tools can be used to fetch packages with matching symbol tables for use by |
17 | perf report. | 17 | perf report. |
18 | 18 | ||
19 | It can also be used to show the build id of the running kernel or in an ELF | ||
20 | file using -i/--input. | ||
21 | |||
19 | OPTIONS | 22 | OPTIONS |
20 | ------- | 23 | ------- |
21 | -H:: | 24 | -H:: |
@@ -23,10 +26,13 @@ OPTIONS | |||
23 | Show only DSOs with hits. | 26 | Show only DSOs with hits. |
24 | -i:: | 27 | -i:: |
25 | --input=:: | 28 | --input=:: |
26 | Input file name. (default: perf.data) | 29 | Input file name. (default: perf.data unless stdin is a fifo) |
27 | -f:: | 30 | -f:: |
28 | --force:: | 31 | --force:: |
29 | Don't do ownership validation. | 32 | Don't do ownership validation. |
33 | -k:: | ||
34 | --kernel:: | ||
35 | Show running kernel build id. | ||
30 | -v:: | 36 | -v:: |
31 | --verbose:: | 37 | --verbose:: |
32 | Be more verbose. | 38 | Be more verbose. |
diff --git a/tools/perf/Documentation/perf-evlist.txt b/tools/perf/Documentation/perf-evlist.txt index 0cada9e053dc..0507ec7bad71 100644 --- a/tools/perf/Documentation/perf-evlist.txt +++ b/tools/perf/Documentation/perf-evlist.txt | |||
@@ -18,7 +18,7 @@ OPTIONS | |||
18 | ------- | 18 | ------- |
19 | -i:: | 19 | -i:: |
20 | --input=:: | 20 | --input=:: |
21 | Input file name. (default: perf.data) | 21 | Input file name. (default: perf.data unless stdin is a fifo) |
22 | 22 | ||
23 | SEE ALSO | 23 | SEE ALSO |
24 | -------- | 24 | -------- |
diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt index a52fcde894c7..7c8fbbf3f61c 100644 --- a/tools/perf/Documentation/perf-kmem.txt +++ b/tools/perf/Documentation/perf-kmem.txt | |||
@@ -23,7 +23,7 @@ OPTIONS | |||
23 | ------- | 23 | ------- |
24 | -i <file>:: | 24 | -i <file>:: |
25 | --input=<file>:: | 25 | --input=<file>:: |
26 | Select the input file (default: perf.data) | 26 | Select the input file (default: perf.data unless stdin is a fifo) |
27 | 27 | ||
28 | --caller:: | 28 | --caller:: |
29 | Show per-callsite statistics | 29 | Show per-callsite statistics |
diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt index 4a26a2f3a6a3..d6b2a4f2108b 100644 --- a/tools/perf/Documentation/perf-lock.txt +++ b/tools/perf/Documentation/perf-lock.txt | |||
@@ -29,7 +29,7 @@ COMMON OPTIONS | |||
29 | 29 | ||
30 | -i:: | 30 | -i:: |
31 | --input=<file>:: | 31 | --input=<file>:: |
32 | Input file name. | 32 | Input file name. (default: perf.data unless stdin is a fifo) |
33 | 33 | ||
34 | -v:: | 34 | -v:: |
35 | --verbose:: | 35 | --verbose:: |
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index 5a520f825295..2937f7e14bb7 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt | |||
@@ -89,7 +89,7 @@ OPTIONS | |||
89 | 89 | ||
90 | -m:: | 90 | -m:: |
91 | --mmap-pages=:: | 91 | --mmap-pages=:: |
92 | Number of mmap data pages. | 92 | Number of mmap data pages. Must be a power of two. |
93 | 93 | ||
94 | -g:: | 94 | -g:: |
95 | --call-graph:: | 95 | --call-graph:: |
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt index 04253c07d19a..9b430e98712e 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt | |||
@@ -19,7 +19,7 @@ OPTIONS | |||
19 | ------- | 19 | ------- |
20 | -i:: | 20 | -i:: |
21 | --input=:: | 21 | --input=:: |
22 | Input file name. (default: perf.data) | 22 | Input file name. (default: perf.data unless stdin is a fifo) |
23 | 23 | ||
24 | -v:: | 24 | -v:: |
25 | --verbose:: | 25 | --verbose:: |
@@ -39,7 +39,7 @@ OPTIONS | |||
39 | -T:: | 39 | -T:: |
40 | --threads:: | 40 | --threads:: |
41 | Show per-thread event counters | 41 | Show per-thread event counters |
42 | -C:: | 42 | -c:: |
43 | --comms=:: | 43 | --comms=:: |
44 | Only consider symbols in these comms. CSV that understands | 44 | Only consider symbols in these comms. CSV that understands |
45 | file://filename entries. | 45 | file://filename entries. |
@@ -80,9 +80,10 @@ OPTIONS | |||
80 | --dump-raw-trace:: | 80 | --dump-raw-trace:: |
81 | Dump raw trace in ASCII. | 81 | Dump raw trace in ASCII. |
82 | 82 | ||
83 | -g [type,min,order]:: | 83 | -g [type,min[,limit],order]:: |
84 | --call-graph:: | 84 | --call-graph:: |
85 | Display call chains using type, min percent threshold and order. | 85 | Display call chains using type, min percent threshold, optional print |
86 | limit and order. | ||
86 | type can be either: | 87 | type can be either: |
87 | - flat: single column, linear exposure of call chains. | 88 | - flat: single column, linear exposure of call chains. |
88 | - graph: use a graph tree, displaying absolute overhead rates. | 89 | - graph: use a graph tree, displaying absolute overhead rates. |
@@ -128,12 +129,30 @@ OPTIONS | |||
128 | --symfs=<directory>:: | 129 | --symfs=<directory>:: |
129 | Look for files with symbols relative to this directory. | 130 | Look for files with symbols relative to this directory. |
130 | 131 | ||
131 | -c:: | 132 | -C:: |
132 | --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can | 133 | --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can |
133 | be provided as a comma-separated list with no space: 0,1. Ranges of | 134 | be provided as a comma-separated list with no space: 0,1. Ranges of |
134 | CPUs are specified with -: 0-2. Default is to report samples on all | 135 | CPUs are specified with -: 0-2. Default is to report samples on all |
135 | CPUs. | 136 | CPUs. |
136 | 137 | ||
138 | -M:: | ||
139 | --disassembler-style=:: Set disassembler style for objdump. | ||
140 | |||
141 | --source:: | ||
142 | Interleave source code with assembly code. Enabled by default, | ||
143 | disable with --no-source. | ||
144 | |||
145 | --asm-raw:: | ||
146 | Show raw instruction encoding of assembly instructions. | ||
147 | |||
148 | --show-total-period:: Show a column with the sum of periods. | ||
149 | |||
150 | -I:: | ||
151 | --show-info:: | ||
152 | Display extended information about the perf.data file. This adds | ||
153 | information which may be very large and thus may clutter the display. | ||
154 | It currently includes: cpu and numa topology of the host system. | ||
155 | |||
137 | SEE ALSO | 156 | SEE ALSO |
138 | -------- | 157 | -------- |
139 | linkperf:perf-stat[1] | 158 | linkperf:perf-stat[1], linkperf:perf-annotate[1] |
diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt index 46822d5fde1c..8ff4df956951 100644 --- a/tools/perf/Documentation/perf-sched.txt +++ b/tools/perf/Documentation/perf-sched.txt | |||
@@ -8,7 +8,7 @@ perf-sched - Tool to trace/measure scheduler properties (latencies) | |||
8 | SYNOPSIS | 8 | SYNOPSIS |
9 | -------- | 9 | -------- |
10 | [verse] | 10 | [verse] |
11 | 'perf sched' {record|latency|map|replay|trace} | 11 | 'perf sched' {record|latency|map|replay|script} |
12 | 12 | ||
13 | DESCRIPTION | 13 | DESCRIPTION |
14 | ----------- | 14 | ----------- |
@@ -20,8 +20,8 @@ There are five variants of perf sched: | |||
20 | 'perf sched latency' to report the per task scheduling latencies | 20 | 'perf sched latency' to report the per task scheduling latencies |
21 | and other scheduling properties of the workload. | 21 | and other scheduling properties of the workload. |
22 | 22 | ||
23 | 'perf sched trace' to see a detailed trace of the workload that | 23 | 'perf sched script' to see a detailed trace of the workload that |
24 | was recorded. | 24 | was recorded (aliased to 'perf script' for now). |
25 | 25 | ||
26 | 'perf sched replay' to simulate the workload that was recorded | 26 | 'perf sched replay' to simulate the workload that was recorded |
27 | via perf sched record. (this is done by starting up mockup threads | 27 | via perf sched record. (this is done by starting up mockup threads |
@@ -40,7 +40,7 @@ OPTIONS | |||
40 | ------- | 40 | ------- |
41 | -i:: | 41 | -i:: |
42 | --input=<file>:: | 42 | --input=<file>:: |
43 | Input file name. (default: perf.data) | 43 | Input file name. (default: perf.data unless stdin is a fifo) |
44 | 44 | ||
45 | -v:: | 45 | -v:: |
46 | --verbose:: | 46 | --verbose:: |
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index db017867d9e8..2f6cef43da25 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt | |||
@@ -106,7 +106,7 @@ OPTIONS | |||
106 | 106 | ||
107 | -i:: | 107 | -i:: |
108 | --input=:: | 108 | --input=:: |
109 | Input file name. | 109 | Input file name. (default: perf.data unless stdin is a fifo) |
110 | 110 | ||
111 | -d:: | 111 | -d:: |
112 | --debug-mode:: | 112 | --debug-mode:: |
@@ -182,12 +182,24 @@ OPTIONS | |||
182 | --hide-call-graph:: | 182 | --hide-call-graph:: |
183 | When printing symbols do not display call chain. | 183 | When printing symbols do not display call chain. |
184 | 184 | ||
185 | -c:: | 185 | -C:: |
186 | --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can | 186 | --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can |
187 | be provided as a comma-separated list with no space: 0,1. Ranges of | 187 | be provided as a comma-separated list with no space: 0,1. Ranges of |
188 | CPUs are specified with -: 0-2. Default is to report samples on all | 188 | CPUs are specified with -: 0-2. Default is to report samples on all |
189 | CPUs. | 189 | CPUs. |
190 | 190 | ||
191 | -c:: | ||
192 | --comms=:: | ||
193 | Only display events for these comms. CSV that understands | ||
194 | file://filename entries. | ||
195 | |||
196 | -I:: | ||
197 | --show-info:: | ||
198 | Display extended information about the perf.data file. This adds | ||
199 | information which may be very large and thus may clutter the display. | ||
200 | It currently includes: cpu and numa topology of the host system. | ||
201 | It can only be used with the perf script report mode. | ||
202 | |||
191 | SEE ALSO | 203 | SEE ALSO |
192 | -------- | 204 | -------- |
193 | linkperf:perf-record[1], linkperf:perf-script-perl[1], | 205 | linkperf:perf-record[1], linkperf:perf-script-perl[1], |
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 918cc38ee6d1..8966b9ab2014 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt | |||
@@ -94,6 +94,22 @@ an empty cgroup (monitor all the time) using, e.g., -G foo,,bar. Cgroups must ha | |||
94 | corresponding events, i.e., they always refer to events defined earlier on the command | 94 | corresponding events, i.e., they always refer to events defined earlier on the command |
95 | line. | 95 | line. |
96 | 96 | ||
97 | -o file:: | ||
98 | --output file:: | ||
99 | Print the output into the designated file. | ||
100 | |||
101 | --append:: | ||
102 | Append to the output file designated with the -o option. Ignored if -o is not specified. | ||
103 | |||
104 | --log-fd:: | ||
105 | |||
106 | Log output to fd, instead of stderr. Complementary to --output, and mutually exclusive | ||
107 | with it. --append may be used here. Examples: | ||
108 | 3>results perf stat --log-fd 3 -- $cmd | ||
109 | 3>>results perf stat --log-fd 3 --append -- $cmd | ||
110 | |||
111 | |||
112 | |||
97 | EXAMPLES | 113 | EXAMPLES |
98 | -------- | 114 | -------- |
99 | 115 | ||
diff --git a/tools/perf/Documentation/perf-test.txt b/tools/perf/Documentation/perf-test.txt index 2c3b462f64b0..b24ac40fcd58 100644 --- a/tools/perf/Documentation/perf-test.txt +++ b/tools/perf/Documentation/perf-test.txt | |||
@@ -8,13 +8,19 @@ perf-test - Runs sanity tests. | |||
8 | SYNOPSIS | 8 | SYNOPSIS |
9 | -------- | 9 | -------- |
10 | [verse] | 10 | [verse] |
11 | 'perf test <options>' | 11 | 'perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]' |
12 | 12 | ||
13 | DESCRIPTION | 13 | DESCRIPTION |
14 | ----------- | 14 | ----------- |
15 | This command does assorted sanity tests, initially through linked routines but | 15 | This command does assorted sanity tests, initially through linked routines but |
16 | also will look for a directory with more tests in the form of scripts. | 16 | also will look for a directory with more tests in the form of scripts. |
17 | 17 | ||
18 | To get a list of available tests use 'perf test list', specifying a test name | ||
19 | fragment will show all tests that have it. | ||
20 | |||
21 | To run just specific tests, inform test name fragments or the numbers obtained | ||
22 | from 'perf test list'. | ||
23 | |||
18 | OPTIONS | 24 | OPTIONS |
19 | ------- | 25 | ------- |
20 | -v:: | 26 | -v:: |
diff --git a/tools/perf/Documentation/perf-timechart.txt b/tools/perf/Documentation/perf-timechart.txt index d7b79e2ba2ad..1632b0efc757 100644 --- a/tools/perf/Documentation/perf-timechart.txt +++ b/tools/perf/Documentation/perf-timechart.txt | |||
@@ -27,7 +27,7 @@ OPTIONS | |||
27 | Select the output file (default: output.svg) | 27 | Select the output file (default: output.svg) |
28 | -i:: | 28 | -i:: |
29 | --input=:: | 29 | --input=:: |
30 | Select the input file (default: perf.data) | 30 | Select the input file (default: perf.data unless stdin is a fifo) |
31 | -w:: | 31 | -w:: |
32 | --width=:: | 32 | --width=:: |
33 | Select the width of the SVG file (default: 1000) | 33 | Select the width of the SVG file (default: 1000) |
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt index f6eb1cdafb77..b1a5bbbfebef 100644 --- a/tools/perf/Documentation/perf-top.txt +++ b/tools/perf/Documentation/perf-top.txt | |||
@@ -106,6 +106,51 @@ Default is to monitor all CPUS. | |||
106 | --zero:: | 106 | --zero:: |
107 | Zero history across display updates. | 107 | Zero history across display updates. |
108 | 108 | ||
109 | -s:: | ||
110 | --sort:: | ||
111 | Sort by key(s): pid, comm, dso, symbol, parent | ||
112 | |||
113 | -n:: | ||
114 | --show-nr-samples:: | ||
115 | Show a column with the number of samples. | ||
116 | |||
117 | --show-total-period:: | ||
118 | Show a column with the sum of periods. | ||
119 | |||
120 | --dsos:: | ||
121 | Only consider symbols in these dsos. | ||
122 | |||
123 | --comms:: | ||
124 | Only consider symbols in these comms. | ||
125 | |||
126 | --symbols:: | ||
127 | Only consider these symbols. | ||
128 | |||
129 | -M:: | ||
130 | --disassembler-style=:: Set disassembler style for objdump. | ||
131 | |||
132 | --source:: | ||
133 | Interleave source code with assembly code. Enabled by default, | ||
134 | disable with --no-source. | ||
135 | |||
136 | --asm-raw:: | ||
137 | Show raw instruction encoding of assembly instructions. | ||
138 | |||
139 | -G [type,min,order]:: | ||
140 | --call-graph:: | ||
141 | Display call chains using type, min percent threshold and order. | ||
142 | type can be either: | ||
143 | - flat: single column, linear exposure of call chains. | ||
144 | - graph: use a graph tree, displaying absolute overhead rates. | ||
145 | - fractal: like graph, but displays relative rates. Each branch of | ||
146 | the tree is considered as a new profiled object. | ||
147 | |||
148 | order can be either: | ||
149 | - callee: callee based call graph. | ||
150 | - caller: inverted caller based call graph. | ||
151 | |||
152 | Default: fractal,0.5,callee. | ||
153 | |||
109 | INTERACTIVE PROMPTING KEYS | 154 | INTERACTIVE PROMPTING KEYS |
110 | -------------------------- | 155 | -------------------------- |
111 | 156 | ||
@@ -130,9 +175,6 @@ INTERACTIVE PROMPTING KEYS | |||
130 | [S]:: | 175 | [S]:: |
131 | Stop annotation, return to full profile display. | 176 | Stop annotation, return to full profile display. |
132 | 177 | ||
133 | [w]:: | ||
134 | Toggle between weighted sum and individual count[E]r profile. | ||
135 | |||
136 | [z]:: | 178 | [z]:: |
137 | Toggle event count zeroing across display updates. | 179 | Toggle event count zeroing across display updates. |
138 | 180 | ||
diff --git a/tools/perf/Documentation/perfconfig.example b/tools/perf/Documentation/perfconfig.example new file mode 100644 index 000000000000..d1448668f4d4 --- /dev/null +++ b/tools/perf/Documentation/perfconfig.example | |||
@@ -0,0 +1,20 @@ | |||
1 | [colors] | ||
2 | |||
3 | # These were the old defaults | ||
4 | top = red, lightgray | ||
5 | medium = green, lightgray | ||
6 | normal = black, lightgray | ||
7 | selected = lightgray, magenta | ||
8 | code = blue, lightgray | ||
9 | |||
10 | [tui] | ||
11 | |||
12 | # Defaults if linked with libslang | ||
13 | report = on | ||
14 | annotate = on | ||
15 | top = on | ||
16 | |||
17 | [buildid] | ||
18 | |||
19 | # Default, disable using /dev/null | ||
20 | dir = /root/.debug | ||
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index e9d5c271db69..ac86d67b636e 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -278,6 +278,7 @@ LIB_H += util/strbuf.h | |||
278 | LIB_H += util/strlist.h | 278 | LIB_H += util/strlist.h |
279 | LIB_H += util/strfilter.h | 279 | LIB_H += util/strfilter.h |
280 | LIB_H += util/svghelper.h | 280 | LIB_H += util/svghelper.h |
281 | LIB_H += util/tool.h | ||
281 | LIB_H += util/run-command.h | 282 | LIB_H += util/run-command.h |
282 | LIB_H += util/sigchain.h | 283 | LIB_H += util/sigchain.h |
283 | LIB_H += util/symbol.h | 284 | LIB_H += util/symbol.h |
@@ -466,13 +467,13 @@ else | |||
466 | LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o | 467 | LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o |
467 | LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o | 468 | LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o |
468 | LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o | 469 | LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o |
469 | LIB_OBJS += $(OUTPUT)util/ui/browsers/top.o | ||
470 | LIB_OBJS += $(OUTPUT)util/ui/helpline.o | 470 | LIB_OBJS += $(OUTPUT)util/ui/helpline.o |
471 | LIB_OBJS += $(OUTPUT)util/ui/progress.o | 471 | LIB_OBJS += $(OUTPUT)util/ui/progress.o |
472 | LIB_OBJS += $(OUTPUT)util/ui/util.o | 472 | LIB_OBJS += $(OUTPUT)util/ui/util.o |
473 | LIB_H += util/ui/browser.h | 473 | LIB_H += util/ui/browser.h |
474 | LIB_H += util/ui/browsers/map.h | 474 | LIB_H += util/ui/browsers/map.h |
475 | LIB_H += util/ui/helpline.h | 475 | LIB_H += util/ui/helpline.h |
476 | LIB_H += util/ui/keysyms.h | ||
476 | LIB_H += util/ui/libslang.h | 477 | LIB_H += util/ui/libslang.h |
477 | LIB_H += util/ui/progress.h | 478 | LIB_H += util/ui/progress.h |
478 | LIB_H += util/ui/util.h | 479 | LIB_H += util/ui/util.h |
@@ -729,9 +730,6 @@ $(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS | |||
729 | $(OUTPUT)util/ui/browsers/annotate.o: util/ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS | 730 | $(OUTPUT)util/ui/browsers/annotate.o: util/ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS |
730 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< | 731 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< |
731 | 732 | ||
732 | $(OUTPUT)util/ui/browsers/top.o: util/ui/browsers/top.c $(OUTPUT)PERF-CFLAGS | ||
733 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< | ||
734 | |||
735 | $(OUTPUT)util/ui/browsers/hists.o: util/ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS | 733 | $(OUTPUT)util/ui/browsers/hists.o: util/ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS |
736 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< | 734 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< |
737 | 735 | ||
diff --git a/tools/perf/arch/powerpc/Makefile b/tools/perf/arch/powerpc/Makefile index 15130b50dfe3..744e629797be 100644 --- a/tools/perf/arch/powerpc/Makefile +++ b/tools/perf/arch/powerpc/Makefile | |||
@@ -2,3 +2,4 @@ ifndef NO_DWARF | |||
2 | PERF_HAVE_DWARF_REGS := 1 | 2 | PERF_HAVE_DWARF_REGS := 1 |
3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o | 3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o |
4 | endif | 4 | endif |
5 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o | ||
diff --git a/tools/perf/arch/powerpc/util/dwarf-regs.c b/tools/perf/arch/powerpc/util/dwarf-regs.c index 48ae0c5e3f73..7cdd61d0e27c 100644 --- a/tools/perf/arch/powerpc/util/dwarf-regs.c +++ b/tools/perf/arch/powerpc/util/dwarf-regs.c | |||
@@ -9,7 +9,10 @@ | |||
9 | * 2 of the License, or (at your option) any later version. | 9 | * 2 of the License, or (at your option) any later version. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <stdlib.h> | ||
13 | #ifndef __UCLIBC__ | ||
12 | #include <libio.h> | 14 | #include <libio.h> |
15 | #endif | ||
13 | #include <dwarf-regs.h> | 16 | #include <dwarf-regs.h> |
14 | 17 | ||
15 | 18 | ||
diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c new file mode 100644 index 000000000000..eba80c292945 --- /dev/null +++ b/tools/perf/arch/powerpc/util/header.c | |||
@@ -0,0 +1,36 @@ | |||
1 | #include <sys/types.h> | ||
2 | #include <unistd.h> | ||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | #include "../../util/header.h" | ||
8 | |||
9 | #define __stringify_1(x) #x | ||
10 | #define __stringify(x) __stringify_1(x) | ||
11 | |||
12 | #define mfspr(rn) ({unsigned long rval; \ | ||
13 | asm volatile("mfspr %0," __stringify(rn) \ | ||
14 | : "=r" (rval)); rval; }) | ||
15 | |||
16 | #define SPRN_PVR 0x11F /* Processor Version Register */ | ||
17 | #define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */ | ||
18 | #define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */ | ||
19 | |||
20 | int | ||
21 | get_cpuid(char *buffer, size_t sz) | ||
22 | { | ||
23 | unsigned long pvr; | ||
24 | int nb; | ||
25 | |||
26 | pvr = mfspr(SPRN_PVR); | ||
27 | |||
28 | nb = snprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr)); | ||
29 | |||
30 | /* look for end marker to ensure the entire data fit */ | ||
31 | if (strchr(buffer, '$')) { | ||
32 | buffer[nb-1] = '\0'; | ||
33 | return 0; | ||
34 | } | ||
35 | return -1; | ||
36 | } | ||
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile index 15130b50dfe3..744e629797be 100644 --- a/tools/perf/arch/x86/Makefile +++ b/tools/perf/arch/x86/Makefile | |||
@@ -2,3 +2,4 @@ ifndef NO_DWARF | |||
2 | PERF_HAVE_DWARF_REGS := 1 | 2 | PERF_HAVE_DWARF_REGS := 1 |
3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o | 3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o |
4 | endif | 4 | endif |
5 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o | ||
diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c new file mode 100644 index 000000000000..f94006068d2b --- /dev/null +++ b/tools/perf/arch/x86/util/header.c | |||
@@ -0,0 +1,59 @@ | |||
1 | #include <sys/types.h> | ||
2 | #include <unistd.h> | ||
3 | #include <stdio.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | #include "../../util/header.h" | ||
8 | |||
9 | static inline void | ||
10 | cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c, | ||
11 | unsigned int *d) | ||
12 | { | ||
13 | __asm__ __volatile__ (".byte 0x53\n\tcpuid\n\t" | ||
14 | "movl %%ebx, %%esi\n\t.byte 0x5b" | ||
15 | : "=a" (*a), | ||
16 | "=S" (*b), | ||
17 | "=c" (*c), | ||
18 | "=d" (*d) | ||
19 | : "a" (op)); | ||
20 | } | ||
21 | |||
22 | int | ||
23 | get_cpuid(char *buffer, size_t sz) | ||
24 | { | ||
25 | unsigned int a, b, c, d, lvl; | ||
26 | int family = -1, model = -1, step = -1; | ||
27 | int nb; | ||
28 | char vendor[16]; | ||
29 | |||
30 | cpuid(0, &lvl, &b, &c, &d); | ||
31 | strncpy(&vendor[0], (char *)(&b), 4); | ||
32 | strncpy(&vendor[4], (char *)(&d), 4); | ||
33 | strncpy(&vendor[8], (char *)(&c), 4); | ||
34 | vendor[12] = '\0'; | ||
35 | |||
36 | if (lvl >= 1) { | ||
37 | cpuid(1, &a, &b, &c, &d); | ||
38 | |||
39 | family = (a >> 8) & 0xf; /* bits 11 - 8 */ | ||
40 | model = (a >> 4) & 0xf; /* Bits 7 - 4 */ | ||
41 | step = a & 0xf; | ||
42 | |||
43 | /* extended family */ | ||
44 | if (family == 0xf) | ||
45 | family += (a >> 20) & 0xff; | ||
46 | |||
47 | /* extended model */ | ||
48 | if (family >= 0x6) | ||
49 | model += ((a >> 16) & 0xf) << 4; | ||
50 | } | ||
51 | nb = snprintf(buffer, sz, "%s,%u,%u,%u$", vendor, family, model, step); | ||
52 | |||
53 | /* look for end marker to ensure the entire data fit */ | ||
54 | if (strchr(buffer, '$')) { | ||
55 | buffer[nb-1] = '\0'; | ||
56 | return 0; | ||
57 | } | ||
58 | return -1; | ||
59 | } | ||
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 555aefd7fe01..214ba7f9f577 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -27,32 +27,32 @@ | |||
27 | #include "util/sort.h" | 27 | #include "util/sort.h" |
28 | #include "util/hist.h" | 28 | #include "util/hist.h" |
29 | #include "util/session.h" | 29 | #include "util/session.h" |
30 | #include "util/tool.h" | ||
30 | 31 | ||
31 | #include <linux/bitmap.h> | 32 | #include <linux/bitmap.h> |
32 | 33 | ||
33 | static char const *input_name = "perf.data"; | 34 | struct perf_annotate { |
34 | 35 | struct perf_tool tool; | |
35 | static bool force, use_tui, use_stdio; | 36 | char const *input_name; |
36 | 37 | bool force, use_tui, use_stdio; | |
37 | static bool full_paths; | 38 | bool full_paths; |
38 | 39 | bool print_line; | |
39 | static bool print_line; | 40 | const char *sym_hist_filter; |
40 | 41 | const char *cpu_list; | |
41 | static const char *sym_hist_filter; | 42 | DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
42 | 43 | }; | |
43 | static const char *cpu_list; | ||
44 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); | ||
45 | 44 | ||
46 | static int perf_evlist__add_sample(struct perf_evlist *evlist, | 45 | static int perf_evsel__add_sample(struct perf_evsel *evsel, |
47 | struct perf_sample *sample, | 46 | struct perf_sample *sample, |
48 | struct perf_evsel *evsel, | 47 | struct addr_location *al, |
49 | struct addr_location *al) | 48 | struct perf_annotate *ann) |
50 | { | 49 | { |
51 | struct hist_entry *he; | 50 | struct hist_entry *he; |
52 | int ret; | 51 | int ret; |
53 | 52 | ||
54 | if (sym_hist_filter != NULL && | 53 | if (ann->sym_hist_filter != NULL && |
55 | (al->sym == NULL || strcmp(sym_hist_filter, al->sym->name) != 0)) { | 54 | (al->sym == NULL || |
55 | strcmp(ann->sym_hist_filter, al->sym->name) != 0)) { | ||
56 | /* We're only interested in a symbol named sym_hist_filter */ | 56 | /* We're only interested in a symbol named sym_hist_filter */ |
57 | if (al->sym != NULL) { | 57 | if (al->sym != NULL) { |
58 | rb_erase(&al->sym->rb_node, | 58 | rb_erase(&al->sym->rb_node, |
@@ -69,8 +69,7 @@ static int perf_evlist__add_sample(struct perf_evlist *evlist, | |||
69 | ret = 0; | 69 | ret = 0; |
70 | if (he->ms.sym != NULL) { | 70 | if (he->ms.sym != NULL) { |
71 | struct annotation *notes = symbol__annotation(he->ms.sym); | 71 | struct annotation *notes = symbol__annotation(he->ms.sym); |
72 | if (notes->src == NULL && | 72 | if (notes->src == NULL && symbol__alloc_hist(he->ms.sym) < 0) |
73 | symbol__alloc_hist(he->ms.sym, evlist->nr_entries) < 0) | ||
74 | return -ENOMEM; | 73 | return -ENOMEM; |
75 | 74 | ||
76 | ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); | 75 | ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); |
@@ -81,25 +80,26 @@ static int perf_evlist__add_sample(struct perf_evlist *evlist, | |||
81 | return ret; | 80 | return ret; |
82 | } | 81 | } |
83 | 82 | ||
84 | static int process_sample_event(union perf_event *event, | 83 | static int process_sample_event(struct perf_tool *tool, |
84 | union perf_event *event, | ||
85 | struct perf_sample *sample, | 85 | struct perf_sample *sample, |
86 | struct perf_evsel *evsel, | 86 | struct perf_evsel *evsel, |
87 | struct perf_session *session) | 87 | struct machine *machine) |
88 | { | 88 | { |
89 | struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool); | ||
89 | struct addr_location al; | 90 | struct addr_location al; |
90 | 91 | ||
91 | if (perf_event__preprocess_sample(event, session, &al, sample, | 92 | if (perf_event__preprocess_sample(event, machine, &al, sample, |
92 | symbol__annotate_init) < 0) { | 93 | symbol__annotate_init) < 0) { |
93 | pr_warning("problem processing %d event, skipping it.\n", | 94 | pr_warning("problem processing %d event, skipping it.\n", |
94 | event->header.type); | 95 | event->header.type); |
95 | return -1; | 96 | return -1; |
96 | } | 97 | } |
97 | 98 | ||
98 | if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) | 99 | if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap)) |
99 | return 0; | 100 | return 0; |
100 | 101 | ||
101 | if (!al.filtered && | 102 | if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) { |
102 | perf_evlist__add_sample(session->evlist, sample, evsel, &al)) { | ||
103 | pr_warning("problem incrementing symbol count, " | 103 | pr_warning("problem incrementing symbol count, " |
104 | "skipping event\n"); | 104 | "skipping event\n"); |
105 | return -1; | 105 | return -1; |
@@ -108,16 +108,18 @@ static int process_sample_event(union perf_event *event, | |||
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
111 | static int hist_entry__tty_annotate(struct hist_entry *he, int evidx) | 111 | static int hist_entry__tty_annotate(struct hist_entry *he, int evidx, |
112 | struct perf_annotate *ann) | ||
112 | { | 113 | { |
113 | return symbol__tty_annotate(he->ms.sym, he->ms.map, evidx, | 114 | return symbol__tty_annotate(he->ms.sym, he->ms.map, evidx, |
114 | print_line, full_paths, 0, 0); | 115 | ann->print_line, ann->full_paths, 0, 0); |
115 | } | 116 | } |
116 | 117 | ||
117 | static void hists__find_annotations(struct hists *self, int evidx) | 118 | static void hists__find_annotations(struct hists *self, int evidx, |
119 | struct perf_annotate *ann) | ||
118 | { | 120 | { |
119 | struct rb_node *nd = rb_first(&self->entries), *next; | 121 | struct rb_node *nd = rb_first(&self->entries), *next; |
120 | int key = KEY_RIGHT; | 122 | int key = K_RIGHT; |
121 | 123 | ||
122 | while (nd) { | 124 | while (nd) { |
123 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 125 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
@@ -129,7 +131,7 @@ static void hists__find_annotations(struct hists *self, int evidx) | |||
129 | notes = symbol__annotation(he->ms.sym); | 131 | notes = symbol__annotation(he->ms.sym); |
130 | if (notes->src == NULL) { | 132 | if (notes->src == NULL) { |
131 | find_next: | 133 | find_next: |
132 | if (key == KEY_LEFT) | 134 | if (key == K_LEFT) |
133 | nd = rb_prev(nd); | 135 | nd = rb_prev(nd); |
134 | else | 136 | else |
135 | nd = rb_next(nd); | 137 | nd = rb_next(nd); |
@@ -137,12 +139,12 @@ find_next: | |||
137 | } | 139 | } |
138 | 140 | ||
139 | if (use_browser > 0) { | 141 | if (use_browser > 0) { |
140 | key = hist_entry__tui_annotate(he, evidx); | 142 | key = hist_entry__tui_annotate(he, evidx, NULL, NULL, 0); |
141 | switch (key) { | 143 | switch (key) { |
142 | case KEY_RIGHT: | 144 | case K_RIGHT: |
143 | next = rb_next(nd); | 145 | next = rb_next(nd); |
144 | break; | 146 | break; |
145 | case KEY_LEFT: | 147 | case K_LEFT: |
146 | next = rb_prev(nd); | 148 | next = rb_prev(nd); |
147 | break; | 149 | break; |
148 | default: | 150 | default: |
@@ -152,7 +154,7 @@ find_next: | |||
152 | if (next != NULL) | 154 | if (next != NULL) |
153 | nd = next; | 155 | nd = next; |
154 | } else { | 156 | } else { |
155 | hist_entry__tty_annotate(he, evidx); | 157 | hist_entry__tty_annotate(he, evidx, ann); |
156 | nd = rb_next(nd); | 158 | nd = rb_next(nd); |
157 | /* | 159 | /* |
158 | * Since we have a hist_entry per IP for the same | 160 | * Since we have a hist_entry per IP for the same |
@@ -165,33 +167,26 @@ find_next: | |||
165 | } | 167 | } |
166 | } | 168 | } |
167 | 169 | ||
168 | static struct perf_event_ops event_ops = { | 170 | static int __cmd_annotate(struct perf_annotate *ann) |
169 | .sample = process_sample_event, | ||
170 | .mmap = perf_event__process_mmap, | ||
171 | .comm = perf_event__process_comm, | ||
172 | .fork = perf_event__process_task, | ||
173 | .ordered_samples = true, | ||
174 | .ordering_requires_timestamps = true, | ||
175 | }; | ||
176 | |||
177 | static int __cmd_annotate(void) | ||
178 | { | 171 | { |
179 | int ret; | 172 | int ret; |
180 | struct perf_session *session; | 173 | struct perf_session *session; |
181 | struct perf_evsel *pos; | 174 | struct perf_evsel *pos; |
182 | u64 total_nr_samples; | 175 | u64 total_nr_samples; |
183 | 176 | ||
184 | session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops); | 177 | session = perf_session__new(ann->input_name, O_RDONLY, |
178 | ann->force, false, &ann->tool); | ||
185 | if (session == NULL) | 179 | if (session == NULL) |
186 | return -ENOMEM; | 180 | return -ENOMEM; |
187 | 181 | ||
188 | if (cpu_list) { | 182 | if (ann->cpu_list) { |
189 | ret = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap); | 183 | ret = perf_session__cpu_bitmap(session, ann->cpu_list, |
184 | ann->cpu_bitmap); | ||
190 | if (ret) | 185 | if (ret) |
191 | goto out_delete; | 186 | goto out_delete; |
192 | } | 187 | } |
193 | 188 | ||
194 | ret = perf_session__process_events(session, &event_ops); | 189 | ret = perf_session__process_events(session, &ann->tool); |
195 | if (ret) | 190 | if (ret) |
196 | goto out_delete; | 191 | goto out_delete; |
197 | 192 | ||
@@ -215,12 +210,12 @@ static int __cmd_annotate(void) | |||
215 | total_nr_samples += nr_samples; | 210 | total_nr_samples += nr_samples; |
216 | hists__collapse_resort(hists); | 211 | hists__collapse_resort(hists); |
217 | hists__output_resort(hists); | 212 | hists__output_resort(hists); |
218 | hists__find_annotations(hists, pos->idx); | 213 | hists__find_annotations(hists, pos->idx, ann); |
219 | } | 214 | } |
220 | } | 215 | } |
221 | 216 | ||
222 | if (total_nr_samples == 0) { | 217 | if (total_nr_samples == 0) { |
223 | ui__warning("The %s file has no samples!\n", input_name); | 218 | ui__warning("The %s file has no samples!\n", session->filename); |
224 | goto out_delete; | 219 | goto out_delete; |
225 | } | 220 | } |
226 | out_delete: | 221 | out_delete: |
@@ -244,39 +239,57 @@ static const char * const annotate_usage[] = { | |||
244 | NULL | 239 | NULL |
245 | }; | 240 | }; |
246 | 241 | ||
247 | static const struct option options[] = { | 242 | int cmd_annotate(int argc, const char **argv, const char *prefix __used) |
248 | OPT_STRING('i', "input", &input_name, "file", | 243 | { |
244 | struct perf_annotate annotate = { | ||
245 | .tool = { | ||
246 | .sample = process_sample_event, | ||
247 | .mmap = perf_event__process_mmap, | ||
248 | .comm = perf_event__process_comm, | ||
249 | .fork = perf_event__process_task, | ||
250 | .ordered_samples = true, | ||
251 | .ordering_requires_timestamps = true, | ||
252 | }, | ||
253 | }; | ||
254 | const struct option options[] = { | ||
255 | OPT_STRING('i', "input", &annotate.input_name, "file", | ||
249 | "input file name"), | 256 | "input file name"), |
250 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", | 257 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", |
251 | "only consider symbols in these dsos"), | 258 | "only consider symbols in these dsos"), |
252 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", | 259 | OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol", |
253 | "symbol to annotate"), | 260 | "symbol to annotate"), |
254 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 261 | OPT_BOOLEAN('f', "force", &annotate.force, "don't complain, do it"), |
255 | OPT_INCR('v', "verbose", &verbose, | 262 | OPT_INCR('v', "verbose", &verbose, |
256 | "be more verbose (show symbol address, etc)"), | 263 | "be more verbose (show symbol address, etc)"), |
257 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 264 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
258 | "dump raw trace in ASCII"), | 265 | "dump raw trace in ASCII"), |
259 | OPT_BOOLEAN(0, "tui", &use_tui, "Use the TUI interface"), | 266 | OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"), |
260 | OPT_BOOLEAN(0, "stdio", &use_stdio, "Use the stdio interface"), | 267 | OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"), |
261 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | 268 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
262 | "file", "vmlinux pathname"), | 269 | "file", "vmlinux pathname"), |
263 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, | 270 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
264 | "load module symbols - WARNING: use only with -k and LIVE kernel"), | 271 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
265 | OPT_BOOLEAN('l', "print-line", &print_line, | 272 | OPT_BOOLEAN('l', "print-line", &annotate.print_line, |
266 | "print matching source lines (may be slow)"), | 273 | "print matching source lines (may be slow)"), |
267 | OPT_BOOLEAN('P', "full-paths", &full_paths, | 274 | OPT_BOOLEAN('P', "full-paths", &annotate.full_paths, |
268 | "Don't shorten the displayed pathnames"), | 275 | "Don't shorten the displayed pathnames"), |
269 | OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"), | 276 | OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"), |
277 | OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory", | ||
278 | "Look for files with symbols relative to this directory"), | ||
279 | OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src, | ||
280 | "Interleave source code with assembly code (default)"), | ||
281 | OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw, | ||
282 | "Display raw encoding of assembly instructions (default)"), | ||
283 | OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", | ||
284 | "Specify disassembler style (e.g. -M intel for intel syntax)"), | ||
270 | OPT_END() | 285 | OPT_END() |
271 | }; | 286 | }; |
272 | 287 | ||
273 | int cmd_annotate(int argc, const char **argv, const char *prefix __used) | ||
274 | { | ||
275 | argc = parse_options(argc, argv, options, annotate_usage, 0); | 288 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
276 | 289 | ||
277 | if (use_stdio) | 290 | if (annotate.use_stdio) |
278 | use_browser = 0; | 291 | use_browser = 0; |
279 | else if (use_tui) | 292 | else if (annotate.use_tui) |
280 | use_browser = 1; | 293 | use_browser = 1; |
281 | 294 | ||
282 | setup_browser(true); | 295 | setup_browser(true); |
@@ -297,7 +310,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
297 | if (argc > 1) | 310 | if (argc > 1) |
298 | usage_with_options(annotate_usage, options); | 311 | usage_with_options(annotate_usage, options); |
299 | 312 | ||
300 | sym_hist_filter = argv[0]; | 313 | annotate.sym_hist_filter = argv[0]; |
301 | } | 314 | } |
302 | 315 | ||
303 | if (field_sep && *field_sep == '.') { | 316 | if (field_sep && *field_sep == '.') { |
@@ -305,5 +318,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
305 | return -1; | 318 | return -1; |
306 | } | 319 | } |
307 | 320 | ||
308 | return __cmd_annotate(); | 321 | return __cmd_annotate(&annotate); |
309 | } | 322 | } |
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index 5af32ae9031e..52480467e9ff 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * builtin-buildid-list.c | 2 | * builtin-buildid-list.c |
3 | * | 3 | * |
4 | * Builtin buildid-list command: list buildids in perf.data | 4 | * Builtin buildid-list command: list buildids in perf.data, in the running |
5 | * kernel and in ELF files. | ||
5 | * | 6 | * |
6 | * Copyright (C) 2009, Red Hat Inc. | 7 | * Copyright (C) 2009, Red Hat Inc. |
7 | * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com> | 8 | * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com> |
@@ -15,8 +16,11 @@ | |||
15 | #include "util/session.h" | 16 | #include "util/session.h" |
16 | #include "util/symbol.h" | 17 | #include "util/symbol.h" |
17 | 18 | ||
18 | static char const *input_name = "perf.data"; | 19 | #include <libelf.h> |
20 | |||
21 | static const char *input_name; | ||
19 | static bool force; | 22 | static bool force; |
23 | static bool show_kernel; | ||
20 | static bool with_hits; | 24 | static bool with_hits; |
21 | 25 | ||
22 | static const char * const buildid_list_usage[] = { | 26 | static const char * const buildid_list_usage[] = { |
@@ -29,29 +33,74 @@ static const struct option options[] = { | |||
29 | OPT_STRING('i', "input", &input_name, "file", | 33 | OPT_STRING('i', "input", &input_name, "file", |
30 | "input file name"), | 34 | "input file name"), |
31 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 35 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
36 | OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"), | ||
32 | OPT_INCR('v', "verbose", &verbose, | 37 | OPT_INCR('v', "verbose", &verbose, |
33 | "be more verbose"), | 38 | "be more verbose"), |
34 | OPT_END() | 39 | OPT_END() |
35 | }; | 40 | }; |
36 | 41 | ||
37 | static int __cmd_buildid_list(void) | 42 | static int sysfs__fprintf_build_id(FILE *fp) |
43 | { | ||
44 | u8 kallsyms_build_id[BUILD_ID_SIZE]; | ||
45 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
46 | |||
47 | if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id, | ||
48 | sizeof(kallsyms_build_id)) != 0) | ||
49 | return -1; | ||
50 | |||
51 | build_id__sprintf(kallsyms_build_id, sizeof(kallsyms_build_id), | ||
52 | sbuild_id); | ||
53 | fprintf(fp, "%s\n", sbuild_id); | ||
54 | return 0; | ||
55 | } | ||
56 | |||
57 | static int filename__fprintf_build_id(const char *name, FILE *fp) | ||
58 | { | ||
59 | u8 build_id[BUILD_ID_SIZE]; | ||
60 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
61 | |||
62 | if (filename__read_build_id(name, build_id, | ||
63 | sizeof(build_id)) != sizeof(build_id)) | ||
64 | return 0; | ||
65 | |||
66 | build_id__sprintf(build_id, sizeof(build_id), sbuild_id); | ||
67 | return fprintf(fp, "%s\n", sbuild_id); | ||
68 | } | ||
69 | |||
70 | static int perf_session__list_build_ids(void) | ||
38 | { | 71 | { |
39 | struct perf_session *session; | 72 | struct perf_session *session; |
40 | 73 | ||
74 | elf_version(EV_CURRENT); | ||
75 | |||
41 | session = perf_session__new(input_name, O_RDONLY, force, false, | 76 | session = perf_session__new(input_name, O_RDONLY, force, false, |
42 | &build_id__mark_dso_hit_ops); | 77 | &build_id__mark_dso_hit_ops); |
43 | if (session == NULL) | 78 | if (session == NULL) |
44 | return -1; | 79 | return -1; |
45 | 80 | ||
81 | /* | ||
82 | * See if this is an ELF file first: | ||
83 | */ | ||
84 | if (filename__fprintf_build_id(session->filename, stdout)) | ||
85 | goto out; | ||
86 | |||
46 | if (with_hits) | 87 | if (with_hits) |
47 | perf_session__process_events(session, &build_id__mark_dso_hit_ops); | 88 | perf_session__process_events(session, &build_id__mark_dso_hit_ops); |
48 | 89 | ||
49 | perf_session__fprintf_dsos_buildid(session, stdout, with_hits); | 90 | perf_session__fprintf_dsos_buildid(session, stdout, with_hits); |
50 | 91 | out: | |
51 | perf_session__delete(session); | 92 | perf_session__delete(session); |
52 | return 0; | 93 | return 0; |
53 | } | 94 | } |
54 | 95 | ||
96 | static int __cmd_buildid_list(void) | ||
97 | { | ||
98 | if (show_kernel) | ||
99 | return sysfs__fprintf_build_id(stdout); | ||
100 | |||
101 | return perf_session__list_build_ids(); | ||
102 | } | ||
103 | |||
55 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) | 104 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) |
56 | { | 105 | { |
57 | argc = parse_options(argc, argv, options, buildid_list_usage, 0); | 106 | argc = parse_options(argc, argv, options, buildid_list_usage, 0); |
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index e8219990f8b8..4f19513d7dda 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -9,7 +9,9 @@ | |||
9 | #include "util/debug.h" | 9 | #include "util/debug.h" |
10 | #include "util/event.h" | 10 | #include "util/event.h" |
11 | #include "util/hist.h" | 11 | #include "util/hist.h" |
12 | #include "util/evsel.h" | ||
12 | #include "util/session.h" | 13 | #include "util/session.h" |
14 | #include "util/tool.h" | ||
13 | #include "util/sort.h" | 15 | #include "util/sort.h" |
14 | #include "util/symbol.h" | 16 | #include "util/symbol.h" |
15 | #include "util/util.h" | 17 | #include "util/util.h" |
@@ -30,14 +32,15 @@ static int hists__add_entry(struct hists *self, | |||
30 | return -ENOMEM; | 32 | return -ENOMEM; |
31 | } | 33 | } |
32 | 34 | ||
33 | static int diff__process_sample_event(union perf_event *event, | 35 | static int diff__process_sample_event(struct perf_tool *tool __used, |
36 | union perf_event *event, | ||
34 | struct perf_sample *sample, | 37 | struct perf_sample *sample, |
35 | struct perf_evsel *evsel __used, | 38 | struct perf_evsel *evsel __used, |
36 | struct perf_session *session) | 39 | struct machine *machine) |
37 | { | 40 | { |
38 | struct addr_location al; | 41 | struct addr_location al; |
39 | 42 | ||
40 | if (perf_event__preprocess_sample(event, session, &al, sample, NULL) < 0) { | 43 | if (perf_event__preprocess_sample(event, machine, &al, sample, NULL) < 0) { |
41 | pr_warning("problem processing %d event, skipping it.\n", | 44 | pr_warning("problem processing %d event, skipping it.\n", |
42 | event->header.type); | 45 | event->header.type); |
43 | return -1; | 46 | return -1; |
@@ -46,16 +49,16 @@ static int diff__process_sample_event(union perf_event *event, | |||
46 | if (al.filtered || al.sym == NULL) | 49 | if (al.filtered || al.sym == NULL) |
47 | return 0; | 50 | return 0; |
48 | 51 | ||
49 | if (hists__add_entry(&session->hists, &al, sample->period)) { | 52 | if (hists__add_entry(&evsel->hists, &al, sample->period)) { |
50 | pr_warning("problem incrementing symbol period, skipping event\n"); | 53 | pr_warning("problem incrementing symbol period, skipping event\n"); |
51 | return -1; | 54 | return -1; |
52 | } | 55 | } |
53 | 56 | ||
54 | session->hists.stats.total_period += sample->period; | 57 | evsel->hists.stats.total_period += sample->period; |
55 | return 0; | 58 | return 0; |
56 | } | 59 | } |
57 | 60 | ||
58 | static struct perf_event_ops event_ops = { | 61 | static struct perf_tool perf_diff = { |
59 | .sample = diff__process_sample_event, | 62 | .sample = diff__process_sample_event, |
60 | .mmap = perf_event__process_mmap, | 63 | .mmap = perf_event__process_mmap, |
61 | .comm = perf_event__process_comm, | 64 | .comm = perf_event__process_comm, |
@@ -145,13 +148,13 @@ static int __cmd_diff(void) | |||
145 | int ret, i; | 148 | int ret, i; |
146 | struct perf_session *session[2]; | 149 | struct perf_session *session[2]; |
147 | 150 | ||
148 | session[0] = perf_session__new(input_old, O_RDONLY, force, false, &event_ops); | 151 | session[0] = perf_session__new(input_old, O_RDONLY, force, false, &perf_diff); |
149 | session[1] = perf_session__new(input_new, O_RDONLY, force, false, &event_ops); | 152 | session[1] = perf_session__new(input_new, O_RDONLY, force, false, &perf_diff); |
150 | if (session[0] == NULL || session[1] == NULL) | 153 | if (session[0] == NULL || session[1] == NULL) |
151 | return -ENOMEM; | 154 | return -ENOMEM; |
152 | 155 | ||
153 | for (i = 0; i < 2; ++i) { | 156 | for (i = 0; i < 2; ++i) { |
154 | ret = perf_session__process_events(session[i], &event_ops); | 157 | ret = perf_session__process_events(session[i], &perf_diff); |
155 | if (ret) | 158 | if (ret) |
156 | goto out_delete; | 159 | goto out_delete; |
157 | } | 160 | } |
@@ -162,7 +165,7 @@ static int __cmd_diff(void) | |||
162 | 165 | ||
163 | hists__match(&session[0]->hists, &session[1]->hists); | 166 | hists__match(&session[0]->hists, &session[1]->hists); |
164 | hists__fprintf(&session[1]->hists, &session[0]->hists, | 167 | hists__fprintf(&session[1]->hists, &session[0]->hists, |
165 | show_displacement, stdout); | 168 | show_displacement, true, 0, 0, stdout); |
166 | out_delete: | 169 | out_delete: |
167 | for (i = 0; i < 2; ++i) | 170 | for (i = 0; i < 2; ++i) |
168 | perf_session__delete(session[i]); | 171 | perf_session__delete(session[i]); |
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index 4c5e9e04a41f..26760322c4f4 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c | |||
@@ -15,7 +15,7 @@ | |||
15 | #include "util/parse-options.h" | 15 | #include "util/parse-options.h" |
16 | #include "util/session.h" | 16 | #include "util/session.h" |
17 | 17 | ||
18 | static char const *input_name = "perf.data"; | 18 | static const char *input_name; |
19 | 19 | ||
20 | static int __cmd_evlist(void) | 20 | static int __cmd_evlist(void) |
21 | { | 21 | { |
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 8dfc12bb119b..09c106193e65 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
@@ -9,6 +9,7 @@ | |||
9 | 9 | ||
10 | #include "perf.h" | 10 | #include "perf.h" |
11 | #include "util/session.h" | 11 | #include "util/session.h" |
12 | #include "util/tool.h" | ||
12 | #include "util/debug.h" | 13 | #include "util/debug.h" |
13 | 14 | ||
14 | #include "util/parse-options.h" | 15 | #include "util/parse-options.h" |
@@ -16,8 +17,9 @@ | |||
16 | static char const *input_name = "-"; | 17 | static char const *input_name = "-"; |
17 | static bool inject_build_ids; | 18 | static bool inject_build_ids; |
18 | 19 | ||
19 | static int perf_event__repipe_synth(union perf_event *event, | 20 | static int perf_event__repipe_synth(struct perf_tool *tool __used, |
20 | struct perf_session *session __used) | 21 | union perf_event *event, |
22 | struct machine *machine __used) | ||
21 | { | 23 | { |
22 | uint32_t size; | 24 | uint32_t size; |
23 | void *buf = event; | 25 | void *buf = event; |
@@ -36,41 +38,70 @@ static int perf_event__repipe_synth(union perf_event *event, | |||
36 | return 0; | 38 | return 0; |
37 | } | 39 | } |
38 | 40 | ||
39 | static int perf_event__repipe(union perf_event *event, | 41 | static int perf_event__repipe_op2_synth(struct perf_tool *tool, |
42 | union perf_event *event, | ||
43 | struct perf_session *session __used) | ||
44 | { | ||
45 | return perf_event__repipe_synth(tool, event, NULL); | ||
46 | } | ||
47 | |||
48 | static int perf_event__repipe_event_type_synth(struct perf_tool *tool, | ||
49 | union perf_event *event) | ||
50 | { | ||
51 | return perf_event__repipe_synth(tool, event, NULL); | ||
52 | } | ||
53 | |||
54 | static int perf_event__repipe_tracing_data_synth(union perf_event *event, | ||
55 | struct perf_session *session __used) | ||
56 | { | ||
57 | return perf_event__repipe_synth(NULL, event, NULL); | ||
58 | } | ||
59 | |||
60 | static int perf_event__repipe_attr(union perf_event *event, | ||
61 | struct perf_evlist **pevlist __used) | ||
62 | { | ||
63 | return perf_event__repipe_synth(NULL, event, NULL); | ||
64 | } | ||
65 | |||
66 | static int perf_event__repipe(struct perf_tool *tool, | ||
67 | union perf_event *event, | ||
40 | struct perf_sample *sample __used, | 68 | struct perf_sample *sample __used, |
41 | struct perf_session *session) | 69 | struct machine *machine) |
42 | { | 70 | { |
43 | return perf_event__repipe_synth(event, session); | 71 | return perf_event__repipe_synth(tool, event, machine); |
44 | } | 72 | } |
45 | 73 | ||
46 | static int perf_event__repipe_sample(union perf_event *event, | 74 | static int perf_event__repipe_sample(struct perf_tool *tool, |
75 | union perf_event *event, | ||
47 | struct perf_sample *sample __used, | 76 | struct perf_sample *sample __used, |
48 | struct perf_evsel *evsel __used, | 77 | struct perf_evsel *evsel __used, |
49 | struct perf_session *session) | 78 | struct machine *machine) |
50 | { | 79 | { |
51 | return perf_event__repipe_synth(event, session); | 80 | return perf_event__repipe_synth(tool, event, machine); |
52 | } | 81 | } |
53 | 82 | ||
54 | static int perf_event__repipe_mmap(union perf_event *event, | 83 | static int perf_event__repipe_mmap(struct perf_tool *tool, |
84 | union perf_event *event, | ||
55 | struct perf_sample *sample, | 85 | struct perf_sample *sample, |
56 | struct perf_session *session) | 86 | struct machine *machine) |
57 | { | 87 | { |
58 | int err; | 88 | int err; |
59 | 89 | ||
60 | err = perf_event__process_mmap(event, sample, session); | 90 | err = perf_event__process_mmap(tool, event, sample, machine); |
61 | perf_event__repipe(event, sample, session); | 91 | perf_event__repipe(tool, event, sample, machine); |
62 | 92 | ||
63 | return err; | 93 | return err; |
64 | } | 94 | } |
65 | 95 | ||
66 | static int perf_event__repipe_task(union perf_event *event, | 96 | static int perf_event__repipe_task(struct perf_tool *tool, |
97 | union perf_event *event, | ||
67 | struct perf_sample *sample, | 98 | struct perf_sample *sample, |
68 | struct perf_session *session) | 99 | struct machine *machine) |
69 | { | 100 | { |
70 | int err; | 101 | int err; |
71 | 102 | ||
72 | err = perf_event__process_task(event, sample, session); | 103 | err = perf_event__process_task(tool, event, sample, machine); |
73 | perf_event__repipe(event, sample, session); | 104 | perf_event__repipe(tool, event, sample, machine); |
74 | 105 | ||
75 | return err; | 106 | return err; |
76 | } | 107 | } |
@@ -80,7 +111,7 @@ static int perf_event__repipe_tracing_data(union perf_event *event, | |||
80 | { | 111 | { |
81 | int err; | 112 | int err; |
82 | 113 | ||
83 | perf_event__repipe_synth(event, session); | 114 | perf_event__repipe_synth(NULL, event, NULL); |
84 | err = perf_event__process_tracing_data(event, session); | 115 | err = perf_event__process_tracing_data(event, session); |
85 | 116 | ||
86 | return err; | 117 | return err; |
@@ -100,10 +131,10 @@ static int dso__read_build_id(struct dso *self) | |||
100 | return -1; | 131 | return -1; |
101 | } | 132 | } |
102 | 133 | ||
103 | static int dso__inject_build_id(struct dso *self, struct perf_session *session) | 134 | static int dso__inject_build_id(struct dso *self, struct perf_tool *tool, |
135 | struct machine *machine) | ||
104 | { | 136 | { |
105 | u16 misc = PERF_RECORD_MISC_USER; | 137 | u16 misc = PERF_RECORD_MISC_USER; |
106 | struct machine *machine; | ||
107 | int err; | 138 | int err; |
108 | 139 | ||
109 | if (dso__read_build_id(self) < 0) { | 140 | if (dso__read_build_id(self) < 0) { |
@@ -111,17 +142,11 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session) | |||
111 | return -1; | 142 | return -1; |
112 | } | 143 | } |
113 | 144 | ||
114 | machine = perf_session__find_host_machine(session); | ||
115 | if (machine == NULL) { | ||
116 | pr_err("Can't find machine for session\n"); | ||
117 | return -1; | ||
118 | } | ||
119 | |||
120 | if (self->kernel) | 145 | if (self->kernel) |
121 | misc = PERF_RECORD_MISC_KERNEL; | 146 | misc = PERF_RECORD_MISC_KERNEL; |
122 | 147 | ||
123 | err = perf_event__synthesize_build_id(self, misc, perf_event__repipe, | 148 | err = perf_event__synthesize_build_id(tool, self, misc, perf_event__repipe, |
124 | machine, session); | 149 | machine); |
125 | if (err) { | 150 | if (err) { |
126 | pr_err("Can't synthesize build_id event for %s\n", self->long_name); | 151 | pr_err("Can't synthesize build_id event for %s\n", self->long_name); |
127 | return -1; | 152 | return -1; |
@@ -130,10 +155,11 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session) | |||
130 | return 0; | 155 | return 0; |
131 | } | 156 | } |
132 | 157 | ||
133 | static int perf_event__inject_buildid(union perf_event *event, | 158 | static int perf_event__inject_buildid(struct perf_tool *tool, |
159 | union perf_event *event, | ||
134 | struct perf_sample *sample, | 160 | struct perf_sample *sample, |
135 | struct perf_evsel *evsel __used, | 161 | struct perf_evsel *evsel __used, |
136 | struct perf_session *session) | 162 | struct machine *machine) |
137 | { | 163 | { |
138 | struct addr_location al; | 164 | struct addr_location al; |
139 | struct thread *thread; | 165 | struct thread *thread; |
@@ -141,21 +167,21 @@ static int perf_event__inject_buildid(union perf_event *event, | |||
141 | 167 | ||
142 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 168 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
143 | 169 | ||
144 | thread = perf_session__findnew(session, event->ip.pid); | 170 | thread = machine__findnew_thread(machine, event->ip.pid); |
145 | if (thread == NULL) { | 171 | if (thread == NULL) { |
146 | pr_err("problem processing %d event, skipping it.\n", | 172 | pr_err("problem processing %d event, skipping it.\n", |
147 | event->header.type); | 173 | event->header.type); |
148 | goto repipe; | 174 | goto repipe; |
149 | } | 175 | } |
150 | 176 | ||
151 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, | 177 | thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION, |
152 | event->ip.pid, event->ip.ip, &al); | 178 | event->ip.ip, &al); |
153 | 179 | ||
154 | if (al.map != NULL) { | 180 | if (al.map != NULL) { |
155 | if (!al.map->dso->hit) { | 181 | if (!al.map->dso->hit) { |
156 | al.map->dso->hit = 1; | 182 | al.map->dso->hit = 1; |
157 | if (map__load(al.map, NULL) >= 0) { | 183 | if (map__load(al.map, NULL) >= 0) { |
158 | dso__inject_build_id(al.map->dso, session); | 184 | dso__inject_build_id(al.map->dso, tool, machine); |
159 | /* | 185 | /* |
160 | * If this fails, too bad, let the other side | 186 | * If this fails, too bad, let the other side |
161 | * account this as unresolved. | 187 | * account this as unresolved. |
@@ -168,24 +194,24 @@ static int perf_event__inject_buildid(union perf_event *event, | |||
168 | } | 194 | } |
169 | 195 | ||
170 | repipe: | 196 | repipe: |
171 | perf_event__repipe(event, sample, session); | 197 | perf_event__repipe(tool, event, sample, machine); |
172 | return 0; | 198 | return 0; |
173 | } | 199 | } |
174 | 200 | ||
175 | struct perf_event_ops inject_ops = { | 201 | struct perf_tool perf_inject = { |
176 | .sample = perf_event__repipe_sample, | 202 | .sample = perf_event__repipe_sample, |
177 | .mmap = perf_event__repipe, | 203 | .mmap = perf_event__repipe, |
178 | .comm = perf_event__repipe, | 204 | .comm = perf_event__repipe, |
179 | .fork = perf_event__repipe, | 205 | .fork = perf_event__repipe, |
180 | .exit = perf_event__repipe, | 206 | .exit = perf_event__repipe, |
181 | .lost = perf_event__repipe, | 207 | .lost = perf_event__repipe, |
182 | .read = perf_event__repipe, | 208 | .read = perf_event__repipe_sample, |
183 | .throttle = perf_event__repipe, | 209 | .throttle = perf_event__repipe, |
184 | .unthrottle = perf_event__repipe, | 210 | .unthrottle = perf_event__repipe, |
185 | .attr = perf_event__repipe_synth, | 211 | .attr = perf_event__repipe_attr, |
186 | .event_type = perf_event__repipe_synth, | 212 | .event_type = perf_event__repipe_event_type_synth, |
187 | .tracing_data = perf_event__repipe_synth, | 213 | .tracing_data = perf_event__repipe_tracing_data_synth, |
188 | .build_id = perf_event__repipe_synth, | 214 | .build_id = perf_event__repipe_op2_synth, |
189 | }; | 215 | }; |
190 | 216 | ||
191 | extern volatile int session_done; | 217 | extern volatile int session_done; |
@@ -203,17 +229,17 @@ static int __cmd_inject(void) | |||
203 | signal(SIGINT, sig_handler); | 229 | signal(SIGINT, sig_handler); |
204 | 230 | ||
205 | if (inject_build_ids) { | 231 | if (inject_build_ids) { |
206 | inject_ops.sample = perf_event__inject_buildid; | 232 | perf_inject.sample = perf_event__inject_buildid; |
207 | inject_ops.mmap = perf_event__repipe_mmap; | 233 | perf_inject.mmap = perf_event__repipe_mmap; |
208 | inject_ops.fork = perf_event__repipe_task; | 234 | perf_inject.fork = perf_event__repipe_task; |
209 | inject_ops.tracing_data = perf_event__repipe_tracing_data; | 235 | perf_inject.tracing_data = perf_event__repipe_tracing_data; |
210 | } | 236 | } |
211 | 237 | ||
212 | session = perf_session__new(input_name, O_RDONLY, false, true, &inject_ops); | 238 | session = perf_session__new(input_name, O_RDONLY, false, true, &perf_inject); |
213 | if (session == NULL) | 239 | if (session == NULL) |
214 | return -ENOMEM; | 240 | return -ENOMEM; |
215 | 241 | ||
216 | ret = perf_session__process_events(session, &inject_ops); | 242 | ret = perf_session__process_events(session, &perf_inject); |
217 | 243 | ||
218 | perf_session__delete(session); | 244 | perf_session__delete(session); |
219 | 245 | ||
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 225e963df105..fe1ad8f21961 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include "util/thread.h" | 7 | #include "util/thread.h" |
8 | #include "util/header.h" | 8 | #include "util/header.h" |
9 | #include "util/session.h" | 9 | #include "util/session.h" |
10 | #include "util/tool.h" | ||
10 | 11 | ||
11 | #include "util/parse-options.h" | 12 | #include "util/parse-options.h" |
12 | #include "util/trace-event.h" | 13 | #include "util/trace-event.h" |
@@ -18,7 +19,7 @@ | |||
18 | struct alloc_stat; | 19 | struct alloc_stat; |
19 | typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *); | 20 | typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *); |
20 | 21 | ||
21 | static char const *input_name = "perf.data"; | 22 | static const char *input_name; |
22 | 23 | ||
23 | static int alloc_flag; | 24 | static int alloc_flag; |
24 | static int caller_flag; | 25 | static int caller_flag; |
@@ -303,12 +304,13 @@ static void process_raw_event(union perf_event *raw_event __used, void *data, | |||
303 | } | 304 | } |
304 | } | 305 | } |
305 | 306 | ||
306 | static int process_sample_event(union perf_event *event, | 307 | static int process_sample_event(struct perf_tool *tool __used, |
308 | union perf_event *event, | ||
307 | struct perf_sample *sample, | 309 | struct perf_sample *sample, |
308 | struct perf_evsel *evsel __used, | 310 | struct perf_evsel *evsel __used, |
309 | struct perf_session *session) | 311 | struct machine *machine) |
310 | { | 312 | { |
311 | struct thread *thread = perf_session__findnew(session, event->ip.pid); | 313 | struct thread *thread = machine__findnew_thread(machine, event->ip.pid); |
312 | 314 | ||
313 | if (thread == NULL) { | 315 | if (thread == NULL) { |
314 | pr_debug("problem processing %d event, skipping it.\n", | 316 | pr_debug("problem processing %d event, skipping it.\n", |
@@ -324,7 +326,7 @@ static int process_sample_event(union perf_event *event, | |||
324 | return 0; | 326 | return 0; |
325 | } | 327 | } |
326 | 328 | ||
327 | static struct perf_event_ops event_ops = { | 329 | static struct perf_tool perf_kmem = { |
328 | .sample = process_sample_event, | 330 | .sample = process_sample_event, |
329 | .comm = perf_event__process_comm, | 331 | .comm = perf_event__process_comm, |
330 | .ordered_samples = true, | 332 | .ordered_samples = true, |
@@ -483,7 +485,7 @@ static int __cmd_kmem(void) | |||
483 | { | 485 | { |
484 | int err = -EINVAL; | 486 | int err = -EINVAL; |
485 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, | 487 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, |
486 | 0, false, &event_ops); | 488 | 0, false, &perf_kmem); |
487 | if (session == NULL) | 489 | if (session == NULL) |
488 | return -ENOMEM; | 490 | return -ENOMEM; |
489 | 491 | ||
@@ -494,7 +496,7 @@ static int __cmd_kmem(void) | |||
494 | goto out_delete; | 496 | goto out_delete; |
495 | 497 | ||
496 | setup_pager(); | 498 | setup_pager(); |
497 | err = perf_session__process_events(session, &event_ops); | 499 | err = perf_session__process_events(session, &perf_kmem); |
498 | if (err != 0) | 500 | if (err != 0) |
499 | goto out_delete; | 501 | goto out_delete; |
500 | sort_result(); | 502 | sort_result(); |
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 34d1e853829d..032324a76b87 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c | |||
@@ -38,7 +38,7 @@ static const struct option kvm_options[] = { | |||
38 | OPT_BOOLEAN(0, "guest", &perf_guest, | 38 | OPT_BOOLEAN(0, "guest", &perf_guest, |
39 | "Collect guest os data"), | 39 | "Collect guest os data"), |
40 | OPT_BOOLEAN(0, "host", &perf_host, | 40 | OPT_BOOLEAN(0, "host", &perf_host, |
41 | "Collect guest os data"), | 41 | "Collect host os data"), |
42 | OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory", | 42 | OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory", |
43 | "guest mount directory under which every guest os" | 43 | "guest mount directory under which every guest os" |
44 | " instance has a subdir"), | 44 | " instance has a subdir"), |
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 899080ace267..2296c391d0f5 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include "util/debug.h" | 13 | #include "util/debug.h" |
14 | #include "util/session.h" | 14 | #include "util/session.h" |
15 | #include "util/tool.h" | ||
15 | 16 | ||
16 | #include <sys/types.h> | 17 | #include <sys/types.h> |
17 | #include <sys/prctl.h> | 18 | #include <sys/prctl.h> |
@@ -325,7 +326,7 @@ alloc_failed: | |||
325 | die("memory allocation failed\n"); | 326 | die("memory allocation failed\n"); |
326 | } | 327 | } |
327 | 328 | ||
328 | static char const *input_name = "perf.data"; | 329 | static const char *input_name; |
329 | 330 | ||
330 | struct raw_event_sample { | 331 | struct raw_event_sample { |
331 | u32 size; | 332 | u32 size; |
@@ -845,12 +846,13 @@ static void dump_info(void) | |||
845 | die("Unknown type of information\n"); | 846 | die("Unknown type of information\n"); |
846 | } | 847 | } |
847 | 848 | ||
848 | static int process_sample_event(union perf_event *event, | 849 | static int process_sample_event(struct perf_tool *tool __used, |
850 | union perf_event *event, | ||
849 | struct perf_sample *sample, | 851 | struct perf_sample *sample, |
850 | struct perf_evsel *evsel __used, | 852 | struct perf_evsel *evsel __used, |
851 | struct perf_session *s) | 853 | struct machine *machine) |
852 | { | 854 | { |
853 | struct thread *thread = perf_session__findnew(s, sample->tid); | 855 | struct thread *thread = machine__findnew_thread(machine, sample->tid); |
854 | 856 | ||
855 | if (thread == NULL) { | 857 | if (thread == NULL) { |
856 | pr_debug("problem processing %d event, skipping it.\n", | 858 | pr_debug("problem processing %d event, skipping it.\n", |
@@ -863,7 +865,7 @@ static int process_sample_event(union perf_event *event, | |||
863 | return 0; | 865 | return 0; |
864 | } | 866 | } |
865 | 867 | ||
866 | static struct perf_event_ops eops = { | 868 | static struct perf_tool eops = { |
867 | .sample = process_sample_event, | 869 | .sample = process_sample_event, |
868 | .comm = perf_event__process_comm, | 870 | .comm = perf_event__process_comm, |
869 | .ordered_samples = true, | 871 | .ordered_samples = true, |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 710ae3d0a489..59d43abfbfec 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -46,7 +46,6 @@ | |||
46 | 46 | ||
47 | #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*" | 47 | #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*" |
48 | #define DEFAULT_FUNC_FILTER "!_*" | 48 | #define DEFAULT_FUNC_FILTER "!_*" |
49 | #define MAX_PATH_LEN 256 | ||
50 | 49 | ||
51 | /* Session management structure */ | 50 | /* Session management structure */ |
52 | static struct { | 51 | static struct { |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index f4c3fbee4bad..0abfb18b911f 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "util/evsel.h" | 22 | #include "util/evsel.h" |
23 | #include "util/debug.h" | 23 | #include "util/debug.h" |
24 | #include "util/session.h" | 24 | #include "util/session.h" |
25 | #include "util/tool.h" | ||
25 | #include "util/symbol.h" | 26 | #include "util/symbol.h" |
26 | #include "util/cpumap.h" | 27 | #include "util/cpumap.h" |
27 | #include "util/thread_map.h" | 28 | #include "util/thread_map.h" |
@@ -35,54 +36,36 @@ enum write_mode_t { | |||
35 | WRITE_APPEND | 36 | WRITE_APPEND |
36 | }; | 37 | }; |
37 | 38 | ||
38 | static u64 user_interval = ULLONG_MAX; | 39 | struct perf_record { |
39 | static u64 default_interval = 0; | 40 | struct perf_tool tool; |
40 | 41 | struct perf_record_opts opts; | |
41 | static unsigned int page_size; | 42 | u64 bytes_written; |
42 | static unsigned int mmap_pages = UINT_MAX; | 43 | const char *output_name; |
43 | static unsigned int user_freq = UINT_MAX; | 44 | struct perf_evlist *evlist; |
44 | static int freq = 1000; | 45 | struct perf_session *session; |
45 | static int output; | 46 | const char *progname; |
46 | static int pipe_output = 0; | 47 | int output; |
47 | static const char *output_name = NULL; | 48 | unsigned int page_size; |
48 | static bool group = false; | 49 | int realtime_prio; |
49 | static int realtime_prio = 0; | 50 | enum write_mode_t write_mode; |
50 | static bool nodelay = false; | 51 | bool no_buildid; |
51 | static bool raw_samples = false; | 52 | bool no_buildid_cache; |
52 | static bool sample_id_all_avail = true; | 53 | bool force; |
53 | static bool system_wide = false; | 54 | bool file_new; |
54 | static pid_t target_pid = -1; | 55 | bool append_file; |
55 | static pid_t target_tid = -1; | 56 | long samples; |
56 | static pid_t child_pid = -1; | 57 | off_t post_processing_offset; |
57 | static bool no_inherit = false; | 58 | }; |
58 | static enum write_mode_t write_mode = WRITE_FORCE; | 59 | |
59 | static bool call_graph = false; | 60 | static void advance_output(struct perf_record *rec, size_t size) |
60 | static bool inherit_stat = false; | ||
61 | static bool no_samples = false; | ||
62 | static bool sample_address = false; | ||
63 | static bool sample_time = false; | ||
64 | static bool no_buildid = false; | ||
65 | static bool no_buildid_cache = false; | ||
66 | static struct perf_evlist *evsel_list; | ||
67 | |||
68 | static long samples = 0; | ||
69 | static u64 bytes_written = 0; | ||
70 | |||
71 | static int file_new = 1; | ||
72 | static off_t post_processing_offset; | ||
73 | |||
74 | static struct perf_session *session; | ||
75 | static const char *cpu_list; | ||
76 | |||
77 | static void advance_output(size_t size) | ||
78 | { | 61 | { |
79 | bytes_written += size; | 62 | rec->bytes_written += size; |
80 | } | 63 | } |
81 | 64 | ||
82 | static void write_output(void *buf, size_t size) | 65 | static void write_output(struct perf_record *rec, void *buf, size_t size) |
83 | { | 66 | { |
84 | while (size) { | 67 | while (size) { |
85 | int ret = write(output, buf, size); | 68 | int ret = write(rec->output, buf, size); |
86 | 69 | ||
87 | if (ret < 0) | 70 | if (ret < 0) |
88 | die("failed to write"); | 71 | die("failed to write"); |
@@ -90,30 +73,33 @@ static void write_output(void *buf, size_t size) | |||
90 | size -= ret; | 73 | size -= ret; |
91 | buf += ret; | 74 | buf += ret; |
92 | 75 | ||
93 | bytes_written += ret; | 76 | rec->bytes_written += ret; |
94 | } | 77 | } |
95 | } | 78 | } |
96 | 79 | ||
97 | static int process_synthesized_event(union perf_event *event, | 80 | static int process_synthesized_event(struct perf_tool *tool, |
81 | union perf_event *event, | ||
98 | struct perf_sample *sample __used, | 82 | struct perf_sample *sample __used, |
99 | struct perf_session *self __used) | 83 | struct machine *machine __used) |
100 | { | 84 | { |
101 | write_output(event, event->header.size); | 85 | struct perf_record *rec = container_of(tool, struct perf_record, tool); |
86 | write_output(rec, event, event->header.size); | ||
102 | return 0; | 87 | return 0; |
103 | } | 88 | } |
104 | 89 | ||
105 | static void mmap_read(struct perf_mmap *md) | 90 | static void perf_record__mmap_read(struct perf_record *rec, |
91 | struct perf_mmap *md) | ||
106 | { | 92 | { |
107 | unsigned int head = perf_mmap__read_head(md); | 93 | unsigned int head = perf_mmap__read_head(md); |
108 | unsigned int old = md->prev; | 94 | unsigned int old = md->prev; |
109 | unsigned char *data = md->base + page_size; | 95 | unsigned char *data = md->base + rec->page_size; |
110 | unsigned long size; | 96 | unsigned long size; |
111 | void *buf; | 97 | void *buf; |
112 | 98 | ||
113 | if (old == head) | 99 | if (old == head) |
114 | return; | 100 | return; |
115 | 101 | ||
116 | samples++; | 102 | rec->samples++; |
117 | 103 | ||
118 | size = head - old; | 104 | size = head - old; |
119 | 105 | ||
@@ -122,14 +108,14 @@ static void mmap_read(struct perf_mmap *md) | |||
122 | size = md->mask + 1 - (old & md->mask); | 108 | size = md->mask + 1 - (old & md->mask); |
123 | old += size; | 109 | old += size; |
124 | 110 | ||
125 | write_output(buf, size); | 111 | write_output(rec, buf, size); |
126 | } | 112 | } |
127 | 113 | ||
128 | buf = &data[old & md->mask]; | 114 | buf = &data[old & md->mask]; |
129 | size = head - old; | 115 | size = head - old; |
130 | old += size; | 116 | old += size; |
131 | 117 | ||
132 | write_output(buf, size); | 118 | write_output(rec, buf, size); |
133 | 119 | ||
134 | md->prev = old; | 120 | md->prev = old; |
135 | perf_mmap__write_tail(md, old); | 121 | perf_mmap__write_tail(md, old); |
@@ -137,17 +123,30 @@ static void mmap_read(struct perf_mmap *md) | |||
137 | 123 | ||
138 | static volatile int done = 0; | 124 | static volatile int done = 0; |
139 | static volatile int signr = -1; | 125 | static volatile int signr = -1; |
126 | static volatile int child_finished = 0; | ||
140 | 127 | ||
141 | static void sig_handler(int sig) | 128 | static void sig_handler(int sig) |
142 | { | 129 | { |
130 | if (sig == SIGCHLD) | ||
131 | child_finished = 1; | ||
132 | |||
143 | done = 1; | 133 | done = 1; |
144 | signr = sig; | 134 | signr = sig; |
145 | } | 135 | } |
146 | 136 | ||
147 | static void sig_atexit(void) | 137 | static void perf_record__sig_exit(int exit_status __used, void *arg) |
148 | { | 138 | { |
149 | if (child_pid > 0) | 139 | struct perf_record *rec = arg; |
150 | kill(child_pid, SIGTERM); | 140 | int status; |
141 | |||
142 | if (rec->evlist->workload.pid > 0) { | ||
143 | if (!child_finished) | ||
144 | kill(rec->evlist->workload.pid, SIGTERM); | ||
145 | |||
146 | wait(&status); | ||
147 | if (WIFSIGNALED(status)) | ||
148 | psignal(WTERMSIG(status), rec->progname); | ||
149 | } | ||
151 | 150 | ||
152 | if (signr == -1 || signr == SIGUSR1) | 151 | if (signr == -1 || signr == SIGUSR1) |
153 | return; | 152 | return; |
@@ -156,78 +155,6 @@ static void sig_atexit(void) | |||
156 | kill(getpid(), signr); | 155 | kill(getpid(), signr); |
157 | } | 156 | } |
158 | 157 | ||
159 | static void config_attr(struct perf_evsel *evsel, struct perf_evlist *evlist) | ||
160 | { | ||
161 | struct perf_event_attr *attr = &evsel->attr; | ||
162 | int track = !evsel->idx; /* only the first counter needs these */ | ||
163 | |||
164 | attr->disabled = 1; | ||
165 | attr->inherit = !no_inherit; | ||
166 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | | ||
167 | PERF_FORMAT_TOTAL_TIME_RUNNING | | ||
168 | PERF_FORMAT_ID; | ||
169 | |||
170 | attr->sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID; | ||
171 | |||
172 | if (evlist->nr_entries > 1) | ||
173 | attr->sample_type |= PERF_SAMPLE_ID; | ||
174 | |||
175 | /* | ||
176 | * We default some events to a 1 default interval. But keep | ||
177 | * it a weak assumption overridable by the user. | ||
178 | */ | ||
179 | if (!attr->sample_period || (user_freq != UINT_MAX && | ||
180 | user_interval != ULLONG_MAX)) { | ||
181 | if (freq) { | ||
182 | attr->sample_type |= PERF_SAMPLE_PERIOD; | ||
183 | attr->freq = 1; | ||
184 | attr->sample_freq = freq; | ||
185 | } else { | ||
186 | attr->sample_period = default_interval; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | if (no_samples) | ||
191 | attr->sample_freq = 0; | ||
192 | |||
193 | if (inherit_stat) | ||
194 | attr->inherit_stat = 1; | ||
195 | |||
196 | if (sample_address) { | ||
197 | attr->sample_type |= PERF_SAMPLE_ADDR; | ||
198 | attr->mmap_data = track; | ||
199 | } | ||
200 | |||
201 | if (call_graph) | ||
202 | attr->sample_type |= PERF_SAMPLE_CALLCHAIN; | ||
203 | |||
204 | if (system_wide) | ||
205 | attr->sample_type |= PERF_SAMPLE_CPU; | ||
206 | |||
207 | if (sample_id_all_avail && | ||
208 | (sample_time || system_wide || !no_inherit || cpu_list)) | ||
209 | attr->sample_type |= PERF_SAMPLE_TIME; | ||
210 | |||
211 | if (raw_samples) { | ||
212 | attr->sample_type |= PERF_SAMPLE_TIME; | ||
213 | attr->sample_type |= PERF_SAMPLE_RAW; | ||
214 | attr->sample_type |= PERF_SAMPLE_CPU; | ||
215 | } | ||
216 | |||
217 | if (nodelay) { | ||
218 | attr->watermark = 0; | ||
219 | attr->wakeup_events = 1; | ||
220 | } | ||
221 | |||
222 | attr->mmap = track; | ||
223 | attr->comm = track; | ||
224 | |||
225 | if (target_pid == -1 && target_tid == -1 && !system_wide) { | ||
226 | attr->disabled = 1; | ||
227 | attr->enable_on_exec = 1; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | static bool perf_evlist__equal(struct perf_evlist *evlist, | 158 | static bool perf_evlist__equal(struct perf_evlist *evlist, |
232 | struct perf_evlist *other) | 159 | struct perf_evlist *other) |
233 | { | 160 | { |
@@ -247,15 +174,20 @@ static bool perf_evlist__equal(struct perf_evlist *evlist, | |||
247 | return true; | 174 | return true; |
248 | } | 175 | } |
249 | 176 | ||
250 | static void open_counters(struct perf_evlist *evlist) | 177 | static void perf_record__open(struct perf_record *rec) |
251 | { | 178 | { |
252 | struct perf_evsel *pos; | 179 | struct perf_evsel *pos, *first; |
180 | struct perf_evlist *evlist = rec->evlist; | ||
181 | struct perf_session *session = rec->session; | ||
182 | struct perf_record_opts *opts = &rec->opts; | ||
183 | |||
184 | first = list_entry(evlist->entries.next, struct perf_evsel, node); | ||
253 | 185 | ||
254 | if (evlist->cpus->map[0] < 0) | 186 | perf_evlist__config_attrs(evlist, opts); |
255 | no_inherit = true; | ||
256 | 187 | ||
257 | list_for_each_entry(pos, &evlist->entries, node) { | 188 | list_for_each_entry(pos, &evlist->entries, node) { |
258 | struct perf_event_attr *attr = &pos->attr; | 189 | struct perf_event_attr *attr = &pos->attr; |
190 | struct xyarray *group_fd = NULL; | ||
259 | /* | 191 | /* |
260 | * Check if parse_single_tracepoint_event has already asked for | 192 | * Check if parse_single_tracepoint_event has already asked for |
261 | * PERF_SAMPLE_TIME. | 193 | * PERF_SAMPLE_TIME. |
@@ -270,25 +202,27 @@ static void open_counters(struct perf_evlist *evlist) | |||
270 | */ | 202 | */ |
271 | bool time_needed = attr->sample_type & PERF_SAMPLE_TIME; | 203 | bool time_needed = attr->sample_type & PERF_SAMPLE_TIME; |
272 | 204 | ||
273 | config_attr(pos, evlist); | 205 | if (opts->group && pos != first) |
206 | group_fd = first->fd; | ||
274 | retry_sample_id: | 207 | retry_sample_id: |
275 | attr->sample_id_all = sample_id_all_avail ? 1 : 0; | 208 | attr->sample_id_all = opts->sample_id_all_avail ? 1 : 0; |
276 | try_again: | 209 | try_again: |
277 | if (perf_evsel__open(pos, evlist->cpus, evlist->threads, group) < 0) { | 210 | if (perf_evsel__open(pos, evlist->cpus, evlist->threads, |
211 | opts->group, group_fd) < 0) { | ||
278 | int err = errno; | 212 | int err = errno; |
279 | 213 | ||
280 | if (err == EPERM || err == EACCES) { | 214 | if (err == EPERM || err == EACCES) { |
281 | ui__warning_paranoid(); | 215 | ui__error_paranoid(); |
282 | exit(EXIT_FAILURE); | 216 | exit(EXIT_FAILURE); |
283 | } else if (err == ENODEV && cpu_list) { | 217 | } else if (err == ENODEV && opts->cpu_list) { |
284 | die("No such device - did you specify" | 218 | die("No such device - did you specify" |
285 | " an out-of-range profile CPU?\n"); | 219 | " an out-of-range profile CPU?\n"); |
286 | } else if (err == EINVAL && sample_id_all_avail) { | 220 | } else if (err == EINVAL && opts->sample_id_all_avail) { |
287 | /* | 221 | /* |
288 | * Old kernel, no attr->sample_id_type_all field | 222 | * Old kernel, no attr->sample_id_type_all field |
289 | */ | 223 | */ |
290 | sample_id_all_avail = false; | 224 | opts->sample_id_all_avail = false; |
291 | if (!sample_time && !raw_samples && !time_needed) | 225 | if (!opts->sample_time && !opts->raw_samples && !time_needed) |
292 | attr->sample_type &= ~PERF_SAMPLE_TIME; | 226 | attr->sample_type &= ~PERF_SAMPLE_TIME; |
293 | 227 | ||
294 | goto retry_sample_id; | 228 | goto retry_sample_id; |
@@ -338,10 +272,20 @@ try_again: | |||
338 | exit(-1); | 272 | exit(-1); |
339 | } | 273 | } |
340 | 274 | ||
341 | if (perf_evlist__mmap(evlist, mmap_pages, false) < 0) | 275 | if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) { |
276 | if (errno == EPERM) | ||
277 | die("Permission error mapping pages.\n" | ||
278 | "Consider increasing " | ||
279 | "/proc/sys/kernel/perf_event_mlock_kb,\n" | ||
280 | "or try again with a smaller value of -m/--mmap_pages.\n" | ||
281 | "(current value: %d)\n", opts->mmap_pages); | ||
282 | else if (!is_power_of_2(opts->mmap_pages)) | ||
283 | die("--mmap_pages/-m value must be a power of two."); | ||
284 | |||
342 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); | 285 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
286 | } | ||
343 | 287 | ||
344 | if (file_new) | 288 | if (rec->file_new) |
345 | session->evlist = evlist; | 289 | session->evlist = evlist; |
346 | else { | 290 | else { |
347 | if (!perf_evlist__equal(session->evlist, evlist)) { | 291 | if (!perf_evlist__equal(session->evlist, evlist)) { |
@@ -353,29 +297,32 @@ try_again: | |||
353 | perf_session__update_sample_type(session); | 297 | perf_session__update_sample_type(session); |
354 | } | 298 | } |
355 | 299 | ||
356 | static int process_buildids(void) | 300 | static int process_buildids(struct perf_record *rec) |
357 | { | 301 | { |
358 | u64 size = lseek(output, 0, SEEK_CUR); | 302 | u64 size = lseek(rec->output, 0, SEEK_CUR); |
359 | 303 | ||
360 | if (size == 0) | 304 | if (size == 0) |
361 | return 0; | 305 | return 0; |
362 | 306 | ||
363 | session->fd = output; | 307 | rec->session->fd = rec->output; |
364 | return __perf_session__process_events(session, post_processing_offset, | 308 | return __perf_session__process_events(rec->session, rec->post_processing_offset, |
365 | size - post_processing_offset, | 309 | size - rec->post_processing_offset, |
366 | size, &build_id__mark_dso_hit_ops); | 310 | size, &build_id__mark_dso_hit_ops); |
367 | } | 311 | } |
368 | 312 | ||
369 | static void atexit_header(void) | 313 | static void perf_record__exit(int status __used, void *arg) |
370 | { | 314 | { |
371 | if (!pipe_output) { | 315 | struct perf_record *rec = arg; |
372 | session->header.data_size += bytes_written; | 316 | |
373 | 317 | if (!rec->opts.pipe_output) { | |
374 | if (!no_buildid) | 318 | rec->session->header.data_size += rec->bytes_written; |
375 | process_buildids(); | 319 | |
376 | perf_session__write_header(session, evsel_list, output, true); | 320 | if (!rec->no_buildid) |
377 | perf_session__delete(session); | 321 | process_buildids(rec); |
378 | perf_evlist__delete(evsel_list); | 322 | perf_session__write_header(rec->session, rec->evlist, |
323 | rec->output, true); | ||
324 | perf_session__delete(rec->session); | ||
325 | perf_evlist__delete(rec->evlist); | ||
379 | symbol__exit(); | 326 | symbol__exit(); |
380 | } | 327 | } |
381 | } | 328 | } |
@@ -383,7 +330,7 @@ static void atexit_header(void) | |||
383 | static void perf_event__synthesize_guest_os(struct machine *machine, void *data) | 330 | static void perf_event__synthesize_guest_os(struct machine *machine, void *data) |
384 | { | 331 | { |
385 | int err; | 332 | int err; |
386 | struct perf_session *psession = data; | 333 | struct perf_tool *tool = data; |
387 | 334 | ||
388 | if (machine__is_host(machine)) | 335 | if (machine__is_host(machine)) |
389 | return; | 336 | return; |
@@ -396,8 +343,8 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data) | |||
396 | *method is used to avoid symbol missing when the first addr is | 343 | *method is used to avoid symbol missing when the first addr is |
397 | *in module instead of in guest kernel. | 344 | *in module instead of in guest kernel. |
398 | */ | 345 | */ |
399 | err = perf_event__synthesize_modules(process_synthesized_event, | 346 | err = perf_event__synthesize_modules(tool, process_synthesized_event, |
400 | psession, machine); | 347 | machine); |
401 | if (err < 0) | 348 | if (err < 0) |
402 | pr_err("Couldn't record guest kernel [%d]'s reference" | 349 | pr_err("Couldn't record guest kernel [%d]'s reference" |
403 | " relocation symbol.\n", machine->pid); | 350 | " relocation symbol.\n", machine->pid); |
@@ -406,12 +353,11 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data) | |||
406 | * We use _stext for guest kernel because guest kernel's /proc/kallsyms | 353 | * We use _stext for guest kernel because guest kernel's /proc/kallsyms |
407 | * have no _text sometimes. | 354 | * have no _text sometimes. |
408 | */ | 355 | */ |
409 | err = perf_event__synthesize_kernel_mmap(process_synthesized_event, | 356 | err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event, |
410 | psession, machine, "_text"); | 357 | machine, "_text"); |
411 | if (err < 0) | 358 | if (err < 0) |
412 | err = perf_event__synthesize_kernel_mmap(process_synthesized_event, | 359 | err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event, |
413 | psession, machine, | 360 | machine, "_stext"); |
414 | "_stext"); | ||
415 | if (err < 0) | 361 | if (err < 0) |
416 | pr_err("Couldn't record guest kernel [%d]'s reference" | 362 | pr_err("Couldn't record guest kernel [%d]'s reference" |
417 | " relocation symbol.\n", machine->pid); | 363 | " relocation symbol.\n", machine->pid); |
@@ -422,71 +368,71 @@ static struct perf_event_header finished_round_event = { | |||
422 | .type = PERF_RECORD_FINISHED_ROUND, | 368 | .type = PERF_RECORD_FINISHED_ROUND, |
423 | }; | 369 | }; |
424 | 370 | ||
425 | static void mmap_read_all(void) | 371 | static void perf_record__mmap_read_all(struct perf_record *rec) |
426 | { | 372 | { |
427 | int i; | 373 | int i; |
428 | 374 | ||
429 | for (i = 0; i < evsel_list->nr_mmaps; i++) { | 375 | for (i = 0; i < rec->evlist->nr_mmaps; i++) { |
430 | if (evsel_list->mmap[i].base) | 376 | if (rec->evlist->mmap[i].base) |
431 | mmap_read(&evsel_list->mmap[i]); | 377 | perf_record__mmap_read(rec, &rec->evlist->mmap[i]); |
432 | } | 378 | } |
433 | 379 | ||
434 | if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) | 380 | if (perf_header__has_feat(&rec->session->header, HEADER_TRACE_INFO)) |
435 | write_output(&finished_round_event, sizeof(finished_round_event)); | 381 | write_output(rec, &finished_round_event, sizeof(finished_round_event)); |
436 | } | 382 | } |
437 | 383 | ||
438 | static int __cmd_record(int argc, const char **argv) | 384 | static int __cmd_record(struct perf_record *rec, int argc, const char **argv) |
439 | { | 385 | { |
440 | struct stat st; | 386 | struct stat st; |
441 | int flags; | 387 | int flags; |
442 | int err; | 388 | int err, output; |
443 | unsigned long waking = 0; | 389 | unsigned long waking = 0; |
444 | int child_ready_pipe[2], go_pipe[2]; | ||
445 | const bool forks = argc > 0; | 390 | const bool forks = argc > 0; |
446 | char buf; | ||
447 | struct machine *machine; | 391 | struct machine *machine; |
392 | struct perf_tool *tool = &rec->tool; | ||
393 | struct perf_record_opts *opts = &rec->opts; | ||
394 | struct perf_evlist *evsel_list = rec->evlist; | ||
395 | const char *output_name = rec->output_name; | ||
396 | struct perf_session *session; | ||
397 | |||
398 | rec->progname = argv[0]; | ||
448 | 399 | ||
449 | page_size = sysconf(_SC_PAGE_SIZE); | 400 | rec->page_size = sysconf(_SC_PAGE_SIZE); |
450 | 401 | ||
451 | atexit(sig_atexit); | 402 | on_exit(perf_record__sig_exit, rec); |
452 | signal(SIGCHLD, sig_handler); | 403 | signal(SIGCHLD, sig_handler); |
453 | signal(SIGINT, sig_handler); | 404 | signal(SIGINT, sig_handler); |
454 | signal(SIGUSR1, sig_handler); | 405 | signal(SIGUSR1, sig_handler); |
455 | 406 | ||
456 | if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) { | ||
457 | perror("failed to create pipes"); | ||
458 | exit(-1); | ||
459 | } | ||
460 | |||
461 | if (!output_name) { | 407 | if (!output_name) { |
462 | if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode)) | 408 | if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode)) |
463 | pipe_output = 1; | 409 | opts->pipe_output = true; |
464 | else | 410 | else |
465 | output_name = "perf.data"; | 411 | rec->output_name = output_name = "perf.data"; |
466 | } | 412 | } |
467 | if (output_name) { | 413 | if (output_name) { |
468 | if (!strcmp(output_name, "-")) | 414 | if (!strcmp(output_name, "-")) |
469 | pipe_output = 1; | 415 | opts->pipe_output = true; |
470 | else if (!stat(output_name, &st) && st.st_size) { | 416 | else if (!stat(output_name, &st) && st.st_size) { |
471 | if (write_mode == WRITE_FORCE) { | 417 | if (rec->write_mode == WRITE_FORCE) { |
472 | char oldname[PATH_MAX]; | 418 | char oldname[PATH_MAX]; |
473 | snprintf(oldname, sizeof(oldname), "%s.old", | 419 | snprintf(oldname, sizeof(oldname), "%s.old", |
474 | output_name); | 420 | output_name); |
475 | unlink(oldname); | 421 | unlink(oldname); |
476 | rename(output_name, oldname); | 422 | rename(output_name, oldname); |
477 | } | 423 | } |
478 | } else if (write_mode == WRITE_APPEND) { | 424 | } else if (rec->write_mode == WRITE_APPEND) { |
479 | write_mode = WRITE_FORCE; | 425 | rec->write_mode = WRITE_FORCE; |
480 | } | 426 | } |
481 | } | 427 | } |
482 | 428 | ||
483 | flags = O_CREAT|O_RDWR; | 429 | flags = O_CREAT|O_RDWR; |
484 | if (write_mode == WRITE_APPEND) | 430 | if (rec->write_mode == WRITE_APPEND) |
485 | file_new = 0; | 431 | rec->file_new = 0; |
486 | else | 432 | else |
487 | flags |= O_TRUNC; | 433 | flags |= O_TRUNC; |
488 | 434 | ||
489 | if (pipe_output) | 435 | if (opts->pipe_output) |
490 | output = STDOUT_FILENO; | 436 | output = STDOUT_FILENO; |
491 | else | 437 | else |
492 | output = open(output_name, flags, S_IRUSR | S_IWUSR); | 438 | output = open(output_name, flags, S_IRUSR | S_IWUSR); |
@@ -495,17 +441,21 @@ static int __cmd_record(int argc, const char **argv) | |||
495 | exit(-1); | 441 | exit(-1); |
496 | } | 442 | } |
497 | 443 | ||
444 | rec->output = output; | ||
445 | |||
498 | session = perf_session__new(output_name, O_WRONLY, | 446 | session = perf_session__new(output_name, O_WRONLY, |
499 | write_mode == WRITE_FORCE, false, NULL); | 447 | rec->write_mode == WRITE_FORCE, false, NULL); |
500 | if (session == NULL) { | 448 | if (session == NULL) { |
501 | pr_err("Not enough memory for reading perf file header\n"); | 449 | pr_err("Not enough memory for reading perf file header\n"); |
502 | return -1; | 450 | return -1; |
503 | } | 451 | } |
504 | 452 | ||
505 | if (!no_buildid) | 453 | rec->session = session; |
454 | |||
455 | if (!rec->no_buildid) | ||
506 | perf_header__set_feat(&session->header, HEADER_BUILD_ID); | 456 | perf_header__set_feat(&session->header, HEADER_BUILD_ID); |
507 | 457 | ||
508 | if (!file_new) { | 458 | if (!rec->file_new) { |
509 | err = perf_session__read_header(session, output); | 459 | err = perf_session__read_header(session, output); |
510 | if (err < 0) | 460 | if (err < 0) |
511 | goto out_delete_session; | 461 | goto out_delete_session; |
@@ -514,94 +464,70 @@ static int __cmd_record(int argc, const char **argv) | |||
514 | if (have_tracepoints(&evsel_list->entries)) | 464 | if (have_tracepoints(&evsel_list->entries)) |
515 | perf_header__set_feat(&session->header, HEADER_TRACE_INFO); | 465 | perf_header__set_feat(&session->header, HEADER_TRACE_INFO); |
516 | 466 | ||
517 | /* 512 kiB: default amount of unprivileged mlocked memory */ | 467 | perf_header__set_feat(&session->header, HEADER_HOSTNAME); |
518 | if (mmap_pages == UINT_MAX) | 468 | perf_header__set_feat(&session->header, HEADER_OSRELEASE); |
519 | mmap_pages = (512 * 1024) / page_size; | 469 | perf_header__set_feat(&session->header, HEADER_ARCH); |
470 | perf_header__set_feat(&session->header, HEADER_CPUDESC); | ||
471 | perf_header__set_feat(&session->header, HEADER_NRCPUS); | ||
472 | perf_header__set_feat(&session->header, HEADER_EVENT_DESC); | ||
473 | perf_header__set_feat(&session->header, HEADER_CMDLINE); | ||
474 | perf_header__set_feat(&session->header, HEADER_VERSION); | ||
475 | perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY); | ||
476 | perf_header__set_feat(&session->header, HEADER_TOTAL_MEM); | ||
477 | perf_header__set_feat(&session->header, HEADER_NUMA_TOPOLOGY); | ||
478 | perf_header__set_feat(&session->header, HEADER_CPUID); | ||
520 | 479 | ||
521 | if (forks) { | 480 | if (forks) { |
522 | child_pid = fork(); | 481 | err = perf_evlist__prepare_workload(evsel_list, opts, argv); |
523 | if (child_pid < 0) { | 482 | if (err < 0) { |
524 | perror("failed to fork"); | 483 | pr_err("Couldn't run the workload!\n"); |
525 | exit(-1); | 484 | goto out_delete_session; |
526 | } | ||
527 | |||
528 | if (!child_pid) { | ||
529 | if (pipe_output) | ||
530 | dup2(2, 1); | ||
531 | close(child_ready_pipe[0]); | ||
532 | close(go_pipe[1]); | ||
533 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | ||
534 | |||
535 | /* | ||
536 | * Do a dummy execvp to get the PLT entry resolved, | ||
537 | * so we avoid the resolver overhead on the real | ||
538 | * execvp call. | ||
539 | */ | ||
540 | execvp("", (char **)argv); | ||
541 | |||
542 | /* | ||
543 | * Tell the parent we're ready to go | ||
544 | */ | ||
545 | close(child_ready_pipe[1]); | ||
546 | |||
547 | /* | ||
548 | * Wait until the parent tells us to go. | ||
549 | */ | ||
550 | if (read(go_pipe[0], &buf, 1) == -1) | ||
551 | perror("unable to read pipe"); | ||
552 | |||
553 | execvp(argv[0], (char **)argv); | ||
554 | |||
555 | perror(argv[0]); | ||
556 | kill(getppid(), SIGUSR1); | ||
557 | exit(-1); | ||
558 | } | ||
559 | |||
560 | if (!system_wide && target_tid == -1 && target_pid == -1) | ||
561 | evsel_list->threads->map[0] = child_pid; | ||
562 | |||
563 | close(child_ready_pipe[1]); | ||
564 | close(go_pipe[0]); | ||
565 | /* | ||
566 | * wait for child to settle | ||
567 | */ | ||
568 | if (read(child_ready_pipe[0], &buf, 1) == -1) { | ||
569 | perror("unable to read pipe"); | ||
570 | exit(-1); | ||
571 | } | 485 | } |
572 | close(child_ready_pipe[0]); | ||
573 | } | 486 | } |
574 | 487 | ||
575 | open_counters(evsel_list); | 488 | perf_record__open(rec); |
576 | 489 | ||
577 | /* | 490 | /* |
578 | * perf_session__delete(session) will be called at atexit_header() | 491 | * perf_session__delete(session) will be called at perf_record__exit() |
579 | */ | 492 | */ |
580 | atexit(atexit_header); | 493 | on_exit(perf_record__exit, rec); |
581 | 494 | ||
582 | if (pipe_output) { | 495 | if (opts->pipe_output) { |
583 | err = perf_header__write_pipe(output); | 496 | err = perf_header__write_pipe(output); |
584 | if (err < 0) | 497 | if (err < 0) |
585 | return err; | 498 | return err; |
586 | } else if (file_new) { | 499 | } else if (rec->file_new) { |
587 | err = perf_session__write_header(session, evsel_list, | 500 | err = perf_session__write_header(session, evsel_list, |
588 | output, false); | 501 | output, false); |
589 | if (err < 0) | 502 | if (err < 0) |
590 | return err; | 503 | return err; |
591 | } | 504 | } |
592 | 505 | ||
593 | post_processing_offset = lseek(output, 0, SEEK_CUR); | 506 | if (!!rec->no_buildid |
507 | && !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) { | ||
508 | pr_err("Couldn't generating buildids. " | ||
509 | "Use --no-buildid to profile anyway.\n"); | ||
510 | return -1; | ||
511 | } | ||
512 | |||
513 | rec->post_processing_offset = lseek(output, 0, SEEK_CUR); | ||
594 | 514 | ||
595 | if (pipe_output) { | 515 | machine = perf_session__find_host_machine(session); |
596 | err = perf_session__synthesize_attrs(session, | 516 | if (!machine) { |
597 | process_synthesized_event); | 517 | pr_err("Couldn't find native kernel information.\n"); |
518 | return -1; | ||
519 | } | ||
520 | |||
521 | if (opts->pipe_output) { | ||
522 | err = perf_event__synthesize_attrs(tool, session, | ||
523 | process_synthesized_event); | ||
598 | if (err < 0) { | 524 | if (err < 0) { |
599 | pr_err("Couldn't synthesize attrs.\n"); | 525 | pr_err("Couldn't synthesize attrs.\n"); |
600 | return err; | 526 | return err; |
601 | } | 527 | } |
602 | 528 | ||
603 | err = perf_event__synthesize_event_types(process_synthesized_event, | 529 | err = perf_event__synthesize_event_types(tool, process_synthesized_event, |
604 | session); | 530 | machine); |
605 | if (err < 0) { | 531 | if (err < 0) { |
606 | pr_err("Couldn't synthesize event_types.\n"); | 532 | pr_err("Couldn't synthesize event_types.\n"); |
607 | return err; | 533 | return err; |
@@ -616,56 +542,49 @@ static int __cmd_record(int argc, const char **argv) | |||
616 | * return this more properly and also | 542 | * return this more properly and also |
617 | * propagate errors that now are calling die() | 543 | * propagate errors that now are calling die() |
618 | */ | 544 | */ |
619 | err = perf_event__synthesize_tracing_data(output, evsel_list, | 545 | err = perf_event__synthesize_tracing_data(tool, output, evsel_list, |
620 | process_synthesized_event, | 546 | process_synthesized_event); |
621 | session); | ||
622 | if (err <= 0) { | 547 | if (err <= 0) { |
623 | pr_err("Couldn't record tracing data.\n"); | 548 | pr_err("Couldn't record tracing data.\n"); |
624 | return err; | 549 | return err; |
625 | } | 550 | } |
626 | advance_output(err); | 551 | advance_output(rec, err); |
627 | } | 552 | } |
628 | } | 553 | } |
629 | 554 | ||
630 | machine = perf_session__find_host_machine(session); | 555 | err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event, |
631 | if (!machine) { | 556 | machine, "_text"); |
632 | pr_err("Couldn't find native kernel information.\n"); | ||
633 | return -1; | ||
634 | } | ||
635 | |||
636 | err = perf_event__synthesize_kernel_mmap(process_synthesized_event, | ||
637 | session, machine, "_text"); | ||
638 | if (err < 0) | 557 | if (err < 0) |
639 | err = perf_event__synthesize_kernel_mmap(process_synthesized_event, | 558 | err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event, |
640 | session, machine, "_stext"); | 559 | machine, "_stext"); |
641 | if (err < 0) | 560 | if (err < 0) |
642 | pr_err("Couldn't record kernel reference relocation symbol\n" | 561 | pr_err("Couldn't record kernel reference relocation symbol\n" |
643 | "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" | 562 | "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" |
644 | "Check /proc/kallsyms permission or run as root.\n"); | 563 | "Check /proc/kallsyms permission or run as root.\n"); |
645 | 564 | ||
646 | err = perf_event__synthesize_modules(process_synthesized_event, | 565 | err = perf_event__synthesize_modules(tool, process_synthesized_event, |
647 | session, machine); | 566 | machine); |
648 | if (err < 0) | 567 | if (err < 0) |
649 | pr_err("Couldn't record kernel module information.\n" | 568 | pr_err("Couldn't record kernel module information.\n" |
650 | "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" | 569 | "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" |
651 | "Check /proc/modules permission or run as root.\n"); | 570 | "Check /proc/modules permission or run as root.\n"); |
652 | 571 | ||
653 | if (perf_guest) | 572 | if (perf_guest) |
654 | perf_session__process_machines(session, | 573 | perf_session__process_machines(session, tool, |
655 | perf_event__synthesize_guest_os); | 574 | perf_event__synthesize_guest_os); |
656 | 575 | ||
657 | if (!system_wide) | 576 | if (!opts->system_wide) |
658 | perf_event__synthesize_thread_map(evsel_list->threads, | 577 | perf_event__synthesize_thread_map(tool, evsel_list->threads, |
659 | process_synthesized_event, | 578 | process_synthesized_event, |
660 | session); | 579 | machine); |
661 | else | 580 | else |
662 | perf_event__synthesize_threads(process_synthesized_event, | 581 | perf_event__synthesize_threads(tool, process_synthesized_event, |
663 | session); | 582 | machine); |
664 | 583 | ||
665 | if (realtime_prio) { | 584 | if (rec->realtime_prio) { |
666 | struct sched_param param; | 585 | struct sched_param param; |
667 | 586 | ||
668 | param.sched_priority = realtime_prio; | 587 | param.sched_priority = rec->realtime_prio; |
669 | if (sched_setscheduler(0, SCHED_FIFO, ¶m)) { | 588 | if (sched_setscheduler(0, SCHED_FIFO, ¶m)) { |
670 | pr_err("Could not set realtime priority.\n"); | 589 | pr_err("Could not set realtime priority.\n"); |
671 | exit(-1); | 590 | exit(-1); |
@@ -678,14 +597,14 @@ static int __cmd_record(int argc, const char **argv) | |||
678 | * Let the child rip | 597 | * Let the child rip |
679 | */ | 598 | */ |
680 | if (forks) | 599 | if (forks) |
681 | close(go_pipe[1]); | 600 | perf_evlist__start_workload(evsel_list); |
682 | 601 | ||
683 | for (;;) { | 602 | for (;;) { |
684 | int hits = samples; | 603 | int hits = rec->samples; |
685 | 604 | ||
686 | mmap_read_all(); | 605 | perf_record__mmap_read_all(rec); |
687 | 606 | ||
688 | if (hits == samples) { | 607 | if (hits == rec->samples) { |
689 | if (done) | 608 | if (done) |
690 | break; | 609 | break; |
691 | err = poll(evsel_list->pollfd, evsel_list->nr_fds, -1); | 610 | err = poll(evsel_list->pollfd, evsel_list->nr_fds, -1); |
@@ -706,9 +625,9 @@ static int __cmd_record(int argc, const char **argv) | |||
706 | */ | 625 | */ |
707 | fprintf(stderr, | 626 | fprintf(stderr, |
708 | "[ perf record: Captured and wrote %.3f MB %s (~%" PRIu64 " samples) ]\n", | 627 | "[ perf record: Captured and wrote %.3f MB %s (~%" PRIu64 " samples) ]\n", |
709 | (double)bytes_written / 1024.0 / 1024.0, | 628 | (double)rec->bytes_written / 1024.0 / 1024.0, |
710 | output_name, | 629 | output_name, |
711 | bytes_written / 24); | 630 | rec->bytes_written / 24); |
712 | 631 | ||
713 | return 0; | 632 | return 0; |
714 | 633 | ||
@@ -723,58 +642,89 @@ static const char * const record_usage[] = { | |||
723 | NULL | 642 | NULL |
724 | }; | 643 | }; |
725 | 644 | ||
726 | static bool force, append_file; | 645 | /* |
646 | * XXX Ideally would be local to cmd_record() and passed to a perf_record__new | ||
647 | * because we need to have access to it in perf_record__exit, that is called | ||
648 | * after cmd_record() exits, but since record_options need to be accessible to | ||
649 | * builtin-script, leave it here. | ||
650 | * | ||
651 | * At least we don't ouch it in all the other functions here directly. | ||
652 | * | ||
653 | * Just say no to tons of global variables, sigh. | ||
654 | */ | ||
655 | static struct perf_record record = { | ||
656 | .opts = { | ||
657 | .target_pid = -1, | ||
658 | .target_tid = -1, | ||
659 | .mmap_pages = UINT_MAX, | ||
660 | .user_freq = UINT_MAX, | ||
661 | .user_interval = ULLONG_MAX, | ||
662 | .freq = 1000, | ||
663 | .sample_id_all_avail = true, | ||
664 | }, | ||
665 | .write_mode = WRITE_FORCE, | ||
666 | .file_new = true, | ||
667 | }; | ||
727 | 668 | ||
669 | /* | ||
670 | * XXX Will stay a global variable till we fix builtin-script.c to stop messing | ||
671 | * with it and switch to use the library functions in perf_evlist that came | ||
672 | * from builtin-record.c, i.e. use perf_record_opts, | ||
673 | * perf_evlist__prepare_workload, etc instead of fork+exec'in 'perf record', | ||
674 | * using pipes, etc. | ||
675 | */ | ||
728 | const struct option record_options[] = { | 676 | const struct option record_options[] = { |
729 | OPT_CALLBACK('e', "event", &evsel_list, "event", | 677 | OPT_CALLBACK('e', "event", &record.evlist, "event", |
730 | "event selector. use 'perf list' to list available events", | 678 | "event selector. use 'perf list' to list available events", |
731 | parse_events_option), | 679 | parse_events_option), |
732 | OPT_CALLBACK(0, "filter", &evsel_list, "filter", | 680 | OPT_CALLBACK(0, "filter", &record.evlist, "filter", |
733 | "event filter", parse_filter), | 681 | "event filter", parse_filter), |
734 | OPT_INTEGER('p', "pid", &target_pid, | 682 | OPT_INTEGER('p', "pid", &record.opts.target_pid, |
735 | "record events on existing process id"), | 683 | "record events on existing process id"), |
736 | OPT_INTEGER('t', "tid", &target_tid, | 684 | OPT_INTEGER('t', "tid", &record.opts.target_tid, |
737 | "record events on existing thread id"), | 685 | "record events on existing thread id"), |
738 | OPT_INTEGER('r', "realtime", &realtime_prio, | 686 | OPT_INTEGER('r', "realtime", &record.realtime_prio, |
739 | "collect data with this RT SCHED_FIFO priority"), | 687 | "collect data with this RT SCHED_FIFO priority"), |
740 | OPT_BOOLEAN('D', "no-delay", &nodelay, | 688 | OPT_BOOLEAN('D', "no-delay", &record.opts.no_delay, |
741 | "collect data without buffering"), | 689 | "collect data without buffering"), |
742 | OPT_BOOLEAN('R', "raw-samples", &raw_samples, | 690 | OPT_BOOLEAN('R', "raw-samples", &record.opts.raw_samples, |
743 | "collect raw sample records from all opened counters"), | 691 | "collect raw sample records from all opened counters"), |
744 | OPT_BOOLEAN('a', "all-cpus", &system_wide, | 692 | OPT_BOOLEAN('a', "all-cpus", &record.opts.system_wide, |
745 | "system-wide collection from all CPUs"), | 693 | "system-wide collection from all CPUs"), |
746 | OPT_BOOLEAN('A', "append", &append_file, | 694 | OPT_BOOLEAN('A', "append", &record.append_file, |
747 | "append to the output file to do incremental profiling"), | 695 | "append to the output file to do incremental profiling"), |
748 | OPT_STRING('C', "cpu", &cpu_list, "cpu", | 696 | OPT_STRING('C', "cpu", &record.opts.cpu_list, "cpu", |
749 | "list of cpus to monitor"), | 697 | "list of cpus to monitor"), |
750 | OPT_BOOLEAN('f', "force", &force, | 698 | OPT_BOOLEAN('f', "force", &record.force, |
751 | "overwrite existing data file (deprecated)"), | 699 | "overwrite existing data file (deprecated)"), |
752 | OPT_U64('c', "count", &user_interval, "event period to sample"), | 700 | OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"), |
753 | OPT_STRING('o', "output", &output_name, "file", | 701 | OPT_STRING('o', "output", &record.output_name, "file", |
754 | "output file name"), | 702 | "output file name"), |
755 | OPT_BOOLEAN('i', "no-inherit", &no_inherit, | 703 | OPT_BOOLEAN('i', "no-inherit", &record.opts.no_inherit, |
756 | "child tasks do not inherit counters"), | 704 | "child tasks do not inherit counters"), |
757 | OPT_UINTEGER('F', "freq", &user_freq, "profile at this frequency"), | 705 | OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"), |
758 | OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"), | 706 | OPT_UINTEGER('m', "mmap-pages", &record.opts.mmap_pages, |
759 | OPT_BOOLEAN(0, "group", &group, | 707 | "number of mmap data pages"), |
708 | OPT_BOOLEAN(0, "group", &record.opts.group, | ||
760 | "put the counters into a counter group"), | 709 | "put the counters into a counter group"), |
761 | OPT_BOOLEAN('g', "call-graph", &call_graph, | 710 | OPT_BOOLEAN('g', "call-graph", &record.opts.call_graph, |
762 | "do call-graph (stack chain/backtrace) recording"), | 711 | "do call-graph (stack chain/backtrace) recording"), |
763 | OPT_INCR('v', "verbose", &verbose, | 712 | OPT_INCR('v', "verbose", &verbose, |
764 | "be more verbose (show counter open errors, etc)"), | 713 | "be more verbose (show counter open errors, etc)"), |
765 | OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"), | 714 | OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"), |
766 | OPT_BOOLEAN('s', "stat", &inherit_stat, | 715 | OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat, |
767 | "per thread counts"), | 716 | "per thread counts"), |
768 | OPT_BOOLEAN('d', "data", &sample_address, | 717 | OPT_BOOLEAN('d', "data", &record.opts.sample_address, |
769 | "Sample addresses"), | 718 | "Sample addresses"), |
770 | OPT_BOOLEAN('T', "timestamp", &sample_time, "Sample timestamps"), | 719 | OPT_BOOLEAN('T', "timestamp", &record.opts.sample_time, "Sample timestamps"), |
771 | OPT_BOOLEAN('n', "no-samples", &no_samples, | 720 | OPT_BOOLEAN('P', "period", &record.opts.period, "Sample period"), |
721 | OPT_BOOLEAN('n', "no-samples", &record.opts.no_samples, | ||
772 | "don't sample"), | 722 | "don't sample"), |
773 | OPT_BOOLEAN('N', "no-buildid-cache", &no_buildid_cache, | 723 | OPT_BOOLEAN('N', "no-buildid-cache", &record.no_buildid_cache, |
774 | "do not update the buildid cache"), | 724 | "do not update the buildid cache"), |
775 | OPT_BOOLEAN('B', "no-buildid", &no_buildid, | 725 | OPT_BOOLEAN('B', "no-buildid", &record.no_buildid, |
776 | "do not collect buildids in perf.data"), | 726 | "do not collect buildids in perf.data"), |
777 | OPT_CALLBACK('G', "cgroup", &evsel_list, "name", | 727 | OPT_CALLBACK('G', "cgroup", &record.evlist, "name", |
778 | "monitor event in cgroup name only", | 728 | "monitor event in cgroup name only", |
779 | parse_cgroups), | 729 | parse_cgroups), |
780 | OPT_END() | 730 | OPT_END() |
@@ -784,28 +734,34 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
784 | { | 734 | { |
785 | int err = -ENOMEM; | 735 | int err = -ENOMEM; |
786 | struct perf_evsel *pos; | 736 | struct perf_evsel *pos; |
737 | struct perf_evlist *evsel_list; | ||
738 | struct perf_record *rec = &record; | ||
739 | |||
740 | perf_header__set_cmdline(argc, argv); | ||
787 | 741 | ||
788 | evsel_list = perf_evlist__new(NULL, NULL); | 742 | evsel_list = perf_evlist__new(NULL, NULL); |
789 | if (evsel_list == NULL) | 743 | if (evsel_list == NULL) |
790 | return -ENOMEM; | 744 | return -ENOMEM; |
791 | 745 | ||
746 | rec->evlist = evsel_list; | ||
747 | |||
792 | argc = parse_options(argc, argv, record_options, record_usage, | 748 | argc = parse_options(argc, argv, record_options, record_usage, |
793 | PARSE_OPT_STOP_AT_NON_OPTION); | 749 | PARSE_OPT_STOP_AT_NON_OPTION); |
794 | if (!argc && target_pid == -1 && target_tid == -1 && | 750 | if (!argc && rec->opts.target_pid == -1 && rec->opts.target_tid == -1 && |
795 | !system_wide && !cpu_list) | 751 | !rec->opts.system_wide && !rec->opts.cpu_list) |
796 | usage_with_options(record_usage, record_options); | 752 | usage_with_options(record_usage, record_options); |
797 | 753 | ||
798 | if (force && append_file) { | 754 | if (rec->force && rec->append_file) { |
799 | fprintf(stderr, "Can't overwrite and append at the same time." | 755 | fprintf(stderr, "Can't overwrite and append at the same time." |
800 | " You need to choose between -f and -A"); | 756 | " You need to choose between -f and -A"); |
801 | usage_with_options(record_usage, record_options); | 757 | usage_with_options(record_usage, record_options); |
802 | } else if (append_file) { | 758 | } else if (rec->append_file) { |
803 | write_mode = WRITE_APPEND; | 759 | rec->write_mode = WRITE_APPEND; |
804 | } else { | 760 | } else { |
805 | write_mode = WRITE_FORCE; | 761 | rec->write_mode = WRITE_FORCE; |
806 | } | 762 | } |
807 | 763 | ||
808 | if (nr_cgroups && !system_wide) { | 764 | if (nr_cgroups && !rec->opts.system_wide) { |
809 | fprintf(stderr, "cgroup monitoring only available in" | 765 | fprintf(stderr, "cgroup monitoring only available in" |
810 | " system-wide mode\n"); | 766 | " system-wide mode\n"); |
811 | usage_with_options(record_usage, record_options); | 767 | usage_with_options(record_usage, record_options); |
@@ -823,7 +779,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
823 | "If some relocation was applied (e.g. kexec) symbols may be misresolved\n" | 779 | "If some relocation was applied (e.g. kexec) symbols may be misresolved\n" |
824 | "even with a suitable vmlinux or kallsyms file.\n\n"); | 780 | "even with a suitable vmlinux or kallsyms file.\n\n"); |
825 | 781 | ||
826 | if (no_buildid_cache || no_buildid) | 782 | if (rec->no_buildid_cache || rec->no_buildid) |
827 | disable_buildid_cache(); | 783 | disable_buildid_cache(); |
828 | 784 | ||
829 | if (evsel_list->nr_entries == 0 && | 785 | if (evsel_list->nr_entries == 0 && |
@@ -832,43 +788,37 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
832 | goto out_symbol_exit; | 788 | goto out_symbol_exit; |
833 | } | 789 | } |
834 | 790 | ||
835 | if (target_pid != -1) | 791 | if (rec->opts.target_pid != -1) |
836 | target_tid = target_pid; | 792 | rec->opts.target_tid = rec->opts.target_pid; |
837 | 793 | ||
838 | if (perf_evlist__create_maps(evsel_list, target_pid, | 794 | if (perf_evlist__create_maps(evsel_list, rec->opts.target_pid, |
839 | target_tid, cpu_list) < 0) | 795 | rec->opts.target_tid, rec->opts.cpu_list) < 0) |
840 | usage_with_options(record_usage, record_options); | 796 | usage_with_options(record_usage, record_options); |
841 | 797 | ||
842 | list_for_each_entry(pos, &evsel_list->entries, node) { | 798 | list_for_each_entry(pos, &evsel_list->entries, node) { |
843 | if (perf_evsel__alloc_fd(pos, evsel_list->cpus->nr, | ||
844 | evsel_list->threads->nr) < 0) | ||
845 | goto out_free_fd; | ||
846 | if (perf_header__push_event(pos->attr.config, event_name(pos))) | 799 | if (perf_header__push_event(pos->attr.config, event_name(pos))) |
847 | goto out_free_fd; | 800 | goto out_free_fd; |
848 | } | 801 | } |
849 | 802 | ||
850 | if (perf_evlist__alloc_pollfd(evsel_list) < 0) | 803 | if (rec->opts.user_interval != ULLONG_MAX) |
851 | goto out_free_fd; | 804 | rec->opts.default_interval = rec->opts.user_interval; |
852 | 805 | if (rec->opts.user_freq != UINT_MAX) | |
853 | if (user_interval != ULLONG_MAX) | 806 | rec->opts.freq = rec->opts.user_freq; |
854 | default_interval = user_interval; | ||
855 | if (user_freq != UINT_MAX) | ||
856 | freq = user_freq; | ||
857 | 807 | ||
858 | /* | 808 | /* |
859 | * User specified count overrides default frequency. | 809 | * User specified count overrides default frequency. |
860 | */ | 810 | */ |
861 | if (default_interval) | 811 | if (rec->opts.default_interval) |
862 | freq = 0; | 812 | rec->opts.freq = 0; |
863 | else if (freq) { | 813 | else if (rec->opts.freq) { |
864 | default_interval = freq; | 814 | rec->opts.default_interval = rec->opts.freq; |
865 | } else { | 815 | } else { |
866 | fprintf(stderr, "frequency and count are zero, aborting\n"); | 816 | fprintf(stderr, "frequency and count are zero, aborting\n"); |
867 | err = -EINVAL; | 817 | err = -EINVAL; |
868 | goto out_free_fd; | 818 | goto out_free_fd; |
869 | } | 819 | } |
870 | 820 | ||
871 | err = __cmd_record(argc, argv); | 821 | err = __cmd_record(&record, argc, argv); |
872 | out_free_fd: | 822 | out_free_fd: |
873 | perf_evlist__delete_maps(evsel_list); | 823 | perf_evlist__delete_maps(evsel_list); |
874 | out_symbol_exit: | 824 | out_symbol_exit: |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index d7ff277bdb78..25d34d483e49 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "util/evsel.h" | 25 | #include "util/evsel.h" |
26 | #include "util/header.h" | 26 | #include "util/header.h" |
27 | #include "util/session.h" | 27 | #include "util/session.h" |
28 | #include "util/tool.h" | ||
28 | 29 | ||
29 | #include "util/parse-options.h" | 30 | #include "util/parse-options.h" |
30 | #include "util/parse-events.h" | 31 | #include "util/parse-events.h" |
@@ -35,37 +36,35 @@ | |||
35 | 36 | ||
36 | #include <linux/bitmap.h> | 37 | #include <linux/bitmap.h> |
37 | 38 | ||
38 | static char const *input_name = "perf.data"; | 39 | struct perf_report { |
39 | 40 | struct perf_tool tool; | |
40 | static bool force, use_tui, use_stdio; | 41 | struct perf_session *session; |
41 | static bool hide_unresolved; | 42 | char const *input_name; |
42 | static bool dont_use_callchains; | 43 | bool force, use_tui, use_stdio; |
43 | 44 | bool hide_unresolved; | |
44 | static bool show_threads; | 45 | bool dont_use_callchains; |
45 | static struct perf_read_values show_threads_values; | 46 | bool show_full_info; |
46 | 47 | bool show_threads; | |
47 | static const char default_pretty_printing_style[] = "normal"; | 48 | bool inverted_callchain; |
48 | static const char *pretty_printing_style = default_pretty_printing_style; | 49 | struct perf_read_values show_threads_values; |
49 | 50 | const char *pretty_printing_style; | |
50 | static char callchain_default_opt[] = "fractal,0.5,callee"; | 51 | symbol_filter_t annotate_init; |
51 | static bool inverted_callchain; | 52 | const char *cpu_list; |
52 | static symbol_filter_t annotate_init; | 53 | DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
53 | 54 | }; | |
54 | static const char *cpu_list; | ||
55 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); | ||
56 | 55 | ||
57 | static int perf_session__add_hist_entry(struct perf_session *session, | 56 | static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, |
58 | struct addr_location *al, | 57 | struct addr_location *al, |
59 | struct perf_sample *sample, | 58 | struct perf_sample *sample, |
60 | struct perf_evsel *evsel) | 59 | struct machine *machine) |
61 | { | 60 | { |
62 | struct symbol *parent = NULL; | 61 | struct symbol *parent = NULL; |
63 | int err = 0; | 62 | int err = 0; |
64 | struct hist_entry *he; | 63 | struct hist_entry *he; |
65 | 64 | ||
66 | if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { | 65 | if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { |
67 | err = perf_session__resolve_callchain(session, al->thread, | 66 | err = machine__resolve_callchain(machine, evsel, al->thread, |
68 | sample->callchain, &parent); | 67 | sample->callchain, &parent); |
69 | if (err) | 68 | if (err) |
70 | return err; | 69 | return err; |
71 | } | 70 | } |
@@ -75,7 +74,8 @@ static int perf_session__add_hist_entry(struct perf_session *session, | |||
75 | return -ENOMEM; | 74 | return -ENOMEM; |
76 | 75 | ||
77 | if (symbol_conf.use_callchain) { | 76 | if (symbol_conf.use_callchain) { |
78 | err = callchain_append(he->callchain, &session->callchain_cursor, | 77 | err = callchain_append(he->callchain, |
78 | &evsel->hists.callchain_cursor, | ||
79 | sample->period); | 79 | sample->period); |
80 | if (err) | 80 | if (err) |
81 | return err; | 81 | return err; |
@@ -91,8 +91,7 @@ static int perf_session__add_hist_entry(struct perf_session *session, | |||
91 | assert(evsel != NULL); | 91 | assert(evsel != NULL); |
92 | 92 | ||
93 | err = -ENOMEM; | 93 | err = -ENOMEM; |
94 | if (notes->src == NULL && | 94 | if (notes->src == NULL && symbol__alloc_hist(he->ms.sym) < 0) |
95 | symbol__alloc_hist(he->ms.sym, session->evlist->nr_entries) < 0) | ||
96 | goto out; | 95 | goto out; |
97 | 96 | ||
98 | err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); | 97 | err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); |
@@ -105,30 +104,32 @@ out: | |||
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||
108 | static int process_sample_event(union perf_event *event, | 107 | static int process_sample_event(struct perf_tool *tool, |
108 | union perf_event *event, | ||
109 | struct perf_sample *sample, | 109 | struct perf_sample *sample, |