Skip to content

Commit e68fe94

Browse files
authored
Enable per-thread instances for histogram stress test (#2659)
1 parent 0592075 commit e68fe94

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

stress/src/metrics_histogram.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,30 @@ lazy_static! {
3737
thread_local! {
3838
/// Store random number generator for each thread
3939
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
40+
41+
static PROVIDER_PER_THREAD: SdkMeterProvider = SdkMeterProvider::builder()
42+
.with_reader(ManualReader::builder().build())
43+
.build();
44+
45+
static HISTOGRAM_PER_THREAD: Histogram<u64> = PROVIDER_PER_THREAD.with(|h|h.meter("test").u64_histogram("hello").build());
4046
}
4147

4248
fn main() {
43-
throughput::test_throughput(test_histogram);
49+
match std::env::args().find(|arg| arg == "--per-thread") {
50+
None => throughput::test_throughput(test_histogram_shared),
51+
Some(_) => throughput::test_throughput(test_histogram_per_thread),
52+
}
53+
}
54+
55+
fn test_histogram_shared() {
56+
test_histogram(&HISTOGRAM);
57+
}
58+
59+
fn test_histogram_per_thread() {
60+
HISTOGRAM_PER_THREAD.with(|h| test_histogram(h));
4461
}
4562

46-
fn test_histogram() {
63+
fn test_histogram(histogram: &Histogram<u64>) {
4764
let len = ATTRIBUTE_VALUES.len();
4865
let rands = CURRENT_RNG.with(|rng| {
4966
let mut rng = rng.borrow_mut();
@@ -58,7 +75,7 @@ fn test_histogram() {
5875
let index_third_attribute = rands[2];
5976

6077
// each attribute has 10 possible values, so there are 1000 possible combinations (time-series)
61-
HISTOGRAM.record(
78+
histogram.record(
6279
1,
6380
&[
6481
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),

0 commit comments

Comments
 (0)