11use crate :: utils:: is_installed;
22use crate :: utils:: mangling:: demangle_file;
33use anyhow:: Context ;
4+ use std:: fs:: File ;
45use std:: io:: { BufRead , Write } ;
56use std:: path:: Path ;
67use std:: process:: { Command , Stdio } ;
@@ -61,8 +62,9 @@ pub fn cachegrind_annotate(
6162 cg_annotate_cmd
6263 . arg ( "--auto=yes" )
6364 . arg ( "--show-percs=yes" )
64- . arg ( cgout_output) ;
65- fs:: write ( cgann_output, cg_annotate_cmd. output ( ) ?. stdout ) ?;
65+ . arg ( cgout_output)
66+ . stdout ( File :: create ( cgann_output) ?) ;
67+ cg_annotate_cmd. status ( ) ?;
6668 Ok ( ( ) )
6769}
6870
@@ -81,38 +83,32 @@ fn run_cg_diff(cgout1: &Path, cgout2: &Path, path: &Path) -> anyhow::Result<()>
8183 if !is_installed ( "cg_diff" ) {
8284 anyhow:: bail!( "`cg_diff` not installed." ) ;
8385 }
84- let output = Command :: new ( "cg_diff" )
86+ let status = Command :: new ( "cg_diff" )
8587 . arg ( r"--mod-filename=s/\/rustc\/[^\/]*\///" )
8688 . arg ( "--mod-funcname=s/[.]llvm[.].*//" )
8789 . arg ( cgout1)
8890 . arg ( cgout2)
8991 . stderr ( Stdio :: inherit ( ) )
90- . output ( )
92+ . stdout ( File :: create ( path) ?)
93+ . status ( )
9194 . context ( "failed to run `cg_diff`" ) ?;
9295
93- if !output. status . success ( ) {
94- anyhow:: bail!( "failed to generate cachegrind diff" ) ;
95- }
96-
97- fs:: write ( path, output. stdout ) . context ( "failed to write `cg_diff` output" ) ?;
96+ anyhow:: ensure!( status. success( ) , "failed to generate cachegrind diff" ) ;
9897
9998 Ok ( ( ) )
10099}
101100
102101/// Postprocess Cachegrind output file and writes the result to `path`.
103102fn annotate_diff ( cgout : & Path , path : & Path ) -> anyhow:: Result < ( ) > {
104- let output = Command :: new ( "cg_annotate" )
103+ let status = Command :: new ( "cg_annotate" )
105104 . arg ( "--show-percs=no" )
106105 . arg ( cgout)
107106 . stderr ( Stdio :: inherit ( ) )
108- . output ( )
107+ . stdout ( File :: create ( path) ?)
108+ . status ( )
109109 . context ( "failed to run `cg_annotate`" ) ?;
110110
111- if !output. status . success ( ) {
112- anyhow:: bail!( "failed to annotate cachegrind output" ) ;
113- }
114-
115- fs:: write ( path, output. stdout ) . context ( "failed to write `cg_annotate` output" ) ?;
111+ anyhow:: ensure!( status. success( ) , "failed to annotate cachegrind output" ) ;
116112
117113 Ok ( ( ) )
118114}
0 commit comments