summaryrefslogtreecommitdiff
path: root/profcollectd/libprofcollectd/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'profcollectd/libprofcollectd/config.rs')
-rw-r--r--profcollectd/libprofcollectd/config.rs50
1 files changed, 36 insertions, 14 deletions
diff --git a/profcollectd/libprofcollectd/config.rs b/profcollectd/libprofcollectd/config.rs
index 87242489..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 = "profcollect_native_boot";
+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.
@@ -57,12 +58,12 @@ pub struct Config {
pub build_fingerprint: String,
/// Interval between collections.
pub collection_interval: Duration,
- /// Length of time each collection lasts for.
- pub sampling_period: Duration,
/// 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 {
@@ -75,19 +76,16 @@ impl Config {
"collection_interval",
600,
)?),
- sampling_period: Duration::from_millis(get_device_config("sampling_period", 500)?),
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."))
}
}
@@ -123,6 +121,13 @@ where
Ok(T::from_str(&config)?)
}
+pub fn get_sampling_period() -> Duration {
+ let default_period = 500;
+ Duration::from_millis(
+ get_device_config("sampling_period", default_period).unwrap_or(default_period),
+ )
+}
+
fn get_property<T>(key: &str, default_value: T) -> Result<T>
where
T: FromStr + ToString,
@@ -147,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)?
@@ -162,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(())
+}