Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/executor/helpers/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ pub fn get_base_injected_env(
"0".into()
},
),
// Java: Enable frame pointers and perf map generation for flamegraph profiling.
// - UnlockDiagnosticVMOptions must come before DumpPerfMapAtExit (diagnostic option).
// - PreserveFramePointer: Preserves frame pointers for profiling.
// - DumpPerfMapAtExit: Writes /tmp/perf-<pid>.map on JVM exit for symbol resolution.
// - DebugNonSafepoints: Enables debug info for JIT-compiled non-safepoint code.
(
"JAVA_TOOL_OPTIONS",
if mode == RunnerMode::Walltime {
"-XX:+PreserveFramePointer -XX:+UnlockDiagnosticVMOptions -XX:+DumpPerfMapAtExit -XX:+DebugNonSafepoints".into()
} else {
"".into()
},
),
("ARCH", ARCH.into()),
("CODSPEED_ENV", "runner".into()),
(
Expand Down
2 changes: 1 addition & 1 deletion src/executor/helpers/run_with_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn create_env_file(extra_env: &HashMap<&'static str, String>) -> Result<NamedTem
let system_env = get_exported_system_env()?;
let base_injected_env = extra_env
.iter()
.map(|(k, v)| format!("export {k}={v}"))
.map(|(k, v)| format!("export {k}='{v}'"))
.collect::<Vec<_>>()
.join("\n");

Expand Down
13 changes: 13 additions & 0 deletions src/executor/wall_time/perf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ impl PerfRunner {
// Infer the unwinding mode from the benchmark cmd
let (cg_mode, stack_size) = if let Some(mode) = config.perf_unwinding_mode {
(mode, None)
} else if config.command.contains("gradle") | config.command.contains("java") | config.command.contains("maven") {
// In Java, we must use FP unwinding otherwise we'll have broken call stacks.
(UnwindingMode::FramePointer, None)
} else if config.command.contains("cargo") {
(UnwindingMode::Dwarf, None)
} else if config.command.contains("pytest")
Expand Down Expand Up @@ -216,6 +219,16 @@ impl PerfRunner {
let on_cmd = async |cmd: &FifoCommand| {
#[allow(deprecated)]
match cmd {
// Print /proc/{pid}/maps for the benchmark process. This helps with debugging missing symbols, as
// it allows finding the module in which an address is located.
FifoCommand::CurrentBenchmark { pid, .. } if is_codspeed_debug_enabled() => {
let maps_path = format!("/proc/{pid}/maps");
match std::fs::read_to_string(&maps_path) {
Ok(maps) => debug!("/proc/{pid}/maps:\n{maps}"),
Err(e) => debug!("Failed to read {maps_path}: {e}"),
}
return Ok(None);
}
FifoCommand::StartBenchmark => {
perf_fifo.start_events().await?;
}
Expand Down
Loading