Skip to content

Commit 14f8640

Browse files
authored
Add AllocSize and ExtraAllocBytes metric in jit-analyze (#311)
* Add allocSize diffing * Add ExtraAllocBytes diffing * fix the displayname
1 parent 23756f4 commit 14f8640

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/jit-analyze/jit-analyze.cs

+32-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Config(string[] args)
7171
syntax.DefineOption("w|warn", ref _warn,
7272
"Generate warning output for files/methods that only "
7373
+ "exists in one dataset or the other (only in base or only in diff).");
74-
syntax.DefineOption("m|metric", ref _metric, "Metric to use for diff computations. Available metrics: CodeSize(default), PerfScore, PrologSize, InstrCount, DebugClauseCount, DebugVarCount");
74+
syntax.DefineOption("m|metric", ref _metric, "Metric to use for diff computations. Available metrics: CodeSize(default), PerfScore, PrologSize, InstrCount, AllocSize, ExtraAllocBytes, DebugClauseCount, DebugVarCount");
7575
syntax.DefineOption("note", ref _note,
7676
"Descriptive note to add to summary output");
7777
syntax.DefineOption("noreconcile", ref _noreconcile,
@@ -226,6 +226,25 @@ public class InstrCountMetric : Metric
226226
public override string ValueString => $"{Value}";
227227
}
228228

229+
public class AllocSizeMetric : Metric
230+
{
231+
public override string Name => "AllocSize";
232+
public override string DisplayName => "Allocation Size";
233+
public override string Unit => "byte";
234+
public override bool LowerIsBetter => true;
235+
public override Metric Clone() => new AllocSizeMetric();
236+
public override string ValueString => $"{Value}";
237+
}
238+
239+
public class ExtraAllocBytesMetric : Metric
240+
{
241+
public override string Name => "ExtraAllocBytes";
242+
public override string DisplayName => "Extra Allocation Size";
243+
public override string Unit => "byte";
244+
public override bool LowerIsBetter => true;
245+
public override Metric Clone() => new ExtraAllocBytesMetric();
246+
public override string ValueString => $"{Value}";
247+
}
229248
public class DebugClauseMetric : Metric
230249
{
231250
public override string Name => "DebugClauseCount";
@@ -253,7 +272,7 @@ public class MetricCollection
253272

254273
static MetricCollection()
255274
{
256-
s_metrics = new Metric[] { new CodeSizeMetric(), new PrologSizeMetric(), new PerfScoreMetric(), new InstrCountMetric(), new DebugClauseMetric(), new DebugVarMetric() };
275+
s_metrics = new Metric[] { new CodeSizeMetric(), new PrologSizeMetric(), new PerfScoreMetric(), new InstrCountMetric(), new AllocSizeMetric(), new ExtraAllocBytesMetric(), new DebugClauseMetric(), new DebugVarMetric() };
257276
s_metricNameToIndex = new Dictionary<string, int>(s_metrics.Length);
258277

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

546566
var result =
@@ -555,6 +575,7 @@ public static IEnumerable<MethodInfo> ExtractMethodInfo(string filePath)
555575
var codeAndPrologSizeMatch = codeAndPrologSizePattern.Match(x.line);
556576
var perfScoreMatch = perfScorePattern.Match(x.line);
557577
var instrCountMatch = instrCountPattern.Match(x.line);
578+
var allocSizeMatch = allocSizePattern.Match(x.line);
558579
var debugInfoMatch = debugInfoPattern.Match(x.line);
559580
return new
560581
{
@@ -568,6 +589,8 @@ public static IEnumerable<MethodInfo> ExtractMethodInfo(string filePath)
568589
Double.Parse(perfScoreMatch.Groups[2].Value) : 0,
569590
instrCount = instrCountMatch.Success ?
570591
Int32.Parse(instrCountMatch.Groups[1].Value) : 0,
592+
allocSize = allocSizeMatch.Success ?
593+
Int32.Parse(allocSizeMatch.Groups[1].Value) : 0,
571594
debugClauseCount = debugInfoMatch.Success ?
572595
Int32.Parse(debugInfoMatch.Groups[1].Value) : 0,
573596
debugVarCount = debugInfoMatch.Success ?
@@ -590,10 +613,16 @@ public static IEnumerable<MethodInfo> ExtractMethodInfo(string filePath)
590613
.Select(z => z.functionOffset).ToList()
591614
};
592615

593-
mi.Metrics.Add("CodeSize", x.Sum(z => z.totalBytes));
616+
int totalCodeSize = x.Sum(z => z.totalBytes);
617+
int totalAllocSize = x.Sum(z => z.allocSize);
618+
Debug.Assert(totalCodeSize <= totalAllocSize);
619+
620+
mi.Metrics.Add("CodeSize", totalCodeSize);
594621
mi.Metrics.Add("PrologSize", x.Sum(z => z.prologBytes));
595622
mi.Metrics.Add("PerfScore", x.Sum(z => z.perfScore));
596623
mi.Metrics.Add("InstrCount", x.Sum(z => z.instrCount));
624+
mi.Metrics.Add("AllocSize", totalAllocSize);
625+
mi.Metrics.Add("ExtraAllocBytes", totalAllocSize - totalCodeSize);
597626
mi.Metrics.Add("DebugClauseCount", x.Sum(z => z.debugClauseCount));
598627
mi.Metrics.Add("DebugVarCount", x.Sum(z => z.debugVarCount));
599628

src/jit-diff/jit-diff.cs

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

0 commit comments

Comments
 (0)