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

Add `DisassemblyDiagnoser` for outputting disassembled JITed code. #437

Closed
nietras opened this Issue Apr 29, 2017 · 7 comments

Comments

Projects
None yet
3 participants
@nietras
Contributor

nietras commented Apr 29, 2017

As in TryRoslyn (ashmind/SharpLab#39 this uses https://github.com/spazzarama/SharpDisasm) but after each benchmark run for a given method get the disassembled x86/x64 (and ARM/ARM64 in the future) JITed code for a given benchmark method. Preferably to full or a certain prespecified call depth.

For example via attribute:

using System;
using System.Security.Cryptography;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

namespace MyBenchmarks
{
    [DisassemblyDiagnoser]
    public class Md5VsSha256
    {
        private const int N = 10000;
        private readonly byte[] data;

        private readonly SHA256 sha256 = SHA256.Create();
        private readonly MD5 md5 = MD5.Create();

        public Md5VsSha256()
        {
            data = new byte[N];
            new Random(42).NextBytes(data);
        }

        [Benchmark]
        public byte[] Sha256() => sha256.ComputeHash(data);

        [Benchmark]
        public byte[] Md5() => md5.ComputeHash(data);
    }

    public class Program
    {
        public static void Main(string[] args)
        {
            var summary = BenchmarkRunner.Run<Md5VsSha256>();
        }
    }
}

Output would then have a file per method i.e. Sha256.asm and Md5.asm for each JIT being benchmarked.

Naming and details regarding this needs to be carefully considered. I specifically chose not to call AssemblyDiagnoser as this could be confused with a .NET assembly. We are interested in the native code generated so this can be inspected for further optimization.

Related to this I could suggest a ILDiagnoser that outputs IL for the functions too, for easy IL inspection too.

Ideally, this could also output a navigatable html file with asm in it so one could navigate calls easily.

@adamsitnik

This comment has been minimized.

Show comment
Hide comment
@adamsitnik

adamsitnik Apr 29, 2017

Member

Hi @nietras

I like this idea, we even used to have sth like this. @mattwarren implemented it some time ago.

I remember that the ClrMd api has changed and it just stopped working/compiling #160

Member

adamsitnik commented Apr 29, 2017

Hi @nietras

I like this idea, we even used to have sth like this. @mattwarren implemented it some time ago.

I remember that the ClrMd api has changed and it just stopped working/compiling #160

@nietras

This comment has been minimized.

Show comment
Hide comment
@nietras

nietras Apr 29, 2017

Contributor
Contributor

nietras commented Apr 29, 2017

@nietras

This comment has been minimized.

Show comment
Hide comment
@nietras

nietras Aug 18, 2017

Contributor

Saw @adamsitnik blog post http://adamsitnik.com/Disassembly-Diagnoser/ this is absolutely awesome! 😃

Contributor

nietras commented Aug 18, 2017

Saw @adamsitnik blog post http://adamsitnik.com/Disassembly-Diagnoser/ this is absolutely awesome! 😃

@nietras

This comment has been minimized.

Show comment
Hide comment
@nietras

nietras Aug 18, 2017

Contributor

Remember to close this with the PR when it gets in if not already. If already a link to PR would be good.

Contributor

nietras commented Aug 18, 2017

Remember to close this with the PR when it gets in if not already. If already a link to PR would be good.

@adamsitnik

This comment has been minimized.

Show comment
Hide comment
@adamsitnik

adamsitnik Aug 18, 2017

Member

@nietras thanks!

I am going to close this issue as soon as I write the documentation (should be this weekend)

btw here is the merge commit and here you can find the most important part.

Member

adamsitnik commented Aug 18, 2017

@nietras thanks!

I am going to close this issue as soon as I write the documentation (should be this weekend)

btw here is the merge commit and here you can find the most important part.

@adamsitnik

This comment has been minimized.

Show comment
Hide comment
@adamsitnik

adamsitnik Aug 22, 2017

Member

I added the docs, simplified installation process and added the navigable html exporter. I am done ;)

Member

adamsitnik commented Aug 22, 2017

I added the docs, simplified installation process and added the navigable html exporter. I am done ;)

@adamsitnik adamsitnik closed this Aug 22, 2017

@nietras

This comment has been minimized.

Show comment
Hide comment
@nietras

nietras Aug 22, 2017

Contributor

Awesome, great work! 👍

Contributor

nietras commented Aug 22, 2017

Awesome, great work! 👍

alinasmirnova added a commit to alinasmirnova/BenchmarkDotNet that referenced this issue Sep 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment