diff --git a/src/data.rs b/src/data.rs index 6c7e0d7a..940ddc8e 100644 --- a/src/data.rs +++ b/src/data.rs @@ -46,6 +46,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fs::{File, OpenOptions}; use std::ops::Sub; +use std::path::PathBuf; use sysctldata::SysctlData; use systeminfo::SystemInfo; use vmstat::{Vmstat, VmstatRaw}; @@ -54,11 +55,11 @@ use vmstat::{Vmstat, VmstatRaw}; pub struct CollectorParams { pub collection_time: u64, pub elapsed_time: u64, - pub data_file_path: String, - pub data_dir: String, + pub data_file_path: PathBuf, + pub data_dir: PathBuf, pub run_name: String, pub profile: HashMap, - pub tmp_dir: String, + pub tmp_dir: PathBuf, } impl CollectorParams { @@ -66,11 +67,11 @@ impl CollectorParams { CollectorParams { collection_time: 0, elapsed_time: 0, - data_file_path: String::new(), - data_dir: String::new(), + data_file_path: PathBuf::new(), + data_dir: PathBuf::new(), run_name: String::new(), profile: HashMap::new(), - tmp_dir: String::new(), + tmp_dir: PathBuf::new(), } } } @@ -117,15 +118,15 @@ impl DataType { let full_path = format!("{}/{}", param.dir_name, name); self.file_name = name; - self.full_path = full_path; + self.full_path = full_path.clone(); self.dir_name = param.dir_name.clone(); self.collector_params.run_name = param.dir_name.clone(); self.collector_params.collection_time = param.period; self.collector_params.elapsed_time = 0; - self.collector_params.data_file_path = self.full_path.clone(); - self.collector_params.data_dir = param.dir_name.clone(); + self.collector_params.data_file_path = PathBuf::from(full_path); + self.collector_params.data_dir = PathBuf::from(param.dir_name); self.collector_params.profile = param.profile.clone(); - self.collector_params.tmp_dir = param.tmp_dir.clone(); + self.collector_params.tmp_dir = PathBuf::from(param.tmp_dir); self.file_handle = Some( OpenOptions::new() diff --git a/src/data/flamegraphs.rs b/src/data/flamegraphs.rs index 4117a043..3fd19c0e 100644 --- a/src/data/flamegraphs.rs +++ b/src/data/flamegraphs.rs @@ -50,8 +50,10 @@ impl CollectData for FlamegraphRaw { fn after_data_collection(&mut self, params: CollectorParams) -> Result<()> { let data_dir = PathBuf::from(¶ms.data_dir); - let file_pathbuf = - data_dir.join(get_file_name(params.data_dir, "perf_profile".to_string())?); + let file_pathbuf = data_dir.join(get_file_name( + params.data_dir.display().to_string(), + "perf_profile".to_string(), + )?); let perf_jit_loc = data_dir.join("perf.data.jit"); diff --git a/src/data/java_profile.rs b/src/data/java_profile.rs index f9e728ae..a5a207c5 100644 --- a/src/data/java_profile.rs +++ b/src/data/java_profile.rs @@ -9,7 +9,6 @@ use log::{debug, error, trace}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::io::Write; -use std::path::PathBuf; use std::process::{Child, Command}; use std::sync::Mutex; use std::{fs, fs::File}; @@ -47,7 +46,9 @@ impl JavaProfileRaw { "-f", format!( "{}/{}-java-flamegraph-{}.html", - params.tmp_dir, params.run_name, jid + params.tmp_dir.display(), + params.run_name, + jid ) .as_str(), jid.as_str(), @@ -211,7 +212,7 @@ impl CollectData for JavaProfileRaw { } } - let data_dir = PathBuf::from(params.data_dir.clone()); + let data_dir = params.data_dir.clone(); for key in self.process_map.keys() { let mut html_path = data_dir.clone(); html_path.push(format!("{}-java-flamegraph-{}.html", params.run_name, key)); @@ -219,7 +220,9 @@ impl CollectData for JavaProfileRaw { let html_loc = html_path.to_str().unwrap(); let tmp_loc = format!( "{}/{}-java-flamegraph-{}.html", - params.tmp_dir, params.run_name, key + params.tmp_dir.display(), + params.run_name, + key ); fs::rename(tmp_loc.clone(), html_loc).ok(); diff --git a/src/data/perf_profile.rs b/src/data/perf_profile.rs index 81af1cbc..6a5780b5 100644 --- a/src/data/perf_profile.rs +++ b/src/data/perf_profile.rs @@ -7,10 +7,10 @@ use anyhow::Result; use ctor::ctor; use log::{error, trace}; use serde::{Deserialize, Serialize}; +use std::fs; use std::io::Write; use std::process::{Child, Command, Stdio}; use std::sync::Mutex; -use std::{fs, path::PathBuf}; pub static PERF_PROFILE_FILE_NAME: &str = "perf_profile"; pub static PERF_TOP_FUNCTIONS_FILE_NAME: &str = "top_functions"; @@ -48,7 +48,7 @@ impl CollectData for PerfProfileRaw { "-e", "cpu-clock:pppH", "-o", - ¶ms.data_file_path, + ¶ms.data_file_path.display().to_string(), "--", "sleep", ¶ms.collection_time.to_string(), @@ -88,7 +88,7 @@ impl CollectData for PerfProfileRaw { Ok(_) => trace!("'perf record' executed successfully."), } let mut top_functions_file = - fs::File::create(PathBuf::from(params.data_dir).join(PERF_TOP_FUNCTIONS_FILE_NAME))?; + fs::File::create(params.data_dir.join(PERF_TOP_FUNCTIONS_FILE_NAME))?; let out = Command::new("perf") .args([ @@ -97,7 +97,7 @@ impl CollectData for PerfProfileRaw { "--percent-limit", "1", "-i", - ¶ms.data_file_path, + ¶ms.data_file_path.display().to_string(), ]) .output();