@@ -77,7 +77,7 @@ private async Task ConnectAndStartProfilingImpl(int pid, bool sampler, string ba
77
77
78
78
public async Task StartProfiling ( CancellationToken token )
79
79
{
80
- // We want to make sure that we are not disposing while we are connecting
80
+ // We want to make sure that we are not disposing while we are starting a session
81
81
await _semaphoreSlim . WaitAsync ( token ) ;
82
82
83
83
try
@@ -143,6 +143,9 @@ public async Task WaitForConnectAndStartSession()
143
143
var pattern = $ "dotnet-diagnostic-{ pid } -*-socket";
144
144
string ? diagnosticPortSocket = null ;
145
145
146
+ int waitForNextCheckDelayInMs = 10 ;
147
+
148
+ // This loop is blocking until a file is available or the token is cancelled
146
149
while ( true )
147
150
{
148
151
if ( Directory . Exists ( tempFolder ) )
@@ -166,7 +169,11 @@ public async Task WaitForConnectAndStartSession()
166
169
}
167
170
}
168
171
169
- await Task . Delay ( 10 , token ) . ConfigureAwait ( false ) ;
172
+ await Task . Delay ( waitForNextCheckDelayInMs , token ) . ConfigureAwait ( false ) ;
173
+
174
+ // Let's increase the delay after each check to lower the overhead
175
+ waitForNextCheckDelayInMs += 10 ;
176
+ waitForNextCheckDelayInMs = Math . Max ( waitForNextCheckDelayInMs , 100 ) ;
170
177
}
171
178
172
179
return diagnosticPortSocket ;
@@ -246,38 +253,4 @@ public async ValueTask StopAndDisposeAsync()
246
253
_cancelConnectSource . Dispose ( ) ;
247
254
}
248
255
}
249
-
250
- private async Task StopAsync ( CancellationToken token )
251
- {
252
- if ( _eventPipeSession is null ) return ;
253
-
254
- try
255
- {
256
- await _eventPipeSession . StopAsync ( token ) . ConfigureAwait ( false ) ;
257
- }
258
- catch ( EndOfStreamException )
259
- {
260
-
261
- }
262
- catch ( TimeoutException )
263
- {
264
-
265
- }
266
- catch ( OperationCanceledException )
267
- {
268
-
269
- }
270
- catch ( PlatformNotSupportedException )
271
- {
272
-
273
- }
274
- catch ( ServerNotAvailableException )
275
- {
276
-
277
- }
278
- catch ( SocketException )
279
- {
280
-
281
- }
282
- }
283
256
}
0 commit comments