Skip to content

fix stale session state when loading a second (new) trace via file>open#42

Merged
jhpohovey merged 4 commits into
mainfrom
user/johnpohovey/fix-stale-profile-on-reopen
Mar 25, 2026
Merged

fix stale session state when loading a second (new) trace via file>open#42
jhpohovey merged 4 commits into
mainfrom
user/johnpohovey/fix-stale-profile-on-reopen

Conversation

@jhpohovey

Copy link
Copy Markdown
Member

Opening a second trace via File > Open while another trace is already loaded might show wrong data in the function table (stale functions from the previous trace persist with 0ms weights).

Two things were leaking across trace loads on occasion:

  • moduleSummaries_ in SectionPanel was never cleared, so old functions accumulated alongside new ones
  • Static frame caches in ResolvedProfileStack and thread-local IpToImageCache entries survived across loads since thread pool threads get reused

Clearing these on new trace load makes results deterministic, regardless of order we open trace after trace in.

Tested by loading the same trace fresh vs after another trace, and seeing that now the weights, etc., are equal.

@jhpohovey jhpohovey marked this pull request as ready for review March 19, 2026 18:10
Copilot AI review requested due to automatic review settings March 19, 2026 18:10

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.

Pull request overview

Fixes stale UI/profile state when loading multiple traces sequentially via File > Open, ensuring deterministic function table contents by clearing per-session and cache state between loads.

Changes:

  • Add APIs to clear SectionPanel module summaries and invoke them during section panel setup.
  • Clear static frame caches in ResolvedProfileStack and thread-local caches used during ETW load.
  • Force function list refresh when setting the main summary for a new session.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ProfileExplorerUI/Panels/SectionPanelPair.xaml.cs Adds a passthrough method to clear module summaries from the main section panel.
src/ProfileExplorerUI/Panels/SectionPanel.xaml.cs Implements clearing moduleSummaries_ and related computed state.
src/ProfileExplorerUI/MainWindowPanels.cs Clears stale module summaries and refreshes function list during section panel setup; adds trace logging.
src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs Clears static frame caches and thread-local caches to prevent cross-trace leakage.
src/ProfileExplorerCore/Profile/Data/RawProfileData.cs Adds API to clear caches used for IP-to-image resolution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ProfileExplorerUI/MainWindowPanels.cs Outdated
Comment thread src/ProfileExplorerUI/MainWindowPanels.cs
Comment thread src/ProfileExplorerCore/Profile/Data/RawProfileData.cs
Comment thread src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs Outdated
@jhpohovey jhpohovey assigned jhpohovey and ivberg and unassigned jhpohovey Mar 19, 2026
@jhpohovey jhpohovey enabled auto-merge (squash) March 19, 2026 18:46
@jhpohovey jhpohovey requested a review from Copilot March 19, 2026 18:46

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.

Pull request overview

Fixes stale state persisting when opening multiple traces in the same app session, which could lead to incorrect function-table data (e.g., old functions persisting with 0ms weights).

Changes:

  • Clears SectionPanel’s accumulated module summaries when setting up a new trace.
  • Resets static frame caches in ResolvedProfileStack to prevent cross-trace frame/function reuse.
  • Clears thread-local IP→image caches to avoid leaking per-thread state across trace loads.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ProfileExplorerUI/Panels/SectionPanelPair.xaml.cs Adds pass-through API to clear module summaries.
src/ProfileExplorerUI/Panels/SectionPanel.xaml.cs Implements clearing of cached module summaries / computed state.
src/ProfileExplorerUI/MainWindowPanels.cs Clears summaries on setup and forces function list update on main summary load.
src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs Resets static caches on provider construction and clears thread-local caches during chunk collection.
src/ProfileExplorerCore/Profile/Data/ResolvedProfileStack.cs Adds ResetCaches() for static frame caches.
src/ProfileExplorerCore/Profile/Data/RawProfileData.cs Adds API to clear thread-local caches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs
Comment thread src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs
Comment thread src/ProfileExplorerCore/Profile/Data/RawProfileData.cs

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.

Pull request overview

Fixes nondeterministic/stale UI profiling data when loading a second trace by clearing state that can leak across trace loads (UI module summaries and static/thread-local frame/image caches).

Changes:

  • Add ClearModuleSummaries() to SectionPanel (and a forwarding method on SectionPanelPair) to reset optional module summary state between loads.
  • Clear ResolvedProfileStack static caches at ETW provider construction time and clear thread-local image caches at the start of chunk processing.
  • Ensure the section panel initialization path clears prior module summaries when setting up panels for a new load.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/ProfileExplorerUI/Panels/SectionPanelPair.xaml.cs Adds a ClearModuleSummaries() forwarder to the main section panel.
src/ProfileExplorerUI/Panels/SectionPanel.xaml.cs Implements ClearModuleSummaries() to reset stored optional module summaries.
src/ProfileExplorerUI/MainWindowPanels.cs Clears module summaries during section panel setup and forces function list refresh on main summary set.
src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs Resets static frame caches per load and clears thread-local caches per chunk worker start.
src/ProfileExplorerCore/Profile/Data/ResolvedProfileStack.cs Adds ResetCaches() API for static frame cache dictionaries.
src/ProfileExplorerCore/Profile/Data/RawProfileData.cs Adds ClearThreadLocalCaches() helper to reset per-thread IP→image caches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ProfileExplorerUI/MainWindowPanels.cs Outdated
Comment thread src/ProfileExplorerUI/MainWindowPanels.cs Outdated
@jhpohovey jhpohovey disabled auto-merge March 19, 2026 22:02
@jhpohovey jhpohovey force-pushed the user/johnpohovey/fix-stale-profile-on-reopen branch from 7be56c3 to 11deb4e Compare March 19, 2026 22:25
@jhpohovey jhpohovey force-pushed the user/johnpohovey/fix-stale-profile-on-reopen branch from 11deb4e to c1e898e Compare March 19, 2026 22:41

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ProfileExplorerUI/MainWindowPanels.cs
@jhpohovey jhpohovey enabled auto-merge (squash) March 20, 2026 16:48
@jhpohovey jhpohovey merged commit c5c5048 into main Mar 25, 2026
10 checks passed
@jhpohovey jhpohovey deleted the user/johnpohovey/fix-stale-profile-on-reopen branch March 25, 2026 18:20
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