Skip to content

Commit

Permalink
Generalize to handle crossgen
Browse files Browse the repository at this point in the history
Currently don't see how to get at jit events during crossgen. But
basic instructions retired accounting is there.
  • Loading branch information
AndyAyersMS committed Aug 7, 2017
1 parent 36a35da commit d476f9c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
15 changes: 15 additions & 0 deletions inst-retired-crossgen.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
setlocal

set CORE_ROOT=D:\repos\coreclr\bin\tests\Windows_NT.x64.release\Tests\Core_Root
cd /d %CORE_ROOT%

c:\xperf\xperf -on PROC_THREAD+LOADER+pmc_profile+profile -pmcprofile InstructionRetired -f c:\home\kernel.etl
c:\xperf\xperf -start clr -on e13c0d23-ccbc-4e12-931b-d9cc2eee27e4:0x1CCBD:0x5 -f c:\home\clr.etl
crossgen.exe %*
c:\xperf\xperf -stop clr
c:\xperf\xperf -stop
c:\xperf\xperf -merge c:\home\clr.etl c:\home\kernel.etl c:\home\perf.etl




14 changes: 1 addition & 13 deletions instr-retired.bat
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
setlocal

set CORE_ROOT=C:\repos\coreclr\bin\tests\Windows_NT.x64.release\Tests\Core_Root
set CORE_ROOT=D:\repos\coreclr\bin\tests\Windows_NT.x64.release\Tests\Core_Root
cd /d %CORE_ROOT%

goto :CLR

c:\xperf\xperf -on PROC_THREAD+LOADER+pmc_profile+profile -pmcprofile InstructionRetired -f c:\home\kernel.etl
corerun.exe %*
c:\xperf\xperf -d c:\home\perf.etl

goto :EOF

@rem clr event variant

:CLR

c:\xperf\xperf -on PROC_THREAD+LOADER+pmc_profile+profile -pmcprofile InstructionRetired -f c:\home\kernel.etl
c:\xperf\xperf -start clr -on e13c0d23-ccbc-4e12-931b-d9cc2eee27e4:0x1CCBD:0x5 -f c:\home\clr.etl
corerun.exe %*
Expand Down
2 changes: 0 additions & 2 deletions src/InstRetired.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Diagnostics.Tracing.TraceEvent, Version=1.0.41.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\lib\net40\Microsoft.Diagnostics.Tracing.TraceEvent.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -76,7 +75,6 @@
<Compile Include="instretired.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="_TraceEventProgrammersGuide.docx" />
</ItemGroup>
Expand Down
50 changes: 36 additions & 14 deletions src/instretired.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ImageInfo(string name, ulong baseAddress, int size)
Size = size;
EndAddress = baseAddress + (uint)Size;
SampleCount = 0;
IsJitGeneratedCode = false;
IsJitGeneratedCode = false;
}

public static int LowerAddress(ImageInfo x, ImageInfo y)
Expand Down Expand Up @@ -73,6 +73,8 @@ public class Program
public static ulong JitGeneratedCodeSampleCount = 0;
public static ulong JittedCodeSampleCount = 0;
public static ulong UnknownImageCount = 0;
public static ulong JittedCodeSize = 0;
public static ulong ManagedMethodCount = 0;

static void UpdateSampleCountMap(ulong address, ulong count)
{
Expand Down Expand Up @@ -104,7 +106,7 @@ static void AttributeSampleCounts()
int imageIndex = 0;
ImageInfo image = imageArray[imageIndex];

foreach(ulong address in SampleCountMap.Keys)
foreach (ulong address in SampleCountMap.Keys)
{
while ((imageIndex < imageArray.Length) && (address >= image.EndAddress))
{
Expand Down Expand Up @@ -169,11 +171,24 @@ private static string GetName(MethodLoadUnloadVerboseTraceData data)
return className + sep + data.MethodName + sig;
}

public static void Main(string[] args)
public static int Main(string[] args)
{
if (args.Length != 1 && args.Length != 3)
{
Console.WriteLine("Usage: instretired file.etl [-process process-name]");
Console.WriteLine(" process defaults to corerun");
return -1;
}

string traceFile = args[0];
string benchmarkName = "dotnet";
string benchmarkName = "corerun";
int benchmarkPid = -2;
if (args.Length == 3)
{
benchmarkName = args[2];
}

Console.WriteLine("Mining ETL from {0} for process {1}", traceFile, benchmarkName);

Dictionary<string, uint> allEventCounts = new Dictionary<string, uint>();
Dictionary<string, uint> eventCounts = new Dictionary<string, uint>();
Expand Down Expand Up @@ -343,14 +358,24 @@ public static void Main(string[] args)
{
JitSampleCount += j.FinalThreadCount - j.InitialThreadCount;
}

ManagedMethodCount++;
JittedCodeSize += (ulong)loadUnloadData.MethodExtent;
}
else
{
// ?
}
break;
}
case "Method/UnloadVerbose":
}
case "Method/UnloadVerbose":
{
// Pretend this is an "image"
MethodLoadUnloadVerboseTraceData loadUnloadData = (MethodLoadUnloadVerboseTraceData)data;
string fullName = GetName(loadUnloadData);
string key = fullName + "@" + loadUnloadData.MethodID.ToString("X");
if (!ImageMap.ContainsKey(key))
{
// Pretend this is an "image"
MethodLoadUnloadVerboseTraceData loadUnloadData = (MethodLoadUnloadVerboseTraceData)data;
Expand Down Expand Up @@ -380,22 +405,17 @@ public static void Main(string[] args)

AttributeSampleCounts();

//foreach (var e in allEventCounts)
//{
// Console.WriteLine("Event {0} occurred {1} times", e.Key, e.Value);
//}
//foreach (var e in processCounts)
//{
// Console.WriteLine("Process {0} had {1} events", e.Key, e.Value);
//}
foreach (var e in allEventCounts)
{
Console.WriteLine("Event {0} occurred {1} times", e.Key, e.Value);
}

if (!eventCounts.ContainsKey("PerfInfo/PMCSample"))
{
Console.WriteLine("No PMC events seen, sorry.");
}
else
{

ulong InstrsPerEvent = 65536;
ulong pmcEvents = eventCounts["PerfInfo/PMCSample"];

Expand Down Expand Up @@ -441,6 +461,8 @@ public static void Main(string[] args)
i.Name);
}
}

return 0;
}
}
}

0 comments on commit d476f9c

Please sign in to comment.