Skip to content

Commit

Permalink
bug 1704106 - Expose timespan's set_raw to Rust consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
chutten committed Apr 9, 2021
1 parent 1c08e76 commit 83fd676
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* RLB
* Provide an internal-use-only API to pass in raw samples for timing distributions ([#1561](https://github.com/mozilla/glean/pull/1561)).
* Expose Timespan's `set_raw` to Rust ([#1578](https://github.com/mozilla/glean/pull/1578)).
* Android
* BUGFIX: `TimespanMetricType.measure` and `TimingDistributionMetricType.measure` won't get inlined anymore ([#1560](https://github.com/mozilla/glean/pull/1560)).
This avoids a potential bug where a `return` used inside the closure would end up not measuring the time.
Expand Down
11 changes: 11 additions & 0 deletions glean-core/rlb/src/private/timespan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use std::sync::{Arc, RwLock};
use std::time::Duration;

use inherent::inherent;

Expand Down Expand Up @@ -68,6 +69,16 @@ impl glean_core::traits::Timespan for TimespanMetric {
});
}

fn set_raw(&self, elapsed: Duration) {
let metric = Arc::clone(&self.0);
crate::launch_with_glean(move |glean| {
let inner = metric
.write()
.expect("Lock poisoned for timespan metric on set_raw.");
inner.set_raw(glean, elapsed)
});
}

fn test_get_value<'a, S: Into<Option<&'a str>>>(&self, ping_name: S) -> Option<u64> {
crate::block_on_dispatcher();

Expand Down
12 changes: 12 additions & 0 deletions glean-core/src/traits/timespan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::ErrorType;
use std::time::Duration;

/// A description for the [`TimespanMetric`](crate::metrics::TimespanMetric) type.
///
Expand All @@ -28,6 +29,17 @@ pub trait Timespan {
/// if no [`start`](Timespan::start) was called.
fn cancel(&self);

/// Explicitly sets the timespan value.
///
/// This API should only be used if your library or application requires recording
/// spans of time in a way that cannot make use of
/// [`start`](Timespan::start)/[`stop`](Timespan::stop)/[`cancel`](Timespan::cancel).
///
/// # Arguments
///
/// * `elapsed` - The elapsed time to record.
fn set_raw(&self, elapsed: Duration);

/// **Exported for test purposes.**
///
/// Gets the currently stored value as an integer.
Expand Down

0 comments on commit 83fd676

Please sign in to comment.