-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (50 loc) · 2.29 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (50 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using BenchmarkDotNet.Diagnosers;
using System.Diagnostics;
using System.Xml;
using System.Xml.Serialization;
namespace BenchmarkDotNet.Disassemblers
{
internal static class Program
{
// the goals of the existence of this process:
// 1. attach to benchmarked process
// 2. disassemble the code
// 3. save it to xml file
// 4. detach & shut down
public static void Main(string[] args)
{
var options = ClrMdArgs.FromArgs(args);
if (Process.GetProcessById(options.ProcessId).HasExited) // possible when benchmark has already finished
throw new Exception($"The process {options.ProcessId} has already exited"); // if we don't throw here the Clrmd will fail with some mysterious HRESULT: 0xd000010a ;)
try
{
var methodsToExport = DisassemblyDiagnoser.GetClrMdDisassembler().AttachAndDisassemble(options);
SaveToFile(methodsToExport, options.ResultsPath);
}
catch (OutOfMemoryException) // thrown by clrmd when pdb is missing or in invalid format
{
Console.WriteLine("\\ ---------------------------");
Console.WriteLine("Failed to read source code location!");
Console.WriteLine("Please make sure that the project, which defines benchmarks contains following settings:");
Console.WriteLine("\t <DebugType>pdbonly</DebugType>");
Console.WriteLine("\t <DebugSymbols>true</DebugSymbols>");
Console.WriteLine("\\ ---------------------------");
}
catch (Exception ex)
{
Console.WriteLine("Failed to disassemble with following exception:");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
private static void SaveToFile(DisassemblyResult disassemblyResult, string filePath)
{
using (var stream = new FileStream(filePath, FileMode.Append, FileAccess.Write))
using (var writer = XmlWriter.Create(stream))
{
var serializer = new XmlSerializer(typeof(DisassemblyResult));
serializer.Serialize(writer, disassemblyResult);
}
}
}
}