@@ -19,73 +19,79 @@ use metrics_util::{
19
19
} ;
20
20
21
21
pub ( crate ) struct AtomicCounter {
22
- is_absolute : AtomicBool ,
23
- last : AtomicU64 ,
22
+ // is_absolute: AtomicBool,
23
+ // last: AtomicU64,
24
24
current : AtomicU64 ,
25
- updates : AtomicU64 ,
25
+ // updates: AtomicU64,
26
26
}
27
27
28
28
impl AtomicCounter {
29
29
/// Creates a new `AtomicCounter`.
30
30
fn new ( ) -> Self {
31
31
Self {
32
- is_absolute : AtomicBool :: new ( false ) ,
33
- last : AtomicU64 :: new ( 0 ) ,
32
+ // is_absolute: AtomicBool::new(false),
33
+ // last: AtomicU64::new(0),
34
34
current : AtomicU64 :: new ( 0 ) ,
35
- updates : AtomicU64 :: new ( 0 ) ,
35
+ // updates: AtomicU64::new(0),
36
36
}
37
37
}
38
38
39
39
/// Flushes the current counter value, returning the delta of the counter value, and the number of updates, since
40
40
/// the last flush.
41
41
pub fn flush ( & self ) -> ( u64 , u64 ) {
42
- let current = self . current . load ( Acquire ) ;
43
- let last = self . last . swap ( current, AcqRel ) ;
44
- let delta = current. wrapping_sub ( last) ;
45
- let updates = self . updates . swap ( 0 , AcqRel ) ;
46
-
47
- ( delta, updates)
42
+ //let current = self.current.load(Acquire);
43
+ //let last = self.last.swap(current, AcqRel);
44
+ //let delta = current.wrapping_sub(last);
45
+ //let updates = self.updates.swap(0, AcqRel);
46
+
47
+ //(delta, updates)
48
+ let delta = self . current . swap ( 0 , Relaxed ) ;
49
+ ( delta, if delta > 0 { 1 } else { 0 } )
48
50
}
49
51
}
50
52
51
53
impl CounterFn for AtomicCounter {
52
54
fn increment ( & self , value : u64 ) {
53
- self . is_absolute . store ( false , Release ) ;
55
+ // self.is_absolute.store(false, Release);
54
56
self . current . fetch_add ( value, Relaxed ) ;
55
- self . updates . fetch_add ( 1 , Relaxed ) ;
57
+ // self.updates.fetch_add(1, Relaxed);
56
58
}
57
59
58
60
fn absolute ( & self , value : u64 ) {
59
61
// Ensure the counter is in absolute mode, and if it wasn't already, reset `last` to `value` to give ourselves a
60
62
// consistent starting point when flushing. This ensures that we only start flushing deltas once we've gotten
61
63
// two consecutive absolute values, since otherwise we might be calculating a delta between a `last` of 0 and a
62
64
// very large `current` value.
63
- if !self . is_absolute . swap ( true , Release ) {
64
- self . last . store ( value, Release ) ;
65
- }
65
+ // if !self.is_absolute.swap(true, Release) {
66
+ // self.last.store(value, Release);
67
+ // }
66
68
67
- self . current . store ( value, Release ) ;
68
- self . updates . fetch_add ( 1 , Relaxed ) ;
69
+ // self.current.store(value, Release);
70
+ // self.updates.fetch_add(1, Relaxed);
69
71
}
70
72
}
71
73
72
74
pub ( crate ) struct AtomicGauge {
73
75
inner : AtomicU64 ,
74
- updates : AtomicU64 ,
76
+ // updates: AtomicU64,
75
77
}
76
78
77
79
impl AtomicGauge {
78
80
/// Creates a new `AtomicGauge`.
79
81
fn new ( ) -> Self {
80
- Self { inner : AtomicU64 :: new ( 0.0f64 . to_bits ( ) ) , updates : AtomicU64 :: new ( 0 ) }
82
+ Self {
83
+ inner : AtomicU64 :: new ( 0.0f64 . to_bits ( ) ) ,
84
+ //updates: AtomicU64::new(0),
85
+ }
81
86
}
82
87
83
88
/// Flushes the current gauge value and the number of updates since the last flush.
84
89
pub fn flush ( & self ) -> ( f64 , u64 ) {
85
90
let current = f64:: from_bits ( self . inner . load ( Acquire ) ) ;
86
- let updates = self . updates . swap ( 0 , AcqRel ) ;
91
+ // let updates = self.updates.swap(0, AcqRel);
87
92
88
- ( current, updates)
93
+ //(current, updates)
94
+ ( current, 0 )
89
95
}
90
96
}
91
97
@@ -97,7 +103,7 @@ impl GaugeFn for AtomicGauge {
97
103
Some ( f64:: to_bits ( new) )
98
104
} )
99
105
. expect ( "should never fail to update gauge" ) ;
100
- self . updates . fetch_add ( 1 , Relaxed ) ;
106
+ // self.updates.fetch_add(1, Relaxed);
101
107
}
102
108
103
109
fn decrement ( & self , value : f64 ) {
@@ -107,12 +113,12 @@ impl GaugeFn for AtomicGauge {
107
113
Some ( f64:: to_bits ( new) )
108
114
} )
109
115
. expect ( "should never fail to update gauge" ) ;
110
- self . updates . fetch_add ( 1 , Relaxed ) ;
116
+ // self.updates.fetch_add(1, Relaxed);
111
117
}
112
118
113
119
fn set ( & self , value : f64 ) {
114
120
self . inner . store ( value. to_bits ( ) , Release ) ;
115
- self . updates . fetch_add ( 1 , Relaxed ) ;
121
+ // self.updates.fetch_add(1, Relaxed);
116
122
}
117
123
}
118
124
0 commit comments