diff --git a/src/env_vars.ml b/src/env_vars.ml index 68c83a61c..c62cf9898 100644 --- a/src/env_vars.ml +++ b/src/env_vars.ml @@ -15,6 +15,9 @@ let perf_path = Option.value ~default:"perf" (Unix.getenv "MAGIC_TRACE_PERF_PATH checks around kernel tracing when not root. *) let perf_is_privileged = Option.is_some (Unix.getenv "MAGIC_TRACE_PERF_IS_PRIVILEGED") +(** Override whether kcore will be used (in the case that [perf] supports it at all). *) +let perf_no_kcore = Option.is_some (Unix.getenv "MAGIC_TRACE_PERF_NO_KCORE") + (* Turns on hidden command line options and attached "[inferred start time]" to functions with inferred start times. diff --git a/src/env_vars.mli b/src/env_vars.mli index 9bf742f65..67f6b915b 100644 --- a/src/env_vars.mli +++ b/src/env_vars.mli @@ -4,6 +4,7 @@ val debug : bool val experimental : bool val perf_path : string val perf_is_privileged : bool +val perf_no_kcore : bool val perfetto_dir : string option val no_dlfilter : bool val fzf_demangle_symbols : bool diff --git a/src/perf_tool_backend.ml b/src/perf_tool_backend.ml index a3de02488..ce10634b4 100644 --- a/src/perf_tool_backend.ml +++ b/src/perf_tool_backend.ml @@ -319,24 +319,29 @@ module Recording = struct |> Deferred.return in let kcore_opts = - match - collection_mode, trace_scope, Perf_capabilities.(do_intersect capabilities kcore) - with - | Intel_processor_trace _, Userspace, _ | Stacktrace_sampling _, _, _ -> [] - | Intel_processor_trace _, (Kernel | Userspace_and_kernel), true -> [ "--kcore" ] - | Intel_processor_trace _, (Kernel | Userspace_and_kernel), false -> - (* Strictly speaking, we could recreate tools/perf/perf-with-kcore.sh - here instead of bailing. But that's tricky, and upgrading to a newer - perf is easier. *) - Core.eprintf - "Warning: old perf version detected! perf userspace tools v5.5 contain an \ - important feature, kcore, that make decoding kernel traces more reliable. In \ - our experience, tracing the kernel mostly works without this feature, but you \ - may run into problems if you're trying to trace through self-modifying code \ - (the kernel may do this more than you think). Install a perf version >= 5.5 \ - to avoid this.\n\ - %!"; - [] + if Env_vars.perf_no_kcore + then [] + else ( + match + ( collection_mode + , trace_scope + , Perf_capabilities.(do_intersect capabilities kcore) ) + with + | Intel_processor_trace _, Userspace, _ | Stacktrace_sampling _, _, _ -> [] + | Intel_processor_trace _, (Kernel | Userspace_and_kernel), true -> [ "--kcore" ] + | Intel_processor_trace _, (Kernel | Userspace_and_kernel), false -> + (* Strictly speaking, we could recreate tools/perf/perf-with-kcore.sh + here instead of bailing. But that's tricky, and upgrading to a newer + perf is easier. *) + Core.eprintf + "Warning: old perf version detected! perf userspace tools v5.5 contain an \ + important feature, kcore, that make decoding kernel traces more reliable. \ + In our experience, tracing the kernel mostly works without this feature, \ + but you may run into problems if you're trying to trace through \ + self-modifying code (the kernel may do this more than you think). Install a \ + perf version >= 5.5 to avoid this.\n\ + %!"; + []) in let snapshot_size_opt = match snapshot_size, collection_mode with