diff --git a/stress/src/metrics_histogram.rs b/stress/src/metrics_histogram.rs index 860d2bdd20..e74a2b3d10 100644 --- a/stress/src/metrics_histogram.rs +++ b/stress/src/metrics_histogram.rs @@ -37,13 +37,30 @@ lazy_static! { thread_local! { /// Store random number generator for each thread static CURRENT_RNG: RefCell = RefCell::new(rngs::SmallRng::from_entropy()); + + static PROVIDER_PER_THREAD: SdkMeterProvider = SdkMeterProvider::builder() + .with_reader(ManualReader::builder().build()) + .build(); + + static HISTOGRAM_PER_THREAD: Histogram = PROVIDER_PER_THREAD.with(|h|h.meter("test").u64_histogram("hello").build()); } fn main() { - throughput::test_throughput(test_histogram); + match std::env::args().find(|arg| arg == "--per-thread") { + None => throughput::test_throughput(test_histogram_shared), + Some(_) => throughput::test_throughput(test_histogram_per_thread), + } +} + +fn test_histogram_shared() { + test_histogram(&HISTOGRAM); +} + +fn test_histogram_per_thread() { + HISTOGRAM_PER_THREAD.with(|h| test_histogram(h)); } -fn test_histogram() { +fn test_histogram(histogram: &Histogram) { let len = ATTRIBUTE_VALUES.len(); let rands = CURRENT_RNG.with(|rng| { let mut rng = rng.borrow_mut(); @@ -58,7 +75,7 @@ fn test_histogram() { let index_third_attribute = rands[2]; // each attribute has 10 possible values, so there are 1000 possible combinations (time-series) - HISTOGRAM.record( + histogram.record( 1, &[ KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),