-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently it only contains one very simplistic benchmark: Setting 2 metrics and submitting a custom ping. Why an additional crate? This way we don't add any new (dev) dependencies to the crates that get released.
- Loading branch information
Showing
8 changed files
with
818 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "benchmark" | ||
version = "0.1.0" | ||
authors = ["Jan-Erik Rediger <jrediger@mozilla.com>"] | ||
description = "Benchmark the glean-core crate" | ||
readme = "README.md" | ||
license = "MPL-2.0" | ||
edition = "2018" | ||
publish = false | ||
|
||
[lib] | ||
bench = false | ||
|
||
[dependencies] | ||
# No version specified, this crate never gets published | ||
glean-core = { path = ".." } | ||
|
||
[dev-dependencies] | ||
tempfile = "3.1.0" | ||
criterion = "0.3" | ||
|
||
[[bench]] | ||
name = "bench_basic" | ||
harness = false |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Glean Benchmarks | ||
|
||
The `Glean SDK` is a modern approach for a Telemetry library and is part of the [Glean project](https://docs.telemetry.mozilla.org/concepts/glean/glean.html). | ||
|
||
## Benchmarks | ||
|
||
This crates provides simple benchmarks for Glean, based on the [criterion benchmark framework](https://bheisler.github.io/criterion.rs/book/criterion_rs.html). | ||
The library itself does not contain additional code. | ||
|
||
### Available benchmarks | ||
|
||
* [`benches/bench_basic.rs`](benches/bench_basic.rs) - Setting metrics and submitting a custom ping | ||
|
||
### How to run the benchmarks | ||
|
||
From the top-level directory of the repository run: | ||
|
||
``` | ||
cargo bench -p benchmark | ||
``` | ||
|
||
This is also available as a `make` task: | ||
|
||
``` | ||
make bench-rust | ||
``` | ||
|
||
Any additional run compare results to the preceding run. | ||
|
||
### Results | ||
|
||
After running the benchmarks, an HTML-rendered report can be found in `target/criterion/report/index.html`. | ||
We do not provide any results here as the absolute numbers are unreliable. | ||
Benchmark timings across code changes are more important. | ||
|
||
### Why an additional crate? | ||
|
||
This way we don't add any new (dev) dependencies to the crates that get released. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use benchmark::glean_core::{metrics::*, CommonMetricData, Configuration, Glean}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
/// Set metrics and submit a custom ping. | ||
/// | ||
/// Glean, the metrics and the custom ping are instantiated before benchmarking the set/submit | ||
/// functionality. | ||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let data_dir = tempfile::tempdir().unwrap(); | ||
let tmpname = data_dir.path().display().to_string(); | ||
let cfg = Configuration { | ||
upload_enabled: true, | ||
data_path: tmpname, | ||
application_id: "glean.bench".into(), | ||
max_events: None, | ||
delay_ping_lifetime_io: false, | ||
}; | ||
|
||
let mut glean = Glean::new(cfg).unwrap(); | ||
|
||
let ping = PingType::new("sample", true, false); | ||
glean.register_ping_type(&ping); | ||
|
||
let call_counter: CounterMetric = CounterMetric::new(CommonMetricData { | ||
name: "calls".into(), | ||
category: "local".into(), | ||
send_in_pings: vec!["sample".into()], | ||
..Default::default() | ||
}); | ||
|
||
let string: StringMetric = StringMetric::new(CommonMetricData { | ||
name: "string".into(), | ||
category: "local".into(), | ||
send_in_pings: vec!["sample".into()], | ||
..Default::default() | ||
}); | ||
|
||
c.bench_function("glean set and submit", |b| { | ||
b.iter(|| { | ||
call_counter.add(&glean, 1); | ||
string.set(&glean, "hello world"); | ||
glean.submit_ping(&ping).unwrap(); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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 https://mozilla.org/MPL/2.0/. | ||
|
||
//! # Glean benchmarks | ||
//! | ||
//! Benchmarking the glean-core crate. Find benchmarks in the `benches/` directory. | ||
//! | ||
//! All documentation for Glean can be found online: | ||
//! | ||
//! ## [The Glean SDK Book](https://mozilla.github.io/glean) | ||
|
||
// Re-export glean_core in total. | ||
pub use glean_core; |