From e3170ed8e844174decc7cdea1396f4893c75bd52 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 21 Apr 2026 15:58:30 -0400 Subject: [PATCH 1/2] Use glean-sym to record (duped) metrics from places Rust implementation --- Cargo.lock | 111 ++++++++++++++++++++++++++++++-- components/places/Cargo.toml | 2 + components/places/build.rs | 8 +++ components/places/metrics.yaml | 114 +++++++++++++++++++++++++++++++++ components/places/src/ffi.rs | 31 +++++++-- components/places/src/lib.rs | 5 ++ tools/dependency_summary.py | 10 +++ 7 files changed, 272 insertions(+), 9 deletions(-) create mode 100644 components/places/metrics.yaml diff --git a/Cargo.lock b/Cargo.lock index 97f7edc586..1f146fef81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -540,7 +540,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-link", + "windows-link 0.1.3", ] [[package]] @@ -597,7 +597,7 @@ checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", - "libloading", + "libloading 0.8.0", ] [[package]] @@ -1044,7 +1044,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading", + "libloading 0.8.0", ] [[package]] @@ -1509,6 +1509,17 @@ dependencies = [ "instant", ] +[[package]] +name = "fd-lock" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c44818c96aec5cadc9dacfb97bbcbcfc19a0de75b218412d56f57fbaab94e439" +dependencies = [ + "cfg-if", + "rustix 0.38.25", + "windows-sys 0.59.0", +] + [[package]] name = "ffi-support" version = "0.4.4" @@ -1794,6 +1805,25 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "glean-build" +version = "19.1.0" +source = "git+https://github.com/mozilla/glean?rev=0401cd87c365fd8356e5d3bb6d72a67c8940c934#0401cd87c365fd8356e5d3bb6d72a67c8940c934" +dependencies = [ + "xshell-venv", +] + +[[package]] +name = "glean-sym" +version = "0.1.0" +source = "git+https://github.com/mozilla/glean?rev=0401cd87c365fd8356e5d3bb6d72a67c8940c934#0401cd87c365fd8356e5d3bb6d72a67c8940c934" +dependencies = [ + "libloading 0.9.0", + "once_cell", + "serde", + "uniffi", +] + [[package]] name = "glob" version = "0.3.1" @@ -2441,6 +2471,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libloading" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "754ca22de805bb5744484a5b151a9e1a8e837d5dc232c2d7d8c2e3492edc8b60" +dependencies = [ + "cfg-if", + "windows-link 0.2.1", +] + [[package]] name = "libm" version = "0.2.7" @@ -2496,6 +2536,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f508063cc7bb32987c71511216bd5a32be15bccb6a80b52df8b9d7f01fc3aa2" +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "litemap" version = "0.8.0" @@ -3114,9 +3160,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.2" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "oneshot" @@ -3310,6 +3356,8 @@ dependencies = [ "bitflags 1.3.2", "dogear", "error-support", + "glean-build", + "glean-sym", "icu_casemap", "idna", "interrupt-support", @@ -3892,6 +3940,19 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustix" +version = "0.38.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +dependencies = [ + "bitflags 2.11.0", + "errno 0.3.1", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.48.0", +] + [[package]] name = "rustversion" version = "1.0.12" @@ -5508,6 +5569,12 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "windows-sys" version = "0.36.1" @@ -5545,6 +5612,15 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.0" @@ -5826,6 +5902,31 @@ version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a56c84a8ccd4258aed21c92f70c0f6dea75356b6892ae27c24139da456f9336" +[[package]] +name = "xshell" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d" +dependencies = [ + "xshell-macros", +] + +[[package]] +name = "xshell-macros" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547" + +[[package]] +name = "xshell-venv" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7933fb25d6b9716ede532410214bbc9b0fd08aa7a7a499788ede2d2c23dc4b02" +dependencies = [ + "fd-lock", + "xshell", +] + [[package]] name = "xz2" version = "0.1.7" diff --git a/components/places/Cargo.toml b/components/places/Cargo.toml index a537c44610..990da5af1b 100644 --- a/components/places/Cargo.toml +++ b/components/places/Cargo.toml @@ -32,6 +32,7 @@ sync-guid = { path = "../support/guid", features = ["rusqlite_support", "random" thiserror = "2" anyhow = "1.0" uniffi = { version = "0.31" } +glean-sym = { git = "https://github.com/mozilla/glean", rev = "0401cd87c365fd8356e5d3bb6d72a67c8940c934" } [dev-dependencies] error-support = { path = "../support/error", features = ["testing"] } @@ -40,3 +41,4 @@ sql-support = { path = "../support/sql" } [build-dependencies] uniffi = { version = "0.31", features=["build"]} +glean-build = { git = "https://github.com/mozilla/glean", rev = "0401cd87c365fd8356e5d3bb6d72a67c8940c934" } diff --git a/components/places/build.rs b/components/places/build.rs index 9889857733..deabb9fe2e 100644 --- a/components/places/build.rs +++ b/components/places/build.rs @@ -2,6 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use glean_build::Builder; + fn main() { uniffi::generate_scaffolding("./src/places.udl").unwrap(); + + Builder::default() + .file("metrics.yaml") + .format("rust_sym") + .generate() + .expect("Error generating Glean Rust bindings"); } diff --git a/components/places/metrics.yaml b/components/places/metrics.yaml new file mode 100644 index 0000000000..4d03733236 --- /dev/null +++ b/components/places/metrics.yaml @@ -0,0 +1,114 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +--- +$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 + +places_manager: + connection_initialized: + type: counter + description: | + Number of times a `PlacesConnection` was initialized. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=2034534 + data_reviews: + - https://github.com/mozilla/application-services/pull/7336 + notification_emails: + - jrediger@mozilla.com + expires: 2026-11-13 + data_sensitivity: + - technical + + run_maintenance_prune_time_temp: + type: timing_distribution + description: | + Time taken to execute `prune_older_visits()` inside `run_maintenance()` + + Duplication of `run_maintenance_prune_time` for glean-sym testing. + time_unit: millisecond + bugs: + - https://github.com/mozilla/application-services/issues/5246 + - https://bugzilla.mozilla.org/show_bug.cgi?id=2034534 + data_reviews: + - https://github.com/mozilla/application-services/issues/5247 + - https://github.com/mozilla/application-services/issues/5387 + - https://github.com/mozilla/application-services/issues/5830 + - https://github.com/mozilla/application-services/pull/7336 + notification_emails: + - synced-client-integrations@mozilla.com + - bdk@mozilla.com + - jrediger@mozilla.com + expires: 2026-11-13 + data_sensitivity: + - technical + no_lint: [COMMON_PREFIX] + + run_maintenance_vacuum_time_temp: + type: timing_distribution + description: | + Time taken to execute `VACUUM` inside `run_maintenance()` + + Duplication of `run_maintenance_vacuum_time` for glean-sym testing. + time_unit: millisecond + bugs: + - https://github.com/mozilla/application-services/issues/5246 + - https://bugzilla.mozilla.org/show_bug.cgi?id=2034534 + data_reviews: + - https://github.com/mozilla/application-services/issues/5247 + - https://github.com/mozilla/application-services/issues/5387 + - https://github.com/mozilla/application-services/issues/5830 + - https://github.com/mozilla/application-services/pull/7336 + notification_emails: + - synced-client-integrations@mozilla.com + - bdk@mozilla.com + - jrediger@mozilla.com + expires: 2026-11-13 + data_sensitivity: + - technical + + run_maintenance_optimize_time_temp: + type: timing_distribution + description: | + Time taken to execute `PRAGMA optimize` inside `run_maintenance()` + + Duplication of `run_maintenance_optimize_time` for glean-sym testing. + time_unit: millisecond + bugs: + - https://github.com/mozilla/application-services/issues/5246 + - https://bugzilla.mozilla.org/show_bug.cgi?id=2034534 + data_reviews: + - https://github.com/mozilla/application-services/issues/5247 + - https://github.com/mozilla/application-services/issues/5387 + - https://github.com/mozilla/application-services/issues/5830 + - https://github.com/mozilla/application-services/pull/7336 + notification_emails: + - synced-client-integrations@mozilla.com + - bdk@mozilla.com + - jrediger@mozilla.com + expires: 2026-11-13 + data_sensitivity: + - technical + + run_maintenance_chk_pnt_time_temp: + type: timing_distribution + description: | + Time taken to execute `PRAGMA_CHECKPOINT` inside `run_maintenance()` + + Duplication of `run_maintenance_chk_pnt_time_temp` for glean-sym testing. + time_unit: millisecond + bugs: + - https://github.com/mozilla/application-services/issues/5246 + - https://bugzilla.mozilla.org/show_bug.cgi?id=2034534 + data_reviews: + - https://github.com/mozilla/application-services/issues/5247 + - https://github.com/mozilla/application-services/issues/5387 + - https://github.com/mozilla/application-services/issues/5830 + - https://github.com/mozilla/application-services/pull/7336 + notification_emails: + - synced-client-integrations@mozilla.com + - bdk@mozilla.com + - jrediger@mozilla.com + expires: 2026-11-13 + data_sensitivity: + - technical diff --git a/components/places/src/ffi.rs b/components/places/src/ffi.rs index f5e35f645b..6ca2d177d2 100644 --- a/components/places/src/ffi.rs +++ b/components/places/src/ffi.rs @@ -8,6 +8,7 @@ use crate::api::matcher::{self, search_frecent, SearchParams}; pub use crate::api::places_api::places_api_new; pub use crate::error::{warn, Result}; pub use crate::error::{ApiResult, PlacesApiError}; +use crate::glean_metrics::places_manager; pub use crate::import::common::HistoryMigrationResult; use crate::import::import_ios_history; use crate::storage; @@ -111,6 +112,7 @@ pub struct PlacesConnection { impl PlacesConnection { pub fn new(db: PlacesDb) -> Self { + places_manager::connection_initialized.add(1); Self { interrupt_handle: db.new_interrupt_handle(), db: Mutex::new(db), @@ -384,22 +386,43 @@ impl PlacesConnection { db_size_limit: u32, prune_limit: u32, ) -> ApiResult { - self.with_conn(|conn| storage::run_maintenance_prune(conn, db_size_limit, prune_limit)) + let timer_id = places_manager::run_maintenance_prune_time_temp.start(); + let res = + self.with_conn(|conn| storage::run_maintenance_prune(conn, db_size_limit, prune_limit)); + + places_manager::run_maintenance_prune_time_temp.stop_and_accumulate(timer_id); + + res } #[handle_error(crate::Error)] pub fn run_maintenance_vacuum(&self) -> ApiResult<()> { - self.with_conn(storage::run_maintenance_vacuum) + let timer_id = places_manager::run_maintenance_vacuum_time_temp.start(); + let res = self.with_conn(storage::run_maintenance_vacuum); + + places_manager::run_maintenance_vacuum_time_temp.stop_and_accumulate(timer_id); + + res } #[handle_error(crate::Error)] pub fn run_maintenance_optimize(&self) -> ApiResult<()> { - self.with_conn(storage::run_maintenance_optimize) + let timer_id = places_manager::run_maintenance_optimize_time_temp.start(); + let res = self.with_conn(storage::run_maintenance_optimize); + + places_manager::run_maintenance_optimize_time_temp.stop_and_accumulate(timer_id); + + res } #[handle_error(crate::Error)] pub fn run_maintenance_checkpoint(&self) -> ApiResult<()> { - self.with_conn(storage::run_maintenance_checkpoint) + let timer_id = places_manager::run_maintenance_chk_pnt_time_temp.start(); + let res = self.with_conn(storage::run_maintenance_checkpoint); + + places_manager::run_maintenance_chk_pnt_time_temp.stop_and_accumulate(timer_id); + + res } #[handle_error(crate::Error)] diff --git a/components/places/src/lib.rs b/components/places/src/lib.rs index 3e7ff3df5c..432ce70113 100644 --- a/components/places/src/lib.rs +++ b/components/places/src/lib.rs @@ -38,4 +38,9 @@ pub use crate::types::*; pub use ffi::*; +#[allow(clippy::all)] // Don't lint generated code. +pub mod glean_metrics { + include!(concat!(env!("OUT_DIR"), "/glean_metrics.rs")); +} + uniffi::include_scaffolding!("places"); diff --git a/tools/dependency_summary.py b/tools/dependency_summary.py index 6dae4f2153..3e9dfddd91 100755 --- a/tools/dependency_summary.py +++ b/tools/dependency_summary.py @@ -718,6 +718,16 @@ "fixup": "https://raw.githubusercontent.com/mozilla/glean/main/LICENSE", }, }, + "glean-sym": { + "license_url": { + "check": None, + "fixup": "https://github.com/mozilla/glean/blob/main/LICENSE", + }, + "license_file": { + "check": None, + "fixup": "https://raw.githubusercontent.com/mozilla/glean/main/LICENSE", + }, + }, "lmdb-rkv-sys": { "license_url": { "check": None, From 12393f6aa742b01224b42620453ad664a4b4ef33 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Wed, 13 May 2026 14:39:34 +0200 Subject: [PATCH 2/2] Limit glean-sym usage to android --- components/places/build.rs | 15 ++++++++++----- components/places/src/ffi.rs | 11 +++++++++++ components/places/src/lib.rs | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/places/build.rs b/components/places/build.rs index deabb9fe2e..fa4b5578a1 100644 --- a/components/places/build.rs +++ b/components/places/build.rs @@ -7,9 +7,14 @@ use glean_build::Builder; fn main() { uniffi::generate_scaffolding("./src/places.udl").unwrap(); - Builder::default() - .file("metrics.yaml") - .format("rust_sym") - .generate() - .expect("Error generating Glean Rust bindings"); + if let Ok("android") = std::env::var("CARGO_CFG_TARGET_OS") + .as_ref() + .map(String::as_str) + { + Builder::default() + .file("metrics.yaml") + .format("rust_sym") + .generate() + .expect("Error generating Glean Rust bindings"); + } } diff --git a/components/places/src/ffi.rs b/components/places/src/ffi.rs index 6ca2d177d2..492a0c2761 100644 --- a/components/places/src/ffi.rs +++ b/components/places/src/ffi.rs @@ -8,6 +8,7 @@ use crate::api::matcher::{self, search_frecent, SearchParams}; pub use crate::api::places_api::places_api_new; pub use crate::error::{warn, Result}; pub use crate::error::{ApiResult, PlacesApiError}; +#[cfg(target_os = "android")] use crate::glean_metrics::places_manager; pub use crate::import::common::HistoryMigrationResult; use crate::import::import_ios_history; @@ -112,7 +113,9 @@ pub struct PlacesConnection { impl PlacesConnection { pub fn new(db: PlacesDb) -> Self { + #[cfg(target_os = "android")] places_manager::connection_initialized.add(1); + Self { interrupt_handle: db.new_interrupt_handle(), db: Mutex::new(db), @@ -386,10 +389,12 @@ impl PlacesConnection { db_size_limit: u32, prune_limit: u32, ) -> ApiResult { + #[cfg(target_os = "android")] let timer_id = places_manager::run_maintenance_prune_time_temp.start(); let res = self.with_conn(|conn| storage::run_maintenance_prune(conn, db_size_limit, prune_limit)); + #[cfg(target_os = "android")] places_manager::run_maintenance_prune_time_temp.stop_and_accumulate(timer_id); res @@ -397,9 +402,11 @@ impl PlacesConnection { #[handle_error(crate::Error)] pub fn run_maintenance_vacuum(&self) -> ApiResult<()> { + #[cfg(target_os = "android")] let timer_id = places_manager::run_maintenance_vacuum_time_temp.start(); let res = self.with_conn(storage::run_maintenance_vacuum); + #[cfg(target_os = "android")] places_manager::run_maintenance_vacuum_time_temp.stop_and_accumulate(timer_id); res @@ -407,9 +414,11 @@ impl PlacesConnection { #[handle_error(crate::Error)] pub fn run_maintenance_optimize(&self) -> ApiResult<()> { + #[cfg(target_os = "android")] let timer_id = places_manager::run_maintenance_optimize_time_temp.start(); let res = self.with_conn(storage::run_maintenance_optimize); + #[cfg(target_os = "android")] places_manager::run_maintenance_optimize_time_temp.stop_and_accumulate(timer_id); res @@ -417,9 +426,11 @@ impl PlacesConnection { #[handle_error(crate::Error)] pub fn run_maintenance_checkpoint(&self) -> ApiResult<()> { + #[cfg(target_os = "android")] let timer_id = places_manager::run_maintenance_chk_pnt_time_temp.start(); let res = self.with_conn(storage::run_maintenance_checkpoint); + #[cfg(target_os = "android")] places_manager::run_maintenance_chk_pnt_time_temp.stop_and_accumulate(timer_id); res diff --git a/components/places/src/lib.rs b/components/places/src/lib.rs index 432ce70113..e6e3499ba3 100644 --- a/components/places/src/lib.rs +++ b/components/places/src/lib.rs @@ -38,6 +38,7 @@ pub use crate::types::*; pub use ffi::*; +#[cfg(target_os = "android")] #[allow(clippy::all)] // Don't lint generated code. pub mod glean_metrics { include!(concat!(env!("OUT_DIR"), "/glean_metrics.rs"));