Skip to content
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

Producing the asm diff reports on demand - fix for #936 #937

Merged
merged 4 commits into from
Oct 31, 2018
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
4 changes: 3 additions & 1 deletion docs/articles/guides/console-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ You can also filter the benchmarks by categories:
## Diagnosers

* `-m`, `--memory` - enables MemoryDiagnoser and prints memory statistics
* `-d`, `--disassm`- enables DisassemblyDiagnoser and exports diassembly of benchmarked code
* `-d`, `--disasm`- enables DisassemblyDiagnoser and exports diassembly of benchmarked code. When you enable this option, you can use:
- `--disasmDepth` - Sets the recursive depth for the disassembler.
- `--disasmDiff` - Generates diff reports for the disassembler.
Copy link
Member

Choose a reason for hiding this comment

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

thanks for updating the docs! 🥇


## Runtimes

Expand Down
2 changes: 1 addition & 1 deletion samples/BenchmarkDotNet.Samples/IntroDisassemblyAllJits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MultipleJits()
// RyuJit for .NET Core 2.1
Add(Job.ShortRun.With(Jit.RyuJit).With(Platform.X64).With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp21));

Add(DisassemblyDiagnoser.Create(new DisassemblyDiagnoserConfig(printAsm: true, printPrologAndEpilog: true, recursiveDepth: 3)));
Add(DisassemblyDiagnoser.Create(new DisassemblyDiagnoserConfig(printAsm: true, printPrologAndEpilog: true, recursiveDepth: 3, printDiff: true)));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public class CommandLineOptions
[Option("disasmDepth", Required = false, Default = 1, HelpText = "Sets the recursive depth for the disassembler.")]
public int DisassemblerRecursiveDepth { get; set; }

[Option("disasmDiff", Required = false, Default = false, HelpText = "Generates diff reports for the disassembler.")]
public bool DisassemblerDiff { get; set; }

[Option("buildTimeout", Required = false, HelpText = "Build timeout in seconds.")]
public int? TimeOutInSeconds { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static ReadOnlyConfig CreateConfig(CommandLineOptions options, IConfig g
if (options.UseMemoryDiagnoser)
config.Add(MemoryDiagnoser.Default);
if (options.UseDisassemblyDiagnoser)
config.Add(DisassemblyDiagnoser.Create(new DisassemblyDiagnoserConfig(recursiveDepth: options.DisassemblerRecursiveDepth, printPrologAndEpilog: true)));
config.Add(DisassemblyDiagnoser.Create(new DisassemblyDiagnoserConfig(recursiveDepth: options.DisassemblerRecursiveDepth, printPrologAndEpilog: true, printDiff: options.DisassemblerDiff)));
if (!string.IsNullOrEmpty(options.Profiler))
config.Add(DiagnosersLoader.GetImplementation<IProfiler>(profiler => profiler.ShortName.EqualsWithIgnoreCase(options.Profiler)));

Expand Down
22 changes: 14 additions & 8 deletions src/BenchmarkDotNet/Diagnosers/DisassemblyDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ private DisassemblyDiagnoser(WindowsDisassembler windowsDisassembler, MonoDisass
this.monoDisassembler = monoDisassembler;

results = new Dictionary<BenchmarkCase, DisassemblyResult>();
Exporters = new IExporter[]
{
new CombinedDisassemblyExporter(results),
new RawDisassemblyExporter(results),
new PrettyHtmlDisassemblyExporter(results),
new PrettyGithubMarkdownDisassemblyExporter(results),
new PrettyGithubMarkdownDiffDisassemblyExporter(results)
};
Exporters = GetExporters(results, config);
}

public static IConfigurableDiagnoser<DisassemblyDiagnoserConfig> Create(DisassemblyDiagnoserConfig config)
Expand Down Expand Up @@ -107,5 +100,18 @@ private static bool ShouldUseMonoDisassembler(BenchmarkCase benchmarkCase)

private static bool ShouldUseWindowsDisassembler(BenchmarkCase benchmarkCase)
=> !(benchmarkCase.Job.Environment.Runtime is MonoRuntime) && RuntimeInformation.IsWindows();

private static IEnumerable<IExporter> GetExporters(Dictionary<BenchmarkCase, DisassemblyResult> results, DisassemblyDiagnoserConfig config)
{
yield return new CombinedDisassemblyExporter(results);
yield return new RawDisassemblyExporter(results);
yield return new PrettyHtmlDisassemblyExporter(results);
yield return new PrettyGithubMarkdownDisassemblyExporter(results);

if (config.PrintDiff)
{
yield return new PrettyGithubMarkdownDiffDisassemblyExporter(results);
}
}
}
}
8 changes: 6 additions & 2 deletions src/BenchmarkDotNet/Diagnosers/DisassemblyDiagnoserConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ public class DisassemblyDiagnoserConfig
[PublicAPI] public static readonly DisassemblyDiagnoserConfig AsmFullRecursive = new DisassemblyDiagnoserConfig(printAsm: true, printPrologAndEpilog: true, recursiveDepth: int.MaxValue);
[PublicAPI] public static readonly DisassemblyDiagnoserConfig IL = new DisassemblyDiagnoserConfig(printAsm: false, printIL: true);
[PublicAPI] public static readonly DisassemblyDiagnoserConfig AsmAndIL = new DisassemblyDiagnoserConfig(printAsm: true, printIL: true);
[PublicAPI] public static readonly DisassemblyDiagnoserConfig All = new DisassemblyDiagnoserConfig(true, true, true, true, int.MaxValue);
[PublicAPI] public static readonly DisassemblyDiagnoserConfig AsmAndILAddDiff = new DisassemblyDiagnoserConfig(printAsm: true, printIL: true, printDiff: true);
[PublicAPI] public static readonly DisassemblyDiagnoserConfig All = new DisassemblyDiagnoserConfig(true, true, true, true, int.MaxValue, true);

/// <param name="printIL">IL will be printed. False by default.</param>
/// <param name="printAsm">ASM will be printed. True by default.</param>
/// <param name="printSource">C# source code will be printed. False by default.</param>
/// <param name="printPrologAndEpilog">ASM for prolog and epilog will be printed. False by default.</param>
/// <param name="recursiveDepth">Includes called methods to given level. 1 by default, indexed from 1. To print just benchmark set to 0</param>
/// <param name="printDiff">Diff will be printed. False by default.</param>
[PublicAPI]
public DisassemblyDiagnoserConfig(bool printAsm = true, bool printIL = false, bool printSource = false, bool printPrologAndEpilog = false,
int recursiveDepth = 1)
int recursiveDepth = 1, bool printDiff = false)
{
PrintAsm = printAsm;
PrintIL = printIL;
PrintSource = printSource;
PrintPrologAndEpilog = printPrologAndEpilog;
RecursiveDepth = recursiveDepth;
PrintDiff = printDiff;
}

public bool PrintAsm { get; }
public bool PrintIL { get; }
public bool PrintSource { get; }
public bool PrintPrologAndEpilog { get; }
public int RecursiveDepth { get; }
public bool PrintDiff { get; }
}
}