Skip to content

Add support for showing stacks from selected events - #2418

Open
Paul Dorn (paulusakademius) wants to merge 1 commit into
microsoft:mainfrom
paulusakademius:stack-feature
Open

Add support for showing stacks from selected events#2418
Paul Dorn (paulusakademius) wants to merge 1 commit into
microsoft:mainfrom
paulusakademius:stack-feature

Conversation

@paulusakademius

Copy link
Copy Markdown
Contributor

This pull request introduces the ability to show stacks for selected events with the 'Open Any Stacks' function, regardless of the column of the event selected. Previously, stacks were only accessible for either a single time or a time range and defaulted to the everything when some other selection happened. With this update:

  • Stacks are now filtered by event ID in addition to time.
  • Selecting any number of events and viewing their stacks is possible.
  • Behavior for selecting time ranges remains unchanged.

Issue #2394

- Before this commit you could only show stacks for either a single time or a time range
- This commit makes selecting any amount of events (no matterer what column of the event) and opening its stack (if there is one) possible
- The stacks shown are now not only filtered by the time but also event id  so no other events that happened at the same time are shown.
- The behavior for selecting a time range remains the same as before
@paulusakademius
Paul Dorn (paulusakademius) requested a review from a team as a code owner April 29, 2026 15:23
@paulusakademius

Copy link
Copy Markdown
Contributor Author

I thought this might be the most intuitive solution because it gives you the stacks for the events you selected. I kept the functionality for selecting a time range as it is, but when I noticed it only filters by time and it is possible for other events to happen at the same time, I thought maybe you could filter there for the event id too, like I did in the feature I implemented. What do you think about this, I think it might be more intuitive for the selection in the EventViewer. I am looking forward to hear your opinion on the idea and the code I already wrote.

@rauhs

Copy link
Copy Markdown

Brian Robbins (@brianrob) Hi Brian, have you had any chance to look at this? If there are any issues let us know.
Cheers

@brianrob

Copy link
Copy Markdown
Member

Thank you for pinging me on this one. I had not looked yet - I am looking now. With my initial testing, it looks great. I'm reviewing the code now and will get back to you on that.

@brianrob Brian Robbins (brianrob) left a comment

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.

Thank you very much for contributing this feature. I tried it out and it's slick.

I've added some comments and questions. It would also be great to have some additional test coverage for this UI feature to make sure that we keep it functional as changes are made in the future. The PerfView tests have a good pattern for implementing UI tests and AI agents are pretty good at picking it up.

if (selectedCells.Count != 1)
{
StatusBar.LogError("Could not parse " + start + " as a number.");
OpenSelectedStacks(stackSourceName, selectedCells);

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.

Previous behavior was that if no cells were selected, the views would still open and populate. Now, they populate with no data. It would be good to preserve this behavior.


// For ETW sources, filter by exact EventIndex so concurrent events on other
// threads at the same timestamp are excluded.
var etwRecords = uniqueRecords.OfType<ETWEventSource.ETWEventRecord>().ToList();

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.

Another potential type that could be held in uniqueRecords is CsvEventRecord. In that case, this will produce an empty list and Min and Max will throw. Will need to handle that here.

}
}
this.StatusBar.LogError("Could not parse " + end + " as a number.");
this.OpenSelectedStacks(stackSourceName, selectedCells);

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 previous behavior was that if nothing was selected then the views would populate with all data. Now, the views will come up but with no data. We should preserve the previous behavior.

// TODO not clear I want this method
public virtual StackSource GetStackSource(TextWriter log, double startRelativeMSec, double endRelativeMSec, Predicate<TraceEvent> predicate)
{
StackSource ret = DataFile.OpenStackSourceImpl(SourceName, log, startRelativeMSec, endRelativeMSec, predicate);

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.

If a predicate is specified, I think we ought to be using it. It might toss all of the events, but if it does, then we shouldn't fall back. Is there a specific reason for the fallback behavior?

}

// Collect unique event records (a row may have multiple selected cells).
var uniqueRecords = selectedCells

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.

selectedCells is a reference to Grid.SelectedCells. You'll need to copy this collection before the call to StatusBar.StartWork to ensure that the collection doesn't change underneath you, since the UI is still fluid.

else
{
// Fall back to per-event time windows for non-ETW sources.
var sources = new List<StackSource>();

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.

I think a reasonable fallback here is to find the min and max and just make a single call that filters the data. I worry that this could be relatively large set of selected fields and we'll be doing lots of work unintentionally.

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