Skip to content

Commit 7bc4c9e

Browse files
committed
AddSupportForExaminingTypeLoadOperations
1 parent b1a21d6 commit 7bc4c9e

File tree

5 files changed

+319
-4
lines changed

5 files changed

+319
-4
lines changed

src/PerfView/CommandProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ public void Start(CommandLineArgs parsedArgs)
356356
if (parsedArgs.RuntimeLoading)
357357
{
358358
parsedArgs.ClrEvents |= ClrTraceEventParser.Keywords.CompilationDiagnostic;
359+
parsedArgs.ClrEvents |= ClrTraceEventParser.Keywords.MethodDiagnostic;
360+
parsedArgs.ClrEvents |= ClrTraceEventParser.Keywords.TypeDiagnostic;
359361
}
360362

361363
if (profilerKeywords != 0)

src/PerfView/PerfViewData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3545,7 +3545,7 @@ protected override string DoCommand(string command, StatusBar worker)
35453545
if (m_interestingProcesses.ContainsKey(processId))
35463546
{
35473547
var proc = m_interestingEtlxProcesses[processId];
3548-
var txtFile = CacheFiles.FindFile(FilePath, ".runtimeLoadertats." + processId.ToString() + ".txt");
3548+
var txtFile = CacheFiles.FindFile(FilePath, ".runtimeLoaderstats." + processId.ToString() + ".txt");
35493549
if (!File.Exists(txtFile) || File.GetLastWriteTimeUtc(txtFile) < File.GetLastWriteTimeUtc(FilePath) ||
35503550
File.GetLastWriteTimeUtc(txtFile) < File.GetLastWriteTimeUtc(SupportFiles.MainAssemblyPath))
35513551
{

src/PerfView/UserCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ public static MutableTraceEventStackSource ThreadTimeStacks(this TraceLog eventL
18741874
return stackSource;
18751875
}
18761876

1877-
public static StackSource RuntimeOperationsStacks(this TraceLog eventLog, TraceProcess process = null, Predicate<TraceEvent> predicate = null)
1877+
public static StackSource RuntimeLoaderStacks(this TraceLog eventLog, TraceProcess process = null, Predicate<TraceEvent> predicate = null)
18781878
{
18791879
TraceEvents events;
18801880
if (process == null)

src/TraceEvent/Computers/CLRRuntimeActivityComputer.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct IncompleteActionDesc
5555

5656
Dictionary<IdOfIncompleteAction, IncompleteActionDesc> _incompleteJitEvents = new Dictionary<IdOfIncompleteAction, IncompleteActionDesc>();
5757
Dictionary<IdOfIncompleteAction, IncompleteActionDesc> _incompleteR2REvents = new Dictionary<IdOfIncompleteAction, IncompleteActionDesc>();
58+
Dictionary<IdOfIncompleteAction, IncompleteActionDesc> _incompleteTypeLoadEvents = new Dictionary<IdOfIncompleteAction, IncompleteActionDesc>();
5859

5960
public Dictionary<int, List<StartStopStackMingledComputer.StartStopThreadEventData>> StartStopEvents { get; } = new Dictionary<int, List<StartStopStackMingledComputer.StartStopThreadEventData>>();
6061

@@ -65,12 +66,18 @@ public CLRRuntimeActivityComputer(TraceLogEventSource source)
6566
source.Clr.MethodLoadVerbose += Clr_MethodLoadVerbose;
6667
source.Clr.MethodLoad += Clr_MethodLoad;
6768
source.Clr.LoaderAssemblyLoad += Clr_LoaderAssemblyLoad;
69+
source.Clr.MethodR2RGetEntryPointStarted += Clr_R2RGetEntryPointStarted;
70+
source.Clr.TypeLoadStart += Clr_TypeLoadStart;
71+
source.Clr.TypeLoadStop += Clr_TypeLoadStop;
6872
source.Process();
6973
source.Clr.MethodJittingStarted -= Clr_MethodJittingStarted;
74+
source.Clr.MethodR2RGetEntryPointStarted -= Clr_R2RGetEntryPointStarted;
7075
source.Clr.MethodR2RGetEntryPoint -= Clr_MethodR2RGetEntryPoint;
7176
source.Clr.MethodLoadVerbose -= Clr_MethodLoadVerbose;
7277
source.Clr.MethodLoad -= Clr_MethodLoad;
7378
source.Clr.LoaderAssemblyLoad -= Clr_LoaderAssemblyLoad;
79+
source.Clr.TypeLoadStart -= Clr_TypeLoadStart;
80+
source.Clr.TypeLoadStop -= Clr_TypeLoadStop;
7481
}
7582

7683
private void AddStartStopData(int threadId, StartStopStackMingledComputer.EventUID start, StartStopStackMingledComputer.EventUID end, string name)
@@ -127,6 +134,20 @@ private void Clr_MethodJittingStarted(MethodJittingStartedTraceData obj)
127134
_incompleteJitEvents[id] = incompleteDesc;
128135
}
129136

137+
private void Clr_R2RGetEntryPointStarted(R2RGetEntryPointStartedTraceData obj)
138+
{
139+
IncompleteActionDesc incompleteDesc = new IncompleteActionDesc();
140+
incompleteDesc.Start = new StartStopStackMingledComputer.EventUID(obj);
141+
incompleteDesc.Name = "";
142+
incompleteDesc.OperationType = "R2R";
143+
144+
IdOfIncompleteAction id = new IdOfIncompleteAction();
145+
id.Identifier = obj.MethodID;
146+
id.ThreadID = obj.ThreadID;
147+
148+
_incompleteR2REvents[id] = incompleteDesc;
149+
}
150+
130151
private void Clr_MethodR2RGetEntryPoint(R2RGetEntryPointTraceData obj)
131152
{
132153
IdOfIncompleteAction id = new IdOfIncompleteAction();
@@ -139,7 +160,7 @@ private void Clr_MethodR2RGetEntryPoint(R2RGetEntryPointTraceData obj)
139160
if (_incompleteR2REvents.TryGetValue(id, out IncompleteActionDesc r2rStartData))
140161
{
141162
startUID = r2rStartData.Start;
142-
_incompleteJitEvents.Remove(id);
163+
_incompleteR2REvents.Remove(id);
143164
}
144165

145166
if (obj.EntryPoint == 0)
@@ -152,5 +173,37 @@ private void Clr_MethodR2RGetEntryPoint(R2RGetEntryPointTraceData obj)
152173
AddStartStopData(id.ThreadID, startUID, new StartStopStackMingledComputer.EventUID(obj), "R2R_Found" + "(" + JITStats.GetMethodName(obj) + ")");
153174
}
154175
}
176+
177+
private void Clr_TypeLoadStart(TypeLoadStartTraceData obj)
178+
{
179+
IncompleteActionDesc incompleteDesc = new IncompleteActionDesc();
180+
incompleteDesc.Start = new StartStopStackMingledComputer.EventUID(obj);
181+
incompleteDesc.Name = "";
182+
incompleteDesc.OperationType = "TypeLoad";
183+
184+
IdOfIncompleteAction id = new IdOfIncompleteAction();
185+
id.Identifier = obj.TypeLoadStartID;
186+
id.ThreadID = obj.ThreadID;
187+
188+
_incompleteTypeLoadEvents[id] = incompleteDesc;
189+
}
190+
191+
private void Clr_TypeLoadStop(TypeLoadStopTraceData obj)
192+
{
193+
IdOfIncompleteAction id = new IdOfIncompleteAction();
194+
id.Identifier = obj.TypeLoadStartID;
195+
id.ThreadID = obj.ThreadID;
196+
197+
// If we had a TypeLoad start lookup event, capture that start time, otherwise, use the TypeLoadStop
198+
// data as both start and stop
199+
StartStopStackMingledComputer.EventUID startUID = new StartStopStackMingledComputer.EventUID(obj);
200+
if (_incompleteTypeLoadEvents.TryGetValue(id, out IncompleteActionDesc typeLoadStartData))
201+
{
202+
startUID = typeLoadStartData.Start;
203+
_incompleteTypeLoadEvents.Remove(id);
204+
}
205+
206+
AddStartStopData(id.ThreadID, startUID, new StartStopStackMingledComputer.EventUID(obj), $"TypeLoad ({obj.TypeName}, {obj.LoadLevel})");
207+
}
155208
}
156209
}

0 commit comments

Comments
 (0)