@@ -74,6 +74,8 @@ pub(crate) struct Connection {
7474
7575 pub ( crate ) generation : ConnectionGeneration ,
7676
77+ pub ( crate ) time_created : Instant ,
78+
7779 /// The cached StreamDescription from the connection's handshake.
7880 pub ( super ) stream_description : Option < StreamDescription > ,
7981
@@ -127,11 +129,13 @@ impl Connection {
127129 stream : AsyncStream ,
128130 id : u32 ,
129131 generation : ConnectionGeneration ,
132+ time_created : Instant ,
130133 ) -> Self {
131134 Self {
132135 id,
133136 server_id : None ,
134137 generation,
138+ time_created,
135139 pool_manager : None ,
136140 command_executing : false ,
137141 ready_and_available_time : None ,
@@ -159,6 +163,7 @@ impl Connection {
159163 stream,
160164 pending_connection. id ,
161165 generation,
166+ pending_connection. time_created ,
162167 ) ;
163168 conn. event_emitter = Some ( pending_connection. event_emitter ) ;
164169 conn
@@ -167,7 +172,13 @@ impl Connection {
167172 /// Create a connection intended for monitoring purposes.
168173 /// TODO: RUST-1454 Rename this to just `new`, drop the pooling-specific data.
169174 pub ( crate ) fn new_monitoring ( address : ServerAddress , stream : AsyncStream , id : u32 ) -> Self {
170- Self :: new ( address, stream, id, ConnectionGeneration :: Monitoring )
175+ Self :: new (
176+ address,
177+ stream,
178+ id,
179+ ConnectionGeneration :: Monitoring ,
180+ Instant :: now ( ) ,
181+ )
171182 }
172183
173184 pub ( crate ) fn info ( & self ) -> ConnectionInfo {
@@ -226,10 +237,11 @@ impl Connection {
226237 }
227238
228239 /// Helper to create a `ConnectionCheckedOutEvent` for the connection.
229- pub ( super ) fn checked_out_event ( & self ) -> ConnectionCheckedOutEvent {
240+ pub ( super ) fn checked_out_event ( & self , time_started : Instant ) -> ConnectionCheckedOutEvent {
230241 ConnectionCheckedOutEvent {
231242 address : self . address . clone ( ) ,
232243 connection_id : self . id ,
244+ duration : Instant :: now ( ) - time_started,
233245 }
234246 }
235247
@@ -246,6 +258,7 @@ impl Connection {
246258 ConnectionReadyEvent {
247259 address : self . address . clone ( ) ,
248260 connection_id : self . id ,
261+ duration : Instant :: now ( ) - self . time_created ,
249262 }
250263 }
251264
@@ -422,6 +435,7 @@ impl Connection {
422435 server_id : self . server_id ,
423436 address : self . address . clone ( ) ,
424437 generation : self . generation ,
438+ time_created : self . time_created ,
425439 stream : std:: mem:: replace ( & mut self . stream , BufStream :: new ( AsyncStream :: Null ) ) ,
426440 event_emitter : self . event_emitter . take ( ) ,
427441 stream_description : self . stream_description . take ( ) ,
@@ -599,6 +613,7 @@ pub(crate) struct PendingConnection {
599613 pub ( crate ) address : ServerAddress ,
600614 pub ( crate ) generation : PoolGeneration ,
601615 pub ( crate ) event_emitter : CmapEventEmitter ,
616+ pub ( crate ) time_created : Instant ,
602617}
603618
604619impl PendingConnection {
0 commit comments