From bede7eb7c7bf3d590c4b830d9e001ab8edb7eab0 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Wed, 10 Apr 2019 15:29:46 +0200 Subject: [PATCH] Query specific store --- glean-core/examples/sample.rs | 5 +++-- glean-core/src/storage/boolean.rs | 4 ++-- glean-core/src/storage/mod.rs | 10 +++++----- glean-core/src/storage/string.rs | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/glean-core/examples/sample.rs b/glean-core/examples/sample.rs index a1c3989f3..95ceaaa31 100644 --- a/glean-core/examples/sample.rs +++ b/glean-core/examples/sample.rs @@ -6,7 +6,7 @@ lazy_static! { pub static ref GLOBAL_METRIC: BooleanMetric = BooleanMetric::new(CommonMetricData { name: "global_metric".into(), category: "global".into(), - send_in_pings: vec!["core".into()], + send_in_pings: vec!["core".into(), "metrics".into()], lifetime: Lifetime::Ping, disabled: false, }); @@ -26,5 +26,6 @@ fn main() { GLOBAL_METRIC.set(true); local_metric.set("I can set this"); - println!("{}", storage::StorageManager.dump()); + println!("Core Data:\n{}", storage::StorageManager.dump("core")); + println!("Metrics Data:\n{}", storage::StorageManager.dump("metrics")); } diff --git a/glean-core/src/storage/boolean.rs b/glean-core/src/storage/boolean.rs index 414324ed7..4cd0a4ac5 100644 --- a/glean-core/src/storage/boolean.rs +++ b/glean-core/src/storage/boolean.rs @@ -26,7 +26,7 @@ impl BooleanStorageImpl { } impl StorageDump for BooleanStorageImpl { - fn dump(&self) -> Option { - self.store.get("core").map(|store| json!(store)) + fn dump(&self, store_name: &str) -> Option { + self.store.get(store_name).map(|store| json!(store)) } } diff --git a/glean-core/src/storage/mod.rs b/glean-core/src/storage/mod.rs index 0e778d2dc..e5e0ec352 100644 --- a/glean-core/src/storage/mod.rs +++ b/glean-core/src/storage/mod.rs @@ -18,16 +18,16 @@ lazy_static! { } pub trait StorageDump { - fn dump(&self) -> Option; + fn dump(&self, store_name: &str) -> Option; } pub struct StorageManager; macro_rules! dump_storages { - ($(($name:expr, $storage:tt),)+) => {{ + ($store_name:expr => $(( $name:expr, $storage:tt),)+) => {{ let data = json!({ $( - $name: $storage.read().unwrap().dump(), + $name: $storage.read().unwrap().dump($store_name), )+ }); data @@ -35,8 +35,8 @@ macro_rules! dump_storages { } impl StorageManager { - pub fn dump(&self) -> String { - let data = dump_storages!(("bool", BooleanStorage), ("string", StringStorage),); + pub fn dump(&self, store_name: &str) -> String { + let data = dump_storages!(store_name => ("bool", BooleanStorage), ("string", StringStorage),); ::serde_json::to_string_pretty(&data).unwrap() } diff --git a/glean-core/src/storage/string.rs b/glean-core/src/storage/string.rs index f596332f2..f4f6757a1 100644 --- a/glean-core/src/storage/string.rs +++ b/glean-core/src/storage/string.rs @@ -26,7 +26,7 @@ impl StringStorageImpl { } impl StorageDump for StringStorageImpl { - fn dump(&self) -> Option { - self.store.get("core").map(|store| json!(store)) + fn dump(&self, store_name: &str) -> Option { + self.store.get(store_name).map(|store| json!(store)) } }