Skip to content

Commit

Permalink
Binary_size_bench: Fix file not found error (#20)
Browse files Browse the repository at this point in the history
* Fix file not found error

Signed-off-by: 191220029 <[email protected]>

* fmt fix

Signed-off-by: 191220029 <[email protected]>

---------

Signed-off-by: 191220029 <[email protected]>
Co-authored-by: 191220029 <[email protected]>
  • Loading branch information
191220029 and 191220029 authored Apr 10, 2024
1 parent 3329f01 commit 03c626c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 27 deletions.
1 change: 1 addition & 0 deletions collector/src/benchmark/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ pub struct BenchmarkConfig {
pub runtime_test_type: Option<RuntimeTestType>,
pub example_lst: Option<Vec<String>>,
pub runtime_args: Option<String>,
pub target_path: Option<PathBuf>,
/// The file that should be touched to ensure cargo re-checks the leaf crate
/// we're interested in. Likely, something similar to `src/lib.rs`. The
/// default if this is not present is to touch all .rs files in the
Expand Down
35 changes: 22 additions & 13 deletions collector/src/compile_time/binary_size/binary_package_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct BinaryPackageProcess<'a> {
pub rustc_args: Vec<String>,
pub touch_file: Option<String>,
pub packages: Vec<String>,
pub target_path: Option<PathBuf>,
}

impl<'a> BinaryProcess for BinaryPackageProcess<'a> {
Expand All @@ -32,12 +33,21 @@ impl<'a> BinaryProcess for BinaryPackageProcess<'a> {
.arg("rustc")
.arg("--manifest-path")
.arg(&self.manifest_path)
.arg("--profile")
.arg(self.profile.to_string())
.arg("--package")
.arg(package)
.args(&self.cargo_args);

match self.profile {
Profile::Check => {
cmd.arg("--profile").arg("check");
}
Profile::Debug => (),
Profile::Doc => unimplemented!(),
Profile::Release => {
cmd.arg("--release");
}
}

cmd.stdout(Stdio::null()).stderr(Stdio::null());

cmd.spawn()?
Expand All @@ -47,17 +57,16 @@ impl<'a> BinaryProcess for BinaryPackageProcess<'a> {

let mut binary_size = 0;

let mut target_dir = PathBuf::from(self.cwd);
if self.manifest_path.contains('/') {
let segment = self.manifest_path.split('/');
let toml = segment.clone().last().unwrap();
segment.for_each(|s| {
if s != toml {
target_dir = target_dir.join(s);
}
});
}
target_dir = target_dir.join("target").join(self.profile.to_string());
let target_dir = if let Some(target_path) = &self.target_path {
PathBuf::from(self.cwd)
.join(target_path)
.join("target")
.join(self.profile.to_string())
} else {
PathBuf::from(self.cwd)
.join("target")
.join(self.profile.to_string())
};

let dir = read_dir(target_dir)?;
for entry in dir {
Expand Down
36 changes: 23 additions & 13 deletions collector/src/compile_time/binary_size/binary_single_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,49 @@ pub struct BinarySingleProcess<'a> {
pub cargo_args: Vec<String>,
pub rustc_args: Vec<String>,
pub touch_file: Option<String>,
pub target_path: Option<PathBuf>,
}

impl<'a> BinaryProcess for BinarySingleProcess<'a> {
fn run_rustc(&self) -> anyhow::Result<Option<Stats>> {
let mut cmd = Command::new(Path::new(self.compiler.cargo));

cmd.current_dir(self.cwd)
.env("RUSTC", &*self.compiler.rustc)
.env("CARGO_INCREMENTAL", "0")
.env("RUSTC_BOOTSTRAP", "1")
.arg("rustc")
.arg("--manifest-path")
.arg(&self.manifest_path)
.arg("--profile")
.arg(self.profile.to_string())
.args(&self.cargo_args);

match self.profile {
Profile::Check => {
cmd.arg("--profile").arg("check");
}
Profile::Debug => (),
Profile::Doc => unimplemented!(),
Profile::Release => {
cmd.arg("--release");
}
}

cmd.stdout(Stdio::null()).stderr(Stdio::null());

cmd.spawn()?
.wait()
.expect(format!("Fail to compile {}.", self.processor_name).as_str());

let mut target_dir = PathBuf::from(self.cwd);
if self.manifest_path.contains('/') {
let segment = self.manifest_path.split('/');
let toml = segment.clone().last().unwrap();
segment.for_each(|s| {
if s != toml {
target_dir = target_dir.join(s);
}
});
}
target_dir = target_dir.join("target").join(self.profile.to_string());
let target_dir = if let Some(target_path) = &self.target_path {
PathBuf::from(self.cwd)
.join(target_path)
.join("target")
.join(self.profile.to_string())
} else {
PathBuf::from(self.cwd)
.join("target")
.join(self.profile.to_string())
};

let mut binary_size = 0;
let dir = read_dir(target_dir)?;
Expand Down
11 changes: 10 additions & 1 deletion collector/src/compile_time/binary_size/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ pub trait BinaryProcess {
/// Files with ".d" suffix or directorys that are not relevant to the
/// binary target should be filtered out.
fn is_filtered_file_name(&self, file_name: OsString) -> bool {
let filted_names = vec!["build", "deps", "examples", "incremental"];
let filted_names = vec![
"build",
"deps",
"examples",
"incremental",
".fingerprint",
".cargo-lock",
];
if let Some(file_name) = file_name.to_str() {
filted_names.contains(&file_name) | file_name.ends_with(".d")
} else {
Expand Down Expand Up @@ -149,6 +156,7 @@ impl Benchamrk {
.map(String::from)
.collect(),
touch_file: self.config.touch_file.clone(),
target_path: self.config.target_path.clone(),
}),
CompileTimeType::Packages => Box::new(BinaryPackageProcess {
compiler,
Expand Down Expand Up @@ -180,6 +188,7 @@ impl Benchamrk {
.collect(),
touch_file: self.config.touch_file.clone(),
packages: self.config.packages.clone().unwrap(),
target_path: self.config.target_path.clone(),
}),
}
}
Expand Down
1 change: 1 addition & 0 deletions collector/src/mir_analyze/mir_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ mod test {
touch_file: None,
disabled: false,
runs: 0,
target_path: None,
},
};

Expand Down

0 comments on commit 03c626c

Please sign in to comment.