Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use better lock, include overlap in graph titles, minor other fixes
  • Loading branch information
jakobbotsch committed Nov 17, 2021
commit 4dc9fa2ab797fb6aa8c9997cffe0fd81cd834811
8 changes: 2 additions & 6 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10843,10 +10843,8 @@ void CodeGen::genDumpPreciseDebugInfo()
if (JitConfig.JitDumpPreciseDebugInfoFile() == nullptr)
return;

static unsigned int s_flag;

while (InterlockedCompareExchange(&s_flag, 1, 0) != 0)
System_YieldProcessor();
static CritSecObject s_critSect;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we don't want the jit to take locks but using one during bring-up like this is ok.

CritSecHolder holder(s_critSect);

FILE* file = _wfopen(JitConfig.JitDumpPreciseDebugInfoFile(), W("a"));
if (file == nullptr)
Expand Down Expand Up @@ -10878,8 +10876,6 @@ void CodeGen::genDumpPreciseDebugInfo()
fprintf(file, "]}\n");

fclose(file);

InterlockedCompareExchange(&s_flag, 0, 1);
}

void CodeGen::genAddPreciseIPMappingHere(const DebugInfo& di)
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/dotnet-pgo/MethodMemoryMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public MethodMemoryMap(
TraceTypeSystemContext tsc,
TraceRuntimeDescToTypeSystemDesc idParser,
int clrInstanceID,
string preciseDebugInfoFile,
FileInfo preciseDebugInfoFile,
Logger logger)
{
// Capture the addresses of jitted code
Expand Down Expand Up @@ -161,10 +161,10 @@ public MethodMemoryMap(
}

List<PreciseDebugInfo> preciseInfos = null;
if (File.Exists(preciseDebugInfoFile))
if (preciseDebugInfoFile != null)
{
preciseInfos =
File.ReadAllLines(preciseDebugInfoFile)
File.ReadAllLines(preciseDebugInfoFile.FullName)
.Select(l => JsonSerializer.Deserialize<PreciseDebugInfo>(l))
.ToList();
}
Expand Down
37 changes: 31 additions & 6 deletions src/coreclr/tools/dotnet-pgo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,21 +623,46 @@ string FormatDevirt(GetLikelyClassResult result)

if (options.DumpWorstOverlapGraphsTo != null)
{
IEnumerable<(MethodDesc Method, double Overlap)> toDump;
IEnumerable<MethodDesc> toDump;
if (options.DumpWorstOverlapGraphs == -1)
toDump = blockOverlaps.OrderBy(t => t.Overlap).TakeWhile(t => t.Overlap < 0.5);
{
// Take all with less than 0.5 overlap in order.
toDump =
blockOverlaps
.Concat(edgeOverlaps)
.OrderBy(t => t.Overlap)
.TakeWhile(t => t.Overlap < 0.5)
.Select(t => t.Method)
.Distinct();
}
else
toDump = blockOverlaps.OrderBy(t => t.Overlap).Take(options.DumpWorstOverlapGraphs);
{
// Take the first N methods ordered by min(blockOverlap, edgeOverlap).
toDump =
blockOverlaps
.Concat(edgeOverlaps)
.GroupBy(t => t.Method)
.Select(g => (Method: g.Key, Overlap: g.Select(t => t.Overlap).Min()))
.OrderBy(t => t.Overlap)
.Select(t => t.Method)
.Take(options.DumpWorstOverlapGraphs);
}

foreach ((MethodDesc method, double overlap) in toDump)
foreach (MethodDesc method in toDump)
{
PgoCompareMethodFlowGraph fg = fgMatches[method];

string title = $"Flowgraph for {method}\\n{name1} vs {name2}";
if (fg.ProfilesHadBasicBlocks)
{
title += $"\\nBasic block counts: {fg.TotalBlockCount1} vs {fg.TotalEdgeCount2}";
title += $"\\nBasic block count overlap: {fg.ComputeBlockOverlap() * 100:F2}%";
}
if (fg.ProfilesHadEdges)
title += $"\\Edge counts: {fg.TotalEdgeCount1} vs {fg.TotalEdgeCount2}";
{
title += $"\\nEdge counts: {fg.TotalEdgeCount1} vs {fg.TotalEdgeCount2}";
title += $"\\nEdge count overlap: {fg.ComputeEdgeOverlap() * 100:F2}%";
}

string dot = fg.Dump(title);

Expand Down Expand Up @@ -1290,7 +1315,7 @@ MethodMemoryMap GetMethodMemMap()
tsc,
idParser,
clrInstanceId.Value,
commandLineOptions.PreciseDebugInfoFile?.FullName,
commandLineOptions.PreciseDebugInfoFile,
s_logger);
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/dotnet-pgo/SPGO/SampleCorrelator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Microsoft.Diagnostics.Tools.Pgo
{
/// <summary>
/// A class that handles correlation IP samples/LBR samples back to managed methods.
/// A class that handles correlating IP samples/LBR samples back to managed methods.
/// </summary>
internal class SampleCorrelator
{
Expand Down