File tree 2 files changed +14
-7
lines changed
2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -442,8 +442,7 @@ impl<M: Manager> Pool<M> {
442
442
443
443
let mut internals = self . 0 . internals . lock ( ) . await ;
444
444
445
- internals. wait_duration += wait_guard. elapsed ( ) ;
446
- drop ( wait_guard) ;
445
+ internals. wait_duration += wait_guard. into_elapsed ( ) ;
447
446
448
447
let conn = internals. free_conns . pop ( ) ;
449
448
let internal_config = internals. config . clone ( ) ;
Original file line number Diff line number Diff line change @@ -59,25 +59,33 @@ impl Drop for GaugeGuard {
59
59
}
60
60
61
61
pub ( crate ) struct DurationHistogramGuard {
62
- start : Instant ,
62
+ start : Option < Instant > ,
63
63
key : & ' static str ,
64
64
}
65
65
66
66
impl DurationHistogramGuard {
67
67
pub ( crate ) fn start ( key : & ' static str ) -> Self {
68
68
Self {
69
- start : Instant :: now ( ) ,
69
+ start : Some ( Instant :: now ( ) ) ,
70
70
key,
71
71
}
72
72
}
73
73
74
- pub ( crate ) fn elapsed ( & self ) -> Duration {
75
- self . start . elapsed ( )
74
+ pub ( crate ) fn into_elapsed ( mut self ) -> Duration {
75
+ let start = self
76
+ . start
77
+ . take ( )
78
+ . expect ( "start time was unset without consuming or dropping the guard" ) ;
79
+ let elapsed = start. elapsed ( ) ;
80
+ histogram ! ( self . key) . record ( elapsed) ;
81
+ elapsed
76
82
}
77
83
}
78
84
79
85
impl Drop for DurationHistogramGuard {
80
86
fn drop ( & mut self ) {
81
- histogram ! ( self . key) . record ( self . start . elapsed ( ) ) ;
87
+ if let Some ( start) = self . start . take ( ) {
88
+ histogram ! ( self . key) . record ( start. elapsed ( ) ) ;
89
+ }
82
90
}
83
91
}
You can’t perform that action at this time.
0 commit comments