Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a2e17fb

Browse files
authored
Merge pull request #10995 from svick/patch-1
Update Viewing JIT dumps to 2.0 and csproj
2 parents 8f32fb0 + 44f2953 commit a2e17fb

File tree

1 file changed

+78
-88
lines changed

1 file changed

+78
-88
lines changed

Documentation/building/viewing-jit-dumps.md

Lines changed: 78 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,115 +8,105 @@ To make sense of the results, it is recommended you also read the [Reading a Jit
88

99
The first thing we want to do is setup the .NET Core app we want to dump. Here are the steps to do this, if you don't have one ready:
1010

11-
* Perform a debug build of the CoreCLR repo
12-
* Install the [.NET CLI](http://microsoft.com/net/core), which we'll use to compile/publish our app
13-
* `cd` to where you want your app to be placed, and run `dotnet new`
14-
* Modify your `project.json` file so that it contains a RID (runtime ID) corresponding to the OS you're using in the `runtimes` section. For example, I have a Windows 10 x64 machine, so here's my project file:
15-
16-
```json
17-
{
18-
"buildOptions": {
19-
"emitEntryPoint": true
20-
},
21-
"dependencies": {
22-
"Microsoft.NETCore.App": "1.0.0-*"
23-
},
24-
"frameworks": {
25-
"netcoreapp1.0": {
26-
"imports": [
27-
"dnxcore50",
28-
"portable-net45+win8"
29-
]
30-
}
31-
},
32-
"runtimes": {
33-
"win10-x64": {}
34-
}
35-
}
36-
```
11+
* Perform a debug build of the CoreCLR repo.
12+
* Install the [.NET CLI 2.0 preview](https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/dogfooding.md), which we'll use to compile/publish our app.
13+
* `cd` to where you want your app to be placed, and run `dotnet new console`.
14+
* Modify your `csproj` file so that it contains a RID (runtime ID) corresponding to the OS you're using in the `<RuntimeIdentifier>` tag. For example, for Windows 10 x64 machine, the project file is:
15+
16+
```xml
17+
<Project Sdk="Microsoft.NET.Sdk">
3718

38-
You can find a list of RIDs and their corresponding OSes [here](https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog).
19+
<PropertyGroup>
20+
<OutputType>Exe</OutputType>
21+
<TargetFramework>netcoreapp2.0</TargetFramework>
22+
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
23+
</PropertyGroup>
24+
25+
</Project>
26+
```
27+
28+
You can find a list of RIDs and their corresponding OSes [here](https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog).
3929

4030
* Edit `Program.cs`, and call the method(s) you want to dump in there. Make sure they are, directly or indirectly, called from `Main`. In this example, we'll be looking at the disassembly of our custom function `InefficientJoin`:
4131

42-
```cs
43-
using System;
44-
using System.Collections.Generic;
45-
using System.Runtime.CompilerServices;
32+
```cs
33+
using System;
34+
using System.Collections.Generic;
35+
using System.Runtime.CompilerServices;
4636

47-
namespace ConsoleApplication
48-
{
49-
public class Program
37+
namespace ConsoleApplication
5038
{
51-
public static void Main(string[] args)
39+
public class Program
5240
{
53-
Console.WriteLine(InefficientJoin(args));
54-
}
55-
56-
// Add NoInlining to prevent this from getting
57-
// mixed up with the rest of the code in Main
58-
[MethodImpl(MethodImplOptions.NoInlining)]
59-
private static string InefficientJoin(IEnumerable<string> args)
60-
{
61-
var result = string.Empty;
62-
foreach (var arg in args) result += (arg + ' ');
63-
return result.Substring(0, result.Length - 1);
41+
public static void Main(string[] args)
42+
{
43+
Console.WriteLine(InefficientJoin(args));
44+
}
45+
46+
// Add NoInlining to prevent this from getting
47+
// mixed up with the rest of the code in Main
48+
[MethodImpl(MethodImplOptions.NoInlining)]
49+
private static string InefficientJoin(IEnumerable<string> args)
50+
{
51+
var result = string.Empty;
52+
foreach (var arg in args) result += (arg + ' ');
53+
return result.Substring(0, Math.Max(0, result.Length - 1));
54+
}
6455
}
6556
}
66-
}
67-
```
57+
```
6858

69-
* After you've finished editing the code, run `dotnet publish -c Release`. This should drop all of the binaries needed to run your app in `bin/Release/<configuration>/<rid>/publish`.
59+
* After you've finished editing the code, run `dotnet restore` and `dotnet publish -c Release`. This should drop all of the binaries needed to run your app in `bin/Release/<configuration>/<rid>/publish`.
7060
* Overwrite the CLR dlls with the ones you've built locally. If you're a fan of the command line, here are some shell commands for doing this:
7161

72-
```shell
73-
# Windows
74-
robocopy /e <coreclr path>\bin\Product\Windows_NT.<arch>.Debug <app root>\bin\Release\netcoreapp1.0\<rid>\publish > NUL
62+
```shell
63+
# Windows
64+
robocopy /e <coreclr path>\bin\Product\Windows_NT.<arch>.Debug <app root>\bin\Release\netcoreapp2.0\<rid>\publish > NUL
7565

76-
# Unix
77-
cp -rT <coreclr path>/bin/Product/<OS>.<arch>.Debug <app root>/bin/Release/netcoreapp1.0/<rid>/publish
78-
```
66+
# Unix
67+
cp -rT <coreclr path>/bin/Product/<OS>.<arch>.Debug <app root>/bin/Release/netcoreapp2.0/<rid>/publish
68+
```
7969

8070
* Set the configuration knobs you need (see below) and run your published app. The info you want should be dumped to stdout.
8171

82-
Here's some sample output on my machine showing the disassembly for `InefficientJoin`:
83-
84-
```asm
85-
G_M2530_IG01:
86-
55 push rbp
87-
4883EC40 sub rsp, 64
88-
488D6C2440 lea rbp, [rsp+40H]
89-
33C0 xor rax, rax
90-
488945F8 mov qword ptr [rbp-08H], rax
91-
488965E0 mov qword ptr [rbp-20H], rsp
92-
93-
G_M2530_IG02:
94-
49BB60306927E5010000 mov r11, 0x1E527693060
95-
4D8B1B mov r11, gword ptr [r11]
96-
4C895DF8 mov gword ptr [rbp-08H], r11
97-
49BB200058F7FD7F0000 mov r11, 0x7FFDF7580020
98-
3909 cmp dword ptr [rcx], ecx
99-
41FF13 call gword ptr [r11]System.Collections.Generic.IEnumerable`1[__Canon][System.__Canon]:GetEnumerator():ref:this
100-
488945F0 mov gword ptr [rbp-10H], rax
101-
102-
; ...
103-
```
72+
Here's some sample output on my machine showing the disassembly for `InefficientJoin`:
73+
74+
```asm
75+
G_M2530_IG01:
76+
55 push rbp
77+
4883EC40 sub rsp, 64
78+
488D6C2440 lea rbp, [rsp+40H]
79+
33C0 xor rax, rax
80+
488945F8 mov qword ptr [rbp-08H], rax
81+
488965E0 mov qword ptr [rbp-20H], rsp
82+
83+
G_M2530_IG02:
84+
49BB60306927E5010000 mov r11, 0x1E527693060
85+
4D8B1B mov r11, gword ptr [r11]
86+
4C895DF8 mov gword ptr [rbp-08H], r11
87+
49BB200058F7FD7F0000 mov r11, 0x7FFDF7580020
88+
3909 cmp dword ptr [rcx], ecx
89+
41FF13 call gword ptr [r11]System.Collections.Generic.IEnumerable`1[__Canon][System.__Canon]:GetEnumerator():ref:this
90+
488945F0 mov gword ptr [rbp-10H], rax
91+
92+
; ...
93+
```
10494

10595
## Setting configuration variables
10696

107-
The behavior of the JIT can be controlled via a number of configuration variables. These are declared in [inc/clrconfigvalues.h](https://github.com/dotnet/coreclr/blob/master/src/inc/clrconfigvalues.h). When used as an environment variable, the string name generally has COMPlus_ prepended. When used as a registry value name, the configuration name is used directly.
97+
The behavior of the JIT can be controlled via a number of configuration variables. These are declared in [inc/clrconfigvalues.h](https://github.com/dotnet/coreclr/blob/master/src/inc/clrconfigvalues.h). When used as an environment variable, the string name generally has `COMPlus_` prepended. When used as a registry value name, the configuration name is used directly.
10898

10999
These can be set in one of three ways:
110100

111-
* Setting the environment variable `COMPlus_<flagname>`. For example, the following will set the `JitDump` flag so that the compilation of all methods named Main will be dumped:
101+
* Setting the environment variable `COMPlus_<flagname>`. For example, the following will set the `JitDump` flag so that the compilation of all methods named `Main` will be dumped:
112102

113-
```shell
114-
# Windows
115-
set COMPlus_JitDump=Main
103+
```shell
104+
# Windows
105+
set COMPlus_JitDump=Main
116106

117-
# Unix
118-
export COMPlus_JitDump=Main
119-
```
107+
# Unix
108+
export COMPlus_JitDump=Main
109+
```
120110

121111
* *Windows-only:* Setting the registry key `HKCU\Software\Microsoft\.NETFramework`, Value `<flagName>`, type `REG_SZ` or `REG_DWORD` (depending on the flag).
122112
* *Windows-only:* Setting the registry key `HKLM\Software\Microsoft\.NETFramework`, Value `<flagName>`, type `REG_SZ` or `REG_DWORD` (depending on the flag).
@@ -143,13 +133,13 @@ Main
143133

144134
will match all methods named Main from any class and any number of arguments.
145135

146-
<types> is a comma separated list of type names. Note that presently only the number of arguments and not the types themselves are used to distinguish methods. Thus, `Main(Foo, Bar)` and `Main(int, int)` will both match any main method with two arguments.
136+
`<types>` is a comma separated list of type names. Note that presently only the number of arguments and not the types themselves are used to distinguish methods. Thus, `Main(Foo, Bar)` and `Main(int, int)` will both match any main method with two arguments.
147137

148-
The wildcard character * can be used for <ClassName> and <MethodName>. In particular * by itself indicates every method.
138+
The wildcard character `*` can be used for `<ClassName>` and `<MethodName>`. In particular `*` by itself indicates every method.
149139

150140
## Useful COMPlus variables
151141

152-
Below are some of the most useful `COMPlus` variables. Where {method-list} is specified in the list below, you can supply a space-separated list of either fully-qualified or simple method names (the former is useful when running something that has many methods of the same name), or you can specific ‘* to mean all methods.
142+
Below are some of the most useful `COMPlus` variables. Where {method-list} is specified in the list below, you can supply a space-separated list of either fully-qualified or simple method names (the former is useful when running something that has many methods of the same name), or you can specify `*` to mean all methods.
153143

154144
* `COMPlus_JitDump`={method-list} – dump lots of useful information about what the JIT is doing. See [Reading a JitDump](../botr/ryujit-overview.md#reading-a-jitdump) for more on how to analyze this data.
155145
* `COMPlus_JitDisasm`={method-list} – dump a disassembly listing of each method.

0 commit comments

Comments
 (0)