aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Documentation/perf-record.txt4
-rw-r--r--tools/perf/Makefile.perf4
-rw-r--r--tools/perf/builtin-kmem.c1
-rw-r--r--tools/perf/builtin-record.c4
-rw-r--r--tools/perf/builtin-sched.c17
-rw-r--r--tools/perf/util/probe-event.c105
-rw-r--r--tools/perf/util/symbol-elf.c6
7 files changed, 97 insertions, 44 deletions
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 27fc3617c6a4..5054d9147f0f 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -430,6 +430,10 @@ that gets then processed, possibly via a perf script, to decide if that
430particular perf.data snapshot should be kept or not. 430particular perf.data snapshot should be kept or not.
431 431
432Implies --timestamp-filename, --no-buildid and --no-buildid-cache. 432Implies --timestamp-filename, --no-buildid and --no-buildid-cache.
433The reason for the latter two is to reduce the data file switching
434overhead. You can still switch them on with:
435
436 --switch-output --no-no-buildid --no-no-buildid-cache
433 437
434--dry-run:: 438--dry-run::
435Parse options then exit. --dry-run can be used to detect errors in cmdline 439Parse options then exit. --dry-run can be used to detect errors in cmdline
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 8fc24824705e..8bb16aa9d661 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -704,9 +704,9 @@ install-tests: all install-gtk
704 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ 704 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \
705 $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr' 705 $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'
706 706
707install-bin: install-tools install-tests 707install-bin: install-tools install-tests install-traceevent-plugins
708 708
709install: install-bin try-install-man install-traceevent-plugins 709install: install-bin try-install-man
710 710
711install-python_ext: 711install-python_ext:
712 $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' 712 $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 35a02f8e5a4a..915869e00d86 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -655,7 +655,6 @@ static const struct {
655 { "__GFP_RECLAIM", "R" }, 655 { "__GFP_RECLAIM", "R" },
656 { "__GFP_DIRECT_RECLAIM", "DR" }, 656 { "__GFP_DIRECT_RECLAIM", "DR" },
657 { "__GFP_KSWAPD_RECLAIM", "KR" }, 657 { "__GFP_KSWAPD_RECLAIM", "KR" },
658 { "__GFP_OTHER_NODE", "ON" },
659}; 658};
660 659
661static size_t max_gfp_len; 660static size_t max_gfp_len;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 74d6a035133a..4ec10e9427d9 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1405,7 +1405,7 @@ static bool dry_run;
1405 * perf_evlist__prepare_workload, etc instead of fork+exec'in 'perf record', 1405 * perf_evlist__prepare_workload, etc instead of fork+exec'in 'perf record',
1406 * using pipes, etc. 1406 * using pipes, etc.
1407 */ 1407 */
1408struct option __record_options[] = { 1408static struct option __record_options[] = {
1409 OPT_CALLBACK('e', "event", &record.evlist, "event", 1409 OPT_CALLBACK('e', "event", &record.evlist, "event",
1410 "event selector. use 'perf list' to list available events", 1410 "event selector. use 'perf list' to list available events",
1411 parse_events_option), 1411 parse_events_option),
@@ -1636,7 +1636,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
1636 * overhead. Still generate buildid if they are required 1636 * overhead. Still generate buildid if they are required
1637 * explicitly using 1637 * explicitly using
1638 * 1638 *
1639 * perf record --signal-trigger --no-no-buildid \ 1639 * perf record --switch-output --no-no-buildid \
1640 * --no-no-buildid-cache 1640 * --no-no-buildid-cache
1641 * 1641 *
1642 * Following code equals to: 1642 * Following code equals to:
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index d53e706a6f17..5b134b0d1ff3 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -209,6 +209,7 @@ struct perf_sched {
209 u64 skipped_samples; 209 u64 skipped_samples;
210 const char *time_str; 210 const char *time_str;
211 struct perf_time_interval ptime; 211 struct perf_time_interval ptime;
212 struct perf_time_interval hist_time;
212}; 213};
213 214
214/* per thread run time data */ 215/* per thread run time data */
@@ -2460,6 +2461,11 @@ static int timehist_sched_change_event(struct perf_tool *tool,
2460 timehist_print_sample(sched, sample, &al, thread, t); 2461 timehist_print_sample(sched, sample, &al, thread, t);
2461 2462
2462out: 2463out:
2464 if (sched->hist_time.start == 0 && t >= ptime->start)
2465 sched->hist_time.start = t;
2466 if (ptime->end == 0 || t <= ptime->end)
2467 sched->hist_time.end = t;
2468
2463 if (tr) { 2469 if (tr) {
2464 /* time of this sched_switch event becomes last time task seen */ 2470 /* time of this sched_switch event becomes last time task seen */
2465 tr->last_time = sample->time; 2471 tr->last_time = sample->time;
@@ -2624,6 +2630,7 @@ static void timehist_print_summary(struct perf_sched *sched,
2624 struct thread *t; 2630 struct thread *t;
2625 struct thread_runtime *r; 2631 struct thread_runtime *r;
2626 int i; 2632 int i;
2633 u64 hist_time = sched->hist_time.end - sched->hist_time.start;
2627 2634
2628 memset(&totals, 0, sizeof(totals)); 2635 memset(&totals, 0, sizeof(totals));
2629 2636
@@ -2665,7 +2672,7 @@ static void timehist_print_summary(struct perf_sched *sched,
2665 totals.sched_count += r->run_stats.n; 2672 totals.sched_count += r->run_stats.n;
2666 printf(" CPU %2d idle for ", i); 2673 printf(" CPU %2d idle for ", i);
2667 print_sched_time(r->total_run_time, 6); 2674 print_sched_time(r->total_run_time, 6);
2668 printf(" msec\n"); 2675 printf(" msec (%6.2f%%)\n", 100.0 * r->total_run_time / hist_time);
2669 } else 2676 } else
2670 printf(" CPU %2d idle entire time window\n", i); 2677 printf(" CPU %2d idle entire time window\n", i);
2671 } 2678 }
@@ -2701,12 +2708,16 @@ static void timehist_print_summary(struct perf_sched *sched,
2701 2708
2702 printf("\n" 2709 printf("\n"
2703 " Total number of unique tasks: %" PRIu64 "\n" 2710 " Total number of unique tasks: %" PRIu64 "\n"
2704 "Total number of context switches: %" PRIu64 "\n" 2711 "Total number of context switches: %" PRIu64 "\n",
2705 " Total run time (msec): ",
2706 totals.task_count, totals.sched_count); 2712 totals.task_count, totals.sched_count);
2707 2713
2714 printf(" Total run time (msec): ");
2708 print_sched_time(totals.total_run_time, 2); 2715 print_sched_time(totals.total_run_time, 2);
2709 printf("\n"); 2716 printf("\n");
2717
2718 printf(" Total scheduling time (msec): ");
2719 print_sched_time(hist_time, 2);
2720 printf(" (x %d)\n", sched->max_cpu);
2710} 2721}
2711 2722
2712typedef int (*sched_handler)(struct perf_tool *tool, 2723typedef int (*sched_handler)(struct perf_tool *tool,
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d281ae2b54e8..4a57c8a60bd9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -163,7 +163,7 @@ static struct map *kernel_get_module_map(const char *module)
163 163
164 /* A file path -- this is an offline module */ 164 /* A file path -- this is an offline module */
165 if (module && strchr(module, '/')) 165 if (module && strchr(module, '/'))
166 return machine__findnew_module_map(host_machine, 0, module); 166 return dso__new_map(module);
167 167
168 if (!module) 168 if (!module)
169 module = "kernel"; 169 module = "kernel";
@@ -173,6 +173,7 @@ static struct map *kernel_get_module_map(const char *module)
173 if (strncmp(pos->dso->short_name + 1, module, 173 if (strncmp(pos->dso->short_name + 1, module,
174 pos->dso->short_name_len - 2) == 0 && 174 pos->dso->short_name_len - 2) == 0 &&
175 module[pos->dso->short_name_len - 2] == '\0') { 175 module[pos->dso->short_name_len - 2] == '\0') {
176 map__get(pos);
176 return pos; 177 return pos;
177 } 178 }
178 } 179 }
@@ -188,15 +189,6 @@ struct map *get_target_map(const char *target, bool user)
188 return kernel_get_module_map(target); 189 return kernel_get_module_map(target);
189} 190}
190 191
191static void put_target_map(struct map *map, bool user)
192{
193 if (map && user) {
194 /* Only the user map needs to be released */
195 map__put(map);
196 }
197}
198
199
200static int convert_exec_to_group(const char *exec, char **result) 192static int convert_exec_to_group(const char *exec, char **result)
201{ 193{
202 char *ptr1, *ptr2, *exec_copy; 194 char *ptr1, *ptr2, *exec_copy;
@@ -268,21 +260,6 @@ static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
268} 260}
269 261
270/* 262/*
271 * NOTE:
272 * '.gnu.linkonce.this_module' section of kernel module elf directly
273 * maps to 'struct module' from linux/module.h. This section contains
274 * actual module name which will be used by kernel after loading it.
275 * But, we cannot use 'struct module' here since linux/module.h is not
276 * exposed to user-space. Offset of 'name' has remained same from long
277 * time, so hardcoding it here.
278 */
279#ifdef __LP64__
280#define MOD_NAME_OFFSET 24
281#else
282#define MOD_NAME_OFFSET 12
283#endif
284
285/*
286 * @module can be module name of module file path. In case of path, 263 * @module can be module name of module file path. In case of path,
287 * inspect elf and find out what is actual module name. 264 * inspect elf and find out what is actual module name.
288 * Caller has to free mod_name after using it. 265 * Caller has to free mod_name after using it.
@@ -296,6 +273,7 @@ static char *find_module_name(const char *module)
296 Elf_Data *data; 273 Elf_Data *data;
297 Elf_Scn *sec; 274 Elf_Scn *sec;
298 char *mod_name = NULL; 275 char *mod_name = NULL;
276 int name_offset;
299 277
300 fd = open(module, O_RDONLY); 278 fd = open(module, O_RDONLY);
301 if (fd < 0) 279 if (fd < 0)
@@ -317,7 +295,21 @@ static char *find_module_name(const char *module)
317 if (!data || !data->d_buf) 295 if (!data || !data->d_buf)
318 goto ret_err; 296 goto ret_err;
319 297
320 mod_name = strdup((char *)data->d_buf + MOD_NAME_OFFSET); 298 /*
299 * NOTE:
300 * '.gnu.linkonce.this_module' section of kernel module elf directly
301 * maps to 'struct module' from linux/module.h. This section contains
302 * actual module name which will be used by kernel after loading it.
303 * But, we cannot use 'struct module' here since linux/module.h is not
304 * exposed to user-space. Offset of 'name' has remained same from long
305 * time, so hardcoding it here.
306 */
307 if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
308 name_offset = 12;
309 else /* expect ELFCLASS64 by default */
310 name_offset = 24;
311
312 mod_name = strdup((char *)data->d_buf + name_offset);
321 313
322ret_err: 314ret_err:
323 elf_end(elf); 315 elf_end(elf);
@@ -412,7 +404,7 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
412 } 404 }
413 405
414out: 406out:
415 put_target_map(map, uprobes); 407 map__put(map);
416 return ret; 408 return ret;
417 409
418} 410}
@@ -618,6 +610,51 @@ error:
618 return ret ? : -ENOENT; 610 return ret ? : -ENOENT;
619} 611}
620 612
613/*
614 * Rename DWARF symbols to ELF symbols -- gcc sometimes optimizes functions
615 * and generate new symbols with suffixes such as .constprop.N or .isra.N
616 * etc. Since those symbols are not recorded in DWARF, we have to find
617 * correct generated symbols from offline ELF binary.
618 * For online kernel or uprobes we don't need this because those are
619 * rebased on _text, or already a section relative address.
620 */
621static int
622post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
623 int ntevs, const char *pathname)
624{
625 struct symbol *sym;
626 struct map *map;
627 unsigned long stext = 0;
628 u64 addr;
629 int i;
630
631 /* Prepare a map for offline binary */
632 map = dso__new_map(pathname);
633 if (!map || get_text_start_address(pathname, &stext) < 0) {
634 pr_warning("Failed to get ELF symbols for %s\n", pathname);
635 return -EINVAL;
636 }
637
638 for (i = 0; i < ntevs; i++) {
639 addr = tevs[i].point.address + tevs[i].point.offset - stext;
640 sym = map__find_symbol(map, addr);
641 if (!sym)
642 continue;
643 if (!strcmp(sym->name, tevs[i].point.symbol))
644 continue;
645 /* If we have no realname, use symbol for it */
646 if (!tevs[i].point.realname)
647 tevs[i].point.realname = tevs[i].point.symbol;
648 else
649 free(tevs[i].point.symbol);
650 tevs[i].point.symbol = strdup(sym->name);
651 tevs[i].point.offset = addr - sym->start;
652 }
653 map__put(map);
654
655 return 0;
656}
657
621static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs, 658static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
622 int ntevs, const char *exec) 659 int ntevs, const char *exec)
623{ 660{
@@ -679,7 +716,8 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
679 716
680 /* Skip post process if the target is an offline kernel */ 717 /* Skip post process if the target is an offline kernel */
681 if (symbol_conf.ignore_vmlinux_buildid) 718 if (symbol_conf.ignore_vmlinux_buildid)
682 return 0; 719 return post_process_offline_probe_trace_events(tevs, ntevs,
720 symbol_conf.vmlinux_name);
683 721
684 reloc_sym = kernel_get_ref_reloc_sym(); 722 reloc_sym = kernel_get_ref_reloc_sym();
685 if (!reloc_sym) { 723 if (!reloc_sym) {
@@ -2869,7 +2907,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
2869 } 2907 }
2870 2908
2871out: 2909out:
2872 put_target_map(map, pev->uprobes); 2910 map__put(map);
2873 free(syms); 2911 free(syms);
2874 return ret; 2912 return ret;
2875 2913
@@ -3362,10 +3400,7 @@ int show_available_funcs(const char *target, struct strfilter *_filter,
3362 return ret; 3400 return ret;
3363 3401
3364 /* Get a symbol map */ 3402 /* Get a symbol map */
3365 if (user) 3403 map = get_target_map(target, user);
3366 map = dso__new_map(target);
3367 else
3368 map = kernel_get_module_map(target);
3369 if (!map) { 3404 if (!map) {
3370 pr_err("Failed to get a map for %s\n", (target) ? : "kernel"); 3405 pr_err("Failed to get a map for %s\n", (target) ? : "kernel");
3371 return -EINVAL; 3406 return -EINVAL;
@@ -3397,9 +3432,7 @@ int show_available_funcs(const char *target, struct strfilter *_filter,
3397 } 3432 }
3398 3433
3399end: 3434end:
3400 if (user) { 3435 map__put(map);
3401 map__put(map);
3402 }
3403 exit_probe_symbol_maps(); 3436 exit_probe_symbol_maps();
3404 3437
3405 return ret; 3438 return ret;
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 99400b0e8f2a..adbc6c02c3aa 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -537,6 +537,12 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
537 break; 537 break;
538 } else { 538 } else {
539 int n = namesz + descsz; 539 int n = namesz + descsz;
540
541 if (n > (int)sizeof(bf)) {
542 n = sizeof(bf);
543 pr_debug("%s: truncating reading of build id in sysfs file %s: n_namesz=%u, n_descsz=%u.\n",
544 __func__, filename, nhdr.n_namesz, nhdr.n_descsz);
545 }
540 if (read(fd, bf, n) != n) 546 if (read(fd, bf, n) != n)
541 break; 547 break;
542 } 548 }