You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/diagnostics/trace-perfcollect-lttng.md
+56-59
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Tracing .NET applications with PerfCollect.
3
3
description: A tutorial that walks you through collecting a trace with perfcollect in .NET.
4
4
ms.topic: tutorial
5
-
ms.date: 10/23/2020
5
+
ms.date: 04/10/2025
6
6
---
7
7
8
8
# Trace .NET applications with PerfCollect
@@ -22,27 +22,26 @@ Follow these steps to prepare your machine to collect a performance trace with `
22
22
23
23
1. Download `perfcollect`.
24
24
25
-
> ```bash
26
-
>curl -OL https://aka.ms/perfcollect
27
-
>```
25
+
```bash
26
+
curl -OL https://aka.ms/perfcollect
27
+
```
28
28
29
-
2. Make the script executable.
29
+
1. Make the script executable.
30
30
31
-
>```bash
32
-
>chmod +x perfcollect
33
-
>```
31
+
```bash
32
+
chmod +x perfcollect
33
+
```
34
34
35
-
3. Install tracing prerequisites - these are the actual tracing libraries.
35
+
1. Install tracing prerequisites - these are the actual tracing libraries.
36
36
37
-
>```bash
38
-
>sudo ./perfcollect install
39
-
>```
37
+
```bash
38
+
sudo ./perfcollect install
39
+
```
40
40
41
41
This will install the following prerequisites on your machine:
42
42
43
43
1. `perf`: the Linux Performance Events subsystem and companion user-mode collection/viewer application. `perf` is part of the Linux kernel source, but is not usually installed by default.
44
-
45
-
2. `LTTng`: Used to capture event data emitted at run time by CoreCLR. This data is then used to analyze the behavior of various runtime components such as the GC, JIT, and thread pool.
44
+
1. `LTTng`: Used to capture event data emitted at run time by CoreCLR. This data is then used to analyze the behavior of various runtime components such as the GC, JIT, and thread pool.
46
45
47
46
Recent versions of .NET Core and the Linux perf tool support automatic resolution of method names for framework code.
48
47
@@ -51,62 +50,63 @@ For resolving method names of native runtime DLLs (such as libcoreclr.so), `perf
51
50
## Collect a trace
52
51
53
52
1. Have two shells available - one for controlling tracing, referred to as **[Trace]**, and one for running the application, referred to as **[App]**.
53
+
1. **[Trace]** Start collection.
54
54
55
-
2. **[Trace]** Start collection.
56
-
57
-
>```bash
58
-
> sudo ./perfcollect collect sampleTrace
59
-
>```
55
+
```bash
56
+
sudo ./perfcollect collect sampleTrace
57
+
```
60
58
61
59
Expected Output:
62
60
63
-
>```bash
64
-
>Collection started. Press CTRL+C to stop.
65
-
>```
61
+
```bash
62
+
Collection started. Press CTRL+C to stop.
63
+
```
66
64
67
-
3. **[App]** Set up the application shell with the following environment variables - this enables tracing configuration of CoreCLR.
65
+
> [!NOTE]
66
+
> LTTng had a breaking change between versions 2.12 and 2.13. The .NET runtime currently supports version 2.12. If your Linux distribution has adopted 2.13 or later then we recommend disabling the LTTng portion of the perfcollect functionality. To do this add the option '-nolttng' to the perfcollect command-line and in step 3 do not set the DOTNET_EnableEventLog environment variable.
68
67
69
-
>```bash
70
-
>export DOTNET_PerfMapEnabled=1
71
-
>export DOTNET_EnableEventLog=1
72
-
>```
68
+
1. **[App]** Set up the application shell with the following environment variables - this enables tracing configuration of CoreCLR.
69
+
1. **[App]** Set up the application shell with the following environment variables - this enables tracing configuration of CoreCLR.
70
+
71
+
```bash
72
+
export DOTNET_PerfMapEnabled=1
73
+
export DOTNET_EnableEventLog=1
74
+
```
73
75
74
76
> [!NOTE]
75
77
> When executing the app with .NET 7, you must also set`DOTNET_EnableWriteXorExecute=0`in addition to the preceding environment variables. For example:
4. **[App]** Run the app - let it run as long as you need to in order to capture the performance problem. The exact length can be as short as you need as long as it sufficiently captures the window of time where the performance problem you want to investigate occurs.
1. **[App]** Run the app - let it run as long as you need to in order to capture the performance problem. The exact length can be as short as you need as long as it sufficiently captures the window of time where the performance problem you want to investigate occurs.
88
87
89
-
5. **[Trace]** Stop collection - hit CTRL+C.
88
+
```bash
89
+
dotnet run
90
+
```
90
91
91
-
>```bash
92
-
> ^C
93
-
> ...STOPPED.
94
-
>
95
-
> Starting post-processing. This may take some time.
Starting post-processing. This may take some time.
98
+
Generating native image symbol files
99
+
...SKIPPED
100
+
Saving native symbols
101
+
...FINISHED
102
+
Exporting perf.data file
103
+
...FINISHED
104
+
Compressing trace files
105
+
...FINISHED
106
+
Cleaning up artifacts
107
+
...FINISHED
108
+
Trace saved to sampleTrace.trace.zip
109
+
```
110
110
111
111
The compressed trace file is now stored in the current working directory.
112
112
@@ -147,18 +147,15 @@ To see an aggregate view of both the CPU sample and the events, you can use `Per
147
147
148
148
3. Run PerfView.exe
149
149
150
-
>```cmd
151
-
>PerfView.exe <path to trace.zip file>
152
-
>```
150
+
```cmd
151
+
PerfView.exe <path to trace.zip file>
152
+
```
153
153
154
154
PerfView will display the list of views that are supported based on the data contained in the trace file.
155
155
156
156
- For CPU investigations, choose **CPU stacks**.
157
-
158
157
- For detailed GC information, choose **GCStats**.
159
-
160
158
- For per-process/module/method JIT information, choose **JITStats**.
161
-
162
159
- If there is not a view forthe information you need, you can try looking for the eventsin the raw events view. Choose **Events**.
163
160
164
161
For more information on how to interpret views in PerfView, see help links in the view itself, or from the main window in PerfView, choose **Help->Users Guide**.
0 commit comments