Skip to content

Commit 42b7c90

Browse files
committed
Add an override to avoid using --kcore
Signed-off-by: Tudor Brindus <[email protected]>
1 parent 78aa314 commit 42b7c90

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/env_vars.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ let perf_path = Option.value ~default:"perf" (Unix.getenv "MAGIC_TRACE_PERF_PATH
1515
checks around kernel tracing when not root. *)
1616
let perf_is_privileged = Option.is_some (Unix.getenv "MAGIC_TRACE_PERF_IS_PRIVILEGED")
1717

18+
(** Override whether kcore will be used (in the case that [perf] supports it at all). *)
19+
let perf_no_kcore = Option.is_some (Unix.getenv "MAGIC_TRACE_PERF_NO_KCORE")
20+
1821
(* Turns on hidden command line options and attached "[inferred start time]" to functions
1922
with inferred start times.
2023

src/env_vars.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ val debug : bool
44
val experimental : bool
55
val perf_path : string
66
val perf_is_privileged : bool
7+
val perf_no_kcore : bool
78
val perfetto_dir : string option
89
val no_dlfilter : bool
910
val fzf_demangle_symbols : bool

src/perf_tool_backend.ml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -319,24 +319,29 @@ module Recording = struct
319319
|> Deferred.return
320320
in
321321
let kcore_opts =
322-
match
323-
collection_mode, trace_scope, Perf_capabilities.(do_intersect capabilities kcore)
324-
with
325-
| Intel_processor_trace _, Userspace, _ | Stacktrace_sampling _, _, _ -> []
326-
| Intel_processor_trace _, (Kernel | Userspace_and_kernel), true -> [ "--kcore" ]
327-
| Intel_processor_trace _, (Kernel | Userspace_and_kernel), false ->
328-
(* Strictly speaking, we could recreate tools/perf/perf-with-kcore.sh
329-
here instead of bailing. But that's tricky, and upgrading to a newer
330-
perf is easier. *)
331-
Core.eprintf
332-
"Warning: old perf version detected! perf userspace tools v5.5 contain an \
333-
important feature, kcore, that make decoding kernel traces more reliable. In \
334-
our experience, tracing the kernel mostly works without this feature, but you \
335-
may run into problems if you're trying to trace through self-modifying code \
336-
(the kernel may do this more than you think). Install a perf version >= 5.5 \
337-
to avoid this.\n\
338-
%!";
339-
[]
322+
if Env_vars.perf_no_kcore
323+
then []
324+
else (
325+
match
326+
( collection_mode
327+
, trace_scope
328+
, Perf_capabilities.(do_intersect capabilities kcore) )
329+
with
330+
| Intel_processor_trace _, Userspace, _ | Stacktrace_sampling _, _, _ -> []
331+
| Intel_processor_trace _, (Kernel | Userspace_and_kernel), true -> [ "--kcore" ]
332+
| Intel_processor_trace _, (Kernel | Userspace_and_kernel), false ->
333+
(* Strictly speaking, we could recreate tools/perf/perf-with-kcore.sh
334+
here instead of bailing. But that's tricky, and upgrading to a newer
335+
perf is easier. *)
336+
Core.eprintf
337+
"Warning: old perf version detected! perf userspace tools v5.5 contain an \
338+
important feature, kcore, that make decoding kernel traces more reliable. \
339+
In our experience, tracing the kernel mostly works without this feature, \
340+
but you may run into problems if you're trying to trace through \
341+
self-modifying code (the kernel may do this more than you think). Install a \
342+
perf version >= 5.5 to avoid this.\n\
343+
%!";
344+
[])
340345
in
341346
let snapshot_size_opt =
342347
match snapshot_size, collection_mode with

0 commit comments

Comments
 (0)