Skip to content

Add collect-linux buffersize option - #5995

Open
hoyosjs wants to merge 4 commits into
dotnet:mainfrom
hoyosjs:hoyosjs/collect-linux-event-buffer-size
Open

Add collect-linux buffersize option#5995
hoyosjs wants to merge 4 commits into
dotnet:mainfrom
hoyosjs:hoyosjs/collect-linux-event-buffer-size

Conversation

@hoyosjs

@hoyosjs hoyosjs commented Sep 2, 2026

Copy link
Copy Markdown
Member

Adds --buffersize to dotnet-trace collect-linux, matching the existing dotnet-trace collect option name. The value is a requested total event-buffer size in megabytes and is forwarded unchanged to one-collect through the generated script. One-collect owns platform-specific normalization.

When omitted, one-collect continues to choose its adaptive default. Zero is rejected before record-trace is invoked. This PR depends on the new Universal script setting in microsoft/one-collect#332 and should consume a package containing that change before merge.

Breaking changes: None.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 04:02
@hoyosjs
hoyosjs requested a review from a team as a code owner September 2, 2026 04:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The newly introduced validation rejecting --event-buffer-size-mb 0 is not currently covered by a functional test, leaving a regression gap for the new option behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a new --event-buffer-size-mb option to dotnet-trace collect-linux so users can explicitly size per-CPU event buffers for bursty workloads, emitting the corresponding with_per_cpu_buffer_bytes(...) directive into the generated record-trace script.

Changes:

  • Add --event-buffer-size-mb CLI option and plumb it through CollectLinuxArgs.
  • Emit with_per_cpu_buffer_bytes(<bytes>) into the generated record-trace script when the option is provided.
  • Add a functional test validating the script emission for an 8 MB buffer size.
File summaries
File Description
src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs Adds the nullable buffer-size option, validates it, and writes the corresponding script directive in bytes.
src/tests/dotnet-trace/CollectLinuxCommandFunctionalTests.cs Updates test argument helper and adds coverage for the emitted script directive.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +382 to 387
Assert.Equal((int)ReturnCode.Ok, exitCode);
Assert.False(File.Exists(scriptPath));
}

[ConditionalFact(nameof(IsCollectLinuxSupported))]
public void CollectLinuxCommand_PrintsStatusOnce_WhenCursorRepositioningUnsupported()
};

private static readonly Option<uint?> EventBufferSizeInMBOption =
new("--event-buffer-size-mb")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the argument doesn't suggest it is per-CPU so I suspect users will assume it is total buffer size. Rather than clarifying the name what if we redefine the behavior to mean the total buffer size and let the tool handle observing the number of CPUs and doing the division? I suspect users will find total buffer size a more natural concept to reason about than per-cpu buffer size.

Assuming we do that, dotnet collect also has a --buffersize argument and I think we should match the naming. Having two commands with different names for a very similarly purposed argument seems like inconsistent UX.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hoyosjs hoyosjs changed the title Add collect-linux event buffer size option Add collect-linux buffersize option Sep 2, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
return Encoding.UTF8.GetBytes(options);
}

internal static ulong GetOnlineProcessorCount()

@noahfalk noahfalk Sep 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digging into this deeper it looks like one-collect doesn't always create buffers for all CPUs so this calculation still might not give the right result overall. Reverse engineering the set of CPUs one-collect actually uses from its configuration also doesn't seem great.

I think we'd need to either:

  • let the one-collect portion of the tool do the global to per-CPU partitioning
  • give up on specifying a global buffer size and offer per-CPU sizing only (with an argument name that clearly conveys it is a 'per-cpu' value).

Which one might depend on how important Beau/Brian think it is that buffers are specified as a per-CPU value in the overall tracing UX. I'm not aware that we've done anything similar in the past for other .NET profiling scenarios (via ETW for instance), but I am less familiar with what the Linux precedents are.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let the one-collect side of things go first then

private static readonly Option<uint?> 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."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."

I think mentioning the size is divided across CPUs is more likely to create confusion than clarity. Users have no idea the interface to one-collect is a per-cpu measurement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants