Skip to content

Commit

Permalink
Allow specifying non-PWD for aperf record/report
Browse files Browse the repository at this point in the history
An aperf_tmp is used for all intermediate steps aperf performs when
forming the report.
  • Loading branch information
janaknat committed May 15, 2023
1 parent 3965f00 commit 6be61ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl PerformanceData {
}

pub fn init_collectors(&mut self) -> Result<()> {
let _ret = fs::create_dir_all(self.init_params.dir_name.clone()).unwrap();
let _ret = fs::create_dir(self.init_params.dir_name.clone())?;

/*
* Create a meta_data.yaml to hold the InitParams that was used by the collector.
Expand Down Expand Up @@ -195,12 +195,13 @@ impl PerformanceData {
}

pub fn create_data_archive(&mut self) -> Result<()> {
let archive_name = format!("{}.tar.gz", self.init_params.dir_name);
let tar_gz = fs::File::create(&archive_name)?;
let dir_name = Path::new(&self.init_params.dir_name).file_stem().unwrap();
let archive_path = format!("{}.tar.gz", self.init_params.dir_name);
let tar_gz = fs::File::create(&archive_path)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&self.init_params.dir_name, &self.init_params.dir_name)?;
info!("Data collected in {}/, archived in {}", self.init_params.dir_name, archive_name);
tar.append_dir_all(&dir_name, &self.init_params.dir_name)?;
info!("Data collected in {}/, archived in {}", self.init_params.dir_name, archive_path);
Ok(())
}
}
Expand Down Expand Up @@ -345,7 +346,7 @@ impl InitParams {
let mut dir_name = format!("./aperf_{}", time_str);
let mut run_name = String::new();
if dir != "" {
dir_name = dir.clone();
dir_name = Path::new(&dir).components().as_path().to_str().unwrap().to_string();
run_name = dir;
} else {
let path = Path::new(&dir_name);
Expand Down
20 changes: 14 additions & 6 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ struct Run {
key_values: HashMap<String, String>,
}

pub static APERF_TMP: &str = "aperf_tmp";

pub fn form_and_copy_archive(loc: String, report_name: &PathBuf) -> Result<()> {
if Path::new(&loc).is_dir() {
let dir_stem = Path::new(&loc).file_stem().unwrap().to_str().unwrap().to_string();

/* Create a temp archive */
let archive_name = format!("{}.tar.gz", &dir_stem);
let tar_gz = fs::File::create(&archive_name)?;
let archive_path = format!("{}/{}", APERF_TMP, archive_name);
let tar_gz = fs::File::create(&archive_path)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&dir_stem, &loc)?;

/* Copy archive to aperf_report */
let archive_dst = report_name.join(format!("data/archive/{}", archive_name));
fs::copy(&archive_name, archive_dst)?;
fs::copy(&archive_path, archive_dst)?;
return Ok(());
}
if infer::get_from_path(&loc)?.unwrap().mime_type() == "application/gzip" {
Expand All @@ -71,14 +74,15 @@ pub fn get_dir(dir: String) -> Result<String> {
let tar_gz = File::open(&dir)?;
let tar = GzDecoder::new(tar_gz);
let mut archive = tar::Archive::new(tar);
archive.unpack(".")?;
let dir_name = dir
archive.unpack(APERF_TMP)?;
let dir_name = Path::new(&dir)
.file_name().unwrap().to_str().unwrap()
.strip_suffix(".tar.gz")
.ok_or(PDError::InvalidArchiveName)?;
if !Path::new(&dir_name).exists() {
if !Path::new(&format!("{}/{}", APERF_TMP, dir_name)).exists() {
return Err(PDError::ArchiveDirectoryMismatch.into());
}
return Ok(dir_name.to_string());
return Ok(format!("{}/{}", APERF_TMP, dir_name));
}
return Err(PDError::RecordNotArchiveOrDirectory.into());
}
Expand All @@ -88,6 +92,9 @@ pub fn report(report: &Report) -> Result<()> {
let mut dir_paths: Vec<String> = Vec::new();
let mut dir_stems: Vec<String> = Vec::new();

/* Create a tmp dir for aperf to work with */
fs::create_dir_all(APERF_TMP)?;

/* Get dir paths, stems */
for dir in &dirs {
let directory = get_dir(dir.to_string())?;
Expand Down Expand Up @@ -220,5 +227,6 @@ pub fn report(report: &Report) -> Result<()> {
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&report_name, &report_name)?;
fs::remove_dir_all(APERF_TMP)?;
Ok(())
}

0 comments on commit 6be61ee

Please sign in to comment.