Skip to content

Add AllocSize and ExtraAllocBytes metric in jit-analyze #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 14, 2021
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
35 changes: 32 additions & 3 deletions src/jit-analyze/jit-analyze.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Config(string[] args)
syntax.DefineOption("w|warn", ref _warn,
"Generate warning output for files/methods that only "
+ "exists in one dataset or the other (only in base or only in diff).");
syntax.DefineOption("m|metric", ref _metric, "Metric to use for diff computations. Available metrics: CodeSize(default), PerfScore, PrologSize, InstrCount, DebugClauseCount, DebugVarCount");
syntax.DefineOption("m|metric", ref _metric, "Metric to use for diff computations. Available metrics: CodeSize(default), PerfScore, PrologSize, InstrCount, AllocSize, ExtraAllocBytes, DebugClauseCount, DebugVarCount");
syntax.DefineOption("note", ref _note,
"Descriptive note to add to summary output");
syntax.DefineOption("noreconcile", ref _noreconcile,
Expand Down Expand Up @@ -226,6 +226,25 @@ public class InstrCountMetric : Metric
public override string ValueString => $"{Value}";
}

public class AllocSizeMetric : Metric
{
public override string Name => "AllocSize";
public override string DisplayName => "Allocation Size";
public override string Unit => "byte";
public override bool LowerIsBetter => true;
public override Metric Clone() => new AllocSizeMetric();
public override string ValueString => $"{Value}";
}

public class ExtraAllocBytesMetric : Metric
{
public override string Name => "ExtraAllocBytes";
public override string DisplayName => "Extra Allocation Size";
public override string Unit => "byte";
public override bool LowerIsBetter => true;
public override Metric Clone() => new ExtraAllocBytesMetric();
public override string ValueString => $"{Value}";
}
public class DebugClauseMetric : Metric
{
public override string Name => "DebugClauseCount";
Expand Down Expand Up @@ -253,7 +272,7 @@ public class MetricCollection

static MetricCollection()
{
s_metrics = new Metric[] { new CodeSizeMetric(), new PrologSizeMetric(), new PerfScoreMetric(), new InstrCountMetric(), new DebugClauseMetric(), new DebugVarMetric() };
s_metrics = new Metric[] { new CodeSizeMetric(), new PrologSizeMetric(), new PerfScoreMetric(), new InstrCountMetric(), new AllocSizeMetric(), new ExtraAllocBytesMetric(), new DebugClauseMetric(), new DebugVarMetric() };
s_metricNameToIndex = new Dictionary<string, int>(s_metrics.Length);

for (int i = 0; i < s_metrics.Length; i++)
Expand Down Expand Up @@ -541,6 +560,7 @@ public static IEnumerable<MethodInfo> ExtractMethodInfo(string filePath)
// use new regex for perf score so we can still parse older files that did not have it.
Regex perfScorePattern = new Regex(@"(PerfScore|perf score) (\d+(\.\d+)?)");
Regex instrCountPattern = new Regex(@"instruction count ([0-9]{1,})");
Regex allocSizePattern = new Regex(@"allocated bytes for code ([0-9]{1,})");
Regex debugInfoPattern = new Regex(@"Variable debug info: ([0-9]{1,}) live range\(s\), ([0-9]{1,}) var\(s\)");

var result =
Expand All @@ -555,6 +575,7 @@ public static IEnumerable<MethodInfo> ExtractMethodInfo(string filePath)
var codeAndPrologSizeMatch = codeAndPrologSizePattern.Match(x.line);
var perfScoreMatch = perfScorePattern.Match(x.line);
var instrCountMatch = instrCountPattern.Match(x.line);
var allocSizeMatch = allocSizePattern.Match(x.line);
var debugInfoMatch = debugInfoPattern.Match(x.line);
return new
{
Expand All @@ -568,6 +589,8 @@ public static IEnumerable<MethodInfo> ExtractMethodInfo(string filePath)
Double.Parse(perfScoreMatch.Groups[2].Value) : 0,
instrCount = instrCountMatch.Success ?
Int32.Parse(instrCountMatch.Groups[1].Value) : 0,
allocSize = allocSizeMatch.Success ?
Int32.Parse(allocSizeMatch.Groups[1].Value) : 0,
debugClauseCount = debugInfoMatch.Success ?
Int32.Parse(debugInfoMatch.Groups[1].Value) : 0,
debugVarCount = debugInfoMatch.Success ?
Expand All @@ -590,10 +613,16 @@ public static IEnumerable<MethodInfo> ExtractMethodInfo(string filePath)
.Select(z => z.functionOffset).ToList()
};

mi.Metrics.Add("CodeSize", x.Sum(z => z.totalBytes));
int totalCodeSize = x.Sum(z => z.totalBytes);
int totalAllocSize = x.Sum(z => z.allocSize);
Debug.Assert(totalCodeSize <= totalAllocSize);

mi.Metrics.Add("CodeSize", totalCodeSize);
mi.Metrics.Add("PrologSize", x.Sum(z => z.prologBytes));
mi.Metrics.Add("PerfScore", x.Sum(z => z.perfScore));
mi.Metrics.Add("InstrCount", x.Sum(z => z.instrCount));
mi.Metrics.Add("AllocSize", totalAllocSize);
mi.Metrics.Add("ExtraAllocBytes", totalAllocSize - totalCodeSize);
mi.Metrics.Add("DebugClauseCount", x.Sum(z => z.debugClauseCount));
mi.Metrics.Add("DebugVarCount", x.Sum(z => z.debugVarCount));

Expand Down
2 changes: 1 addition & 1 deletion src/jit-diff/jit-diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Config(string[] args)
syntax.DefineOption("t|tag", ref _tag, "Name of root in output directory. Allows for many sets of output.");
syntax.DefineOption("c|corelib", ref _corelib, "Diff System.Private.CoreLib.dll.");
syntax.DefineOption("f|frameworks", ref _frameworks, "Diff frameworks.");
syntax.DefineOption("m|metric", ref _metric, false, "Metric to use for diff computations. Available metrics: CodeSize(default), PerfScore, PrologSize, InstrCount, DebugClauseCount, DebugVarCount");
syntax.DefineOption("m|metric", ref _metric, false, "Metric to use for diff computations. Available metrics: CodeSize(default), PerfScore, PrologSize, InstrCount, AllocSize, ExtraAllocBytes, DebugClauseCount, DebugVarCount");
syntax.DefineOption("benchmarks", ref _benchmarks, "Diff core benchmarks.");
syntax.DefineOption("tests", ref _tests, "Diff all tests.");
syntax.DefineOption("gcinfo", ref _gcinfo, "Add GC info to the disasm output.");
Expand Down