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
3 changes: 3 additions & 0 deletions samples/rapid-metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ xflags = "0.3.2"

[build-dependencies]
glean-build = { path = "../../glean-core/build" }

[features]
sqlite = ["glean/sqlite"]
51 changes: 51 additions & 0 deletions samples/rapid-metrics/disk-usage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

TMP="${TMPDIR:-/tmp}"

# Remove the temporary data path on all exit conditions
cleanup() {
if [[ -n "$datapath" ]] && [[ -d "$datapath" ]]; then
rm -r "$datapath"
fi
}
trap cleanup INT ABRT TERM EXIT

maxn=${1:-100}
shift
seed=${2:-100}
shift

function runrapid() {
extraargs="$*"
datapath=$(mktemp -d "${TMP}/glean_rapid_metrics.XXXXXXXXXX")
logout=$(mktemp)

fsnotifywatch -r "${datapath}" > "$logout" 2>&1 &
watchpid=$!

echo target/release/rapid-metrics --maxn "$maxn" --seed "$seed" "$datapath" $extraargs
target/release/rapid-metrics --maxn "$maxn" --seed "$seed" "$datapath" $extraargs

kill $watchpid
wait $watchpid

grep -E "total|${datapath}/db" "$logout"
echo
rm -r "$datapath" "$logout"
}

cargo build -p rapid-metrics --release

echo "===== Full write mode (Rkv) ====="
runrapid

echo "===== delay-ping-lifetime mode (Rkv) ====="
runrapid --delay

cargo build -p rapid-metrics --release --features sqlite

echo "===== Full write mode (SQLite) ====="
runrapid

echo "===== delay-ping-lifetime mode (SQLite) ====="
runrapid --delay
50 changes: 43 additions & 7 deletions samples/rapid-metrics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ pub mod glean_metrics {
include!(concat!(env!("OUT_DIR"), "/glean_metrics.rs"));
}

#[derive(Debug, Clone, Copy)]
#[repr(u8)]
enum Action {
Bool,
Counter,
DualLabeledStatic,
String,
Timing,
DualLabeledDyamic,
Persist,
__Last,
}

impl From<u8> for Action {
fn from(val: u8) -> Action {
match val {
0 => Action::Bool,
1 => Action::Counter,
2 => Action::DualLabeledStatic,
3 => Action::String,
4 => Action::Timing,
5 => Action::DualLabeledDyamic,
6 => Action::Persist,
_ => panic!("can't convert {val} to Action"),
}
}
}

#[derive(Debug)]
struct MockUploader;

Expand All @@ -40,6 +68,8 @@ fn main() {
optional -s,--seed seed: u64
/// Number of threads (default: 4)
optional -t,--threads threads: usize
/// Enable ping lifetime IO.
optional -d,--delay
/// Data directory (default: simple-db)
optional path: PathBuf
};
Expand All @@ -52,11 +82,13 @@ fn main() {
let maxn: usize = flags.maxn.unwrap_or(100);
let seed: Option<u64> = flags.seed;
let nthreads = flags.threads.unwrap_or(4);
let delay = flags.delay;

log::info!("Data path: {}", data_path.display());
log::info!("Iterations: {maxn}");
log::info!("Seed: {seed:?}");
log::info!("Threads: {nthreads}");
log::info!("Delay: {delay}");

let mut rng = match seed {
Some(seed) => {
Expand All @@ -71,6 +103,7 @@ fn main() {
.with_server_endpoint("invalid-test-host")
.with_use_core_mps(true)
.with_uploader(uploader)
.with_delay_ping_lifetime_io(delay)
.build();

let client_info = ClientInfoMetrics {
Expand Down Expand Up @@ -98,7 +131,7 @@ fn main() {
let mut timer_id_start = 0;

for i in 0..maxn {
let dice = rng.u32(0..6);
let dice = rng.u8(0..Action::__Last as u8).into();

if let Some(timer_id) = timer_id.take() {
if (i - timer_id_start) == 10 {
Expand All @@ -108,29 +141,29 @@ fn main() {
}

match dice {
0 => {
Action::Bool => {
let val = rng.bool();
log::info!("Setting bool={val}");
glean_metrics::test_metrics::sample_boolean.set(val);
}
1 => {
Action::Counter => {
let val = rng.i32(0..2);
log::info!("Adding counter={val}");
glean_metrics::test_metrics::sample_counter.add(val);
}
2 => {
Action::DualLabeledStatic => {
let val = rng.i32(1..101);
log::info!("Setting dual-labeld val={val}");
glean_metrics::test_metrics::static_static
.get("key1", "category1")
.add(val);
}
3 => {
Action::String => {
let val = format!("cola-{}", rng.u8(0..100));
log::info!("Setting string val={val}");
glean_metrics::test_metrics::sample_string.set(val);
}
4 => {
Action::Timing => {
if let Some(timer_id) = timer_id.take() {
log::info!("Got timer. Stopping timings.");
glean_metrics::test_metrics::timings
Expand All @@ -140,7 +173,7 @@ fn main() {
timer_id = Some(glean_metrics::test_metrics::timings.start());
timer_id_start = i;
}
5 => {
Action::DualLabeledDyamic => {
let key = format!("key-{}", rng.u8(0..16));
let cat = format!("cat-{}", rng.u8(0..16));
let val = rng.i32(1..101);
Expand All @@ -150,6 +183,9 @@ fn main() {
.get(key, cat)
.add(val);
}
Action::Persist => {
glean::persist_ping_lifetime_data();
}
_ => unreachable!(),
}
}
Expand Down
Loading