Skip to content

Commit 57555a5

Browse files
Copilotbrianrob
andauthored
Add Exception Stacks view when viewing a .nettrace with exceptions (#2223)
* Initial plan for issue * Add Exception Stacks view support for .nettrace files Co-authored-by: brianrob <[email protected]> * Fix OnlyManagedCodeStacks setting for Exceptions to respect hasUniversalSystem Co-authored-by: brianrob <[email protected]> * Update OnlyManagedCodeStacks to use m_supportsProcesses instead of hasUniversalSystem Co-authored-by: brianrob <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: brianrob <[email protected]>
1 parent 1c22582 commit 57555a5

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/PerfView/PerfViewData.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9461,6 +9461,7 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
94619461
bool hasAspNetCoreHosting = false;
94629462
bool hasContention = false;
94639463
bool hasWaitHandle = false;
9464+
bool hasExceptions = false;
94649465
bool hasUniversalSystem = false;
94659466
bool hasUniversalCPU = false;
94669467
if (m_traceLog != null)
@@ -9516,6 +9517,10 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
95169517
{
95179518
hasWaitHandle = true;
95189519
}
9520+
else if (eventStats.EventName.StartsWith("Exception/Start"))
9521+
{
9522+
hasExceptions = true;
9523+
}
95199524
else if (eventStats.ProviderGuid == UniversalSystemTraceEventParser.ProviderGuid)
95209525
{
95219526
hasUniversalSystem = true;
@@ -9610,6 +9615,11 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
96109615
{
96119616
advanced.AddChild(new PerfViewStackSource(this, "WaitHandleWait"));
96129617
}
9618+
9619+
if (hasExceptions)
9620+
{
9621+
advanced.AddChild(new PerfViewStackSource(this, "Exceptions"));
9622+
}
96139623
}
96149624

96159625
if (memory.Children.Count > 0)
@@ -9969,6 +9979,43 @@ protected internal override StackSource OpenStackSourceImpl(string streamName, T
99699979
return null;
99709980
}
99719981

9982+
return stackSource;
9983+
}
9984+
case "Exceptions":
9985+
{
9986+
var eventLog = GetTraceLog(log);
9987+
9988+
var stackSource = new MutableTraceEventStackSource(eventLog);
9989+
// EventPipe currently only has managed code stacks.
9990+
stackSource.OnlyManagedCodeStacks = !m_supportsProcesses;
9991+
stackSource.ShowUnknownAddresses = App.CommandLineArgs.ShowUnknownAddresses;
9992+
stackSource.ShowOptimizationTiers = App.CommandLineArgs.ShowOptimizationTiers;
9993+
9994+
TraceEvents events = eventLog.Events;
9995+
9996+
if (startRelativeMSec != 0 || endRelativeMSec != double.PositiveInfinity)
9997+
{
9998+
events = events.FilterByTime(startRelativeMSec, endRelativeMSec);
9999+
}
10000+
10001+
var eventSource = events.GetSource();
10002+
var sample = new StackSourceSample(stackSource);
10003+
10004+
eventSource.Clr.ExceptionStart += delegate (ExceptionTraceData data)
10005+
{
10006+
sample.Metric = 1;
10007+
sample.TimeRelativeMSec = data.TimeStampRelativeMSec;
10008+
10009+
// Create a call stack that ends with the 'throw'
10010+
var nodeName = "Throw(" + data.ExceptionType + ") " + data.ExceptionMessage;
10011+
var nodeIndex = stackSource.Interner.FrameIntern(nodeName);
10012+
sample.StackIndex = stackSource.Interner.CallStackIntern(nodeIndex, stackSource.GetCallStack(data.CallStackIndex(), data));
10013+
stackSource.AddSample(sample);
10014+
};
10015+
10016+
eventSource.Process();
10017+
stackSource.DoneAddingSamples();
10018+
997210019
return stackSource;
997310020
}
997410021
}

0 commit comments

Comments
 (0)