History

Merge tag 'perf-urgent-for-mingo-4.12-20170608' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent

Pull perf/urgent fixes from Arnaldo Carvalho de Melo: - Fixes for handling compressed kernel modules (Namhyung Kim) - Fix handling old style build-id cache ($HOME/.debug/) (Namhyung Kim) - 'perf script' python/perl documentation fixes: outdated comments, invalid code snippets, etc (SeongJae Park)

Ingo Molnar committed 9 years ago

Commit 47c1ded2 parents cc1582c b89fe6312 files · +136 −135Browse files

Unified · Split

12 files
  1. tools/perf/Documentation/perf-probe.txt +6 −2
  2. tools/perf/Documentation/perf-script-perl.txt +1 −1
  3. tools/perf/Documentation/perf-script-python.txt +9 −14
  4. tools/perf/tests/code-reading.c +19 −1
  5. tools/perf/util/annotate.c +12 −25
  6. tools/perf/util/build-id.c +0 −45
  7. tools/perf/util/build-id.h +0 −1
  8. tools/perf/util/dso.c +79 −6
  9. tools/perf/util/dso.h +6 −0
  10. tools/perf/util/scripting-engines/trace-event-python.c +1 −1
  11. tools/perf/util/symbol-elf.c +3 −35
  12. tools/perf/util/symbol.c +0 −4
tools/perf/Documentation/perf-probe.txt+6−2
@@ -240,9 +240,13 @@ Add a probe on schedule() function 12th line with recording cpu local variable: · 239 unmodified lines
240 or240 or
241 ./perf probe --add='schedule:12 cpu'241 ./perf probe --add='schedule:12 cpu'
242 242
243 this will add one or more probes which has the name start with "schedule".243Add one or more probes which has the name start with "schedule".
244 244
245 Add probes on lines in schedule() function which calls update_rq_clock().245 ./perf probe schedule*
246 or
247 ./perf probe --add='schedule*'
248
249Add probes on lines in schedule() function which calls update_rq_clock().
246 250
247 ./perf probe 'schedule;update_rq_clock*'251 ./perf probe 'schedule;update_rq_clock*'
248 or252 or
tools/perf/Documentation/perf-script-perl.txt+1−1
@@ -39,7 +39,7 @@ EVENT HANDLERS · 38 unmodified lines
39When perf script is invoked using a trace script, a user-defined39When perf script is invoked using a trace script, a user-defined
40'handler function' is called for each event in the trace. If there's40'handler function' is called for each event in the trace. If there's
41no handler function defined for a given event type, the event is41no handler function defined for a given event type, the event is
42ignored (or passed to a 'trace_handled' function, see below) and the42ignored (or passed to a 'trace_unhandled' function, see below) and the
43next event is processed.43next event is processed.
44 44
45Most of the event's field values are passed as arguments to the45Most of the event's field values are passed as arguments to the
tools/perf/Documentation/perf-script-python.txt+9−14
@@ -149,10 +149,8 @@ def raw_syscalls__sys_enter(event_name, context, common_cpu, · 148 unmodified lines
149 print "id=%d, args=%s\n" % \149 print "id=%d, args=%s\n" % \
150 (id, args),150 (id, args),
151 151
152def trace_unhandled(event_name, context, common_cpu, common_secs, common_nsecs,152def trace_unhandled(event_name, context, event_fields_dict):
153 common_pid, common_comm):153 print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
154 print_header(event_name, common_cpu, common_secs, common_nsecs,
155 common_pid, common_comm)
156 154
157def print_header(event_name, cpu, secs, nsecs, pid, comm):155def print_header(event_name, cpu, secs, nsecs, pid, comm):
158 print "%-20s %5u %05u.%09u %8u %-20s " % \156 print "%-20s %5u %05u.%09u %8u %-20s " % \
@@ -321,7 +319,7 @@ So those are the essential steps in writing and running a script. The · 162 unmodified lines
321process can be generalized to any tracepoint or set of tracepoints319process can be generalized to any tracepoint or set of tracepoints
322you're interested in - basically find the tracepoint(s) you're320you're interested in - basically find the tracepoint(s) you're
323interested in by looking at the list of available events shown by321interested in by looking at the list of available events shown by
324'perf list' and/or look in /sys/kernel/debug/tracing events for322'perf list' and/or look in /sys/kernel/debug/tracing/events/ for
325detailed event and field info, record the corresponding trace data323detailed event and field info, record the corresponding trace data
326using 'perf record', passing it the list of interesting events,324using 'perf record', passing it the list of interesting events,
327generate a skeleton script using 'perf script -g python' and modify the325generate a skeleton script using 'perf script -g python' and modify the
@@ -334,7 +332,7 @@ right place, you can have your script listed alongside the other · 6 unmodified lines
334scripts listed by the 'perf script -l' command e.g.:332scripts listed by the 'perf script -l' command e.g.:
335 333
336----334----
337root@tropicana:~# perf script -l335# perf script -l
338List of available trace scripts:336List of available trace scripts:
339 wakeup-latency system-wide min/max/avg wakeup latency337 wakeup-latency system-wide min/max/avg wakeup latency
340 rw-by-file <comm> r/w activity for a program, by file338 rw-by-file <comm> r/w activity for a program, by file
@@ -383,8 +381,6 @@ source tree: · 42 unmodified lines
383 381
384----382----
385# ls -al kernel-source/tools/perf/scripts/python383# ls -al kernel-source/tools/perf/scripts/python
386
387root@tropicana:/home/trz/src/tip# ls -al tools/perf/scripts/python
388total 32384total 32
389drwxr-xr-x 4 trz trz 4096 2010-01-26 22:30 .385drwxr-xr-x 4 trz trz 4096 2010-01-26 22:30 .
390drwxr-xr-x 4 trz trz 4096 2010-01-26 22:29 ..386drwxr-xr-x 4 trz trz 4096 2010-01-26 22:29 ..
@@ -399,7 +395,7 @@ otherwise your script won't show up at run-time), 'perf script -l' · 8 unmodified lines
399should show a new entry for your script:395should show a new entry for your script:
400 396
401----397----
402root@tropicana:~# perf script -l398# perf script -l
403List of available trace scripts:399List of available trace scripts:
404 wakeup-latency system-wide min/max/avg wakeup latency400 wakeup-latency system-wide min/max/avg wakeup latency
405 rw-by-file <comm> r/w activity for a program, by file401 rw-by-file <comm> r/w activity for a program, by file
@@ -437,7 +433,7 @@ EVENT HANDLERS · 31 unmodified lines
437When perf script is invoked using a trace script, a user-defined433When perf script is invoked using a trace script, a user-defined
438'handler function' is called for each event in the trace. If there's434'handler function' is called for each event in the trace. If there's
439no handler function defined for a given event type, the event is435no handler function defined for a given event type, the event is
440ignored (or passed to a 'trace_handled' function, see below) and the436ignored (or passed to a 'trace_unhandled' function, see below) and the
441next event is processed.437next event is processed.
442 438
443Most of the event's field values are passed as arguments to the439Most of the event's field values are passed as arguments to the
@@ -532,7 +528,7 @@ can implement a set of optional functions: · 88 unmodified lines
532gives scripts a chance to do setup tasks:528gives scripts a chance to do setup tasks:
533 529
534----530----
535def trace_begin:531def trace_begin():
536 pass532 pass
537----533----
538 534
@@ -541,7 +537,7 @@ def trace_begin: · 2 unmodified lines
541 as display results:537 as display results:
542 538
543----539----
544def trace_end:540def trace_end():
545 pass541 pass
546----542----
547 543
@@ -550,8 +546,7 @@ def trace_end: · 2 unmodified lines
550 of common arguments are passed into it:546 of common arguments are passed into it:
551 547
552----548----
553def trace_unhandled(event_name, context, common_cpu, common_secs,549def trace_unhandled(event_name, context, event_fields_dict):
554 common_nsecs, common_pid, common_comm):
555 pass550 pass
556----551----
557 552
tools/perf/tests/code-reading.c+19−1
@@ -229,6 +229,8 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, · 228 unmodified lines
229 unsigned char buf2[BUFSZ];229 unsigned char buf2[BUFSZ];
230 size_t ret_len;230 size_t ret_len;
231 u64 objdump_addr;231 u64 objdump_addr;
232 const char *objdump_name;
233 char decomp_name[KMOD_DECOMP_LEN];
232 int ret;234 int ret;
233 235
234 pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);236 pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
@@ -289,9 +291,25 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, · 54 unmodified lines
289 state->done[state->done_cnt++] = al.map->start;291 state->done[state->done_cnt++] = al.map->start;
290 }292 }
291 293
294 objdump_name = al.map->dso->long_name;
295 if (dso__needs_decompress(al.map->dso)) {
296 if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
297 decomp_name,
298 sizeof(decomp_name)) < 0) {
299 pr_debug("decompression failed\n");
300 return -1;
301 }
302
303 objdump_name = decomp_name;
304 }
305
292 /* Read the object code using objdump */306 /* Read the object code using objdump */
293 objdump_addr = map__rip_2objdump(al.map, al.addr);307 objdump_addr = map__rip_2objdump(al.map, al.addr);
294 ret = read_via_objdump(al.map->dso->long_name, objdump_addr, buf2, len);308 ret = read_via_objdump(objdump_name, objdump_addr, buf2, len);
309
310 if (dso__needs_decompress(al.map->dso))
311 unlink(objdump_name);
312
295 if (ret > 0) {313 if (ret > 0) {
296 /*314 /*
297 * The kernel maps are inaccurate - assume objdump is right in315 * The kernel maps are inaccurate - assume objdump is right in
tools/perf/util/annotate.c+12−25
@@ -1321,6 +1321,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil · 1320 unmodified lines
1321 char linkname[PATH_MAX];1321 char linkname[PATH_MAX];
1322 char *build_id_filename;1322 char *build_id_filename;
1323 char *build_id_path = NULL;1323 char *build_id_path = NULL;
1324 char *pos;
1324 1325
1325 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&1326 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
1326 !dso__is_kcore(dso))1327 !dso__is_kcore(dso))
@@ -1340,7 +1341,14 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil · 13 unmodified lines
1340 if (!build_id_path)1341 if (!build_id_path)
1341 return -1;1342 return -1;
1342 1343
1343 dirname(build_id_path);1344 /*
1345 * old style build-id cache has name of XX/XXXXXXX.. while
1346 * new style has XX/XXXXXXX../{elf,kallsyms,vdso}.
1347 * extract the build-id part of dirname in the new style only.
1348 */
1349 pos = strrchr(build_id_path, '/');
1350 if (pos && strlen(pos) < SBUILD_ID_SIZE - 2)
1351 dirname(build_id_path);
1344 1352
1345 if (dso__is_kcore(dso) ||1353 if (dso__is_kcore(dso) ||
1346 readlink(build_id_path, linkname, sizeof(linkname)) < 0 ||1354 readlink(build_id_path, linkname, sizeof(linkname)) < 0 ||
@@ -1423,31 +1431,10 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na · 76 unmodified lines
1423 sizeof(symfs_filename));1431 sizeof(symfs_filename));
1424 }1432 }
1425 } else if (dso__needs_decompress(dso)) {1433 } else if (dso__needs_decompress(dso)) {
1426 char tmp[PATH_MAX];1434 char tmp[KMOD_DECOMP_LEN];
1427 struct kmod_path m;
1428 int fd;
1429 bool ret;
1430
1431 if (kmod_path__parse_ext(&m, symfs_filename))
1432 goto out;
1433
1434 snprintf(tmp, PATH_MAX, "/tmp/perf-kmod-XXXXXX");
1435
1436 fd = mkstemp(tmp);
1437 if (fd < 0) {
1438 free(m.ext);
1439 goto out;
1440 }
1441
1442 ret = decompress_to_file(m.ext, symfs_filename, fd);
1443
1444 if (ret)
1445 pr_err("Cannot decompress %s %s\n", m.ext, symfs_filename);
1446
1447 free(m.ext);
1448 close(fd);
1449 1435
1450 if (!ret)1436 if (dso__decompress_kmodule_path(dso, symfs_filename,
1437 tmp, sizeof(tmp)) < 0)
1451 goto out;1438 goto out;
1452 1439
1453 strcpy(symfs_filename, tmp);1440 strcpy(symfs_filename, tmp);
tools/perf/util/build-id.c+0−45
@@ -278,51 +278,6 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size) · 277 unmodified lines
278 return bf;278 return bf;
279}279}
280 280
281bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size)
282{
283 char *id_name = NULL, *ch;
284 struct stat sb;
285 char sbuild_id[SBUILD_ID_SIZE];
286
287 if (!dso->has_build_id)
288 goto err;
289
290 build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
291 id_name = build_id_cache__linkname(sbuild_id, NULL, 0);
292 if (!id_name)
293 goto err;
294 if (access(id_name, F_OK))
295 goto err;
296 if (lstat(id_name, &sb) == -1)
297 goto err;
298 if ((size_t)sb.st_size > size - 1)
299 goto err;
300 if (readlink(id_name, bf, size - 1) < 0)
301 goto err;
302
303 bf[sb.st_size] = '\0';
304
305 /*
306 * link should be:
307 * ../../lib/modules/4.4.0-rc4/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko/a09fe3eb3147dafa4e3b31dbd6257e4d696bdc92
308 */
309 ch = strrchr(bf, '/');
310 if (!ch)
311 goto err;
312 if (ch - 3 < bf)
313 goto err;
314
315 free(id_name);
316 return strncmp(".ko", ch - 3, 3) == 0;
317err:
318 pr_err("Invalid build id: %s\n", id_name ? :
319 dso->long_name ? :
320 dso->short_name ? :
321 "[unknown]");
322 free(id_name);
323 return false;
324}
325
326#define dsos__for_each_with_build_id(pos, head) \281#define dsos__for_each_with_build_id(pos, head) \
327 list_for_each_entry(pos, head, node) \282 list_for_each_entry(pos, head, node) \
328 if (!pos->has_build_id) \283 if (!pos->has_build_id) \
tools/perf/util/build-id.h+0−1
@@ -17,7 +17,6 @@ char *build_id_cache__kallsyms_path(const char *sbuild_id, char *bf, · 16 unmodified lines
17 size_t size);17 size_t size);
18 18
19char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);19char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);
20bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size);
21 20
22int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,21int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
23 struct perf_sample *sample, struct perf_evsel *evsel,22 struct perf_sample *sample, struct perf_evsel *evsel,
tools/perf/util/dso.c+79−6
@@ -248,6 +248,64 @@ bool dso__needs_decompress(struct dso *dso) · 247 unmodified lines
248 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;248 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
249}249}
250 250
251static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf)
252{
253 int fd = -1;
254 struct kmod_path m;
255
256 if (!dso__needs_decompress(dso))
257 return -1;
258
259 if (kmod_path__parse_ext(&m, dso->long_name))
260 return -1;
261
262 if (!m.comp)
263 goto out;
264
265 fd = mkstemp(tmpbuf);
266 if (fd < 0) {
267 dso->load_errno = errno;
268 goto out;
269 }
270
271 if (!decompress_to_file(m.ext, name, fd)) {
272 dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
273 close(fd);
274 fd = -1;
275 }
276
277out:
278 free(m.ext);
279 return fd;
280}
281
282int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
283{
284 char tmpbuf[] = KMOD_DECOMP_NAME;
285 int fd;
286
287 fd = decompress_kmodule(dso, name, tmpbuf);
288 unlink(tmpbuf);
289 return fd;
290}
291
292int dso__decompress_kmodule_path(struct dso *dso, const char *name,
293 char *pathname, size_t len)
294{
295 char tmpbuf[] = KMOD_DECOMP_NAME;
296 int fd;
297
298 fd = decompress_kmodule(dso, name, tmpbuf);
299 if (fd < 0) {
300 unlink(tmpbuf);
301 return -1;
302 }
303
304 strncpy(pathname, tmpbuf, len);
305 close(fd);
306 return 0;
307}
308
251/*309/*
252 * Parses kernel module specified in @path and updates310 * Parses kernel module specified in @path and updates
253 * @m argument like:311 * @m argument like:
@@ -396,7 +454,7 @@ static int do_open(char *name) · 142 unmodified lines
396 454
397static int __open_dso(struct dso *dso, struct machine *machine)455static int __open_dso(struct dso *dso, struct machine *machine)
398{456{
399 int fd;457 int fd = -EINVAL;
400 char *root_dir = (char *)"";458 char *root_dir = (char *)"";
401 char *name = malloc(PATH_MAX);459 char *name = malloc(PATH_MAX);
402 460
@@ -407,15 +465,30 @@ static int __open_dso(struct dso *dso, struct machine *machine) · 4 unmodified lines
407 root_dir = machine->root_dir;465 root_dir = machine->root_dir;
408 466
409 if (dso__read_binary_type_filename(dso, dso->binary_type,467 if (dso__read_binary_type_filename(dso, dso->binary_type,
410 root_dir, name, PATH_MAX)) {468 root_dir, name, PATH_MAX))
411 free(name);469 goto out;
412 return -EINVAL;
413 }
414 470
415 if (!is_regular_file(name))471 if (!is_regular_file(name))
416 return -EINVAL;472 goto out;
473
474 if (dso__needs_decompress(dso)) {
475 char newpath[KMOD_DECOMP_LEN];
476 size_t len = sizeof(newpath);
477
478 if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
479 fd = -dso->load_errno;
480 goto out;
481 }
482
483 strcpy(name, newpath);
484 }
417 485
418 fd = do_open(name);486 fd = do_open(name);
487
488 if (dso__needs_decompress(dso))
489 unlink(name);
490
491out:
419 free(name);492 free(name);
420 return fd;493 return fd;
421}494}
tools/perf/util/dso.h+6−0
@@ -244,6 +244,12 @@ bool is_supported_compression(const char *ext); · 243 unmodified lines
244bool is_kernel_module(const char *pathname, int cpumode);244bool is_kernel_module(const char *pathname, int cpumode);
245bool decompress_to_file(const char *ext, const char *filename, int output_fd);245bool decompress_to_file(const char *ext, const char *filename, int output_fd);
246bool dso__needs_decompress(struct dso *dso);246bool dso__needs_decompress(struct dso *dso);
247int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
248int dso__decompress_kmodule_path(struct dso *dso, const char *name,
249 char *pathname, size_t len);
250
251#define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX"
252#define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME)
247 253
248struct kmod_path {254struct kmod_path {
249 char *name;255 char *name;
tools/perf/util/scripting-engines/trace-event-python.c+1−1
@@ -1219,7 +1219,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) · 1218 unmodified lines
1219 fprintf(ofp, "# be retrieved using Python functions of the form "1219 fprintf(ofp, "# be retrieved using Python functions of the form "
1220 "common_*(context).\n");1220 "common_*(context).\n");
1221 1221
1222 fprintf(ofp, "# See the perf-trace-python Documentation for the list "1222 fprintf(ofp, "# See the perf-script-python Documentation for the list "
1223 "of available functions.\n\n");1223 "of available functions.\n\n");
1224 1224
1225 fprintf(ofp, "import os\n");1225 fprintf(ofp, "import os\n");
tools/perf/util/symbol-elf.c+3−35
@@ -637,40 +637,6 @@ static int dso__swap_init(struct dso *dso, unsigned char eidata) · 636 unmodified lines
637 return 0;637 return 0;
638}638}
639 639
640static int decompress_kmodule(struct dso *dso, const char *name,
641 enum dso_binary_type type)
642{
643 int fd = -1;
644 char tmpbuf[] = "/tmp/perf-kmod-XXXXXX";
645 struct kmod_path m;
646
647 if (type != DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP &&
648 type != DSO_BINARY_TYPE__GUEST_KMODULE_COMP &&
649 type != DSO_BINARY_TYPE__BUILD_ID_CACHE)
650 return -1;
651
652 if (kmod_path__parse_ext(&m, dso->long_name) || !m.comp)
653 return -1;
654
655 fd = mkstemp(tmpbuf);
656 if (fd < 0) {
657 dso->load_errno = errno;
658 goto out;
659 }
660
661 if (!decompress_to_file(m.ext, name, fd)) {
662 dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
663 close(fd);
664 fd = -1;
665 }
666
667 unlink(tmpbuf);
668
669out:
670 free(m.ext);
671 return fd;
672}
673
674bool symsrc__possibly_runtime(struct symsrc *ss)640bool symsrc__possibly_runtime(struct symsrc *ss)
675{641{
676 return ss->dynsym || ss->opdsec;642 return ss->dynsym || ss->opdsec;
@@ -702,9 +668,11 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, · 25 unmodified lines
702 int fd;668 int fd;
703 669
704 if (dso__needs_decompress(dso)) {670 if (dso__needs_decompress(dso)) {
705 fd = decompress_kmodule(dso, name, type);671 fd = dso__decompress_kmodule_fd(dso, name);
706 if (fd < 0)672 if (fd < 0)
707 return -1;673 return -1;
674
675 type = dso->symtab_type;
708 } else {676 } else {
709 fd = open(name, O_RDONLY);677 fd = open(name, O_RDONLY);
710 if (fd < 0) {678 if (fd < 0) {
tools/perf/util/symbol.c+0−4
@@ -1562,10 +1562,6 @@ int dso__load(struct dso *dso, struct map *map) · 1561 unmodified lines
1562 if (!runtime_ss && syms_ss)1562 if (!runtime_ss && syms_ss)
1563 runtime_ss = syms_ss;1563 runtime_ss = syms_ss;
1564 1564
1565 if (syms_ss && syms_ss->type == DSO_BINARY_TYPE__BUILD_ID_CACHE)
1566 if (dso__build_id_is_kmod(dso, name, PATH_MAX))
1567 kmod = true;
1568
1569 if (syms_ss)1565 if (syms_ss)
1570 ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);1566 ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
1571 else1567 else

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t