From d4268ece62137e89cf7f22b6edc00ce513d137ca Mon Sep 17 00:00:00 2001 From: Lance Lui Date: Wed, 24 Jul 2024 15:02:06 +0000 Subject: [PATCH] address PR comments: tmp path parameter, mv instead of cp tmp files --- src/data.rs | 3 +++ src/data/java_profile.rs | 10 +++++----- src/lib.rs | 2 ++ src/record.rs | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/data.rs b/src/data.rs index 3444dfdf..6c7e0d7a 100644 --- a/src/data.rs +++ b/src/data.rs @@ -58,6 +58,7 @@ pub struct CollectorParams { pub data_dir: String, pub run_name: String, pub profile: HashMap, + pub tmp_dir: String, } impl CollectorParams { @@ -69,6 +70,7 @@ impl CollectorParams { data_dir: String::new(), run_name: String::new(), profile: HashMap::new(), + tmp_dir: String::new(), } } } @@ -123,6 +125,7 @@ impl DataType { self.collector_params.data_file_path = self.full_path.clone(); self.collector_params.data_dir = param.dir_name.clone(); self.collector_params.profile = param.profile.clone(); + self.collector_params.tmp_dir = param.tmp_dir.clone(); self.file_handle = Some( OpenOptions::new() diff --git a/src/data/java_profile.rs b/src/data/java_profile.rs index 6645bbfe..f9e728ae 100644 --- a/src/data/java_profile.rs +++ b/src/data/java_profile.rs @@ -46,8 +46,8 @@ impl JavaProfileRaw { &(params.collection_time - params.elapsed_time).to_string(), "-f", format!( - "/tmp/aperf_tmp/{}-java-flamegraph-{}.html", - params.run_name, jid + "{}/{}-java-flamegraph-{}.html", + params.tmp_dir, params.run_name, jid ) .as_str(), jid.as_str(), @@ -218,11 +218,11 @@ impl CollectData for JavaProfileRaw { let html_loc = html_path.to_str().unwrap(); let tmp_loc = format!( - "/tmp/aperf_tmp/{}-java-flamegraph-{}.html", - params.run_name, key + "{}/{}-java-flamegraph-{}.html", + params.tmp_dir, params.run_name, key ); - fs::copy(tmp_loc.clone(), html_loc).ok(); + fs::rename(tmp_loc.clone(), html_loc).ok(); } let mut jps_map = File::create( diff --git a/src/lib.rs b/src/lib.rs index a0cd76ad..a73bf95e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -478,6 +478,7 @@ pub struct InitParams { pub run_name: String, pub collector_version: String, pub commit_sha_short: String, + pub tmp_dir: String, } impl InitParams { @@ -514,6 +515,7 @@ impl InitParams { run_name, collector_version, commit_sha_short, + tmp_dir: String::new(), } } } diff --git a/src/record.rs b/src/record.rs index e6871faa..215656fc 100644 --- a/src/record.rs +++ b/src/record.rs @@ -65,6 +65,7 @@ pub fn record(record: &Record) -> Result<()> { let mut params = InitParams::new(run_name); params.period = record.period; params.interval = record.interval; + params.tmp_dir = APERF_TMP.to_string(); match &record.profile_java { Some(j) => {