Skip to content

Commit 4e2bf95

Browse files
committed
Adjust trace length status testing seam
1 parent 240ba97 commit 4e2bf95

File tree

3 files changed

+11
-27
lines changed

3 files changed

+11
-27
lines changed

src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public CollectCommandHandler()
2828
Console = new DefaultConsole(false);
2929
StartTraceSessionAsync = async (client, config, ct) => new CollectSession(await client.StartEventPipeSessionAsync(config, ct).ConfigureAwait(false));
3030
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;
3233
}
3334

3435
private void ConsoleWriteLine(string str)
@@ -409,34 +410,21 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
409410
if (printStatusOverTime)
410411
{
411412
rewriter = new LineRewriter(Console) { LineToClear = Console.CursorTop - 1 };
412-
try {
413-
Console.CursorVisible = false;
414-
}
415-
catch {}
413+
Console.CursorVisible = false;
416414
if (!rewriter.IsRewriteConsoleLineSupported)
417415
{
418416
ConsoleWriteLine("Recording trace in progress. Press <Enter> or <Ctrl+C> to exit...");
419417
}
420418
}
421419

422-
FileInfo fileInfo = null;
423-
if (FileSizeForStatus == 0)
424-
{
425-
fileInfo = new(output.FullName);
426-
}
420+
FileInfo fileInfo = new(output.FullName);
427421
Action printStatus = () => {
428422
if (printStatusOverTime && rewriter.IsRewriteConsoleLineSupported)
429423
{
430424
rewriter?.RewriteConsoleLine();
431-
if (fileInfo != null)
432-
{
433-
fileInfo.Refresh();
434-
ConsoleWriteLine($"[{stopwatch.Elapsed:dd\\:hh\\:mm\\:ss}]\tRecording trace {GetSize(fileInfo.Length)}");
435-
}
436-
else
437-
{
438-
ConsoleWriteLine($"[{stopwatch.Elapsed:dd\\:hh\\:mm\\:ss}]\tRecording trace {GetSize(FileSizeForStatus)}");
439-
}
425+
fileInfo.Refresh();
426+
long length = GetFileLength(output.FullName);
427+
ConsoleWriteLine($"[{stopwatch.Elapsed:dd\\:hh\\:mm\\:ss}]\tRecording trace {GetSize(length)}");
440428
ConsoleWriteLine("Press <Enter> or <Ctrl+C> to exit...");
441429
}
442430

@@ -530,11 +518,7 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
530518
{
531519
if (!Console.IsOutputRedirected)
532520
{
533-
try
534-
{
535-
Console.CursorVisible = true;
536-
}
537-
catch { }
521+
Console.CursorVisible = true;
538522
}
539523
}
540524

@@ -766,7 +750,7 @@ private sealed class CollectSession : ICollectSession
766750
internal Func<DiagnosticsClient, CancellationToken, Task> ResumeRuntimeAsync { get; set; }
767751
internal Func<string, Stream> CollectSessionEventStream { get; set; }
768752
internal IConsole Console { get; set; }
769-
internal long FileSizeForStatus { get; set; }
753+
internal Func<string, long> GetFileLength { get; set; }
770754
#endregion
771755
}
772756
}

src/tests/Common/MockConsole.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public MockConsole(int width, int height)
2929

3030
public int WindowWidth { get; init; }
3131

32-
public bool CursorVisible { get => throw new NotSupportedException(); set => throw new NotImplementedException(); }
32+
public bool CursorVisible { get; set; }
3333

3434
public int CursorLeft { get; private set; }
3535

src/tests/dotnet-trace/CollectCommandFunctionalTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static async Task<string[]> RunAsync(CollectArgs config, MockConsole con
6565
handler.ResumeRuntimeAsync = (client, ct) => Task.CompletedTask;
6666
handler.CollectSessionEventStream = (name) => new SlowSinkStream(config.EventStream);
6767
handler.Console = console;
68-
handler.FileSizeForStatus = Encoding.UTF8.GetByteCount(ExpectedPayload);
68+
handler.GetFileLength = (path) => Encoding.UTF8.GetByteCount(ExpectedPayload);
6969

7070
int exit = await handler.Collect(
7171
config.ct,

0 commit comments

Comments
 (0)