From 7a2d6fa1c3432de0c3a26070b2a9c37ab6d716ed Mon Sep 17 00:00:00 2001 From: Juan Sebastian Hoyos Ayala Date: Tue, 1 Sep 2026 21:02:26 -0700 Subject: [PATCH 1/4] Add collect-linux event buffer size option Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Commands/CollectLinuxCommand.cs | 21 ++++++++++++++++ .../CollectLinuxCommandFunctionalTests.cs | 24 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs index ab99addcc6..313180beb9 100644 --- a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs +++ b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs @@ -31,6 +31,7 @@ internal sealed record CollectLinuxArgs( string ClrEvents, string[] PerfEvents, string[] Profiles, + uint? EventBufferSizeInMB, FileInfo Output, TimeSpan Duration, string Name, @@ -175,6 +176,7 @@ public static Command CollectLinuxCommand() CommonOptions.CLREventLevelOption, CommonOptions.CLREventsOption, PerfEventsOption, + EventBufferSizeInMBOption, ProbeOption, CommonOptions.ProfileOption, CommonOptions.OutputPathOption, @@ -198,6 +200,7 @@ public static Command CollectLinuxCommand() ClrEvents: parseResult.GetValue(CommonOptions.CLREventsOption) ?? string.Empty, PerfEvents: perfEventsValue.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), Profiles: profilesValue.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), + EventBufferSizeInMB: parseResult.GetValue(EventBufferSizeInMBOption), Output: parseResult.GetValue(CommonOptions.OutputPathOption) ?? new FileInfo(CommonOptions.DefaultTraceName), Duration: parseResult.GetValue(CommonOptions.DurationOption), Name: parseResult.GetValue(CommonOptions.NameOption) ?? string.Empty, @@ -435,6 +438,18 @@ private byte[] BuildRecordTraceArgs(CollectLinuxArgs args, out string scriptPath } StringBuilder scriptBuilder = new(); + if (args.EventBufferSizeInMB.HasValue) + { + if (args.EventBufferSizeInMB.Value == 0) + { + throw new DiagnosticToolException("Event buffer size must be at least 1 MB."); + } + + ulong eventBufferSizeBytes = args.EventBufferSizeInMB.Value * 1024UL * 1024UL; + scriptBuilder.AppendLine($"with_per_cpu_buffer_bytes({eventBufferSizeBytes});"); + scriptBuilder.AppendLine(); + } + List providerCollection = ProviderUtils.ComputeProviderConfig(args.Providers, args.ClrEvents, args.ClrEventLevel, profiles, true, "collect-linux", Console); foreach (EventPipeProvider provider in providerCollection) { @@ -582,6 +597,12 @@ private int OutputHandler(uint type, IntPtr data, UIntPtr dataLen) Description = @"Comma-separated list of perf events (e.g. syscalls:sys_enter_execve,sched:sched_switch)." }; + private static readonly Option EventBufferSizeInMBOption = + new("--event-buffer-size-mb") + { + Description = "Size of each per-CPU event buffer, in megabytes. Larger buffers can accommodate event bursts but use more memory. When omitted, the recorder chooses a default based on the enabled features." + }; + private static readonly Option ProbeOption = new("--probe") { diff --git a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs index 75149cc5ff..f596673d83 100644 --- a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs +++ b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs @@ -38,6 +38,7 @@ private static CollectLinuxCommandHandler.CollectLinuxArgs TestArgs( string clrEvents = "", string[] perfEvents = null, string[] profile = null, + uint? eventBufferSizeInMB = null, FileInfo output = null, TimeSpan duration = default, string name = "", @@ -50,6 +51,7 @@ private static CollectLinuxCommandHandler.CollectLinuxArgs TestArgs( clrEvents, perfEvents ?? Array.Empty(), profile ?? Array.Empty(), + eventBufferSizeInMB, output ?? new FileInfo("trace.nettrace"), duration, name, @@ -359,6 +361,28 @@ public void CollectLinuxCommand_DoesNotReadKey_WhenInputIsRedirected() Assert.True(callbackInvoked); } + [ConditionalFact(nameof(IsCollectLinuxSupported))] + public void CollectLinuxCommand_AddsEventBufferSizeInMBToScript() + { + string outputPath = Path.Combine(Path.GetTempPath(), $"collect-linux-{Guid.NewGuid():N}.nettrace"); + string scriptPath = Path.ChangeExtension(outputPath, ".script"); + MockConsole console = new(200, 30, _outputHelper); + var handler = new CollectLinuxCommandHandler(console); + handler.RecordTraceInvoker = (cmd, len, cb) => { + Assert.Contains( + "with_per_cpu_buffer_bytes(8388608);", + File.ReadAllText(scriptPath)); + return 0; + }; + + int exitCode = handler.CollectLinux(TestArgs( + eventBufferSizeInMB: 8, + output: new FileInfo(outputPath))); + + Assert.Equal((int)ReturnCode.Ok, exitCode); + Assert.False(File.Exists(scriptPath)); + } + [ConditionalFact(nameof(IsCollectLinuxSupported))] public void CollectLinuxCommand_PrintsStatusOnce_WhenCursorRepositioningUnsupported() { From a986eba262b02bfb20e589bc895a95c2f19a7bfa Mon Sep 17 00:00:00 2001 From: Juan Sebastian Hoyos Ayala Date: Wed, 2 Sep 2026 03:29:13 -0700 Subject: [PATCH 2/4] Use total size for collect-linux buffers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Commands/CollectLinuxCommand.cs | 48 +++++++++++++------ .../CollectLinuxCommandFunctionalTests.cs | 31 +++++++++--- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs index 313180beb9..59543762af 100644 --- a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs +++ b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs @@ -23,6 +23,10 @@ internal partial class CollectLinuxCommandHandler private ProgressWriter progressWriter; private Version minRuntimeSupportingUserEventsIPCCommand = new(10, 0, 0); private readonly bool cancelOnEnter; + private const int ScNProcessorsOnln = 84; + + [LibraryImport("libc", EntryPoint = "sysconf")] + private static partial long SysConf(int name); internal sealed record CollectLinuxArgs( CancellationToken Ct, @@ -31,7 +35,7 @@ internal sealed record CollectLinuxArgs( string ClrEvents, string[] PerfEvents, string[] Profiles, - uint? EventBufferSizeInMB, + uint? BufferSizeInMB, FileInfo Output, TimeSpan Duration, string Name, @@ -176,7 +180,7 @@ public static Command CollectLinuxCommand() CommonOptions.CLREventLevelOption, CommonOptions.CLREventsOption, PerfEventsOption, - EventBufferSizeInMBOption, + BufferSizeInMBOption, ProbeOption, CommonOptions.ProfileOption, CommonOptions.OutputPathOption, @@ -200,7 +204,7 @@ public static Command CollectLinuxCommand() ClrEvents: parseResult.GetValue(CommonOptions.CLREventsOption) ?? string.Empty, PerfEvents: perfEventsValue.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), Profiles: profilesValue.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), - EventBufferSizeInMB: parseResult.GetValue(EventBufferSizeInMBOption), + BufferSizeInMB: parseResult.GetValue(BufferSizeInMBOption), Output: parseResult.GetValue(CommonOptions.OutputPathOption) ?? new FileInfo(CommonOptions.DefaultTraceName), Duration: parseResult.GetValue(CommonOptions.DurationOption), Name: parseResult.GetValue(CommonOptions.NameOption) ?? string.Empty, @@ -430,6 +434,14 @@ private byte[] BuildRecordTraceArgs(CollectLinuxArgs args, out string scriptPath scriptPath = null; List recordTraceArgs = new(); + if (args.BufferSizeInMB.HasValue) + { + if (args.BufferSizeInMB.Value == 0) + { + throw new DiagnosticToolException("Buffer size must be at least 1 MB."); + } + } + string[] profiles = args.Profiles; if (args.Profiles.Length == 0 && args.Providers.Length == 0 && string.IsNullOrEmpty(args.ClrEvents) && args.PerfEvents.Length == 0) { @@ -438,15 +450,12 @@ private byte[] BuildRecordTraceArgs(CollectLinuxArgs args, out string scriptPath } StringBuilder scriptBuilder = new(); - if (args.EventBufferSizeInMB.HasValue) + if (args.BufferSizeInMB.HasValue) { - if (args.EventBufferSizeInMB.Value == 0) - { - throw new DiagnosticToolException("Event buffer size must be at least 1 MB."); - } - - ulong eventBufferSizeBytes = args.EventBufferSizeInMB.Value * 1024UL * 1024UL; - scriptBuilder.AppendLine($"with_per_cpu_buffer_bytes({eventBufferSizeBytes});"); + ulong cpuCount = GetOnlineProcessorCount(); + ulong totalBufferSizeBytes = args.BufferSizeInMB.Value * 1024UL * 1024UL; + ulong perCpuBufferSizeBytes = (totalBufferSizeBytes + cpuCount - 1) / cpuCount; + scriptBuilder.AppendLine($"with_per_cpu_buffer_bytes({perCpuBufferSizeBytes});"); scriptBuilder.AppendLine(); } @@ -540,6 +549,17 @@ private byte[] BuildRecordTraceArgs(CollectLinuxArgs args, out string scriptPath return Encoding.UTF8.GetBytes(options); } + internal static ulong GetOnlineProcessorCount() + { + long cpuCount = SysConf(ScNProcessorsOnln); + if (cpuCount <= 0) + { + throw new DiagnosticToolException("Unable to determine the number of online processors."); + } + + return (ulong)cpuCount; + } + private static FileInfo ResolveOutputPath(FileInfo output, string processName) { if (!string.Equals(output.Name, CommonOptions.DefaultTraceName, StringComparison.OrdinalIgnoreCase)) @@ -597,10 +617,10 @@ private int OutputHandler(uint type, IntPtr data, UIntPtr dataLen) Description = @"Comma-separated list of perf events (e.g. syscalls:sys_enter_execve,sched:sched_switch)." }; - private static readonly Option EventBufferSizeInMBOption = - new("--event-buffer-size-mb") + private static readonly Option BufferSizeInMBOption = + new("--buffersize") { - Description = "Size of each per-CPU event buffer, in megabytes. Larger buffers can accommodate event bursts but use more memory. When omitted, the recorder chooses a default based on the enabled features." + Description = "Requested total size of the event buffers, in megabytes. The size is divided across the available CPUs. When omitted, the recorder chooses a default based on the enabled features." }; private static readonly Option ProbeOption = diff --git a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs index f596673d83..8540238389 100644 --- a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs +++ b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs @@ -38,7 +38,7 @@ private static CollectLinuxCommandHandler.CollectLinuxArgs TestArgs( string clrEvents = "", string[] perfEvents = null, string[] profile = null, - uint? eventBufferSizeInMB = null, + uint? bufferSizeInMB = null, FileInfo output = null, TimeSpan duration = default, string name = "", @@ -51,7 +51,7 @@ private static CollectLinuxCommandHandler.CollectLinuxArgs TestArgs( clrEvents, perfEvents ?? Array.Empty(), profile ?? Array.Empty(), - eventBufferSizeInMB, + bufferSizeInMB, output ?? new FileInfo("trace.nettrace"), duration, name, @@ -362,25 +362,44 @@ public void CollectLinuxCommand_DoesNotReadKey_WhenInputIsRedirected() } [ConditionalFact(nameof(IsCollectLinuxSupported))] - public void CollectLinuxCommand_AddsEventBufferSizeInMBToScript() + public void CollectLinuxCommand_AddsPerCpuBufferSizeToScript() { string outputPath = Path.Combine(Path.GetTempPath(), $"collect-linux-{Guid.NewGuid():N}.nettrace"); string scriptPath = Path.ChangeExtension(outputPath, ".script"); + ulong cpuCount = CollectLinuxCommandHandler.GetOnlineProcessorCount(); + ulong expectedPerCpuBufferSize = (256UL * 1024UL * 1024UL + cpuCount - 1) / cpuCount; MockConsole console = new(200, 30, _outputHelper); var handler = new CollectLinuxCommandHandler(console); handler.RecordTraceInvoker = (cmd, len, cb) => { Assert.Contains( - "with_per_cpu_buffer_bytes(8388608);", + $"with_per_cpu_buffer_bytes({expectedPerCpuBufferSize});", File.ReadAllText(scriptPath)); return 0; }; int exitCode = handler.CollectLinux(TestArgs( - eventBufferSizeInMB: 8, + bufferSizeInMB: 256, output: new FileInfo(outputPath))); Assert.Equal((int)ReturnCode.Ok, exitCode); - Assert.False(File.Exists(scriptPath)); + } + + [ConditionalFact(nameof(IsCollectLinuxSupported))] + public void CollectLinuxCommand_RejectsZeroBufferSize() + { + MockConsole console = new(200, 30, _outputHelper); + var handler = new CollectLinuxCommandHandler(console); + handler.RecordTraceInvoker = (cmd, len, cb) => { + Assert.Fail("RecordTrace should not be invoked for an invalid buffer size."); + return 0; + }; + + int exitCode = handler.CollectLinux(TestArgs(bufferSizeInMB: 0)); + + Assert.Equal((int)ReturnCode.ArgumentError, exitCode); + console.AssertSanitizedLinesEqual( + null, + FormatException("Buffer size must be at least 1 MB.")); } [ConditionalFact(nameof(IsCollectLinuxSupported))] From f7db4f1992464629cbb0235c669571439b5aa361 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Hoyos Ayala Date: Wed, 2 Sep 2026 03:57:03 -0700 Subject: [PATCH 3/4] Read online CPU count from sysfs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Commands/CollectLinuxCommand.cs | 54 ++++++++++++++++--- .../CollectLinuxCommandFunctionalTests.cs | 21 ++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs index 59543762af..4c9d979c49 100644 --- a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs +++ b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs @@ -23,10 +23,6 @@ internal partial class CollectLinuxCommandHandler private ProgressWriter progressWriter; private Version minRuntimeSupportingUserEventsIPCCommand = new(10, 0, 0); private readonly bool cancelOnEnter; - private const int ScNProcessorsOnln = 84; - - [LibraryImport("libc", EntryPoint = "sysconf")] - private static partial long SysConf(int name); internal sealed record CollectLinuxArgs( CancellationToken Ct, @@ -551,13 +547,55 @@ private byte[] BuildRecordTraceArgs(CollectLinuxArgs args, out string scriptPath internal static ulong GetOnlineProcessorCount() { - long cpuCount = SysConf(ScNProcessorsOnln); - if (cpuCount <= 0) + const string OnlineCpusPath = "/sys/devices/system/cpu/online"; + string onlineCpus; + try + { + onlineCpus = File.ReadAllText(OnlineCpusPath); + } + catch (Exception ex) when (ex is FileNotFoundException or DirectoryNotFoundException or IOException or UnauthorizedAccessException) + { + throw new DiagnosticToolException($"Unable to read online processors from '{OnlineCpusPath}': {ex.Message}"); + } + + return ParseOnlineProcessorCount(onlineCpus); + } + + internal static ulong ParseOnlineProcessorCount(string onlineCpus) + { + ulong cpuCount = 0; + + foreach (string range in onlineCpus.Trim().Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) + { + string[] bounds = range.Split('-', 2, StringSplitOptions.TrimEntries); + if (!ulong.TryParse(bounds[0], out ulong first)) + { + throw new DiagnosticToolException($"Invalid online processor range '{range}'."); + } + + ulong last = first; + if (bounds.Length == 2 && + (!ulong.TryParse(bounds[1], out last) || last < first)) + { + throw new DiagnosticToolException($"Invalid online processor range '{range}'."); + } + + try + { + cpuCount = checked(cpuCount + checked(last - first + 1)); + } + catch (OverflowException) + { + throw new DiagnosticToolException("Online processor count is too large."); + } + } + + if (cpuCount == 0) { - throw new DiagnosticToolException("Unable to determine the number of online processors."); + throw new DiagnosticToolException("No online processors were reported."); } - return (ulong)cpuCount; + return cpuCount; } private static FileInfo ResolveOutputPath(FileInfo output, string processName) diff --git a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs index 8540238389..baa8592d97 100644 --- a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs +++ b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs @@ -402,6 +402,27 @@ public void CollectLinuxCommand_RejectsZeroBufferSize() FormatException("Buffer size must be at least 1 MB.")); } + [Theory] + [InlineData("0", 1)] + [InlineData("0-3", 4)] + [InlineData("0-3,8,10-11", 7)] + public void CollectLinuxCommand_ParsesOnlineProcessorRanges(string onlineCpus, ulong expectedCount) + { + Assert.Equal( + expectedCount, + CollectLinuxCommandHandler.ParseOnlineProcessorCount(onlineCpus)); + } + + [Theory] + [InlineData("")] + [InlineData("3-1")] + [InlineData("invalid")] + public void CollectLinuxCommand_RejectsInvalidOnlineProcessorRanges(string onlineCpus) + { + Assert.Throws( + () => CollectLinuxCommandHandler.ParseOnlineProcessorCount(onlineCpus)); + } + [ConditionalFact(nameof(IsCollectLinuxSupported))] public void CollectLinuxCommand_PrintsStatusOnce_WhenCursorRepositioningUnsupported() { From ca11b77a1ee43f97f634502816acd186a2475790 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Hoyos Ayala Date: Tue, 8 Sep 2026 17:08:02 -0700 Subject: [PATCH 4/4] Delegate buffer sizing to one-collect Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Commands/CollectLinuxCommand.cs | 59 +------------------ .../CollectLinuxCommandFunctionalTests.cs | 27 +-------- 2 files changed, 4 insertions(+), 82 deletions(-) diff --git a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs index 4c9d979c49..7d23753279 100644 --- a/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs +++ b/src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs @@ -448,10 +448,8 @@ private byte[] BuildRecordTraceArgs(CollectLinuxArgs args, out string scriptPath StringBuilder scriptBuilder = new(); if (args.BufferSizeInMB.HasValue) { - ulong cpuCount = GetOnlineProcessorCount(); ulong totalBufferSizeBytes = args.BufferSizeInMB.Value * 1024UL * 1024UL; - ulong perCpuBufferSizeBytes = (totalBufferSizeBytes + cpuCount - 1) / cpuCount; - scriptBuilder.AppendLine($"with_per_cpu_buffer_bytes({perCpuBufferSizeBytes});"); + scriptBuilder.AppendLine($"with_buffer_size_bytes({totalBufferSizeBytes});"); scriptBuilder.AppendLine(); } @@ -545,59 +543,6 @@ private byte[] BuildRecordTraceArgs(CollectLinuxArgs args, out string scriptPath return Encoding.UTF8.GetBytes(options); } - internal static ulong GetOnlineProcessorCount() - { - const string OnlineCpusPath = "/sys/devices/system/cpu/online"; - string onlineCpus; - try - { - onlineCpus = File.ReadAllText(OnlineCpusPath); - } - catch (Exception ex) when (ex is FileNotFoundException or DirectoryNotFoundException or IOException or UnauthorizedAccessException) - { - throw new DiagnosticToolException($"Unable to read online processors from '{OnlineCpusPath}': {ex.Message}"); - } - - return ParseOnlineProcessorCount(onlineCpus); - } - - internal static ulong ParseOnlineProcessorCount(string onlineCpus) - { - ulong cpuCount = 0; - - foreach (string range in onlineCpus.Trim().Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) - { - string[] bounds = range.Split('-', 2, StringSplitOptions.TrimEntries); - if (!ulong.TryParse(bounds[0], out ulong first)) - { - throw new DiagnosticToolException($"Invalid online processor range '{range}'."); - } - - ulong last = first; - if (bounds.Length == 2 && - (!ulong.TryParse(bounds[1], out last) || last < first)) - { - throw new DiagnosticToolException($"Invalid online processor range '{range}'."); - } - - try - { - cpuCount = checked(cpuCount + checked(last - first + 1)); - } - catch (OverflowException) - { - throw new DiagnosticToolException("Online processor count is too large."); - } - } - - if (cpuCount == 0) - { - throw new DiagnosticToolException("No online processors were reported."); - } - - return cpuCount; - } - private static FileInfo ResolveOutputPath(FileInfo output, string processName) { if (!string.Equals(output.Name, CommonOptions.DefaultTraceName, StringComparison.OrdinalIgnoreCase)) @@ -658,7 +603,7 @@ private int OutputHandler(uint type, IntPtr data, UIntPtr dataLen) private static readonly Option BufferSizeInMBOption = new("--buffersize") { - Description = "Requested total size of the event buffers, in megabytes. The size is divided across the available CPUs. When omitted, the recorder chooses a default based on the enabled features." + Description = "Requested total size of the event buffers, in megabytes. When omitted, the recorder chooses a default based on the enabled features." }; private static readonly Option ProbeOption = diff --git a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs index baa8592d97..9dcd707c6f 100644 --- a/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs +++ b/src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs @@ -362,17 +362,15 @@ public void CollectLinuxCommand_DoesNotReadKey_WhenInputIsRedirected() } [ConditionalFact(nameof(IsCollectLinuxSupported))] - public void CollectLinuxCommand_AddsPerCpuBufferSizeToScript() + public void CollectLinuxCommand_AddsBufferSizeToScript() { string outputPath = Path.Combine(Path.GetTempPath(), $"collect-linux-{Guid.NewGuid():N}.nettrace"); string scriptPath = Path.ChangeExtension(outputPath, ".script"); - ulong cpuCount = CollectLinuxCommandHandler.GetOnlineProcessorCount(); - ulong expectedPerCpuBufferSize = (256UL * 1024UL * 1024UL + cpuCount - 1) / cpuCount; MockConsole console = new(200, 30, _outputHelper); var handler = new CollectLinuxCommandHandler(console); handler.RecordTraceInvoker = (cmd, len, cb) => { Assert.Contains( - $"with_per_cpu_buffer_bytes({expectedPerCpuBufferSize});", + "with_buffer_size_bytes(268435456);", File.ReadAllText(scriptPath)); return 0; }; @@ -402,27 +400,6 @@ public void CollectLinuxCommand_RejectsZeroBufferSize() FormatException("Buffer size must be at least 1 MB.")); } - [Theory] - [InlineData("0", 1)] - [InlineData("0-3", 4)] - [InlineData("0-3,8,10-11", 7)] - public void CollectLinuxCommand_ParsesOnlineProcessorRanges(string onlineCpus, ulong expectedCount) - { - Assert.Equal( - expectedCount, - CollectLinuxCommandHandler.ParseOnlineProcessorCount(onlineCpus)); - } - - [Theory] - [InlineData("")] - [InlineData("3-1")] - [InlineData("invalid")] - public void CollectLinuxCommand_RejectsInvalidOnlineProcessorRanges(string onlineCpus) - { - Assert.Throws( - () => CollectLinuxCommandHandler.ParseOnlineProcessorCount(onlineCpus)); - } - [ConditionalFact(nameof(IsCollectLinuxSupported))] public void CollectLinuxCommand_PrintsStatusOnce_WhenCursorRepositioningUnsupported() {