Skip to content

Commit 20dacad

Browse files
committed
PR feedback, especially on .md files
1 parent 317b09b commit 20dacad

File tree

4 files changed

+93
-11
lines changed

4 files changed

+93
-11
lines changed

LinuxTraceLogCapture.md

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,46 @@ $ sudo lttng stop
9797
$ sudo lttng destroy
9898
```
9999

100-
# Perf
101-
Perf is used to collect tracepoint events.
100+
# Perf.data
102101

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
113+
[user_events](https://docs.kernel.org/trace/user_events.html)
114+
tracepoints from user-mode programs.
115+
116+
- [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)
104140

105141
If you want to trace .NET Core then you need [perfcollect](http://aka.ms/perfcollect) which capture CPU sampling and more
106142

@@ -109,6 +145,11 @@ If you want to trace .NET Core then you need [perfcollect](http://aka.ms/perfcol
109145
$ sudo apt-get install linux-tools-common
110146
```
111147

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+
112153
## Record a trace
113154
```bash
114155
$ 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
119160
$ Ctrl-C
120161
```
121162

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
165+
166+
```bash
167+
$ sudo perf inject -v -s -i perf_cpu.data -o perf.data.merged
168+
169+
# There is a breaking change where the capitalization of the -f parameter changed.
170+
$ sudo perf script -i perf.data.merged -F comm,pid,tid,cpu,time,period,event,ip,sym,dso,trace > perf.data.txt
171+
172+
if [ $? -ne 0 ]
173+
then
174+
$ sudo perf script -i perf.data.merged -f comm,pid,tid,cpu,time,period,event,ip,sym,dso,trace > perf.data.txt
175+
fi
176+
177+
# If the dump file is zero length, try to collect without the period field, which was added recently.
178+
if [ ! -s perf.data.txt ]
179+
then
180+
$ sudo perf script -i perf.data.merged -f comm,pid,tid,cpu,time,event,ip,sym,dso,trace > perf.data.txt
181+
fi
182+
```
183+
184+
## Capture trace timestamp start
185+
Perf.data.txt only contains relative timestamps. If you want correct absolute timestamps in UI then you will need to know the trace start time.
186+
187+
```bash
188+
$ sudo perf report --header-only -i perf_cpu.data | grep "captured on"
189+
```
190+
191+
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+
122193
# Transferring the files to Windows UI (optional)
123194
You then need to transfer the perf files to a Windows box where WPA runs. The most important file is perf.data.txt
124195

125196
```bash
126-
$ sudo chmod 777 -R perf_cpu.data
197+
$ sudo chmod 777 -R perf*
127198
```
128199

129200
- Copy files from Linux to Windows box with WinSCP/SCP OR
130201
```bash
131-
$ tar -czvf perf_cpu.tar.gz perf_cpu.data
202+
$ tar -czvf perf_cpu.tar.gz perf*
132203
```
204+
- (Optional if you want absolute timestamps) Place timestamp.txt next to perf.data.txt
205+
- Open perf.data.txt with WPA
133206

134-
- Open perf_cpu.data with WPA
135207

136208
# Presentations
137209

PerfDataExtension/pluginManifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.1.2"
66
},
77
"displayName": "Linux - Perf",
8-
"description": "Enables viewing Linux tracepoint events recorded with the perf tool",
8+
"description": "Enables loading Linux events from perf.data files (e.g. generated by the perf tool)",
99
"owners": [
1010
{
1111
"name": "LinuxTracepoints",

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
> Tracing supported:
1010
- [LTTng](https://lttng.org) (Kernel CPU scheduling, Processes, Threads, Block IO/Disk, Syscalls, File events, etc)
11-
- [perf](https://perf.wiki.kernel.org/) (Generic events)
11+
- [perf](https://perf.wiki.kernel.org/) Generic Events, CPU Sampling (cpu-clock)
1212
- [Perfetto](https://perfetto.dev/) Android & Chromium (CPU Scheduling, CPU Sampling, CPU Frequency, FTrace, Android Logs, Generic Events / Default Tracks, GPU Counters, Jank Detection, Processes, Android Packages)
1313

1414
> Logs supported:
@@ -57,7 +57,8 @@ The tools can be run in several modes:
5757
- Used as a library to process traces / logs programatically in a .NET Core language like C#
5858
- Examples:
5959
- [LTTng 1](LTTngDriver/Program.cs), [LTTng 2](LTTngDataExtUnitTest/LTTngUnitTest.cs)
60-
- [Perf](PerfDataUnitTest/PerfDataUnitTest.cs)
60+
- [Perf.data.txt](PerfUnitTest/PerfUnitTest.cs) (CPU Sampling analysis)
61+
- [Perf.data](PerfDataUnitTest/PerfDataUnitTest.cs) (Generic events)
6162
- [LinuxLogs](LinuxLogParsers/LinuxLogParsersUnitTest/LinuxLogParsersUnitTest.cs)
6263
- [Perfetto](PerfettoUnitTest/PerfettoUnitTest.cs)
6364
- With a driver program for example dumping to screen or text format
@@ -113,7 +114,7 @@ The tools can be run in several modes:
113114
- Unified (LTTng, Perfetto, or other multiple different logs files together)
114115
- Once you gather the data, there is a tiny bit of prep needed to open them in a single unified timeline (like the screenshot above)
115116
- If you want to open multiple logs together in single timeline - Copy all trace files and logs you want to open to single folder
116-
- Example: You want to open in the same timeline: LTTng, Perf, Dmesg
117+
- Example: You want to open in the same timeline: LTTng, Perf CPU Sampling, Dmesg
117118
- Ensure that the Linux CTF folder/trace is zipped and renamed to .ctf in the same folder (hack so open Unified works)
118119
- WPA -> File -> Open -> Multi-select all files and choose "Open Unified"
119120

azure-pipelines.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ extends:
7575
LTTngDataExtensions\LTTngDataExtensions.csproj
7676
LTTngDataExtUnitTest\LTTngDataExtUnitTest.csproj
7777
LTTngDriver\LTTngDriver.csproj
78+
PerfDataExtension\PerfDataExtension.csproj
79+
PerfDataUnitTest\PerfDataUnitTest.csproj
7880
PerfDataTxtExtension\PerfDataTxtExtension.csproj
7981
PerfettoCds\PerfettoCds.csproj
8082
PerfUnitTest\PerfUnitTest.csproj
@@ -92,7 +94,14 @@ extends:
9294
inputs:
9395
command: 'test'
9496
projects: '$(System.DefaultWorkingDirectory)/Microsoft-Perf-Tools-Linux-Android.sln'
95-
97+
98+
- task: CopyFiles@2
99+
displayName: Copy PerfDataExtension Build to Output Artifacts
100+
inputs:
101+
SourceFolder: 'PerfDataExtension/bin/$(BuildConfiguration)/netstandard2.1'
102+
Contents: '**'
103+
TargetFolder: '$(Build.ArtifactStagingDirectory)/Microsoft-Performance-Tools-Linux/MicrosoftPerfToolkitAddins/PerfDataExtension'
104+
96105
- task: CopyFiles@2
97106
displayName: Copy PerfDataTxtExtension Build to Output Artifacts
98107
inputs:

0 commit comments

Comments
 (0)