Skip to content

Commit d14f673

Browse files
committed
Drop trace size status validation
1 parent 240ba97 commit d14f673

File tree

3 files changed

+10
-61
lines changed

3 files changed

+10
-61
lines changed

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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);
3232
}
3333

3434
private void ConsoleWriteLine(string str)
@@ -409,34 +409,20 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
409409
if (printStatusOverTime)
410410
{
411411
rewriter = new LineRewriter(Console) { LineToClear = Console.CursorTop - 1 };
412-
try {
413-
Console.CursorVisible = false;
414-
}
415-
catch {}
412+
Console.CursorVisible = false;
416413
if (!rewriter.IsRewriteConsoleLineSupported)
417414
{
418415
ConsoleWriteLine("Recording trace in progress. Press <Enter> or <Ctrl+C> to exit...");
419416
}
420417
}
421418

422-
FileInfo fileInfo = null;
423-
if (FileSizeForStatus == 0)
424-
{
425-
fileInfo = new(output.FullName);
426-
}
419+
FileInfo fileInfo = new(output.FullName);
427420
Action printStatus = () => {
428421
if (printStatusOverTime && rewriter.IsRewriteConsoleLineSupported)
429422
{
430423
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-
}
424+
fileInfo.Refresh();
425+
ConsoleWriteLine($"[{stopwatch.Elapsed:dd\\:hh\\:mm\\:ss}]\tRecording trace {GetSize(fileInfo.Length)}");
440426
ConsoleWriteLine("Press <Enter> or <Ctrl+C> to exit...");
441427
}
442428

@@ -530,11 +516,7 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
530516
{
531517
if (!Console.IsOutputRedirected)
532518
{
533-
try
534-
{
535-
Console.CursorVisible = true;
536-
}
537-
catch { }
519+
Console.CursorVisible = true;
538520
}
539521
}
540522

@@ -766,7 +748,6 @@ private sealed class CollectSession : ICollectSession
766748
internal Func<DiagnosticsClient, CancellationToken, Task> ResumeRuntimeAsync { get; set; }
767749
internal Func<string, Stream> CollectSessionEventStream { get; set; }
768750
internal IConsole Console { get; set; }
769-
internal long FileSizeForStatus { get; set; }
770751
#endregion
771752
}
772753
}

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: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public sealed record CollectArgs(
5050
[MemberData(nameof(BasicCases))]
5151
public async Task CollectCommandProviderConfigurationConsolidation(CollectArgs args, string[] expectedSubset)
5252
{
53-
MockConsole console = new(200, 30) { IsOutputRedirected = false };
53+
MockConsole console = new(200, 30);
5454
string[] rawLines = await RunAsync(args, console).ConfigureAwait(true);
5555
console.AssertSanitizedLinesEqual(CollectSanitizer, expectedSubset);
5656

@@ -63,9 +63,8 @@ private static async Task<string[]> RunAsync(CollectArgs config, MockConsole con
6363
var handler = new CollectCommandHandler();
6464
handler.StartTraceSessionAsync = (client, cfg, ct) => Task.FromResult<CollectCommandHandler.ICollectSession>(new TestCollectSession());
6565
handler.ResumeRuntimeAsync = (client, ct) => Task.CompletedTask;
66-
handler.CollectSessionEventStream = (name) => new SlowSinkStream(config.EventStream);
66+
handler.CollectSessionEventStream = (name) => config.EventStream;
6767
handler.Console = console;
68-
handler.FileSizeForStatus = Encoding.UTF8.GetByteCount(ExpectedPayload);
6968

7069
int exit = await handler.Collect(
7170
config.ct,
@@ -96,32 +95,6 @@ private static async Task<string[]> RunAsync(CollectArgs config, MockConsole con
9695
return console.Lines;
9796
}
9897

99-
// As the test payload is small, we need to delay writes to the output stream to ensure
100-
// that the status update logic in CollectCommandHandler has a chance to run.
101-
private sealed class SlowSinkStream : Stream
102-
{
103-
private readonly Stream _inner;
104-
105-
public SlowSinkStream(Stream inner) { _inner = inner; }
106-
107-
public override bool CanRead => false;
108-
public override bool CanSeek => false;
109-
public override bool CanWrite => true;
110-
public override long Length => throw new NotSupportedException();
111-
public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
112-
113-
public override void Flush() { }
114-
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
115-
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
116-
public override void SetLength(long value) => throw new NotSupportedException();
117-
public override void Write(byte[] buffer, int offset, int count) => _inner.Write(buffer, offset, count);
118-
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
119-
{
120-
await Task.Delay(200, cancellationToken).ConfigureAwait(false);
121-
await _inner.WriteAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
122-
}
123-
}
124-
12598
private static string[] CollectSanitizer(string[] lines)
12699
{
127100
List<string> result = new();
@@ -131,10 +104,6 @@ private static string[] CollectSanitizer(string[] lines)
131104
{
132105
result.Add("Process : <PROCESS>");
133106
}
134-
else if (line.StartsWith('[') && line.Contains("Recording trace"))
135-
{
136-
result.Add("[dd:hh:mm:ss]\t" + line.Substring(14));
137-
}
138107
else
139108
{
140109
result.Add(line);
@@ -250,8 +219,7 @@ public static IEnumerable<object[]> BasicCases()
250219
private static readonly string[] CommonTail = [
251220
"Process : <PROCESS>",
252221
outputFile,
253-
"[dd:hh:mm:ss]\tRecording trace 38.00 (B)",
254-
"Press <Enter> or <Ctrl+C> to exit...",
222+
"",
255223
"\nTrace completed."
256224
];
257225

0 commit comments

Comments
 (0)