From f0979399d7bf1061523c978263328b3fcb128010 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 19 Nov 2020 11:02:21 -0800 Subject: [PATCH 1/3] Add allocSize diffing --- src/jit-analyze/jit-analyze.cs | 19 +++++++++++++++++-- src/jit-diff/jit-diff.cs | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/jit-analyze/jit-analyze.cs b/src/jit-analyze/jit-analyze.cs index fbd5c4cd..2f118cd7 100644 --- a/src/jit-analyze/jit-analyze.cs +++ b/src/jit-analyze/jit-analyze.cs @@ -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, DebugClauseCount, DebugVarCount"); syntax.DefineOption("note", ref _note, "Descriptive note to add to summary output"); syntax.DefineOption("noreconcile", ref _noreconcile, @@ -226,6 +226,16 @@ 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 DebugClauseMetric : Metric { public override string Name => "DebugClauseCount"; @@ -253,7 +263,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 DebugClauseMetric(), new DebugVarMetric() }; s_metricNameToIndex = new Dictionary(s_metrics.Length); for (int i = 0; i < s_metrics.Length; i++) @@ -541,6 +551,7 @@ public static IEnumerable 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 = @@ -555,6 +566,7 @@ public static IEnumerable 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 { @@ -568,6 +580,8 @@ public static IEnumerable 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 ? @@ -594,6 +608,7 @@ public static IEnumerable ExtractMethodInfo(string filePath) 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", x.Sum(z => z.allocSize)); mi.Metrics.Add("DebugClauseCount", x.Sum(z => z.debugClauseCount)); mi.Metrics.Add("DebugVarCount", x.Sum(z => z.debugVarCount)); diff --git a/src/jit-diff/jit-diff.cs b/src/jit-diff/jit-diff.cs index b44e8260..975e15c8 100755 --- a/src/jit-diff/jit-diff.cs +++ b/src/jit-diff/jit-diff.cs @@ -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, 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."); From 4a839fdde01c656923e7e4fff0edaad91d2dda20 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 13 Jan 2021 15:56:03 -0800 Subject: [PATCH 2/3] Add ExtraAllocBytes diffing --- src/jit-analyze/jit-analyze.cs | 22 ++++++++++++++++++---- src/jit-diff/jit-diff.cs | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/jit-analyze/jit-analyze.cs b/src/jit-analyze/jit-analyze.cs index 2f118cd7..c8a706e5 100644 --- a/src/jit-analyze/jit-analyze.cs +++ b/src/jit-analyze/jit-analyze.cs @@ -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, AllocSize, 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, @@ -236,6 +236,15 @@ public class AllocSizeMetric : Metric public override string ValueString => $"{Value}"; } + public class ExtraAllocBytesMetric : Metric + { + public override string Name => "ExtraAllocBytes"; + public override string DisplayName => "(Code Size - Allocation Size) bytes"; + public override string Unit => "ratio"; + 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"; @@ -263,7 +272,7 @@ public class MetricCollection static MetricCollection() { - s_metrics = new Metric[] { new CodeSizeMetric(), new PrologSizeMetric(), new PerfScoreMetric(), new InstrCountMetric(), new AllocSizeMetric(), 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(s_metrics.Length); for (int i = 0; i < s_metrics.Length; i++) @@ -604,11 +613,16 @@ public static IEnumerable 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", x.Sum(z => z.allocSize)); + 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)); diff --git a/src/jit-diff/jit-diff.cs b/src/jit-diff/jit-diff.cs index 975e15c8..88b64813 100755 --- a/src/jit-diff/jit-diff.cs +++ b/src/jit-diff/jit-diff.cs @@ -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, AllocSize, 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."); From 18ad894a945ba5f3f97615f9e9e5f70a7fe76bd4 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 13 Jan 2021 15:58:56 -0800 Subject: [PATCH 3/3] fix the displayname --- src/jit-analyze/jit-analyze.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jit-analyze/jit-analyze.cs b/src/jit-analyze/jit-analyze.cs index c8a706e5..9685e8a1 100644 --- a/src/jit-analyze/jit-analyze.cs +++ b/src/jit-analyze/jit-analyze.cs @@ -239,8 +239,8 @@ public class AllocSizeMetric : Metric public class ExtraAllocBytesMetric : Metric { public override string Name => "ExtraAllocBytes"; - public override string DisplayName => "(Code Size - Allocation Size) bytes"; - public override string Unit => "ratio"; + 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}";