diff options
Diffstat (limited to 'profcollectd/libprofcollectd/config.rs')
-rw-r--r-- | profcollectd/libprofcollectd/config.rs | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/profcollectd/libprofcollectd/config.rs b/profcollectd/libprofcollectd/config.rs index af714242..7dbd708c 100644 --- a/profcollectd/libprofcollectd/config.rs +++ b/profcollectd/libprofcollectd/config.rs @@ -24,14 +24,15 @@ use serde::{Deserialize, Serialize}; use std::error::Error; use std::fs::{read_dir, remove_file}; use std::path::Path; +use std::process::Command; use std::str::FromStr; use std::time::Duration; const PROFCOLLECT_CONFIG_NAMESPACE: &str = "aconfig_flags.profcollect_native_boot"; const PROFCOLLECT_NODE_ID_PROPERTY: &str = "persist.profcollectd.node_id"; -const DEFAULT_BINARY_FILTER: &str = - "(^/(system|apex/.+|vendor)/(bin|lib|lib64)/.+)|kernel.kallsyms"; +const DEFAULT_BINARY_FILTER: &str = "(^/(system|apex/.+|vendor)/(bin|lib64)/.+)|\ + (^/data/app/.+\\.so$)|kernel.kallsyms"; pub const REPORT_RETENTION_SECS: u64 = 14 * 24 * 60 * 60; // 14 days. // Static configs that cannot be changed. @@ -60,7 +61,9 @@ pub struct Config { /// An optional filter to limit which binaries to or not to profile. pub binary_filter: String, /// Maximum size of the trace directory. - pub max_trace_limit: u64, + pub max_trace_limit_mb: u64, + /// The kernel release version + pub kernel_release: String, } impl Config { @@ -74,17 +77,15 @@ impl Config { 600, )?), binary_filter: get_device_config("binary_filter", DEFAULT_BINARY_FILTER.to_string())?, - max_trace_limit: get_device_config( - "max_trace_limit", - /* 512MB */ 512 * 1024 * 1024, - )?, + max_trace_limit_mb: get_device_config("max_trace_limit_mb", 768)?, + kernel_release: get_kernel_release(), }) } } -impl ToString for Config { - fn to_string(&self) -> String { - serde_json::to_string(self).expect("Failed to deserialise configuration.") +impl std::fmt::Display for Config { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", serde_json::to_string(self).expect("Failed to deserialise configuration.")) } } @@ -151,6 +152,15 @@ fn generate_random_node_id() -> MacAddr6 { MacAddr6::from(node_id) } +fn get_kernel_release() -> String { + match Command::new("uname").args(["-r"]).output() { + Ok(output) if output.status.success() => { + String::from_utf8_lossy(&output.stdout).trim().to_string() + } + _ => String::new(), + } +} + pub fn clear_data() -> Result<()> { fn remove_files(path: &Path) -> Result<()> { read_dir(path)? @@ -166,3 +176,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(()) +} |