@@ -144,12 +144,12 @@ private UltraSamplerProfilerState(UltraProfilerOptions options, DiagnosticsClien
144
144
_token = token ;
145
145
_ultraDiagnosticsClient = ultraDiagnosticsClient ;
146
146
_ultraNetTraceFilePath = Path . Combine ( Environment . CurrentDirectory , $ "{ baseName } _sampler_{ pid } .nettrace") ;
147
- _ultraNetTraceFileStream = new FileStream ( _ultraNetTraceFilePath , FileMode . Create , FileAccess . Write , FileShare . Read ) ;
147
+ _ultraNetTraceFileStream = new FileStream ( _ultraNetTraceFilePath , FileMode . Create , FileAccess . Write , FileShare . Read , 65536 , FileOptions . Asynchronous ) ;
148
148
if ( mainDiagnosticsClient != null )
149
149
{
150
150
_mainDiagnosticsClient = mainDiagnosticsClient ;
151
151
_mainNetTraceFilePath = Path . Combine ( Environment . CurrentDirectory , $ "{ baseName } _main_{ pid } .nettrace") ;
152
- _mainNetTraceFileStream = new FileStream ( _mainNetTraceFilePath , FileMode . Create , FileAccess . Write , FileShare . Read ) ;
152
+ _mainNetTraceFileStream = new FileStream ( _mainNetTraceFilePath , FileMode . Create , FileAccess . Write , FileShare . Read , 65536 , FileOptions . Asynchronous ) ;
153
153
}
154
154
}
155
155
@@ -191,18 +191,13 @@ public static async Task<UltraSamplerProfilerState> Connect(string baseName, int
191
191
var diagnosticClientMain = new DiagnosticsClient ( pid ) ;
192
192
var diagnosticClientUltra = await DiagnosticsClientConnector . FromDiagnosticPort ( ultraDiagnosticPortSocket , token ) ;
193
193
194
- if ( diagnosticClientUltra is null )
195
- {
196
-
197
- }
198
-
199
194
var timeoutSource = new CancellationTokenSource ( ) ;
200
195
var linkedCancellationTokenSource = CancellationTokenSource . CreateLinkedTokenSource ( token , timeoutSource . Token ) ;
201
196
202
197
try
203
198
{
204
199
timeoutSource . CancelAfter ( 1000 ) ;
205
- await diagnosticClientUltra . Instance . WaitForConnectionAsync ( linkedCancellationTokenSource . Token ) . ConfigureAwait ( false ) ;
200
+ await diagnosticClientUltra ! . Instance . WaitForConnectionAsync ( linkedCancellationTokenSource . Token ) . ConfigureAwait ( false ) ;
206
201
await diagnosticClientMain . WaitForConnectionAsync ( linkedCancellationTokenSource . Token ) . ConfigureAwait ( false ) ;
207
202
}
208
203
catch ( OperationCanceledException ) when ( timeoutSource . IsCancellationRequested )
@@ -259,23 +254,24 @@ public async Task StartProfiling()
259
254
260
255
public async Task Stop ( )
261
256
{
262
- if ( _ultraSession is not null )
257
+ if ( _ultraEventStreamCopyTask is not null )
263
258
{
264
- await _ultraSession . StopAsync ( _token ) . ConfigureAwait ( false ) ;
259
+ await _ultraEventStreamCopyTask . ConfigureAwait ( false ) ;
265
260
}
266
- if ( _mainSession is not null )
261
+
262
+ if ( _mainEventStreamCopyTask is not null )
267
263
{
268
- await _mainSession . StopAsync ( _token ) . ConfigureAwait ( false ) ;
264
+ await _mainEventStreamCopyTask . ConfigureAwait ( false ) ;
269
265
}
270
266
271
- if ( _ultraEventStreamCopyTask is not null )
267
+ if ( _ultraSession is not null )
272
268
{
273
- await _ultraEventStreamCopyTask . ConfigureAwait ( false ) ;
269
+ await _ultraSession . StopAsync ( _token ) . ConfigureAwait ( false ) ;
274
270
}
275
271
276
- if ( _mainEventStreamCopyTask is not null )
272
+ if ( _mainSession is not null )
277
273
{
278
- await _mainEventStreamCopyTask . ConfigureAwait ( false ) ;
274
+ await _mainSession . StopAsync ( _token ) . ConfigureAwait ( false ) ;
279
275
}
280
276
}
281
277
0 commit comments