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.rs51
1 files changed, 32 insertions, 19 deletions
diff --git a/profcollectd/libprofcollectd/config.rs b/profcollectd/libprofcollectd/config.rs
index d68f02e7..8a6c9e4f 100644
--- a/profcollectd/libprofcollectd/config.rs
+++ b/profcollectd/libprofcollectd/config.rs
@@ -17,8 +17,8 @@
//! ProfCollect configurations.
use anyhow::Result;
-use lazy_static::lazy_static;
use macaddr::MacAddr6;
+use once_cell::sync::Lazy;
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::error::Error;
@@ -27,20 +27,24 @@ use std::path::Path;
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/.+)/(bin|lib|lib64)/.+";
+const DEFAULT_BINARY_FILTER: &str =
+ "(^/(system|apex/.+|vendor)/(bin|lib|lib64)/.+)|kernel.kallsyms";
pub const REPORT_RETENTION_SECS: u64 = 14 * 24 * 60 * 60; // 14 days.
// Static configs that cannot be changed.
-lazy_static! {
- pub static ref TRACE_OUTPUT_DIR: &'static Path = Path::new("/data/misc/profcollectd/trace/");
- pub static ref PROFILE_OUTPUT_DIR: &'static Path = Path::new("/data/misc/profcollectd/output/");
- pub static ref REPORT_OUTPUT_DIR: &'static Path = Path::new("/data/misc/profcollectd/report/");
- pub static ref CONFIG_FILE: &'static Path =
- Path::new("/data/misc/profcollectd/output/config.json");
-}
+pub static TRACE_OUTPUT_DIR: Lazy<&'static Path> =
+ Lazy::new(|| Path::new("/data/misc/profcollectd/trace/"));
+pub static PROFILE_OUTPUT_DIR: Lazy<&'static Path> =
+ Lazy::new(|| Path::new("/data/misc/profcollectd/output/"));
+pub static REPORT_OUTPUT_DIR: Lazy<&'static Path> =
+ Lazy::new(|| Path::new("/data/misc/profcollectd/report/"));
+pub static CONFIG_FILE: Lazy<&'static Path> =
+ Lazy::new(|| Path::new("/data/misc/profcollectd/output/config.json"));
+pub static LOG_FILE: Lazy<&'static Path> =
+ Lazy::new(|| Path::new("/data/misc/profcollectd/output/trace.log"));
/// Dynamic configs, stored in config.json.
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
@@ -53,8 +57,6 @@ 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.
@@ -71,7 +73,6 @@ 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",
@@ -114,14 +115,18 @@ where
T::Err: Error + Send + Sync + 'static,
{
let default_value = default_value.to_string();
- let config = profcollect_libflags_rust::GetServerConfigurableFlag(
- PROFCOLLECT_CONFIG_NAMESPACE,
- key,
- &default_value,
- );
+ let config =
+ flags_rust::GetServerConfigurableFlag(PROFCOLLECT_CONFIG_NAMESPACE, key, &default_value);
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,
@@ -151,7 +156,7 @@ pub fn clear_data() -> Result<()> {
read_dir(path)?
.filter_map(|e| e.ok())
.map(|e| e.path())
- .filter(|e| e.is_file())
+ .filter(|e| e.is_file() && e != *LOG_FILE)
.try_for_each(remove_file)?;
Ok(())
}
@@ -161,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(())
+}