Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test-python: build-python ## Run all Python tests
lint: lint-rust lint-kotlin lint-swift lint-yaml lint-python

lint-rust: ## Run cargo-clippy to lint Rust code
cargo clippy --all --all-targets --features "enable_env_logger gecko benchmark" -- -D warnings -A unknown-lints
cargo clippy --all --all-targets --features "enable_env_logger benchmark" -- -D warnings -A unknown-lints

lint-kotlin: ## Run ktlint to lint Kotlin code
./gradlew lint ktlint detekt
Expand Down
3 changes: 2 additions & 1 deletion glean-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ malloc_size_of_derive = "0.1.3"
malloc_size_of = { version = "0.2.2", package = "wr_malloc_size_of", default-features = false, features = ["once_cell"] }
rusqlite = { version = "0.37.0", features = ["bundled"], optional = true }
rmp-serde = "1.3.1"
gecko-profiler = { version = "0.1.0", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
android_logger = { version = "0.12.0", default-features = false }
Expand All @@ -71,7 +72,7 @@ uniffi = { version = "0.32.0", default-features = false, features = ["build"] }
# Enable `env_logger`. Only works on non-Android non-iOS targets.
enable_env_logger = ["env_logger"]
# Enable gecko-specific APIs
gecko = []
gecko = ["dep:gecko-profiler"]
# Expose some internals for easier benchmarking
benchmark = []
# Explicitly link against m-c libraries
Expand Down
36 changes: 36 additions & 0 deletions glean-core/src/database/rkv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Mutex, RwLock};
use std::time::{Duration, Instant};

#[cfg(feature = "gecko")]
use gecko_profiler::{
gecko_profiler_category, lazy_add_marker, MarkerOptions, MarkerTiming, ProfilerMarker,
ProfilerTime,
};
use malloc_size_of::MallocSizeOf;
use rkv::{StoreError, StoreOptions};

Expand All @@ -37,15 +42,46 @@ macro_rules! unwrap_or {
};
}

#[cfg(feature = "gecko")]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct TimingMarker;

#[cfg(feature = "gecko")]
impl ProfilerMarker for TimingMarker {
fn marker_type_name() -> &'static str {
"TimingMarker"
}

fn marker_type_display() -> gecko_profiler::MarkerSchema {
use gecko_profiler::schema::*;
let schema = MarkerSchema::new(&[Location::MarkerChart, Location::MarkerTable]);
schema
}

fn stream_json_marker_data(&self, _json_writer: &mut gecko_profiler::JSONWriter) {}
}

macro_rules! measure_commit {
($this:ident, $expr:expr) => {{
#[cfg(feature = "gecko")]
let profiler_start = ProfilerTime::now();
let now = ::std::time::Instant::now();
let res = $expr;
let elapsed = now.elapsed();
if let Ok(elapsed) = elapsed.as_micros().try_into() {
let mut samples = $this.write_timings.borrow_mut();
samples.push(elapsed);
}
#[cfg(feature = "gecko")]
lazy_add_marker!(
"glean-core::commit",
gecko_profiler_category!(Telemetry),
MarkerOptions {
timing: MarkerTiming::interval_until_now_from(profiler_start),
..Default::default()
},
TimingMarker
);
res
}};
}
Expand Down
40 changes: 40 additions & 0 deletions glean-core/src/database/sqlite/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
use std::sync::{Mutex, MutexGuard};
use std::{fmt::Debug, num::NonZeroU32, path::Path};

#[cfg(feature = "gecko")]
use gecko_profiler::{
gecko_profiler_category, lazy_add_marker, MarkerOptions, MarkerTiming, ProfilerMarker,
ProfilerTime,
};
use rusqlite::{OpenFlags, Transaction, TransactionBehavior};

/// Sets up an SQLite database connection, and either
Expand Down Expand Up @@ -113,11 +118,46 @@ impl Connection {
let mut conn = self.conn.lock().unwrap();
let mut tx = conn.transaction_with_behavior(TransactionBehavior::Immediate)?;
let result = f(&mut tx)?;

#[cfg(feature = "gecko")]
let profiler_start = ProfilerTime::now();

tx.commit()?;

#[cfg(feature = "gecko")]
lazy_add_marker!(
"glean-core::sqlite-commit",
gecko_profiler_category!(Telemetry),
MarkerOptions {
timing: MarkerTiming::interval_until_now_from(profiler_start),
..Default::default()
},
TimingMarker
);

Ok(result)
}
}

#[cfg(feature = "gecko")]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct TimingMarker;

#[cfg(feature = "gecko")]
impl ProfilerMarker for TimingMarker {
fn marker_type_name() -> &'static str {
"TimingMarker"
}

fn marker_type_display() -> gecko_profiler::MarkerSchema {
use gecko_profiler::schema::*;
let schema = MarkerSchema::new(&[Location::MarkerChart, Location::MarkerTable]);
schema
}

fn stream_json_marker_data(&self, _json_writer: &mut gecko_profiler::JSONWriter) {}
}

impl Debug for Connection {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Connection { .. }")
Expand Down
4 changes: 4 additions & 0 deletions supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ criteria = "safe-to-deploy"
version = "2.9.0"
criteria = "safe-to-deploy"

[[exemptions.gecko-profiler]]
version = "0.1.0"
criteria = "safe-to-deploy"

[[exemptions.getrandom]]
version = "0.2.8"
criteria = "safe-to-deploy"
Expand Down
Loading