Skip to content

Commit 3fcb10e

Browse files
Mark Draytonacmel
authored andcommitted
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 <[email protected]> Acked-by: Song Liu <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 65c9fee commit 3fcb10e

File tree

14 files changed

+39
-50
lines changed

14 files changed

+39
-50
lines changed

tools/perf/Documentation/perf-config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ colors.*::
199199
Colors for headers in the output of a sub-commands (top, report).
200200
Default values are 'white', 'blue'.
201201

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+
202208
tui.*, gtk.*::
203209
Subcommands that can be configured here are 'top', 'report' and 'annotate'.
204210
These values are booleans, for example:

tools/perf/builtin-kvm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
13641364
"show events other than"
13651365
" HLT (x86 only) or Wait state (s390 only)"
13661366
" 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,
13681368
"per thread proc mmap processing timeout in ms"),
13691369
OPT_END()
13701370
};
@@ -1394,7 +1394,6 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
13941394
kvm->opts.target.uses_mmap = false;
13951395
kvm->opts.target.uid_str = NULL;
13961396
kvm->opts.target.uid = UINT_MAX;
1397-
kvm->opts.proc_map_timeout = 500;
13981397

13991398
symbol__init(NULL);
14001399
disable_buildid_cache();
@@ -1453,8 +1452,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
14531452
perf_session__set_id_hdr_size(kvm->session);
14541453
ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true);
14551454
machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target,
1456-
kvm->evlist->threads, false,
1457-
kvm->opts.proc_map_timeout, 1);
1455+
kvm->evlist->threads, false, 1);
14581456
err = kvm_live_open_events(kvm);
14591457
if (err)
14601458
goto out;

tools/perf/builtin-record.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,7 @@ static int record__synthesize_workload(struct record *rec, bool tail)
867867
err = perf_event__synthesize_thread_map(&rec->tool, thread_map,
868868
process_synthesized_event,
869869
&rec->session->machines.host,
870-
rec->opts.sample_address,
871-
rec->opts.proc_map_timeout);
870+
rec->opts.sample_address);
872871
thread_map__put(thread_map);
873872
return err;
874873
}
@@ -1085,7 +1084,7 @@ static int record__synthesize(struct record *rec, bool tail)
10851084

10861085
err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
10871086
process_synthesized_event, opts->sample_address,
1088-
opts->proc_map_timeout, 1);
1087+
1);
10891088
out:
10901089
return err;
10911090
}
@@ -1783,7 +1782,6 @@ static struct record record = {
17831782
.uses_mmap = true,
17841783
.default_per_cpu = true,
17851784
},
1786-
.proc_map_timeout = 500,
17871785
},
17881786
.tool = {
17891787
.sample = process_sample_event,
@@ -1913,7 +1911,7 @@ static struct option __record_options[] = {
19131911
parse_clockid),
19141912
OPT_STRING_OPTARG('S', "snapshot", &record.opts.auxtrace_snapshot_opts,
19151913
"opts", "AUX area tracing Snapshot Mode", ""),
1916-
OPT_UINTEGER(0, "proc-map-timeout", &record.opts.proc_map_timeout,
1914+
OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout,
19171915
"per thread proc mmap processing timeout in ms"),
19181916
OPT_BOOLEAN(0, "namespaces", &record.opts.record_namespaces,
19191917
"Record namespaces events"),

tools/perf/builtin-top.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,6 @@ static int __cmd_top(struct perf_top *top)
10961096

10971097
machine__synthesize_threads(&top->session->machines.host, &opts->target,
10981098
top->evlist->threads, false,
1099-
opts->proc_map_timeout,
11001099
top->nr_threads_synthesize);
11011100

11021101
if (top->nr_threads_synthesize > 1)
@@ -1256,7 +1255,6 @@ int cmd_top(int argc, const char **argv)
12561255
.target = {
12571256
.uses_mmap = true,
12581257
},
1259-
.proc_map_timeout = 500,
12601258
/*
12611259
* FIXME: This will lose PERF_RECORD_MMAP and other metadata
12621260
* when we pause, fix that and reenable. Probably using a
@@ -1369,7 +1367,7 @@ int cmd_top(int argc, const char **argv)
13691367
OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
13701368
"width[,width...]",
13711369
"don't try to adjust column width, use these fixed values"),
1372-
OPT_UINTEGER(0, "proc-map-timeout", &opts->proc_map_timeout,
1370+
OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout,
13731371
"per thread proc mmap processing timeout in ms"),
13741372
OPT_CALLBACK_NOOPT('b', "branch-any", &opts->branch_stack,
13751373
"branch any", "sample any taken branches",

tools/perf/builtin-trace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
12641264

12651265
err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,
12661266
evlist->threads, trace__tool_process, false,
1267-
trace->opts.proc_map_timeout, 1);
1267+
1);
12681268
out:
12691269
if (err)
12701270
symbol__exit();
@@ -3393,7 +3393,6 @@ int cmd_trace(int argc, const char **argv)
33933393
.user_interval = ULLONG_MAX,
33943394
.no_buffering = true,
33953395
.mmap_pages = UINT_MAX,
3396-
.proc_map_timeout = 500,
33973396
},
33983397
.output = stderr,
33993398
.show_comm = true,
@@ -3464,7 +3463,7 @@ int cmd_trace(int argc, const char **argv)
34643463
"Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
34653464
OPT_BOOLEAN(0, "print-sample", &trace.print_sample,
34663465
"print the PERF_RECORD_SAMPLE PERF_SAMPLE_ info, for debugging"),
3467-
OPT_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout,
3466+
OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout,
34683467
"per thread proc mmap processing timeout in ms"),
34693468
OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only",
34703469
trace__parse_cgroups),

tools/perf/perf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ struct record_opts {
8282
bool use_clockid;
8383
clockid_t clockid;
8484
u64 clockid_res_ns;
85-
unsigned int proc_map_timeout;
8685
int nr_cblocks;
8786
};
8887

tools/perf/tests/code-reading.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ static int do_test_code_reading(bool try_kcore)
599599
}
600600

601601
ret = perf_event__synthesize_thread_map(NULL, threads,
602-
perf_event__process, machine, false, 500);
602+
perf_event__process, machine, false);
603603
if (ret < 0) {
604604
pr_debug("perf_event__synthesize_thread_map failed\n");
605605
goto out_err;

tools/perf/tests/dwarf-unwind.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int init_live_machine(struct machine *machine)
3434
pid_t pid = getpid();
3535

3636
return perf_event__synthesize_mmap_events(NULL, &event, pid, pid,
37-
mmap_handler, machine, true, 500);
37+
mmap_handler, machine, true);
3838
}
3939

4040
/*

tools/perf/tests/mmap-thread-lookup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int synth_all(struct machine *machine)
132132
{
133133
return perf_event__synthesize_threads(NULL,
134134
perf_event__process,
135-
machine, 0, 500, 1);
135+
machine, 0, 1);
136136
}
137137

138138
static int synth_process(struct machine *machine)
@@ -144,7 +144,7 @@ static int synth_process(struct machine *machine)
144144

145145
err = perf_event__synthesize_thread_map(NULL, map,
146146
perf_event__process,
147-
machine, 0, 500);
147+
machine, 0);
148148

149149
thread_map__put(map);
150150
return err;

tools/perf/util/config.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "util.h"
1515
#include "cache.h"
1616
#include <subcmd/exec-cmd.h>
17+
#include "util/event.h" /* proc_map_timeout */
1718
#include "util/hist.h" /* perf_hist_config */
1819
#include "util/llvm-utils.h" /* perf_llvm_config */
1920
#include "config.h"
@@ -419,6 +420,9 @@ static int perf_buildid_config(const char *var, const char *value)
419420
static int perf_default_core_config(const char *var __maybe_unused,
420421
const char *value __maybe_unused)
421422
{
423+
if (!strcmp(var, "core.proc-map-timeout"))
424+
proc_map_timeout = strtoul(value, NULL, 10);
425+
422426
/* Add other config variables here. */
423427
return 0;
424428
}

tools/perf/util/event.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "asm/bug.h"
2626
#include "stat.h"
2727

28+
#define DEFAULT_PROC_MAP_PARSE_TIMEOUT 500
29+
2830
static const char *perf_event__names[] = {
2931
[0] = "TOTAL",
3032
[PERF_RECORD_MMAP] = "MMAP",
@@ -72,6 +74,8 @@ static const char *perf_ns__names[] = {
7274
[CGROUP_NS_INDEX] = "cgroup",
7375
};
7476

77+
unsigned int proc_map_timeout = DEFAULT_PROC_MAP_PARSE_TIMEOUT;
78+
7579
const char *perf_event__name(unsigned int id)
7680
{
7781
if (id >= ARRAY_SIZE(perf_event__names))
@@ -323,8 +327,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
323327
pid_t pid, pid_t tgid,
324328
perf_event__handler_t process,
325329
struct machine *machine,
326-
bool mmap_data,
327-
unsigned int proc_map_timeout)
330+
bool mmap_data)
328331
{
329332
char filename[PATH_MAX];
330333
FILE *fp;
@@ -521,8 +524,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
521524
perf_event__handler_t process,
522525
struct perf_tool *tool,
523526
struct machine *machine,
524-
bool mmap_data,
525-
unsigned int proc_map_timeout)
527+
bool mmap_data)
526528
{
527529
char filename[PATH_MAX];
528530
DIR *tasks;
@@ -548,8 +550,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
548550
*/
549551
if (pid == tgid &&
550552
perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
551-
process, machine, mmap_data,
552-
proc_map_timeout))
553+
process, machine, mmap_data))
553554
return -1;
554555

555556
return 0;
@@ -598,7 +599,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
598599
if (_pid == pid) {
599600
/* process the parent's maps too */
600601
rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
601-
process, machine, mmap_data, proc_map_timeout);
602+
process, machine, mmap_data);
602603
if (rc)
603604
break;
604605
}
@@ -612,8 +613,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
612613
struct thread_map *threads,
613614
perf_event__handler_t process,
614615
struct machine *machine,
615-
bool mmap_data,
616-
unsigned int proc_map_timeout)
616+
bool mmap_data)
617617
{
618618
union perf_event *comm_event, *mmap_event, *fork_event;
619619
union perf_event *namespaces_event;
@@ -643,7 +643,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
643643
fork_event, namespaces_event,
644644
thread_map__pid(threads, thread), 0,
645645
process, tool, machine,
646-
mmap_data, proc_map_timeout)) {
646+
mmap_data)) {
647647
err = -1;
648648
break;
649649
}
@@ -669,7 +669,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
669669
fork_event, namespaces_event,
670670
comm_event->comm.pid, 0,
671671
process, tool, machine,
672-
mmap_data, proc_map_timeout)) {
672+
mmap_data)) {
673673
err = -1;
674674
break;
675675
}
@@ -690,7 +690,6 @@ static int __perf_event__synthesize_threads(struct perf_tool *tool,
690690
perf_event__handler_t process,
691691
struct machine *machine,
692692
bool mmap_data,
693-
unsigned int proc_map_timeout,
694693
struct dirent **dirent,
695694
int start,
696695
int num)
@@ -734,8 +733,7 @@ static int __perf_event__synthesize_threads(struct perf_tool *tool,
734733
*/
735734
__event__synthesize_thread(comm_event, mmap_event, fork_event,
736735
namespaces_event, pid, 1, process,
737-
tool, machine, mmap_data,
738-
proc_map_timeout);
736+
tool, machine, mmap_data);
739737
}
740738
err = 0;
741739

@@ -755,7 +753,6 @@ struct synthesize_threads_arg {
755753
perf_event__handler_t process;
756754
struct machine *machine;
757755
bool mmap_data;
758-
unsigned int proc_map_timeout;
759756
struct dirent **dirent;
760757
int num;
761758
int start;
@@ -767,7 +764,7 @@ static void *synthesize_threads_worker(void *arg)
767764

768765
__perf_event__synthesize_threads(args->tool, args->process,
769766
args->machine, args->mmap_data,
770-
args->proc_map_timeout, args->dirent,
767+
args->dirent,
771768
args->start, args->num);
772769
return NULL;
773770
}
@@ -776,7 +773,6 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
776773
perf_event__handler_t process,
777774
struct machine *machine,
778775
bool mmap_data,
779-
unsigned int proc_map_timeout,
780776
unsigned int nr_threads_synthesize)
781777
{
782778
struct synthesize_threads_arg *args = NULL;
@@ -806,7 +802,6 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
806802
if (thread_nr <= 1) {
807803
err = __perf_event__synthesize_threads(tool, process,
808804
machine, mmap_data,
809-
proc_map_timeout,
810805
dirent, base, n);
811806
goto free_dirent;
812807
}
@@ -828,7 +823,6 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
828823
args[i].process = process;
829824
args[i].machine = machine;
830825
args[i].mmap_data = mmap_data;
831-
args[i].proc_map_timeout = proc_map_timeout;
832826
args[i].dirent = dirent;
833827
}
834828
for (i = 0; i < m; i++) {

tools/perf/util/event.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,7 @@ typedef int (*perf_event__handler_t)(struct perf_tool *tool,
669669
int perf_event__synthesize_thread_map(struct perf_tool *tool,
670670
struct thread_map *threads,
671671
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);
674673
int perf_event__synthesize_thread_map2(struct perf_tool *tool,
675674
struct thread_map *threads,
676675
perf_event__handler_t process,
@@ -682,7 +681,6 @@ int perf_event__synthesize_cpu_map(struct perf_tool *tool,
682681
int perf_event__synthesize_threads(struct perf_tool *tool,
683682
perf_event__handler_t process,
684683
struct machine *machine, bool mmap_data,
685-
unsigned int proc_map_timeout,
686684
unsigned int nr_threads_synthesize);
687685
int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
688686
perf_event__handler_t process,
@@ -797,8 +795,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
797795
pid_t pid, pid_t tgid,
798796
perf_event__handler_t process,
799797
struct machine *machine,
800-
bool mmap_data,
801-
unsigned int proc_map_timeout);
798+
bool mmap_data);
802799

803800
int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
804801
perf_event__handler_t process,
@@ -829,5 +826,6 @@ int perf_event_paranoid(void);
829826

830827
extern int sysctl_perf_event_max_stack;
831828
extern int sysctl_perf_event_max_contexts_per_stack;
829+
extern unsigned int proc_map_timeout;
832830

833831
#endif /* __PERF_RECORD_H */

tools/perf/util/machine.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,15 +2493,13 @@ int machines__for_each_thread(struct machines *machines,
24932493
int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
24942494
struct target *target, struct thread_map *threads,
24952495
perf_event__handler_t process, bool data_mmap,
2496-
unsigned int proc_map_timeout,
24972496
unsigned int nr_threads_synthesize)
24982497
{
24992498
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);
25012500
else if (target__has_cpu(target))
25022501
return perf_event__synthesize_threads(tool, process,
25032502
machine, data_mmap,
2504-
proc_map_timeout,
25052503
nr_threads_synthesize);
25062504
/* command specified */
25072505
return 0;

0 commit comments

Comments
 (0)