summaryrefslogtreecommitdiff
path: root/profcollectd
diff options
context:
space:
mode:
authorAbhishek Gadewar <abhishekgadewar@meta.com>2024-05-01 10:59:24 -0700
committerAbhishek Gadewar <abhishekgadewar@meta.com>2024-05-01 11:07:54 -0700
commitb67822c134ab6cc607de011249758dbe83e412c2 (patch)
tree6422322847df96f15bae07bf309247d406221379 /profcollectd
parent5080f93ced2c132b96a775550e62dbc7d3f8770c (diff)
downloadextras-b67822c134ab6cc607de011249758dbe83e412c2.tar.gz
Automatically delete trace files after generating report
Summary: After switching to a time-based approach for report generation, we want to ensure that we don't accidentally include repeated trace files. Thus, after creating a zip file for the report, we delete the originals. Test: Ran adb shell device_config put profcollect_native_boot enabled true and rebooted the device to enable profcollectd. Ranprofcollectctl once to collect trace files, profcollectctl process to process them, and then profcollectctl report to generate the report. Verified that the processed trace files were removed after profcollectctl report was run & that the config.json file remained. Tags: Change-Id: Ic6ab934f52c7af277817ce992faebd96fcde223f Signed-off-by: Abhishek Gadewar <abhishekgadewar@meta.com>
Diffstat (limited to 'profcollectd')
-rw-r--r--profcollectd/libprofcollectd/config.rs8
-rw-r--r--profcollectd/libprofcollectd/report.rs3
2 files changed, 10 insertions, 1 deletions
diff --git a/profcollectd/libprofcollectd/config.rs b/profcollectd/libprofcollectd/config.rs
index af714242..8a6c9e4f 100644
--- a/profcollectd/libprofcollectd/config.rs
+++ b/profcollectd/libprofcollectd/config.rs
@@ -166,3 +166,11 @@ pub fn clear_data() -> Result<()> {
remove_files(&REPORT_OUTPUT_DIR)?;
Ok(())
}
+pub fn clear_processed_files() -> Result<()> {
+ read_dir(&PROFILE_OUTPUT_DIR as &Path)?
+ .filter_map(|e| e.ok())
+ .map(|e| e.path())
+ .filter(|e| e.is_file() && e != (&CONFIG_FILE as &Path))
+ .try_for_each(remove_file)?;
+ Ok(())
+}
diff --git a/profcollectd/libprofcollectd/report.rs b/profcollectd/libprofcollectd/report.rs
index e0f2ec84..60410c1a 100644
--- a/profcollectd/libprofcollectd/report.rs
+++ b/profcollectd/libprofcollectd/report.rs
@@ -29,7 +29,7 @@ use zip::write::FileOptions;
use zip::CompressionMethod::Deflated;
use zip::ZipWriter;
-use crate::config::Config;
+use crate::config::{clear_processed_files, Config};
pub const NO_USAGE_SETTING: i32 = -1;
@@ -80,6 +80,7 @@ pub fn pack_report(
zip.write_all(usage_setting.to_string().as_bytes())?;
}
zip.finish()?;
+ clear_processed_files()?;
Ok(report_filename)
}