Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 6, 2025

When collecting a trace using dotnet-trace collect, the generated .nettrace file contains call stacks for any exceptions thrown. Previously, while users could see exception events in the Events view and find associated stacks in the Any Stacks view by time filtering, there was no dedicated Exception Stacks view like the one available for .etl files.

This PR adds Exception Stacks view support for .nettrace files by porting the logic from the ETL implementation to the EventPipe implementation.

Changes Made

  1. Exception Event Detection: Added detection for "Exception/Start" events in EventPipePerfViewData.OpenImpl() to set the hasExceptions flag
  2. UI Integration: Added "Exceptions" stack source to the Advanced Group when exceptions are detected in the trace
  3. Stack Source Implementation: Implemented the "Exceptions" case in EventPipePerfViewData.OpenStackSourceImpl() that:
    • Creates a MutableTraceEventStackSource with managed-only stacks
    • Listens for ExceptionStart events
    • Creates stack samples with format "Throw(ExceptionType) ExceptionMessage"
    • Preserves the original call stack from the exception event data

Implementation Details

The implementation follows the exact same pattern as the existing ETL exception handling to ensure consistency:

eventSource.Clr.ExceptionStart += delegate (ExceptionTraceData data)
{
    sample.Metric = 1;
    sample.TimeRelativeMSec = data.TimeStampRelativeMSec;

    // Create a call stack that ends with the 'throw'
    var nodeName = "Throw(" + data.ExceptionType + ") " + data.ExceptionMessage;
    var nodeIndex = stackSource.Interner.FrameIntern(nodeName);
    sample.StackIndex = stackSource.Interner.CallStackIntern(nodeIndex, stackSource.GetCallStack(data.CallStackIndex(), data));
    stackSource.AddSample(sample);
};

Users will now see the "Exceptions" stack source in the Advanced Group when opening .nettrace files that contain exception events, providing the same exception analysis capabilities available for .etl files.

Fixes #1797.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Exception Stacks view when viewing a .nettrace with exceptions Add Exception Stacks view when viewing a .nettrace with exceptions Jun 6, 2025
Copilot AI requested a review from brianrob June 6, 2025 00:37

var stackSource = new MutableTraceEventStackSource(eventLog);
// EventPipe currently only has managed code stacks.
stackSource.OnlyManagedCodeStacks = true;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stackSource.OnlyManagedCodeStacks = true;
stackSource.OnlyManagedCodeStacks = !hasUniversalSystem;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the setting to use !hasUniversalSystem to include native stacks when available, matching the ETL implementation behavior. Change implemented in commit 33fe190.

…salSystem

Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>

var stackSource = new MutableTraceEventStackSource(eventLog);
// EventPipe currently only has managed code stacks.
stackSource.OnlyManagedCodeStacks = !hasUniversalSystem;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stackSource.OnlyManagedCodeStacks = !hasUniversalSystem;
stackSource.OnlyManagedCodeStacks = !m_supportsProcesses;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use !m_supportsProcesses which provides a more comprehensive check that includes both system and CPU events, better aligning with the logic for determining stack information availability. Change implemented in commit 2604ed6.

…sUniversalSystem

Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
@brianrob brianrob marked this pull request as ready for review June 6, 2025 19:09
@brianrob
Copy link
Member

brianrob commented Jun 6, 2025

Copilot Post-Mortem:

  • Copilot did quite well with this issue out the gate - it was able to understand the pattern of how to add a stack view without any coaching.
  • In the future, I'd love to be able to have copilot test the feature and show me screenshots, but I realize that's likely a ways off.

Copy link
Collaborator

@marklio marklio left a comment

Choose a reason for hiding this comment

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

Looks reasonable

Copy link
Member

@mconnew mconnew left a comment

Choose a reason for hiding this comment

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

:shipit:

@brianrob brianrob merged commit 57555a5 into main Jun 6, 2025
5 checks passed
@brianrob brianrob deleted the copilot/fix-1797 branch June 6, 2025 20:06
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.

Add Exception Stacks view when viewing a .nettrace with exceptions

4 participants