Skip to content

Commit 2bc2ee9

Browse files
authored
feat(runner): add experimental flag to capture allocation stacks
1 parent bc1c59d commit 2bc2ee9

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎src/cli/exec/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ fn build_orchestrator_config(
100100
.shared
101101
.experimental
102102
.experimental_disable_pythonmalloc_override,
103+
memory_capture_stack: args.shared.experimental.experimental_memory_capture_stack,
103104
})
104105
}
105106

‎src/cli/experimental.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ pub struct ExperimentalArgs {
2626
value_parser = clap::builder::FalseyValueParser::new()
2727
)]
2828
pub experimental_memory_track_physical: bool,
29+
/// Capture allocation call stacks in memory mode.
30+
#[arg(
31+
long,
32+
default_value_t = false,
33+
help_heading = "Experimental",
34+
env = "CODSPEED_EXPERIMENTAL_MEMORY_CAPTURE_STACK"
35+
)]
36+
pub experimental_memory_capture_stack: bool,
2937

3038
/// Do not set PYTHONMALLOC for simulation runs.
3139
#[arg(
@@ -58,6 +66,9 @@ impl ExperimentalArgs {
5866
if self.experimental_disable_pythonmalloc_override {
5967
flags.push("--experimental-disable-pythonmalloc-override");
6068
}
69+
if self.experimental_memory_capture_stack {
70+
flags.push("--experimental-memory-capture-stack");
71+
}
6172
flags
6273
}
6374

‎src/cli/run/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl RunArgs {
8181
},
8282
experimental: ExperimentalArgs {
8383
experimental_fair_sched: false,
84+
experimental_memory_capture_stack: false,
8485
experimental_cycle_estimation: false,
8586
experimental_exclude_allocations: false,
8687
experimental_memory_track_physical: false,
@@ -144,6 +145,7 @@ fn build_orchestrator_config(
144145
.shared
145146
.experimental
146147
.experimental_disable_pythonmalloc_override,
148+
memory_capture_stack: args.shared.experimental.experimental_memory_capture_stack,
147149
})
148150
}
149151

‎src/executor/config.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ pub struct OrchestratorConfig {
102102
pub memory_track_physical: bool,
103103
/// Do not set PYTHONMALLOC for simulation runs.
104104
pub disable_pythonmalloc_override: bool,
105+
/// Capture allocation call stacks in memory mode, so allocations can be
106+
/// attributed to the code that made them.
107+
pub memory_capture_stack: bool,
105108
}
106109

107110
/// Per-execution configuration passed to executors.
@@ -149,6 +152,12 @@ pub struct ExecutorConfig {
149152
pub memory_track_physical: bool,
150153
/// Do not set PYTHONMALLOC for simulation runs.
151154
pub disable_pythonmalloc_override: bool,
155+
/// Capture allocation call stacks in memory mode, so allocations can be
156+
/// attributed to the code that made them.
157+
///
158+
/// Only read by the memory executor, which is Linux-only.
159+
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
160+
pub memory_capture_stack: bool,
152161
}
153162

154163
#[derive(Debug, Clone, PartialEq)]
@@ -223,6 +232,7 @@ impl OrchestratorConfig {
223232
simulation_track_subprocess: self.simulation_track_subprocess,
224233
memory_track_physical: self.memory_track_physical,
225234
disable_pythonmalloc_override: self.disable_pythonmalloc_override,
235+
memory_capture_stack: self.memory_capture_stack,
226236
}
227237
}
228238
}
@@ -260,6 +270,7 @@ impl OrchestratorConfig {
260270
simulation_track_subprocess: false,
261271
memory_track_physical: false,
262272
disable_pythonmalloc_override: false,
273+
memory_capture_stack: false,
263274
}
264275
}
265276
}

‎src/executor/memory/executor.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ impl MemoryExecutor {
7474
cmd_builder.arg("--ipc-server");
7575
cmd_builder.arg(server_name);
7676
cmd_builder.arg(bench_command);
77+
if execution_context.config.memory_capture_stack {
78+
cmd_builder.env("CODSPEED_MEMTRACK_CAPTURE_STACKS", "1");
79+
}
7780

7881
// Set working directory if specified
7982
if let Some(cwd) = &execution_context.config.working_directory {

0 commit comments

Comments
 (0)