@@ -37,13 +37,30 @@ lazy_static! {
37
37
thread_local ! {
38
38
/// Store random number generator for each thread
39
39
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( ) ) ;
40
46
}
41
47
42
48
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) ) ;
44
61
}
45
62
46
- fn test_histogram ( ) {
63
+ fn test_histogram ( histogram : & Histogram < u64 > ) {
47
64
let len = ATTRIBUTE_VALUES . len ( ) ;
48
65
let rands = CURRENT_RNG . with ( |rng| {
49
66
let mut rng = rng. borrow_mut ( ) ;
@@ -58,7 +75,7 @@ fn test_histogram() {
58
75
let index_third_attribute = rands[ 2 ] ;
59
76
60
77
// each attribute has 10 possible values, so there are 1000 possible combinations (time-series)
61
- HISTOGRAM . record (
78
+ histogram . record (
62
79
1 ,
63
80
& [
64
81
KeyValue :: new ( "attribute1" , ATTRIBUTE_VALUES [ index_first_attribute] ) ,
0 commit comments