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: LinuxTraceLogCapture.md
+78-6Lines changed: 78 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,10 +97,46 @@ $ sudo lttng stop
97
97
$ sudo lttng destroy
98
98
```
99
99
100
-
# Perf
101
-
Perf is used to collect tracepoint events.
100
+
# Perf.data
102
101
103
-
[perf](https://perf.wiki.kernel.org/)
102
+
You can collect and view Linux [kernel-mode](https://www.kernel.org/doc/html/latest/trace/tracepoints.html) and [user-mode](https://docs.kernel.org/trace/user_events.html) tracepoints in the `perf.data` file format.
103
+
104
+
- Select existing tracepoints that you want to collect, or write your own programs that generate tracepoint events.
105
+
- Use the Linux `perf` tool or some other tool to collect tracepoint events into `perf.data` files.
106
+
- Use the PerfData extension to view the tracepoints.
107
+
108
+
## Selecting tracepoints
109
+
110
+
The Linux kernel and the kernel modules generate many useful tracepoints that you can collect. Look in `/sys/kernel/tracing/events` for the tracepoints that are available to you.
111
+
112
+
In addition, Linux 6.4 adds support for generating
-[LinuxTracepoints](https://github.com/microsoft/LinuxTracepoints) contains support for generating `user_events` from C/C++ programs.
117
+
-[LinuxTracepoints-Rust](https://github.com/microsoft/LinuxTracepoints-Rust) contains support for generating `user_events` from Rust programs.
118
+
119
+
## Collecting tracepoints
120
+
121
+
The Linux [perf](https://perf.wiki.kernel.org/) tool supports collecting tracepoint events using `perf record`.
122
+
123
+
- Install `perf` from the `linux-perf` or `linux-tools` package.
124
+
- Note that some `perf` packages use a wrapper script to help you match the running kernel version with a version-specific build of the `perf` tool, e.g. `perf_VERSION`. For collecting tracepoints, the version doesn't need to match. If you have version mismatch problems, you can safely bypass the wrapper script and directly use the `perf_VERSION` tool.
125
+
- Install the `libtraceevent1` package to enable `perf` support for tracepoints.
126
+
- Use [perf record](https://www.man7.org/linux/man-pages/man1/perf-record.1.html) to collect traces, e.g. `perf record -o MyFile.perf.data -k monotonic -e "event1_group:event1_name,event2_group:event2_name"`
127
+
- Use `-k monotonic` to include clock offset information in the data file.
128
+
129
+
You can also use other tools that generate `perf.data`-compatible files.
130
+
131
+
-[libtracepoint-control](https://github.com/microsoft/LinuxTracepoints/tree/main/libtracepoint-control-cpp) includes a library for configuring tracepoint collection sessions and collecting `perf.data` files.
132
+
-[tracepoint-collect](https://github.com/microsoft/LinuxTracepoints/blob/main/libtracepoint-control-cpp/tools/tracepoint-collect.cpp) is a simple tool that collects tracepoint events into `perf.data` files.
133
+
134
+
# Perf.data.txt
135
+
Perf is used to collect CPU Sampling (cpu-clock) events as LTTng doesn't support capturing these yet. Note: Stacks may require symbol setup.
136
+
137
+
The perf CPU Sampling analysis plugin uses perf.data.txt files as input.
138
+
139
+
[perf](https://perf.wiki.kernel.org/) CPU Sampling(cpu-clock)
104
140
105
141
If you want to trace .NET Core then you need [perfcollect](http://aka.ms/perfcollect) which capture CPU sampling and more
106
142
@@ -109,6 +145,11 @@ If you want to trace .NET Core then you need [perfcollect](http://aka.ms/perfcol
109
145
$ sudo apt-get install linux-tools-common
110
146
```
111
147
148
+
## User-Mode (UM) Symbols Install
149
+
KM symbols are automatically resolved. If you wish to resolve UM cpu sample functions and stacks, you may need to install debug packages for the binary you are profiling
150
+
151
+
For example, [Debug Symbol Packages on Ubuntu](https://wiki.ubuntu.com/Debug%20Symbol%20Packages)
152
+
112
153
## Record a trace
113
154
```bash
114
155
$ sudo /usr/bin/perf record -g -a -F 999 -e cpu-clock,sched:sched_stat_sleep,sched:sched_switch,sched:sched_process_exit -o perf_cpu.data
@@ -119,19 +160,50 @@ $ sudo /usr/bin/perf record -g -a -F 999 -e cpu-clock,sched:sched_stat_sleep,sch
119
160
$ Ctrl-C
120
161
```
121
162
163
+
## Convert trace to text format
164
+
This is to useful along-side the CTF trace to resolve UM IP/Symbols. Similar to what [perfcollect](https://raw.githubusercontent.com/microsoft/perfview/master/src/perfcollect/perfcollect) uses
Place the "captured on" timestamp for example "Thu Oct 17 15:37:36 2019" in a timestamp.txt file next to the trace folder. The timestamp will be interpreted as UTC
192
+
122
193
# Transferring the files to Windows UI (optional)
123
194
You then need to transfer the perf files to a Windows box where WPA runs. The most important file is perf.data.txt
124
195
125
196
```bash
126
-
$ sudo chmod 777 -R perf_cpu.data
197
+
$ sudo chmod 777 -R perf*
127
198
```
128
199
129
200
- Copy files from Linux to Windows box with WinSCP/SCP OR
130
201
```bash
131
-
$ tar -czvf perf_cpu.tar.gz perf_cpu.data
202
+
$ tar -czvf perf_cpu.tar.gz perf*
132
203
```
204
+
- (Optional if you want absolute timestamps) Place timestamp.txt next to perf.data.txt
0 commit comments