Skip to content

Commit 687cce6

Browse files
authored
Update readme and linux trace capture docs (#1)
* Update readme and linux trace capture docs
1 parent 9246631 commit 687cce6

File tree

5 files changed

+246
-23
lines changed

5 files changed

+246
-23
lines changed

Images/WpaLinux.JPG

437 KB
Loading

LinuxTraceLogCapture.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Overview - Linux Trace and Log Capture
2+
3+
This provides a quick start on how to capture logs on Linux.
4+
5+
Logs:
6+
7+
- [LTTng](https://lttng.org) system trace (requires customized image for boot scenario)
8+
- Perf CPU Sampling
9+
- [cloud-init.log](https://cloud-init.io/)
10+
- Automatically logged by cloud-init to /var/log/cloud-init.log
11+
- [dmesg.iso.log](https://en.wikipedia.org/wiki/Dmesg)
12+
- Standard auto dmesg log doesn't output in absolute time needed for correlation with other logs
13+
- dmesg --time-format iso > dmesg.iso.log
14+
- [waagent.log](https://github.com/Azure/WALinuxAgent)
15+
- Automatically logged by WaLinuxAgent to /var/log/waagent.log
16+
- LogLevel can be turned more verbose in custom image
17+
- /etc/waagent.conf
18+
- Logs.Verbose=y
19+
20+
# LTTng
21+
[LTTng](https://lttng.org) (Kernel CPU scheduling, Processes, Threads, Block IO/Disk, Syscalls, File events, etc)
22+
23+
[LTTng Docs](https://lttng.org/docs/v2.10/) [LTTng](https://lttng.org/) is an open source tracing framework for Linux. Installation instructions for your Linux distro can be found in the docs.
24+
25+
Supports:
26+
- Threads and Processes
27+
- Context Switches / CPU Usage
28+
- Syscalls
29+
- File related events
30+
- Block IO / Disk Activity
31+
- Diagnostic Messages
32+
33+
Once you have everything set up you just need to decide what kind of information you are looking for and begin tracing.
34+
35+
In this example we are looking at process scheduler events. We might use this to determine process lifetime and identify dependencies. You can learn more about what kind of "events" you can enable [here](https://lttng.org/man/1/lttng-enable-event/v2.8/).
36+
```bash
37+
root@xenial:~/tracing# lttng list --kernel # Gives a list of all Kernel events you can trace
38+
root@xenial:~/tracing# lttng list --kernel --syscall # Gives a list of all traceable Linux system calls
39+
40+
root@xenial:~/tracing# lttng create my-kernel-session --output=/tmp/my-kernel-trace
41+
root@xenial:~/tracing# lttng enable-event --kernel sched_process*
42+
root@xenial:~/tracing# lttng start
43+
root@xenial:~/tracing# lttng stop
44+
root@xenial:~/tracing# lttng destroy
45+
```
46+
47+
## Recommended LTTng Tracing
48+
49+
### Install the tracing software:
50+
Example on Ubuntu:
51+
```bash
52+
$ sudo apt-get install lttng-tools lttng-modules-dkms liblttng-ust-dev
53+
```
54+
For more examples see [LTTng Download docs](https://lttng.org/download/)
55+
56+
### Create a session:
57+
```bash
58+
$ sudo lttng create my-kernel-session --output=lttng-kernel-trace
59+
```
60+
61+
### Add the desired events to be recorded:
62+
```bash
63+
$ sudo lttng enable-event --kernel block_rq_complete,block_rq_insert,block_rq_issue,printk_console,sched_wak*,sched_switch,sched_process_fork,sched_process_exit,sched_process_exec,lttng_statedump*
64+
$ sudo lttng enable-event --kernel --syscall –-all
65+
```
66+
67+
### Add context fields to the channel:
68+
```bash
69+
$ sudo lttng add-context --kernel --channel=channel0 --type=tid
70+
$ sudo lttng add-context --kernel --channel=channel0 --type=pid
71+
$ sudo lttng add-context --kernel --channel=channel0 --type=procname
72+
```
73+
74+
### Start the recording:
75+
```bash
76+
$ sudo lttng start
77+
```
78+
79+
### Save the session:
80+
```bash
81+
$ sudo lttng regenerate statedump <- Better correlation / info in Microsoft-Performance-Tools-Linux
82+
$ sudo lttng stop
83+
$ sudo lttng destroy
84+
```
85+
86+
# Perf
87+
Perf is used to collect CPU Sampling (cpu-clock) events as LTTng doesn't support capturing these yet. Note: Stacks may require symbol setup
88+
89+
[perf](https://perf.wiki.kernel.org/) CPU Sampling(cpu-clock)
90+
91+
If you want to trace .NET Core then you need [perfcollect](http://aka.ms/perfcollect) which capture CPU sampling and more
92+
93+
## Perf Install
94+
```bash
95+
$ sudo apt-get install linux-tools-common
96+
```
97+
98+
## User-Mode (UM) Symbols Install
99+
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
100+
101+
For example, [Debug Symbol Packages on Ubuntu](https://wiki.ubuntu.com/Debug%20Symbol%20Packages)
102+
103+
## Record a trace
104+
```bash
105+
$ 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
106+
```
107+
108+
## Stop the Trace
109+
```bash
110+
$ Ctrl-C
111+
```
112+
113+
## Convert trace to text format
114+
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
115+
116+
```bash
117+
$ sudo perf inject -v -s -i perf_cpu.data -o perf.data.merged
118+
119+
# There is a breaking change where the capitalization of the -f parameter changed.
120+
$ sudo perf script -i perf.data.merged -F comm,pid,tid,cpu,time,period,event,ip,sym,dso,trace > perf.data.txt
121+
122+
if [ $? -ne 0 ]
123+
then
124+
$ sudo perf script -i perf.data.merged -f comm,pid,tid,cpu,time,period,event,ip,sym,dso,trace > perf.data.txt
125+
fi
126+
127+
# If the dump file is zero length, try to collect without the period field, which was added recently.
128+
if [ ! -s perf.data.txt ]
129+
then
130+
$ sudo perf script -i perf.data.merged -f comm,pid,tid,cpu,time,event,ip,sym,dso,trace > perf.data.txt
131+
fi
132+
```
133+
134+
## Capture trace timestamp start
135+
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.
136+
137+
```bash
138+
$ sudo perf report --header-only -i perf_cpu.data | grep "captured on"
139+
```
140+
141+
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
142+
143+
### Convert to CTF (Optional) (requires CTF enabled perf)
144+
We have optional support for perf CTF conversion. It it currently NOT RECOMMENDED to use this though as you get less features (like KM/UM stacks) than perf.data.txt support which resolves callstacks on the box.
145+
This only supports KM symbols (for now) supplied by kallsyms. Microsoft-Linux-Perf-Tools support for the perf CTF trace is experimental given lack of UM symbols
146+
147+
```bash
148+
$ perf data convert -i perf_cpu.data --all --to-ctf ./perf_cpu.data-ctf
149+
```
150+
151+
You will need the perf file in converted CTF format which you can do with a custom compiled perf (unless some distro compiled the support in). [Custom build instructions here](https://stackoverflow.com/questions/43576997/building-perf-with-babeltrace-for-perf-to-ctf-conversion)
152+
153+
## Save Kernel Symbols (Optional) (for use with CTF enabled perf)
154+
This is only needed for a perf CTF trace
155+
156+
```bash
157+
$ sudo cat /proc/kallsyms > kallsyms
158+
```
159+
160+
# Transferring the files to Windows UI (optional)
161+
You then need to transfer the perf files to a Windows box where WPA runs. The most important file is perf.data.txt
162+
163+
```bash
164+
$ sudo chmod 777 -R perf*
165+
```
166+
167+
- Copy files from Linux to Windows box with WinSCP/SCP OR
168+
```bash
169+
$ tar -czvf perf_cpu-ctf.tar.gz perf*
170+
```
171+
- (Optional if you want absolute timestamps) Place timestamp.txt next to perf.data.txt
172+
- Open perf.data.txt with WPA
173+
- For the perf CTF file (optional) On Windows, Zip the folder up and rename to .ctf extension. E.g. perf_cpu-ctf.ctf (which is really a .zip file)
174+
- CTF (Optional) Kallsyms needs to be on your Desktop
175+
176+
177+
# Presentations
178+
179+
If you want to see a demo or get more in-depth info on using these tools check out a talk given at the [Linux Tracing Summit](https://www.tracingsummit.org/ts/2019/):
180+
>Linux & Windows Perf Analysis using WPA, ([slides](https://www.tracingsummit.org/ts/2019/files/Tracingsummit2019-wpa-berg-gibeau.pdf)) ([video](https://youtu.be/HUbVaIi-aaw))

Microsoft-Perf-Tools-Linux.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dmesg", "LinuxLogParsers\Li
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WaLinuxAgent", "LinuxLogParsers\LinuxPlugins-MicrosoftPerformanceToolkSDK\WaLinuxAgent\WaLinuxAgent.csproj", "{75AF82A4-AF0E-425F-8CF5-62F4F54380B9}"
3131
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{E48222FC-D167-4281-BC94-961C22908B25}"
33+
ProjectSection(SolutionItems) = preProject
34+
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
35+
LinuxTraceLogCapture.md = LinuxTraceLogCapture.md
36+
NOTICE.md = NOTICE.md
37+
README.md = README.md
38+
SECURITY.md = SECURITY.md
39+
SUPPORT.md = SUPPORT.md
40+
EndProjectSection
41+
EndProject
3242
Global
3343
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3444
Debug|Any CPU = Debug|Any CPU

README.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,60 @@
1-
# Project
1+
# Microsoft Performance Tools Linux
22

3-
> This repo has been populated by an initial template to help get you started. Please
4-
> make sure to update the content to build a great experience for community-building.
3+
> This repo contains various Linux Performance Analysis tools built with the [Microsoft Performance Toolkit SDK](https://github.com/microsoft/microsoft-performance-toolkit-sdk).
54
6-
As the maintainer of this project, please make a few updates:
5+
> Tools are built with open source .NET Core and can be run on the cmd-line or in the WPA GUI. All the logs that are supported are open source.
76
8-
- Improving this README.MD file to provide a great experience
9-
- Updating SUPPORT.MD with content about this project's support experience
10-
- Understanding the security reporting process in SECURITY.MD
11-
- Remove this section from the README
7+
>Not only are the raw logs parsed, but a lot of smart post processing / correlation is done to make your life easier as a perf analyst. We hope you can solve & debug tough issues on you or your customers systems with this toolset!
8+
9+
> Tracing supported: [LTTng](https://lttng.org) (Kernel CPU scheduling, Processes, Threads, Block IO/Disk, Syscalls, File events, etc), [perf](https://perf.wiki.kernel.org/) CPU Sampling(cpu-clock)
10+
11+
> Logs supported: [Dmesg](https://en.wikipedia.org/wiki/Dmesg), [Cloud-Init](https://cloud-init.io/), [WaLinuxAgent](https://github.com/Azure/WALinuxAgent)
12+
13+
**Optional** WPA GUI:
14+
![WpaLinux](Images/WpaLinux.JPG)
15+
16+
# Presentations
17+
18+
If you want to see a demo or get more in-depth info on using these tools check out a talk given at the [Linux Tracing Summit](https://www.tracingsummit.org/ts/2019/):
19+
>Linux & Windows Perf Analysis using WPA, ([slides](https://www.tracingsummit.org/ts/2019/files/Tracingsummit2019-wpa-berg-gibeau.pdf)) ([video](https://youtu.be/HUbVaIi-aaw))
20+
21+
# Prerequisites
22+
23+
## Runtime prereqs
24+
- [.NET Core Runtime 3.1.x](https://dotnet.microsoft.com/download/dotnet-core/3.1)
25+
26+
## Dev prereqs
27+
- [.NET Core SDK 3.1.x](https://dotnet.microsoft.com/download/dotnet-core/3.1)
28+
- [Visual Studio](https://visualstudio.microsoft.com/), [VSCode](https://visualstudio.microsoft.com/), or your favorite editor!
29+
30+
# Download
31+
See [Releases](https://github.com/microsoft/Microsoft-Performance-Tools-Linux/releases)
32+
33+
# How to run the tools
34+
The tools can be run in several modes:
35+
36+
- Cross-platform with .NET Core
37+
- Used as a library
38+
- With a driver program for example dumping to screen or text format
39+
- (Coming soon) (Windows) Command-line dumping to a text format (say CSV)
40+
- (Coming soon) (Windows) Using the WPA GUI to load these tools as plugins
41+
42+
# How to capture a trace or logs
43+
Please see [Linux Trace Log Capture](LinuxTraceLogCapture.md)
44+
45+
# How to load the logs in the UI
46+
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)
47+
48+
- LTTng - If you just need to open only a LTTng trace by itself in folder format
49+
- WPA -> Open -> Folder (Select CTF folder)
50+
- Unified (LTTng or other multiple different logs files together)
51+
- If you want to open other logs together in single timeline - Copy other Linux logs you want to open to single folder
52+
- Example: You want to open in the same timeline: LTTng, Perf CPU Sampling, Dmesg
53+
- Ensure that the Linux CTF folder/trace is zipped and renamed to .ctf in the same folder (hack so open Unified works)
54+
- WPA -> File -> Open -> Multi-select all files and choose "Open Unified"
55+
56+
# How do I use WPA in general?
57+
If you want to learn how to use the GUI UI in general see [WPA MSDN Docs](https://docs.microsoft.com/en-us/windows-hardware/test/wpt/windows-performance-analyzer)
1258

1359
## Contributing
1460

SUPPORT.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
# TODO: The maintainer of this repo has not yet edited this file
2-
3-
**REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project?
4-
5-
- **No CSS support:** Fill out this template with information about how to file issues and get help.
6-
- **Yes CSS support:** Fill out an intake form at [aka.ms/spot](https://aka.ms/spot). CSS will work with/help you to determine next steps. More details also available at [aka.ms/onboardsupport](https://aka.ms/onboardsupport).
7-
- **Not sure?** Fill out a SPOT intake as though the answer were "Yes". CSS will help you decide.
8-
9-
*Then remove this first heading from this SUPPORT.MD file before publishing your repo.*
10-
11-
# Support
121

132
## How to file issues and get help
143

154
This project uses GitHub Issues to track bugs and feature requests. Please search the existing
165
issues before filing new issues to avoid duplicates. For new issues, file your bug or
176
feature request as a new Issue.
187

19-
For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
20-
FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER
21-
CHANNEL. WHERE WILL YOU HELP PEOPLE?**.
8+
For help and questions about using this project, please use https://stackoverflow.com/ with the tag [microsoft-perf-tools-linux]
229

2310
## Microsoft Support Policy
2411

25-
Support for this **PROJECT or PRODUCT** is limited to the resources listed above.
12+
Support for this project is limited to the resources listed above.

0 commit comments

Comments
 (0)