|
1 | 1 | use crate::compile::execute::{PerfTool, ProcessOutputData, Processor, Retry}; |
2 | | -use crate::utils; |
3 | | -use crate::utils::cachegrind::cachegrind_annotate; |
| 2 | +use crate::utils::cachegrind::{cachegrind_annotate, cachegrind_diff}; |
| 3 | +use crate::utils::diff::run_diff; |
| 4 | +use crate::utils::{self}; |
4 | 5 | use anyhow::Context; |
5 | 6 | use std::collections::HashMap; |
| 7 | +use std::fs::File; |
6 | 8 | use std::future::Future; |
7 | 9 | use std::io::BufRead; |
8 | 10 | use std::io::Write; |
@@ -50,6 +52,42 @@ impl Profiler { |
50 | 52 | | Profiler::DepGraph |
51 | 53 | ) |
52 | 54 | } |
| 55 | + |
| 56 | + /// A file prefix added to all files of this profiler. |
| 57 | + pub fn prefix(&self) -> &'static str { |
| 58 | + use Profiler::*; |
| 59 | + match self { |
| 60 | + Cachegrind => "cgout", |
| 61 | + DepGraph => "dep-graph", |
| 62 | + |
| 63 | + SelfProfile | PerfRecord | Oprofile | Samply | Callgrind | Dhat | DhatCopy | Massif |
| 64 | + | Bytehound | Eprintln | LlvmLines | MonoItems | LlvmIr => "", |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /// A postfix added to the file that gets diffed. |
| 69 | + pub fn postfix(&self) -> &'static str { |
| 70 | + use Profiler::*; |
| 71 | + match self { |
| 72 | + Cachegrind => "", |
| 73 | + DepGraph => ".txt", |
| 74 | + |
| 75 | + SelfProfile | PerfRecord | Oprofile | Samply | Callgrind | Dhat | DhatCopy | Massif |
| 76 | + | Bytehound | Eprintln | LlvmLines | MonoItems | LlvmIr => "", |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + /// Actually perform the diff |
| 81 | + pub fn diff(&self, left: &Path, right: &Path, output: &Path) -> anyhow::Result<()> { |
| 82 | + use Profiler::*; |
| 83 | + match self { |
| 84 | + Cachegrind => cachegrind_diff(left, right, output), |
| 85 | + DepGraph => run_diff(left, right, output), |
| 86 | + |
| 87 | + SelfProfile | PerfRecord | Oprofile | Samply | Callgrind | Dhat | DhatCopy | Massif |
| 88 | + | Bytehound | Eprintln | LlvmLines | MonoItems | LlvmIr => Ok(()), |
| 89 | + } |
| 90 | + } |
53 | 91 | } |
54 | 92 |
|
55 | 93 | pub struct ProfileProcessor<'a> { |
@@ -143,10 +181,8 @@ impl<'a> Processor for ProfileProcessor<'a> { |
143 | 181 | // Run `summarize`. |
144 | 182 | let mut summarize_cmd = Command::new("summarize"); |
145 | 183 | summarize_cmd.arg("summarize").arg(&zsp_files_prefix); |
146 | | - fs::write( |
147 | | - summarize_file, |
148 | | - summarize_cmd.output().context("summarize")?.stdout, |
149 | | - )?; |
| 184 | + summarize_cmd.stdout(File::create(summarize_file)?); |
| 185 | + summarize_cmd.status().context("summarize")?; |
150 | 186 |
|
151 | 187 | // Run `flamegraph`. |
152 | 188 | let mut flamegraph_cmd = Command::new("flamegraph"); |
@@ -198,17 +234,19 @@ impl<'a> Processor for ProfileProcessor<'a> { |
198 | 234 | .arg("--debug-info") |
199 | 235 | .arg("--threshold") |
200 | 236 | .arg("0.5") |
201 | | - .arg(&session_dir_arg); |
202 | | - fs::write(oprep_file, op_report_cmd.output()?.stdout)?; |
| 237 | + .arg(&session_dir_arg) |
| 238 | + .stdout(File::create(oprep_file)?); |
| 239 | + op_report_cmd.status()?; |
203 | 240 |
|
204 | 241 | let mut op_annotate_cmd = Command::new("opannotate"); |
205 | 242 | // Other possibly useful args: --assembly |
206 | 243 | op_annotate_cmd |
207 | 244 | .arg("--source") |
208 | 245 | .arg("--threshold") |
209 | 246 | .arg("0.5") |
210 | | - .arg(&session_dir_arg); |
211 | | - fs::write(opann_file, op_annotate_cmd.output()?.stdout)?; |
| 247 | + .arg(&session_dir_arg) |
| 248 | + .stdout(File::create(opann_file)?); |
| 249 | + op_annotate_cmd.status()?; |
212 | 250 | } |
213 | 251 |
|
214 | 252 | // Samply produces (via rustc-fake) a data file called |
@@ -248,8 +286,9 @@ impl<'a> Processor for ProfileProcessor<'a> { |
248 | 286 | clg_annotate_cmd |
249 | 287 | .arg("--auto=yes") |
250 | 288 | .arg("--show-percs=yes") |
251 | | - .arg(&clgout_file); |
252 | | - fs::write(clgann_file, clg_annotate_cmd.output()?.stdout)?; |
| 289 | + .arg(&clgout_file) |
| 290 | + .stdout(File::create(clgann_file)?); |
| 291 | + clg_annotate_cmd.status()?; |
253 | 292 | } |
254 | 293 |
|
255 | 294 | // DHAT produces (via rustc-fake) a data file called `dhout`. We |
@@ -371,13 +410,13 @@ impl<'a> Processor for ProfileProcessor<'a> { |
371 | 410 | Profiler::DepGraph => { |
372 | 411 | let tmp_file = filepath(data.cwd, "dep_graph.txt"); |
373 | 412 | let output = |
374 | | - filepath(self.output_dir, &out_file("dep-graph")).with_extension("txt"); |
| 413 | + filepath(self.output_dir, &format!("{}.txt", out_file("dep-graph"))); |
375 | 414 |
|
376 | 415 | fs::copy(tmp_file, output)?; |
377 | 416 |
|
378 | 417 | let tmp_file = filepath(data.cwd, "dep_graph.dot"); |
379 | 418 | let output = |
380 | | - filepath(self.output_dir, &out_file("dep-graph")).with_extension("dot"); |
| 419 | + filepath(self.output_dir, &format!("{}.dot", out_file("dep-graph"))); |
381 | 420 |
|
382 | 421 | // May not exist if not incremental, but then that's OK. |
383 | 422 | fs::copy(tmp_file, output)?; |
|
0 commit comments