diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-02-09 15:35:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-02-09 15:35:47 +0000 |
commit | 8f68db4a4909cff4a8c4fd524c7b73ebee5504ae (patch) | |
tree | a646a82817dd32bc0d31ca51a36823868286dbb7 /profcollectd | |
parent | 07f13d8da098eeffd143e984123f3414d8f85607 (diff) | |
parent | ce7ab9a78889d17ce471b999dde3a9aff71d537a (diff) | |
download | extras-8f68db4a4909cff4a8c4fd524c7b73ebee5504ae.tar.gz |
Merge "Replace lazy_static with once_cell" into main
Diffstat (limited to 'profcollectd')
-rw-r--r-- | profcollectd/libprofcollectd/Android.bp | 2 | ||||
-rw-r--r-- | profcollectd/libprofcollectd/config.rs | 27 | ||||
-rw-r--r-- | profcollectd/libprofcollectd/report.rs | 8 |
3 files changed, 16 insertions, 21 deletions
diff --git a/profcollectd/libprofcollectd/Android.bp b/profcollectd/libprofcollectd/Android.bp index 39177ec4..62aa6734 100644 --- a/profcollectd/libprofcollectd/Android.bp +++ b/profcollectd/libprofcollectd/Android.bp @@ -45,9 +45,9 @@ rust_library { "libanyhow", "libbinder_rs", // Remove once b/179041241 is fixed. "libchrono", - "liblazy_static", "liblog_rust", "libmacaddr", + "libonce_cell", "librand", "librustutils", "libserde", // Remove once b/179041241 is fixed. diff --git a/profcollectd/libprofcollectd/config.rs b/profcollectd/libprofcollectd/config.rs index 46cd7f25..14236ab9 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; @@ -34,14 +34,16 @@ const DEFAULT_BINARY_FILTER: &str = "^/(system|apex/.+)/(bin|lib|lib64)/.+"; 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 ref LOG_FILE: &'static Path = Path::new("/data/misc/profcollectd/output/trace.log"); -} +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)] @@ -115,11 +117,8 @@ where T::Err: Error + Send + Sync + 'static, { let default_value = default_value.to_string(); - let config = flags_rust::GetServerConfigurableFlag( - PROFCOLLECT_CONFIG_NAMESPACE, - key, - &default_value, - ); + let config = + flags_rust::GetServerConfigurableFlag(PROFCOLLECT_CONFIG_NAMESPACE, key, &default_value); Ok(T::from_str(&config)?) } diff --git a/profcollectd/libprofcollectd/report.rs b/profcollectd/libprofcollectd/report.rs index cbce1d61..e0f2ec84 100644 --- a/profcollectd/libprofcollectd/report.rs +++ b/profcollectd/libprofcollectd/report.rs @@ -17,7 +17,6 @@ //! Pack profiles into reports. use anyhow::{anyhow, Result}; -use lazy_static::lazy_static; use macaddr::MacAddr6; use std::fs::{self, File, Permissions}; use std::io::{Read, Write}; @@ -34,9 +33,7 @@ use crate::config::Config; pub const NO_USAGE_SETTING: i32 = -1; -lazy_static! { - pub static ref UUID_CONTEXT: Context = Context::new(0); -} +pub static UUID_CONTEXT: Context = Context::new(0); pub fn pack_report( profile: &Path, @@ -89,8 +86,7 @@ pub fn pack_report( fn get_report_filename(node_id: &MacAddr6) -> Result<String> { let since_epoch = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; - let ts = - Timestamp::from_unix(&*UUID_CONTEXT, since_epoch.as_secs(), since_epoch.subsec_nanos()); + let ts = Timestamp::from_unix(&UUID_CONTEXT, since_epoch.as_secs(), since_epoch.subsec_nanos()); let uuid = Uuid::new_v1( ts, node_id.as_bytes().try_into().expect("Invalid number of bytes in V1 UUID"), |