MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / get_base_injected_env

Function get_base_injected_env

src/executor/helpers/env.rs:7–70  ·  view source on GitHub ↗
(
    mode: RunnerMode,
    profile_folder: &Path,
    config: &ExecutorConfig,
)

Source from the content-addressed store, hash-verified

5use std::{collections::HashMap, env::consts::ARCH, path::Path};
6
7pub fn get_base_injected_env(
8 mode: RunnerMode,
9 profile_folder: &Path,
10 config: &ExecutorConfig,
11) -> HashMap<String, String> {
12 let runner_mode_internal_env_value = match mode {
13 // While the runner now deprecates the usage of instrumentation with a message, we
14 // internally still use instrumentation temporarily to give time to users to upgrade their
15 // integrations to a version that accepts both instrumentation and simulation.
16 // TODO: Remove Instrumentation mode completely in the next major release, and set this
17 // value to simulation instead.
18 #[allow(deprecated)]
19 RunnerMode::Instrumentation | RunnerMode::Simulation => "instrumentation",
20 RunnerMode::Walltime => "walltime",
21 #[cfg(target_os = "linux")]
22 RunnerMode::Memory => "memory",
23 };
24 let mut env = HashMap::from([
25 ("PYTHONHASHSEED".into(), "0".into()),
26 (
27 "PYTHON_PERF_JIT_SUPPORT".into(),
28 // FIXME(COD-2645): Keep this disabled on macOS. Enabling it causes
29 // many unresolved addresses on the stack when profiling with samply.
30 if mode == RunnerMode::Walltime && !cfg!(target_os = "macos") {
31 "1".into()
32 } else {
33 "0".into()
34 },
35 ),
36 ("ARCH".into(), ARCH.into()),
37 ("CODSPEED_ENV".into(), "runner".into()),
38 (
39 "CODSPEED_RUNNER_MODE".into(),
40 runner_mode_internal_env_value.into(),
41 ),
42 (
43 "CODSPEED_PROFILE_FOLDER".into(),
44 profile_folder.to_string_lossy().to_string(),
45 ),
46 ]);
47
48 // Java: Enable frame pointers and perf map generation for flamegraph profiling.
49 // - UnlockDiagnosticVMOptions must come before DumpPerfMapAtExit (diagnostic option).
50 // - PreserveFramePointer: Preserves frame pointers for profiling.
51 // - DumpPerfMapAtExit: Writes /tmp/perf-<pid>.map on JVM exit for symbol resolution.
52 // - DebugNonSafepoints: Enables debug info for JIT-compiled non-safepoint code.
53 // - EnableDynamicAgentLoading: Suppresses warning when loading JVMTI agents at runtime.
54 // - jdk.attach.allowAttachSelf: Allows the JVM to attach a JVMTI agent to itself
55 // (used by codspeed-jvm's perf-map agent for @Fork(0) benchmarks).
56 if mode == RunnerMode::Walltime {
57 env.insert(
58 "JAVA_TOOL_OPTIONS".into(),
59 "-XX:+PreserveFramePointer -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+EnableDynamicAgentLoading -Djdk.attach.allowAttachSelf=true".into(),
60 );
61 }
62
63 if let Some(version) = &config.go_runner_version {
64 env.insert("CODSPEED_GO_RUNNER_VERSION".into(), version.to_string());

Callers 3

walltime_bench_cmdMethod · 0.85
measureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected