@@ -28,7 +28,8 @@ public CollectCommandHandler()
28
28
Console = new DefaultConsole ( false ) ;
29
29
StartTraceSessionAsync = async ( client , config , ct ) => new CollectSession ( await client . StartEventPipeSessionAsync ( config , ct ) . ConfigureAwait ( false ) ) ;
30
30
ResumeRuntimeAsync = ( client , ct ) => client . ResumeRuntimeAsync ( ct ) ;
31
- CollectSessionEventStream = name => new FileStream ( name , FileMode . Create , FileAccess . Write ) ;
31
+ CollectSessionEventStream = ( name ) => new FileStream ( name , FileMode . Create , FileAccess . Write ) ;
32
+ GetFileLength = ( path ) => new FileInfo ( path ) . Length ;
32
33
}
33
34
34
35
private void ConsoleWriteLine ( string str )
@@ -409,34 +410,21 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
409
410
if ( printStatusOverTime )
410
411
{
411
412
rewriter = new LineRewriter ( Console ) { LineToClear = Console . CursorTop - 1 } ;
412
- try {
413
- Console . CursorVisible = false ;
414
- }
415
- catch { }
413
+ Console . CursorVisible = false ;
416
414
if ( ! rewriter . IsRewriteConsoleLineSupported )
417
415
{
418
416
ConsoleWriteLine ( "Recording trace in progress. Press <Enter> or <Ctrl+C> to exit..." ) ;
419
417
}
420
418
}
421
419
422
- FileInfo fileInfo = null ;
423
- if ( FileSizeForStatus == 0 )
424
- {
425
- fileInfo = new ( output . FullName ) ;
426
- }
420
+ FileInfo fileInfo = new ( output . FullName ) ;
427
421
Action printStatus = ( ) => {
428
422
if ( printStatusOverTime && rewriter . IsRewriteConsoleLineSupported )
429
423
{
430
424
rewriter ? . RewriteConsoleLine ( ) ;
431
- if ( fileInfo != null )
432
- {
433
- fileInfo . Refresh ( ) ;
434
- ConsoleWriteLine ( $ "[{ stopwatch . Elapsed : dd\\:hh\\:mm\\:ss} ]\t Recording trace { GetSize ( fileInfo . Length ) } ") ;
435
- }
436
- else
437
- {
438
- ConsoleWriteLine ( $ "[{ stopwatch . Elapsed : dd\\:hh\\:mm\\:ss} ]\t Recording trace { GetSize ( FileSizeForStatus ) } ") ;
439
- }
425
+ fileInfo . Refresh ( ) ;
426
+ long length = GetFileLength ( output . FullName ) ;
427
+ ConsoleWriteLine ( $ "[{ stopwatch . Elapsed : dd\\:hh\\:mm\\:ss} ]\t Recording trace { GetSize ( length ) } ") ;
440
428
ConsoleWriteLine ( "Press <Enter> or <Ctrl+C> to exit..." ) ;
441
429
}
442
430
@@ -530,11 +518,7 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
530
518
{
531
519
if ( ! Console . IsOutputRedirected )
532
520
{
533
- try
534
- {
535
- Console . CursorVisible = true ;
536
- }
537
- catch { }
521
+ Console . CursorVisible = true ;
538
522
}
539
523
}
540
524
@@ -766,7 +750,7 @@ private sealed class CollectSession : ICollectSession
766
750
internal Func < DiagnosticsClient , CancellationToken , Task > ResumeRuntimeAsync { get ; set ; }
767
751
internal Func < string , Stream > CollectSessionEventStream { get ; set ; }
768
752
internal IConsole Console { get ; set ; }
769
- internal long FileSizeForStatus { get ; set ; }
753
+ internal Func < string , long > GetFileLength { get ; set ; }
770
754
#endregion
771
755
}
772
756
}
0 commit comments