Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ProfileExplorerCore/Profile/Data/RawProfileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public class RawProfileData : IDisposable {
private static ProfileImage lastIpImage_;
[ThreadStatic]
private static IpToImageCache globalIpImageCache_;

/// <summary>
/// Clears thread-local caches on the current thread
/// </summary>
public static void ClearThreadLocalCaches() {
ipImageCache_ = null;
lastIpImage_ = null;
globalIpImageCache_ = null;
}
Comment thread
jhpohovey marked this conversation as resolved.
Comment thread
jhpohovey marked this conversation as resolved.
[ProtoMember(1)]
private List<ProfileSample> samples_;
[ProtoMember(2)]
Expand Down
10 changes: 10 additions & 0 deletions src/ProfileExplorerCore/Profile/Data/ResolvedProfileStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ public sealed class ResolvedProfileStack {
public static ConcurrentDictionary<long, ResolvedProfileStackFrame> frameInstances_ = new();
public static ConcurrentDictionary<long, ResolvedProfileStackFrame> kernelFrameInstances_ = new();

/// <summary>
/// Clears all static frame caches. Must be called before processing a new trace
/// to prevent stale frame references from a previous session.
/// </summary>
public static void ResetCaches() {
uniqueFrames_.Clear();
frameInstances_.Clear();
kernelFrameInstances_.Clear();
}

public ResolvedProfileStack(int frameCount, ProfileContext context) {
StackFrames = new List<ResolvedProfileStackFrame>(frameCount);
Context = context;
Expand Down
10 changes: 10 additions & 0 deletions src/ProfileExplorerCore/Profile/ETW/ETWProfileDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public ETWProfileDataProvider() {
for (int i = 0; i < imageLocks_.Length; i++) {
imageLocks_[i] = new object();
}

// Clear static caches from any previous trace load to prevent
// stale frame/function references leaking across sessions.
ResolvedProfileStack.ResetCaches();
Comment thread
jhpohovey marked this conversation as resolved.
}

public static async Task<List<ProcessSummary>>
Expand Down Expand Up @@ -425,6 +429,12 @@ private void CollectChunkSamples(List<Task<List<(ProfileSample Sample, ResolvedP
SymbolFileSourceSettings symbolSettings,
ProfileLoadProgressHandler progressCallback,
CancelableTask cancelableTask, int chunks) {

// Clear thread-local caches to prevent stale data from previous trace loads
prevImage_ = null;
prevProfileModuleBuilder_ = null;
RawProfileData.ClearThreadLocalCaches();

Comment thread
jhpohovey marked this conversation as resolved.
var totalWeight = TimeSpan.Zero;
var profileWeight = TimeSpan.Zero;
var samples = new List<(ProfileSample Sample, ResolvedProfileStack Stack)>(end - start + 1);
Expand Down
5 changes: 4 additions & 1 deletion src/ProfileExplorerUI/MainWindowPanels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,10 +1032,13 @@ private async Task SetupSectionPanel() {
SectionPanel.CompilerInfo = compilerInfo_;
SectionPanel.Session = this;

// Clear stale module summaries from any previous session
// before adding the new ones.
SectionPanel.ClearModuleSummaries();

foreach (var doc in sessionState_.Documents) {
if (doc != sessionState_.MainDocument &&
doc != sessionState_.DiffDocument) {
// Add optional modules, usually used for profiling.
SectionPanel.AddModuleSummary(doc.Summary);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/ProfileExplorerUI/Panels/SectionPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,11 @@ public void AddModuleSummary(IRTextSummary summary) {
}
}

public void ClearModuleSummaries() {
moduleSummaries_.Clear();
sectionExtensionComputed_ = false;
}

public bool HasSummary(IRTextSummary summary) {
return summary == summary_ ||
moduleSummaries_.Contains(summary);
Expand Down
4 changes: 4 additions & 0 deletions src/ProfileExplorerUI/Panels/SectionPanelPair.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public void AddModuleSummary(IRTextSummary summary) {
MainPanel.AddModuleSummary(summary);
}

public void ClearModuleSummaries() {
MainPanel.ClearModuleSummaries();
}

public async Task RefreshDocumentsDiffs() {
if (MainPanel.CurrentFunction == null) {
return;
Expand Down
Loading