Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Allow specifying proc-map-timeout in config file

The default timeout of 500ms for parsing /proc/<pid>/maps files is too
short for profiling many of our services.

This can be overridden by passing --proc-map-timeout to the relevant
command but it'd be nice to globally increase our default value.

This patch permits setting a different default with the
core.proc-map-timeout config file parameter.

Signed-off-by: Mark Drayton <mbd@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20181204203420.1683114-1-mbd@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Mark Drayton and committed by
Arnaldo Carvalho de Melo
3fcb10e4 65c9fee2

+39 -50
+6
tools/perf/Documentation/perf-config.txt
··· 199 199 Colors for headers in the output of a sub-commands (top, report). 200 200 Default values are 'white', 'blue'. 201 201 202 + core.*:: 203 + core.proc-map-timeout:: 204 + Sets a timeout (in milliseconds) for parsing /proc/<pid>/maps files. 205 + Can be overridden by the --proc-map-timeout option on supported 206 + subcommands. The default timeout is 500ms. 207 + 202 208 tui.*, gtk.*:: 203 209 Subcommands that can be configured here are 'top', 'report' and 'annotate'. 204 210 These values are booleans, for example:
+2 -4
tools/perf/builtin-kvm.c
··· 1364 1364 "show events other than" 1365 1365 " HLT (x86 only) or Wait state (s390 only)" 1366 1366 " that take longer than duration usecs"), 1367 - OPT_UINTEGER(0, "proc-map-timeout", &kvm->opts.proc_map_timeout, 1367 + OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout, 1368 1368 "per thread proc mmap processing timeout in ms"), 1369 1369 OPT_END() 1370 1370 }; ··· 1394 1394 kvm->opts.target.uses_mmap = false; 1395 1395 kvm->opts.target.uid_str = NULL; 1396 1396 kvm->opts.target.uid = UINT_MAX; 1397 - kvm->opts.proc_map_timeout = 500; 1398 1397 1399 1398 symbol__init(NULL); 1400 1399 disable_buildid_cache(); ··· 1452 1453 perf_session__set_id_hdr_size(kvm->session); 1453 1454 ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true); 1454 1455 machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target, 1455 - kvm->evlist->threads, false, 1456 - kvm->opts.proc_map_timeout, 1); 1456 + kvm->evlist->threads, false, 1); 1457 1457 err = kvm_live_open_events(kvm); 1458 1458 if (err) 1459 1459 goto out;
+3 -5
tools/perf/builtin-record.c
··· 867 867 err = perf_event__synthesize_thread_map(&rec->tool, thread_map, 868 868 process_synthesized_event, 869 869 &rec->session->machines.host, 870 - rec->opts.sample_address, 871 - rec->opts.proc_map_timeout); 870 + rec->opts.sample_address); 872 871 thread_map__put(thread_map); 873 872 return err; 874 873 } ··· 1084 1085 1085 1086 err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads, 1086 1087 process_synthesized_event, opts->sample_address, 1087 - opts->proc_map_timeout, 1); 1088 + 1); 1088 1089 out: 1089 1090 return err; 1090 1091 } ··· 1782 1783 .uses_mmap = true, 1783 1784 .default_per_cpu = true, 1784 1785 }, 1785 - .proc_map_timeout = 500, 1786 1786 }, 1787 1787 .tool = { 1788 1788 .sample = process_sample_event, ··· 1911 1913 parse_clockid), 1912 1914 OPT_STRING_OPTARG('S', "snapshot", &record.opts.auxtrace_snapshot_opts, 1913 1915 "opts", "AUX area tracing Snapshot Mode", ""), 1914 - OPT_UINTEGER(0, "proc-map-timeout", &record.opts.proc_map_timeout, 1916 + OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout, 1915 1917 "per thread proc mmap processing timeout in ms"), 1916 1918 OPT_BOOLEAN(0, "namespaces", &record.opts.record_namespaces, 1917 1919 "Record namespaces events"),
+1 -3
tools/perf/builtin-top.c
··· 1096 1096 1097 1097 machine__synthesize_threads(&top->session->machines.host, &opts->target, 1098 1098 top->evlist->threads, false, 1099 - opts->proc_map_timeout, 1100 1099 top->nr_threads_synthesize); 1101 1100 1102 1101 if (top->nr_threads_synthesize > 1) ··· 1255 1256 .target = { 1256 1257 .uses_mmap = true, 1257 1258 }, 1258 - .proc_map_timeout = 500, 1259 1259 /* 1260 1260 * FIXME: This will lose PERF_RECORD_MMAP and other metadata 1261 1261 * when we pause, fix that and reenable. Probably using a ··· 1367 1369 OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str, 1368 1370 "width[,width...]", 1369 1371 "don't try to adjust column width, use these fixed values"), 1370 - OPT_UINTEGER(0, "proc-map-timeout", &opts->proc_map_timeout, 1372 + OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout, 1371 1373 "per thread proc mmap processing timeout in ms"), 1372 1374 OPT_CALLBACK_NOOPT('b', "branch-any", &opts->branch_stack, 1373 1375 "branch any", "sample any taken branches",
+2 -3
tools/perf/builtin-trace.c
··· 1264 1264 1265 1265 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, 1266 1266 evlist->threads, trace__tool_process, false, 1267 - trace->opts.proc_map_timeout, 1); 1267 + 1); 1268 1268 out: 1269 1269 if (err) 1270 1270 symbol__exit(); ··· 3393 3393 .user_interval = ULLONG_MAX, 3394 3394 .no_buffering = true, 3395 3395 .mmap_pages = UINT_MAX, 3396 - .proc_map_timeout = 500, 3397 3396 }, 3398 3397 .output = stderr, 3399 3398 .show_comm = true, ··· 3463 3464 "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)), 3464 3465 OPT_BOOLEAN(0, "print-sample", &trace.print_sample, 3465 3466 "print the PERF_RECORD_SAMPLE PERF_SAMPLE_ info, for debugging"), 3466 - OPT_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout, 3467 + OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout, 3467 3468 "per thread proc mmap processing timeout in ms"), 3468 3469 OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only", 3469 3470 trace__parse_cgroups),
-1
tools/perf/perf.h
··· 82 82 bool use_clockid; 83 83 clockid_t clockid; 84 84 u64 clockid_res_ns; 85 - unsigned int proc_map_timeout; 86 85 int nr_cblocks; 87 86 }; 88 87
+1 -1
tools/perf/tests/code-reading.c
··· 599 599 } 600 600 601 601 ret = perf_event__synthesize_thread_map(NULL, threads, 602 - perf_event__process, machine, false, 500); 602 + perf_event__process, machine, false); 603 603 if (ret < 0) { 604 604 pr_debug("perf_event__synthesize_thread_map failed\n"); 605 605 goto out_err;
+1 -1
tools/perf/tests/dwarf-unwind.c
··· 34 34 pid_t pid = getpid(); 35 35 36 36 return perf_event__synthesize_mmap_events(NULL, &event, pid, pid, 37 - mmap_handler, machine, true, 500); 37 + mmap_handler, machine, true); 38 38 } 39 39 40 40 /*
+2 -2
tools/perf/tests/mmap-thread-lookup.c
··· 132 132 { 133 133 return perf_event__synthesize_threads(NULL, 134 134 perf_event__process, 135 - machine, 0, 500, 1); 135 + machine, 0, 1); 136 136 } 137 137 138 138 static int synth_process(struct machine *machine) ··· 144 144 145 145 err = perf_event__synthesize_thread_map(NULL, map, 146 146 perf_event__process, 147 - machine, 0, 500); 147 + machine, 0); 148 148 149 149 thread_map__put(map); 150 150 return err;
+4
tools/perf/util/config.c
··· 14 14 #include "util.h" 15 15 #include "cache.h" 16 16 #include <subcmd/exec-cmd.h> 17 + #include "util/event.h" /* proc_map_timeout */ 17 18 #include "util/hist.h" /* perf_hist_config */ 18 19 #include "util/llvm-utils.h" /* perf_llvm_config */ 19 20 #include "config.h" ··· 420 419 static int perf_default_core_config(const char *var __maybe_unused, 421 420 const char *value __maybe_unused) 422 421 { 422 + if (!strcmp(var, "core.proc-map-timeout")) 423 + proc_map_timeout = strtoul(value, NULL, 10); 424 + 423 425 /* Add other config variables here. */ 424 426 return 0; 425 427 }
+13 -19
tools/perf/util/event.c
··· 25 25 #include "asm/bug.h" 26 26 #include "stat.h" 27 27 28 + #define DEFAULT_PROC_MAP_PARSE_TIMEOUT 500 29 + 28 30 static const char *perf_event__names[] = { 29 31 [0] = "TOTAL", 30 32 [PERF_RECORD_MMAP] = "MMAP", ··· 73 71 [MNT_NS_INDEX] = "mnt", 74 72 [CGROUP_NS_INDEX] = "cgroup", 75 73 }; 74 + 75 + unsigned int proc_map_timeout = DEFAULT_PROC_MAP_PARSE_TIMEOUT; 76 76 77 77 const char *perf_event__name(unsigned int id) 78 78 { ··· 327 323 pid_t pid, pid_t tgid, 328 324 perf_event__handler_t process, 329 325 struct machine *machine, 330 - bool mmap_data, 331 - unsigned int proc_map_timeout) 326 + bool mmap_data) 332 327 { 333 328 char filename[PATH_MAX]; 334 329 FILE *fp; ··· 524 521 perf_event__handler_t process, 525 522 struct perf_tool *tool, 526 523 struct machine *machine, 527 - bool mmap_data, 528 - unsigned int proc_map_timeout) 524 + bool mmap_data) 529 525 { 530 526 char filename[PATH_MAX]; 531 527 DIR *tasks; ··· 550 548 */ 551 549 if (pid == tgid && 552 550 perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, 553 - process, machine, mmap_data, 554 - proc_map_timeout)) 551 + process, machine, mmap_data)) 555 552 return -1; 556 553 557 554 return 0; ··· 599 598 if (_pid == pid) { 600 599 /* process the parent's maps too */ 601 600 rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, 602 - process, machine, mmap_data, proc_map_timeout); 601 + process, machine, mmap_data); 603 602 if (rc) 604 603 break; 605 604 } ··· 613 612 struct thread_map *threads, 614 613 perf_event__handler_t process, 615 614 struct machine *machine, 616 - bool mmap_data, 617 - unsigned int proc_map_timeout) 615 + bool mmap_data) 618 616 { 619 617 union perf_event *comm_event, *mmap_event, *fork_event; 620 618 union perf_event *namespaces_event; ··· 643 643 fork_event, namespaces_event, 644 644 thread_map__pid(threads, thread), 0, 645 645 process, tool, machine, 646 - mmap_data, proc_map_timeout)) { 646 + mmap_data)) { 647 647 err = -1; 648 648 break; 649 649 } ··· 669 669 fork_event, namespaces_event, 670 670 comm_event->comm.pid, 0, 671 671 process, tool, machine, 672 - mmap_data, proc_map_timeout)) { 672 + mmap_data)) { 673 673 err = -1; 674 674 break; 675 675 } ··· 690 690 perf_event__handler_t process, 691 691 struct machine *machine, 692 692 bool mmap_data, 693 - unsigned int proc_map_timeout, 694 693 struct dirent **dirent, 695 694 int start, 696 695 int num) ··· 733 734 */ 734 735 __event__synthesize_thread(comm_event, mmap_event, fork_event, 735 736 namespaces_event, pid, 1, process, 736 - tool, machine, mmap_data, 737 - proc_map_timeout); 737 + tool, machine, mmap_data); 738 738 } 739 739 err = 0; 740 740 ··· 753 755 perf_event__handler_t process; 754 756 struct machine *machine; 755 757 bool mmap_data; 756 - unsigned int proc_map_timeout; 757 758 struct dirent **dirent; 758 759 int num; 759 760 int start; ··· 764 767 765 768 __perf_event__synthesize_threads(args->tool, args->process, 766 769 args->machine, args->mmap_data, 767 - args->proc_map_timeout, args->dirent, 770 + args->dirent, 768 771 args->start, args->num); 769 772 return NULL; 770 773 } ··· 773 776 perf_event__handler_t process, 774 777 struct machine *machine, 775 778 bool mmap_data, 776 - unsigned int proc_map_timeout, 777 779 unsigned int nr_threads_synthesize) 778 780 { 779 781 struct synthesize_threads_arg *args = NULL; ··· 802 806 if (thread_nr <= 1) { 803 807 err = __perf_event__synthesize_threads(tool, process, 804 808 machine, mmap_data, 805 - proc_map_timeout, 806 809 dirent, base, n); 807 810 goto free_dirent; 808 811 } ··· 823 828 args[i].process = process; 824 829 args[i].machine = machine; 825 830 args[i].mmap_data = mmap_data; 826 - args[i].proc_map_timeout = proc_map_timeout; 827 831 args[i].dirent = dirent; 828 832 } 829 833 for (i = 0; i < m; i++) {
+3 -5
tools/perf/util/event.h
··· 669 669 int perf_event__synthesize_thread_map(struct perf_tool *tool, 670 670 struct thread_map *threads, 671 671 perf_event__handler_t process, 672 - struct machine *machine, bool mmap_data, 673 - unsigned int proc_map_timeout); 672 + struct machine *machine, bool mmap_data); 674 673 int perf_event__synthesize_thread_map2(struct perf_tool *tool, 675 674 struct thread_map *threads, 676 675 perf_event__handler_t process, ··· 681 682 int perf_event__synthesize_threads(struct perf_tool *tool, 682 683 perf_event__handler_t process, 683 684 struct machine *machine, bool mmap_data, 684 - unsigned int proc_map_timeout, 685 685 unsigned int nr_threads_synthesize); 686 686 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, 687 687 perf_event__handler_t process, ··· 795 797 pid_t pid, pid_t tgid, 796 798 perf_event__handler_t process, 797 799 struct machine *machine, 798 - bool mmap_data, 799 - unsigned int proc_map_timeout); 800 + bool mmap_data); 800 801 801 802 int perf_event__synthesize_extra_kmaps(struct perf_tool *tool, 802 803 perf_event__handler_t process, ··· 826 829 827 830 extern int sysctl_perf_event_max_stack; 828 831 extern int sysctl_perf_event_max_contexts_per_stack; 832 + extern unsigned int proc_map_timeout; 829 833 830 834 #endif /* __PERF_RECORD_H */
+1 -3
tools/perf/util/machine.c
··· 2493 2493 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, 2494 2494 struct target *target, struct thread_map *threads, 2495 2495 perf_event__handler_t process, bool data_mmap, 2496 - unsigned int proc_map_timeout, 2497 2496 unsigned int nr_threads_synthesize) 2498 2497 { 2499 2498 if (target__has_task(target)) 2500 - return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap, proc_map_timeout); 2499 + return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap); 2501 2500 else if (target__has_cpu(target)) 2502 2501 return perf_event__synthesize_threads(tool, process, 2503 2502 machine, data_mmap, 2504 - proc_map_timeout, 2505 2503 nr_threads_synthesize); 2506 2504 /* command specified */ 2507 2505 return 0;
-3
tools/perf/util/machine.h
··· 250 250 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, 251 251 struct target *target, struct thread_map *threads, 252 252 perf_event__handler_t process, bool data_mmap, 253 - unsigned int proc_map_timeout, 254 253 unsigned int nr_threads_synthesize); 255 254 static inline 256 255 int machine__synthesize_threads(struct machine *machine, struct target *target, 257 256 struct thread_map *threads, bool data_mmap, 258 - unsigned int proc_map_timeout, 259 257 unsigned int nr_threads_synthesize) 260 258 { 261 259 return __machine__synthesize_threads(machine, NULL, target, threads, 262 260 perf_event__process, data_mmap, 263 - proc_map_timeout, 264 261 nr_threads_synthesize); 265 262 } 266 263