Skip to content

Commit 73dd4b3

Browse files
feat: output perf data directly to profile folder
1 parent 8236ced commit 73dd4b3

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

src/run/runner/wall_time/executor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ impl Executor for WallTimeExecutor {
191191
if let Some(perf) = &self.perf
192192
&& config.enable_perf
193193
{
194-
perf.run(cmd_builder, config).await
194+
perf.run(cmd_builder, config, &run_data.profile_folder)
195+
.await
195196
} else {
196197
let cmd = wrap_with_sudo(cmd_builder)?.build();
197198
debug!("cmd: {cmd:?}");

src/run/runner/wall_time/perf/mod.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use runner_shared::fifo::MarkerType;
2626
use runner_shared::metadata::PerfMetadata;
2727
use runner_shared::unwind_data::UnwindData;
2828
use std::collections::HashSet;
29-
use std::path::{Path, PathBuf};
29+
use std::path::Path;
3030
use std::time::Duration;
3131
use std::{cell::OnceCell, collections::HashMap, process::ExitStatus};
3232

@@ -41,7 +41,7 @@ pub mod perf_map;
4141
pub mod unwind_data;
4242

4343
const PERF_METADATA_CURRENT_VERSION: u64 = 1;
44-
const PERF_DATA_PATH: &str = "/tmp/perf.pipedata";
44+
const PERF_DATA_FILE_NAME: &str = "perf.pipedata";
4545

4646
pub struct PerfRunner {
4747
benchmark_data: OnceCell<BenchmarkData>,
@@ -89,6 +89,7 @@ impl PerfRunner {
8989
&self,
9090
mut cmd_builder: CommandBuilder,
9191
config: &Config,
92+
profile_folder: &Path,
9293
) -> anyhow::Result<ExitStatus> {
9394
let perf_fifo = PerfFifo::new()?;
9495
let runner_fifo = RunnerFifo::new()?;
@@ -144,7 +145,15 @@ impl PerfRunner {
144145
"--",
145146
]);
146147
cmd_builder.wrap_with(perf_wrapper_builder);
147-
let raw_command = format!("{} | cat > PERF_DATA_PATH", &cmd_builder.as_command_line());
148+
149+
// Copy the perf data to the profile folder
150+
let perf_data_file_path = profile_folder.join(PERF_DATA_FILE_NAME);
151+
152+
let raw_command = format!(
153+
"{} | cat > {}",
154+
&cmd_builder.as_command_line(),
155+
perf_data_file_path.to_string_lossy()
156+
);
148157
let mut wrapped_builder = CommandBuilder::new("sh");
149158
wrapped_builder.args(["-c", &raw_command]);
150159
let cmd = wrap_with_sudo(wrapped_builder)?.build();
@@ -160,28 +169,9 @@ impl PerfRunner {
160169
run_command_with_log_pipe_and_callback(cmd, on_process_started).await
161170
}
162171

163-
pub async fn save_files_to(&self, profile_folder: &PathBuf) -> anyhow::Result<()> {
172+
pub async fn save_files_to(&self, profile_folder: &Path) -> anyhow::Result<()> {
164173
let start = std::time::Instant::now();
165174

166-
// We ran perf with sudo, so we have to change the ownership of the perf.data
167-
run_with_sudo(
168-
"chown",
169-
[
170-
"-R",
171-
&format!(
172-
"{}:{}",
173-
nix::unistd::Uid::current(),
174-
nix::unistd::Gid::current()
175-
),
176-
PERF_DATA_PATH,
177-
],
178-
)?;
179-
180-
// Copy the perf data to the profile folder
181-
let perf_data_dest = profile_folder.join("perf.pipedata");
182-
std::fs::copy(PERF_DATA_PATH, &perf_data_dest)
183-
.with_context(|| format!("Failed to copy perf data to {perf_data_dest:?}",))?;
184-
185175
let bench_data = self
186176
.benchmark_data
187177
.get()

0 commit comments

Comments
 (0)