Skip to content

Commit

Permalink
Merge pull request #23 from 191220029/record-compiled-binary-size
Browse files Browse the repository at this point in the history
Binray_size: Fix location & calculation of binary targets
  • Loading branch information
genedna authored Apr 15, 2024
2 parents 2cfea37 + 4ebcde2 commit 3b55547
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 29 deletions.
2 changes: 1 addition & 1 deletion collector/src/benchmark/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl Benchamrk {
use std::process::Command;

let mut cmd = Command::new("cp");
cmd.arg("-pLR").arg(from).arg(to);
cmd.arg("-pLRa").arg(from).arg(to);
command_output(&mut cmd)?;
Ok(())
}
Expand Down
16 changes: 5 additions & 11 deletions collector/src/compile_time/binary_size/binary_package_process.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
fs::read_dir,
path::{Path, PathBuf},
process::{Command, Stdio},
};
Expand Down Expand Up @@ -55,8 +54,6 @@ impl<'a> BinaryProcess for BinaryPackageProcess<'a> {
.expect(format!("Fail to compile {}.", self.processor_name).as_str());
}

let mut binary_size = 0;

let target_dir = if let Some(target_path) = &self.target_path {
PathBuf::from(self.cwd)
.join(target_path)
Expand All @@ -68,16 +65,13 @@ impl<'a> BinaryProcess for BinaryPackageProcess<'a> {
.join(self.profile.to_string())
};

let dir = read_dir(target_dir)?;
for entry in dir {
let entry = entry?;
if !self.is_filtered_file_name(entry.file_name()) {
binary_size += entry.metadata()?.len();
}
}
let binary_size = self.get_binary_size(&target_dir).unwrap();

if binary_size == 0 {
Ok(None)
Result::Err(anyhow::Error::msg(format!(
"Build target not found in `{}`.",
target_dir.to_str().unwrap()
)))
} else {
let mut stats = Stats::new();
stats.stats.insert(
Expand Down
15 changes: 5 additions & 10 deletions collector/src/compile_time/binary_size/binary_single_process.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
fs::read_dir,
path::{Path, PathBuf},
process::{Command, Stdio},
};
Expand Down Expand Up @@ -62,17 +61,13 @@ impl<'a> BinaryProcess for BinarySingleProcess<'a> {
.join(self.profile.to_string())
};

let mut binary_size = 0;
let dir = read_dir(target_dir)?;
for entry in dir {
let entry = entry?;
if !self.is_filtered_file_name(entry.file_name()) {
binary_size += entry.metadata()?.len();
}
}
let binary_size = self.get_binary_size(&target_dir).unwrap();

if binary_size == 0 {
Ok(None)
Result::Err(anyhow::Error::msg(format!(
"Build target not found in `{}`.",
target_dir.to_str().unwrap()
)))
} else {
let mut stats = Stats::new();
stats.stats.insert(
Expand Down
8 changes: 4 additions & 4 deletions collector/src/compile_time/binary_size/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub trait BinaryProcess {
}

/// Calculate the binary size of compiled target.
fn get_binary_size(&self, target_dir: PathBuf) -> anyhow::Result<u64> {
fn get_binary_size(&self, target_dir: &PathBuf) -> anyhow::Result<u64> {
let mut binary_size = 0;
let dir = read_dir(target_dir)?;
for entry in dir {
Expand All @@ -63,7 +63,7 @@ pub trait BinaryProcess {
if md.is_file() {
binary_size += entry.metadata()?.len();
} else if md.is_dir() {
binary_size += self.get_binary_size(entry.path())?;
binary_size += self.get_binary_size(&entry.path())?;
}
}
}
Expand All @@ -90,7 +90,7 @@ pub fn bench_binary_size(

match b.bench_binary_size(ltc, profiles) {
Ok(result) => results.push(result),
Err(e) => eprintln!("Faile to bench '{}'! {}", b.name, e),
Err(e) => eprintln!("Fail to bench '{}'! {}", b.name, e),
};
});

Expand Down Expand Up @@ -310,7 +310,7 @@ mod test_binary_size {
touch_file: None,
target_path: None,
};
let binary_size = binary_process.get_binary_size(PathBuf::from(".")).unwrap();
let binary_size = binary_process.get_binary_size(&PathBuf::from(".")).unwrap();
assert!((binary_size as f64 / (1 << 20) as f64) > 15.);
}
}
2 changes: 1 addition & 1 deletion collector/src/compile_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn bench<'a>(
flamegraph_flag,
out_dir,
)
.with_context(|| format!("Faile to bench '{}'!", b.name));
.with_context(|| format!("Fail to bench '{}'!", b.name));
match result {
core::result::Result::Ok(r) => result_vec.push(r),
Err(s) => {
Expand Down
2 changes: 1 addition & 1 deletion collector/src/runtime/measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'a> Runtime for RuntimeProcess<'a> {
match perf_tool.get_bencher() {
crate::toolchain::Bencher::PerfStat => {
let output = command_output(&mut cmd)
.with_context(|| format!("faile to start benchmark process."))?;
.with_context(|| format!("fail to start benchmark process."))?;
let stats = process_benchmark_output(output)?;
log::info!("stats:{:?}", stats);
result.append(stats);
Expand Down
2 changes: 1 addition & 1 deletion collector/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl ResultWriter {
create_dir_all(&dir).with_context(|| format!("fail to create dir for {:?}", dir))?;
let rw = ResultWriter {
fptr: File::create(&dir.join(file_name))
.with_context(|| format!("Faile to create output file {:?}.", dir))?,
.with_context(|| format!("Fail to create output file {:?}.", dir))?,
};
Ok(rw)
}
Expand Down

0 comments on commit 3b55547

Please sign in to comment.