File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed
Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -165,8 +165,15 @@ internal void ReportPendingConnectionRequestStart()
165165 internal void ReportPendingConnectionRequestStop ( )
166166 => PendingConnectionRequests . Add ( - 1 , _poolNameTag ) ;
167167
168- internal void ReportConnectionCreateTime ( TimeSpan duration )
169- => ConnectionCreateTime . Record ( duration . TotalSeconds , _poolNameTag ) ;
168+ internal void ReportConnectionCreateTime ( long startTimestamp )
169+ {
170+ #if NET7_0_OR_GREATER
171+ var duration = Stopwatch . GetElapsedTime ( startTimestamp ) ;
172+ #else
173+ var duration = new TimeSpan ( ( long ) ( ( Stopwatch . GetTimestamp ( ) - startTimestamp ) * StopWatchTickFrequency ) ) ;
174+ #endif
175+ ConnectionCreateTime . Record ( duration . TotalSeconds , _poolNameTag ) ;
176+ }
170177
171178 static IEnumerable < Measurement < int > > GetConnectionUsage ( )
172179 {
Original file line number Diff line number Diff line change @@ -268,14 +268,10 @@ bool CheckIdleConnector([NotNullWhen(true)] NpgsqlConnector? connector)
268268 try
269269 {
270270 // We've managed to increase the open counter, open a physical connections.
271- #if NET7_0_OR_GREATER
272271 var startTime = Stopwatch . GetTimestamp ( ) ;
273- #endif
274272 var connector = new NpgsqlConnector ( this , conn ) { ClearCounter = _clearCounter } ;
275273 await connector . Open ( timeout , async , cancellationToken ) . ConfigureAwait( false ) ;
276- #if NET7_0_OR_GREATER
277- MetricsReporter . ReportConnectionCreateTime ( Stopwatch . GetElapsedTime ( startTime ) ) ;
278- #endif
274+ MetricsReporter . ReportConnectionCreateTime ( startTime ) ;
279275
280276 var i = 0 ;
281277 for ( ; i < MaxConnections ; i ++ )
You can’t perform that action at this time.
0 commit comments