Skip to content

Commit 21e83a3

Browse files
feat: set NODE_OPTIONS to get perf map from node
1 parent b6f3efe commit 21e83a3

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

crates/exec-harness/src/analysis/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub fn perform_with_valgrind(commands: Vec<BenchmarkCommand>) -> Result<()> {
5959
cmd.env("PYTHONPERFSUPPORT", "1");
6060
cmd.env(constants::URI_ENV, &name_and_uri.uri);
6161

62+
crate::node::set_node_options(&mut cmd);
63+
6264
let mut child = cmd.spawn().context("Failed to spawn command")?;
6365

6466
let status = child.wait().context("Failed to execute command")?;

crates/exec-harness/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::io::{self, BufRead};
55

66
pub mod analysis;
77
pub mod constants;
8+
pub mod node;
89
pub mod prelude;
910
mod uri;
1011
pub mod walltime;

crates/exec-harness/src/node.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::process::Command;
2+
3+
const NODE_OPTIONS_TO_ADD: &[&str] = &["--perf-basic-prof"];
4+
5+
/// Appends CodSpeed-required Node.js options to `NODE_OPTIONS` on a [`Command`],
6+
/// preserving any existing value from the environment.
7+
pub fn set_node_options(cmd: &mut Command) {
8+
let existing = std::env::var("NODE_OPTIONS").unwrap_or_default();
9+
let mut parts: Vec<&str> = existing.split_whitespace().collect();
10+
11+
for opt in NODE_OPTIONS_TO_ADD {
12+
if !parts.contains(opt) {
13+
parts.push(opt);
14+
}
15+
}
16+
17+
cmd.env("NODE_OPTIONS", parts.join(" "));
18+
}

crates/exec-harness/src/walltime/benchmark_loop.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ pub fn run_rounds(
1515
let hooks = InstrumentHooks::instance(INTEGRATION_NAME, INTEGRATION_VERSION);
1616

1717
let do_one_round = || -> Result<(u64, u64)> {
18-
let mut child = Command::new(&command[0])
19-
.args(&command[1..])
20-
.spawn()
21-
.context("Failed to execute command")?;
18+
let mut cmd = Command::new(&command[0]);
19+
cmd.args(&command[1..]);
20+
crate::node::set_node_options(&mut cmd);
21+
let mut child = cmd.spawn().context("Failed to execute command")?;
2222
let bench_round_start_ts_ns = InstrumentHooks::current_timestamp();
2323
let status = child
2424
.wait()

0 commit comments

Comments
 (0)