15
15
using BenchmarkDotNet . Reports ;
16
16
using BenchmarkDotNet . Running ;
17
17
using BenchmarkDotNet . Toolchains . InProcess . NoEmit ;
18
- using BenchmarkDotNet . Toolchains . NativeAot ;
19
18
using BenchmarkDotNet . Validators ;
20
19
21
20
namespace BenchmarkDotNet . Diagnosers
@@ -24,16 +23,16 @@ public class DisassemblyDiagnoser : IDiagnoser
24
23
{
25
24
private static readonly Lazy < string > ptrace_scope = new Lazy < string > ( ( ) => ProcessHelper . RunAndReadOutput ( "cat" , "/proc/sys/kernel/yama/ptrace_scope" ) . Trim ( ) ) ;
26
25
27
- private readonly WindowsDisassembler windowsDisassembler ;
28
- private readonly LinuxDisassembler linuxDisassembler ;
26
+ private readonly WindowsDisassembler windowsDifferentArchitectureDisassembler ;
27
+ private readonly SameArchitectureDisassembler sameArchitectureDisassembler ;
29
28
private readonly MonoDisassembler monoDisassembler ;
30
29
private readonly Dictionary < BenchmarkCase , DisassemblyResult > results ;
31
30
32
31
public DisassemblyDiagnoser ( DisassemblyDiagnoserConfig config )
33
32
{
34
33
Config = config ;
35
- windowsDisassembler = new WindowsDisassembler ( config ) ;
36
- linuxDisassembler = new LinuxDisassembler ( config ) ;
34
+ windowsDifferentArchitectureDisassembler = new WindowsDisassembler ( config ) ;
35
+ sameArchitectureDisassembler = new SameArchitectureDisassembler ( config ) ;
37
36
monoDisassembler = new MonoDisassembler ( config ) ;
38
37
39
38
results = new Dictionary < BenchmarkCase , DisassemblyResult > ( ) ;
@@ -58,9 +57,9 @@ public IEnumerable<Metric> ProcessResults(DiagnoserResults diagnoserResults)
58
57
59
58
public RunMode GetRunMode ( BenchmarkCase benchmarkCase )
60
59
{
61
- if ( ShouldUseWindowsDisassembler ( benchmarkCase ) || ShouldUseLinuxDisassembler ( benchmarkCase ) )
60
+ if ( ShouldUseClrMdDisassembler ( benchmarkCase ) )
62
61
return RunMode . NoOverhead ;
63
- if ( ShouldUseMonoDisassembler ( benchmarkCase ) )
62
+ else if ( ShouldUseMonoDisassembler ( benchmarkCase ) )
64
63
return RunMode . SeparateLogic ;
65
64
66
65
return RunMode . None ;
@@ -74,11 +73,11 @@ public void Handle(HostSignal signal, DiagnoserActionParameters parameters)
74
73
75
74
switch ( signal )
76
75
{
77
- case HostSignal . AfterAll when ShouldUseWindowsDisassembler ( benchmark ) :
78
- results . Add ( benchmark , windowsDisassembler . Disassemble ( parameters ) ) ;
76
+ case HostSignal . AfterAll when ShouldUseSameArchitectureDisassembler ( benchmark , parameters ) :
77
+ results . Add ( benchmark , sameArchitectureDisassembler . Disassemble ( parameters ) ) ;
79
78
break ;
80
- case HostSignal . AfterAll when ShouldUseLinuxDisassembler ( benchmark ) :
81
- results . Add ( benchmark , linuxDisassembler . Disassemble ( parameters ) ) ;
79
+ case HostSignal . AfterAll when RuntimeInformation . IsWindows ( ) && ! ShouldUseMonoDisassembler ( benchmark ) :
80
+ results . Add ( benchmark , windowsDifferentArchitectureDisassembler . Disassemble ( parameters ) ) ;
82
81
break ;
83
82
case HostSignal . SeparateLogic when ShouldUseMonoDisassembler ( benchmark ) :
84
83
results . Add ( benchmark , monoDisassembler . Disassemble ( benchmark , benchmark . Job . Environment . Runtime as MonoRuntime ) ) ;
@@ -112,7 +111,7 @@ public IEnumerable<ValidationError> Validate(ValidationParameters validationPara
112
111
yield return new ValidationError ( true , "Currently NativeAOT has no DisassemblyDiagnoser support" , benchmark ) ;
113
112
}
114
113
115
- if ( ShouldUseLinuxDisassembler ( benchmark ) )
114
+ if ( RuntimeInformation . IsLinux ( ) && ShouldUseClrMdDisassembler ( benchmark ) )
116
115
{
117
116
var runtime = benchmark . Job . ResolveValue ( EnvironmentMode . RuntimeCharacteristic , EnvironmentResolver . Instance ) ;
118
117
@@ -136,11 +135,27 @@ public IEnumerable<ValidationError> Validate(ValidationParameters validationPara
136
135
private static bool ShouldUseMonoDisassembler ( BenchmarkCase benchmarkCase )
137
136
=> benchmarkCase . Job . Environment . Runtime is MonoRuntime || RuntimeInformation . IsMono ;
138
137
139
- private static bool ShouldUseWindowsDisassembler ( BenchmarkCase benchmarkCase )
140
- => ! ( benchmarkCase . Job . Environment . Runtime is MonoRuntime ) && RuntimeInformation . IsWindows ( ) ;
138
+ // when we add macOS support, RuntimeInformation.IsMacOSX() needs to be added here
139
+ private static bool ShouldUseClrMdDisassembler ( BenchmarkCase benchmarkCase )
140
+ => ! ShouldUseMonoDisassembler ( benchmarkCase ) && ( RuntimeInformation . IsWindows ( ) || RuntimeInformation . IsLinux ( ) ) ;
141
141
142
- private static bool ShouldUseLinuxDisassembler ( BenchmarkCase benchmarkCase )
143
- => ! ( benchmarkCase . Job . Environment . Runtime is MonoRuntime ) && RuntimeInformation . IsLinux ( ) ;
142
+ private static bool ShouldUseSameArchitectureDisassembler ( BenchmarkCase benchmarkCase , DiagnoserActionParameters parameters )
143
+ {
144
+ if ( ShouldUseClrMdDisassembler ( benchmarkCase ) )
145
+ {
146
+ if ( RuntimeInformation . IsWindows ( ) )
147
+ {
148
+ return WindowsDisassembler . GetDisassemblerArchitecture ( parameters . Process , benchmarkCase . Job . Environment . Platform )
149
+ == RuntimeInformation . GetCurrentPlatform ( ) ;
150
+ }
151
+
152
+ // on Unix currently host process architecture is always the same as benchmark process architecture
153
+ // (no official x86 support)
154
+ return true ;
155
+ }
156
+
157
+ return false ;
158
+ }
144
159
145
160
private static IEnumerable < IExporter > GetExporters ( Dictionary < BenchmarkCase , DisassemblyResult > results , DisassemblyDiagnoserConfig config )
146
161
{
0 commit comments