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
240240 or
241241 ./perf probe --add='schedule:12 cpu'
242242
243− this will add one or more probes which has the name start with "schedule".
243+Add one or more probes which has the name start with "schedule".
244244
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+
249+Add probes on lines in schedule() function which calls update_rq_clock().
246250
247251 ./perf probe 'schedule;update_rq_clock*'
248252 or
tools/perf/Documentation/perf-script-perl.txt+1−1
@@ -39,7 +39,7 @@ EVENT HANDLERS · 38 unmodified lines
3939 When perf script is invoked using a trace script, a user-defined
4040 'handler function' is called for each event in the trace. If there's
4141 no handler function defined for a given event type, the event is
42−ignored (or passed to a 'trace_handled' function, see below) and the
42+ignored (or passed to a 'trace_unhandled' function, see below) and the
4343 next event is processed.
4444
4545 Most 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
149149 print "id=%d, args=%s\n" % \
150150 (id, args),
151151
152−def trace_unhandled(event_name, context, common_cpu, common_secs, common_nsecs,
153− common_pid, common_comm):
154− print_header(event_name, common_cpu, common_secs, common_nsecs,
155− common_pid, common_comm)
152+def trace_unhandled(event_name, context, event_fields_dict):
153+ print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
156154
157155 def print_header(event_name, cpu, secs, nsecs, pid, comm):
158156 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
321319 process can be generalized to any tracepoint or set of tracepoints
322320 you're interested in - basically find the tracepoint(s) you're
323321 interested in by looking at the list of available events shown by
324−'perf list' and/or look in /sys/kernel/debug/tracing events for
322+'perf list' and/or look in /sys/kernel/debug/tracing/events/ for
325323 detailed event and field info, record the corresponding trace data
326324 using 'perf record', passing it the list of interesting events,
327325 generate 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
334332 scripts listed by the 'perf script -l' command e.g.:
335333
336334 ----
337−root@tropicana:~# perf script -l
335+# perf script -l
338336 List of available trace scripts:
339337 wakeup-latency system-wide min/max/avg wakeup latency
340338 rw-by-file <comm> r/w activity for a program, by file
@@ -383,8 +381,6 @@ source tree: · 42 unmodified lines
383381
384382 ----
385383 # ls -al kernel-source/tools/perf/scripts/python
386−
387−root@tropicana:/home/trz/src/tip# ls -al tools/perf/scripts/python
388384 total 32
389385 drwxr-xr-x 4 trz trz 4096 2010-01-26 22:30 .
390386 drwxr-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
399395 should show a new entry for your script:
400396
401397 ----
402−root@tropicana:~# perf script -l
398+# perf script -l
403399 List of available trace scripts:
404400 wakeup-latency system-wide min/max/avg wakeup latency
405401 rw-by-file <comm> r/w activity for a program, by file
@@ -437,7 +433,7 @@ EVENT HANDLERS · 31 unmodified lines
437433 When perf script is invoked using a trace script, a user-defined
438434 'handler function' is called for each event in the trace. If there's
439435 no handler function defined for a given event type, the event is
440−ignored (or passed to a 'trace_handled' function, see below) and the
436+ignored (or passed to a 'trace_unhandled' function, see below) and the
441437 next event is processed.
442438
443439 Most 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
532528 gives scripts a chance to do setup tasks:
533529
534530 ----
535−def trace_begin:
531+def trace_begin():
536532 pass
537533 ----
538534
@@ -541,7 +537,7 @@ def trace_begin: · 2 unmodified lines
541537 as display results:
542538
543539 ----
544−def trace_end:
540+def trace_end():
545541 pass
546542 ----
547543
@@ -550,8 +546,7 @@ def trace_end: · 2 unmodified lines
550546 of common arguments are passed into it:
551547
552548 ----
553−def trace_unhandled(event_name, context, common_cpu, common_secs,
554− common_nsecs, common_pid, common_comm):
549+def trace_unhandled(event_name, context, event_fields_dict):
555550 pass
556551 ----
557552
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
229229 unsigned char buf2[BUFSZ];
230230 size_t ret_len;
231231 u64 objdump_addr;
232+ const char *objdump_name;
233+ char decomp_name[KMOD_DECOMP_LEN];
232234 int ret;
233235
234236 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
289291 state->done[state->done_cnt++] = al.map->start;
290292 }
291293
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+
292306 /* Read the object code using objdump */
293307 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+
295313 if (ret > 0) {
296314 /*
297315 * 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
13211321 char linkname[PATH_MAX];
13221322 char *build_id_filename;
13231323 char *build_id_path = NULL;
1324+ char *pos;
13241325
13251326 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
13261327 !dso__is_kcore(dso))
@@ -1340,7 +1341,14 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil · 13 unmodified lines
13401341 if (!build_id_path)
13411342 return -1;
13421343
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);
13441352
13451353 if (dso__is_kcore(dso) ||
13461354 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
14231431 sizeof(symfs_filename));
14241432 }
14251433 } else if (dso__needs_decompress(dso)) {
1426− char tmp[PATH_MAX];
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);
1434+ char tmp[KMOD_DECOMP_LEN];
14491435
1450− if (!ret)
1436+ if (dso__decompress_kmodule_path(dso, symfs_filename,
1437+ tmp, sizeof(tmp)) < 0)
14511438 goto out;
14521439
14531440 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
278278 return bf;
279279 }
280280
281−bool 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;
317−err:
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−
326281 #define dsos__for_each_with_build_id(pos, head) \
327282 list_for_each_entry(pos, head, node) \
328283 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
1717 size_t size);
1818
1919 char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);
20−bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size);
2120
2221 int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
2322 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
248248 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
249249 }
250250
251+static 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+
277+out:
278+ free(m.ext);
279+ return fd;
280+}
281+
282+int 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+
292+int 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+
251309 /*
252310 * Parses kernel module specified in @path and updates
253311 * @m argument like:
@@ -396,7 +454,7 @@ static int do_open(char *name) · 142 unmodified lines
396454
397455 static int __open_dso(struct dso *dso, struct machine *machine)
398456 {
399− int fd;
457+ int fd = -EINVAL;
400458 char *root_dir = (char *)"";
401459 char *name = malloc(PATH_MAX);
402460
@@ -407,15 +465,30 @@ static int __open_dso(struct dso *dso, struct machine *machine) · 4 unmodified lines
407465 root_dir = machine->root_dir;
408466
409467 if (dso__read_binary_type_filename(dso, dso->binary_type,
410− root_dir, name, PATH_MAX)) {
411− free(name);
412− return -EINVAL;
413− }
468+ root_dir, name, PATH_MAX))
469+ goto out;
414470
415471 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+ }
417485
418486 fd = do_open(name);
487+
488+ if (dso__needs_decompress(dso))
489+ unlink(name);
490+
491+out:
419492 free(name);
420493 return fd;
421494 }
tools/perf/util/dso.h+6−0
@@ -244,6 +244,12 @@ bool is_supported_compression(const char *ext); · 243 unmodified lines
244244 bool is_kernel_module(const char *pathname, int cpumode);
245245 bool decompress_to_file(const char *ext, const char *filename, int output_fd);
246246 bool dso__needs_decompress(struct dso *dso);
247+int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
248+int 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)
247253
248254 struct kmod_path {
249255 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
12191219 fprintf(ofp, "# be retrieved using Python functions of the form "
12201220 "common_*(context).\n");
12211221
1222− fprintf(ofp, "# See the perf-trace-python Documentation for the list "
1222+ fprintf(ofp, "# See the perf-script-python Documentation for the list "
12231223 "of available functions.\n\n");
12241224
12251225 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
637637 return 0;
638638 }
639639
640−static 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−
669−out:
670− free(m.ext);
671− return fd;
672−}
673−
674640 bool symsrc__possibly_runtime(struct symsrc *ss)
675641 {
676642 return ss->dynsym || ss->opdsec;
@@ -702,9 +668,11 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, · 25 unmodified lines
702668 int fd;
703669
704670 if (dso__needs_decompress(dso)) {
705− fd = decompress_kmodule(dso, name, type);
671+ fd = dso__decompress_kmodule_fd(dso, name);
706672 if (fd < 0)
707673 return -1;
674+
675+ type = dso->symtab_type;
708676 } else {
709677 fd = open(name, O_RDONLY);
710678 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
15621562 if (!runtime_ss && syms_ss)
15631563 runtime_ss = syms_ss;
15641564
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−
15691565 if (syms_ss)
15701566 ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
15711567 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