Skip to content

Commit 317b09b

Browse files
committed
PR feedback
1 parent 4b83ad8 commit 317b09b

File tree

10 files changed

+128
-57
lines changed

10 files changed

+128
-57
lines changed

LTTngDriver/LTTngDriver.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
67
<Version>1.2.1</Version>
78
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
89
<Authors>Microsoft</Authors>

LinuxTraceLogCapture.md

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This provides a quick start on how to capture logs on Linux.
55
Logs:
66

77
- [LTTng](https://lttng.org) system trace (requires customized image for boot scenario)
8-
- Perf CPU Sampling
8+
- [perf](https://perf.wiki.kernel.org/)
99
- [cloud-init.log](https://cloud-init.io/)
1010
- Automatically logged by cloud-init to /var/log/cloud-init.log
1111
- [dmesg.iso.log](https://en.wikipedia.org/wiki/Dmesg)
@@ -98,9 +98,9 @@ $ sudo lttng destroy
9898
```
9999

100100
# Perf
101-
Perf is used to collect CPU Sampling (cpu-clock) events as LTTng doesn't support capturing these yet. Note: Stacks may require symbol setup
101+
Perf is used to collect tracepoint events.
102102

103-
[perf](https://perf.wiki.kernel.org/) CPU Sampling(cpu-clock)
103+
[perf](https://perf.wiki.kernel.org/)
104104

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

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

112-
## User-Mode (UM) Symbols Install
113-
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
114-
115-
For example, [Debug Symbol Packages on Ubuntu](https://wiki.ubuntu.com/Debug%20Symbol%20Packages)
116-
117112
## Record a trace
118113
```bash
119114
$ 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
@@ -124,52 +119,21 @@ $ sudo /usr/bin/perf record -g -a -F 999 -e cpu-clock,sched:sched_stat_sleep,sch
124119
$ Ctrl-C
125120
```
126121

127-
## Convert trace to text format
128-
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
129-
130-
```bash
131-
$ sudo perf inject -v -s -i perf_cpu.data -o perf.data.merged
132-
133-
# There is a breaking change where the capitalization of the -f parameter changed.
134-
$ sudo perf script -i perf.data.merged -F comm,pid,tid,cpu,time,period,event,ip,sym,dso,trace > perf.data.txt
135-
136-
if [ $? -ne 0 ]
137-
then
138-
$ sudo perf script -i perf.data.merged -f comm,pid,tid,cpu,time,period,event,ip,sym,dso,trace > perf.data.txt
139-
fi
140-
141-
# If the dump file is zero length, try to collect without the period field, which was added recently.
142-
if [ ! -s perf.data.txt ]
143-
then
144-
$ sudo perf script -i perf.data.merged -f comm,pid,tid,cpu,time,event,ip,sym,dso,trace > perf.data.txt
145-
fi
146-
```
147-
148-
## Capture trace timestamp start
149-
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.
150-
151-
```bash
152-
$ sudo perf report --header-only -i perf_cpu.data | grep "captured on"
153-
```
154-
155-
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
156-
157122
# Transferring the files to Windows UI (optional)
158123
You then need to transfer the perf files to a Windows box where WPA runs. The most important file is perf.data.txt
159124

160125
```bash
161-
$ sudo chmod 777 -R perf*
126+
$ sudo chmod 777 -R perf_cpu.data
162127
```
163128

164129
- Copy files from Linux to Windows box with WinSCP/SCP OR
165130
```bash
166-
$ tar -czvf perf_cpu.tar.gz perf*
131+
$ tar -czvf perf_cpu.tar.gz perf_cpu.data
167132
```
168-
- (Optional if you want absolute timestamps) Place timestamp.txt next to perf.data.txt
169-
- Open perf.data.txt with WPA
170133

134+
- Open perf_cpu.data with WPA
171135

172136
# Presentations
173137

174138
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/):
175-
>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))
139+
>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-Android.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{
7575
EndProject
7676
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerfDataExtension", "PerfDataExtension\PerfDataExtension.csproj", "{02B6DB71-E796-4AFE-9E18-334E2F803393}"
7777
EndProject
78+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerfDataUnitTest", "PerfDataUnitTest\PerfDataUnitTest.csproj", "{B57A38CD-9641-476C-A2FB-DF24D1700F41}"
79+
EndProject
7880
Global
7981
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8082
Debug|Any CPU = Debug|Any CPU
@@ -169,6 +171,10 @@ Global
169171
{02B6DB71-E796-4AFE-9E18-334E2F803393}.Debug|Any CPU.Build.0 = Debug|Any CPU
170172
{02B6DB71-E796-4AFE-9E18-334E2F803393}.Release|Any CPU.ActiveCfg = Release|Any CPU
171173
{02B6DB71-E796-4AFE-9E18-334E2F803393}.Release|Any CPU.Build.0 = Release|Any CPU
174+
{B57A38CD-9641-476C-A2FB-DF24D1700F41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
175+
{B57A38CD-9641-476C-A2FB-DF24D1700F41}.Debug|Any CPU.Build.0 = Debug|Any CPU
176+
{B57A38CD-9641-476C-A2FB-DF24D1700F41}.Release|Any CPU.ActiveCfg = Release|Any CPU
177+
{B57A38CD-9641-476C-A2FB-DF24D1700F41}.Release|Any CPU.Build.0 = Release|Any CPU
172178
EndGlobalSection
173179
GlobalSection(SolutionProperties) = preSolution
174180
HideSolutionNode = FALSE
@@ -188,6 +194,7 @@ Global
188194
{DB7FCF02-C949-4545-B58C-F514E85AB1FA} = {6A9515FC-D4B2-4221-8E74-78E7AFF0E421}
189195
{9FD0BECC-AC5E-46A8-9749-46CD82BA89DE} = {9B2D4167-1CC7-4D8B-A01C-E9919E809A0A}
190196
{CD7E9DD5-B97F-4B86-999E-92F86A1C1138} = {A42944EE-FFCC-4544-9F17-2BBFC94DFC3B}
197+
{B57A38CD-9641-476C-A2FB-DF24D1700F41} = {A42944EE-FFCC-4544-9F17-2BBFC94DFC3B}
191198
EndGlobalSection
192199
GlobalSection(ExtensibilityGlobals) = postSolution
193200
SolutionGuid = {E96603EA-8E1D-4AA9-A474-D267A116C316}

PerfDataExtension/PerfDataExtension.csproj

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2020
</PropertyGroup>
2121

22-
<ItemGroup>
23-
<PackageReference Include="Microsoft.LinuxTracepoints.Decode" Version="0.1.2.*">
24-
<IncludeAssets></IncludeAssets>
25-
</PackageReference>
26-
<PackageReference Include="Microsoft.Performance.SDK" Version="1.1.13" />
27-
</ItemGroup>
28-
2922
<PropertyGroup>
3023
<Nullable>enable</Nullable>
3124
<WarningLevel>9999</WarningLevel>
@@ -39,10 +32,35 @@
3932
</PropertyGroup>
4033

4134
<ItemGroup>
35+
<None Update="pluginManifest.json">
36+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
37+
</None>
4238
<None Update="README.md">
4339
<Pack>True</Pack>
4440
<PackagePath>\</PackagePath>
4541
</None>
4642
</ItemGroup>
4743

44+
<ItemGroup>
45+
<PackageReference Include="Microsoft.Performance.SDK" Version="1.1.13" />
46+
47+
<PackageReference Include="Microsoft.LinuxTracepoints.Types" Version="0.1.2.*" PrivateAssets="all" GeneratePathProperty="true" />
48+
<CopyToTargetDir Include="$(PkgMicrosoft_LinuxTracepoints_Types)\lib\netstandard2.1\Microsoft.LinuxTracepoints.Types.dll" />
49+
50+
<PackageReference Include="Microsoft.LinuxTracepoints.Decode" Version="0.1.2.*" PrivateAssets="all" GeneratePathProperty="true" />
51+
<CopyToTargetDir Include="$(PkgMicrosoft_LinuxTracepoints_Decode)\lib\netstandard2.1\Microsoft.LinuxTracepoints.Decode.dll" />
52+
</ItemGroup>
53+
54+
<ItemGroup>
55+
<Compile Update="pluginManifest.Designer.cs">
56+
<DesignTime>True</DesignTime>
57+
<AutoGen>True</AutoGen>
58+
<DependentUpon>pluginManifest.json</DependentUpon>
59+
</Compile>
60+
</ItemGroup>
61+
62+
<Target Name="CopyToTargetDirTarget" AfterTargets="Build">
63+
<Copy SourceFiles="@(CopyToTargetDir)" DestinationFolder="$(TargetDir)" />
64+
</Target>
65+
4866
</Project>

PerfDataExtension/PerfDataGenericSourceCooker.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public PerfDataGenericSourceCooker()
4343
public override SourceDataCookerOptions Options => SourceDataCookerOptions.ReceiveAllDataElements;
4444

4545
[DataOutput]
46-
public ProcessedEventData<ValueTuple<PerfDataEvent, PerfDataFileInfo>> Events { get; } = new ProcessedEventData<ValueTuple<PerfDataEvent, PerfDataFileInfo>>();
46+
public ProcessedEventData<ValueTuple<PerfDataEvent, PerfDataFileInfo>> Events { get; } =
47+
new ProcessedEventData<ValueTuple<PerfDataEvent, PerfDataFileInfo>>();
4748

4849
[DataOutput]
4950
public long SessionTimestampOffset { get; private set; } = long.MinValue;
@@ -68,9 +69,7 @@ public override DataProcessingResult CookDataElement(PerfDataEvent data, PerfDat
6869
public override void EndDataCooking(CancellationToken cancellationToken)
6970
{
7071
this.Events.FinalizeData();
71-
this.SessionTimestampOffset = this.lastContext != null
72-
? this.lastContext.SessionTimestampOffset
73-
: 0;
72+
this.SessionTimestampOffset = this.lastContext == null ? 0 : this.lastContext.SessionTimestampOffset;
7473
}
7574
}
7675
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/microsoft-performance-toolkit-sdk/main/src/PluginsSystem/Tools/Microsoft.Performance.Toolkit.Plugins.Cli/Manifest/PluginManifestSchema.json",
3+
"identity": {
4+
"id": "Microsoft.Performance.Toolkit.Plugins.PerfDataExtension",
5+
"version": "0.1.2"
6+
},
7+
"displayName": "Linux - Perf",
8+
"description": "Enables viewing Linux tracepoint events recorded with the perf tool",
9+
"owners": [
10+
{
11+
"name": "LinuxTracepoints",
12+
"address": "1 Microsoft Way, Redmond, WA 98052",
13+
"emailAddresses": [ "linuxtracepoints@microsoft.com" ],
14+
"phoneNumbers": []
15+
}
16+
],
17+
"projectUrl": "https://github.com/microsoft/Microsoft-Performance-Tools-Linux-Android",
18+
"manifestVersion": 1.0
19+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.Performance.Toolkit.Engine;
5+
using Microsoft.Performance.Toolkit.Plugins.PerfDataExtension;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
using System.IO;
8+
using Assembly = System.Reflection.Assembly;
9+
10+
namespace PerfDataUnitTest
11+
{
12+
[TestClass]
13+
public class PerfDataUnitTest
14+
{
15+
[TestMethod]
16+
public void ProcessPerfGenericEvents()
17+
{
18+
// Input data
19+
var inputPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
20+
var perfDataPath = Path.Combine(inputPath, "TestData\\perf.data");
21+
Assert.IsTrue(File.Exists(perfDataPath));
22+
23+
var pluginPath = Path.GetDirectoryName(typeof(PerfDataProcessingSource).Assembly.Location);
24+
using var plugins = PluginSet.Load(pluginPath);
25+
26+
using var dataSources = DataSourceSet.Create(plugins);
27+
dataSources.AddFile(perfDataPath);
28+
29+
var createInfo = new EngineCreateInfo(dataSources.AsReadOnly());
30+
using var engine = Engine.Create(createInfo);
31+
engine.EnableCooker(PerfDataGenericSourceCooker.DataCookerPath);
32+
engine.EnableTable(PerfDataGenericEventsTable.TableDescriptor);
33+
var results = engine.Process();
34+
35+
var table = results.BuildTable(PerfDataGenericEventsTable.TableDescriptor);
36+
Assert.AreEqual(1003, table.RowCount);
37+
}
38+
}
39+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<IsTestProject>true</IsTestProject>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Performance.Toolkit.Engine" Version="1.1.13" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="3.0.0" />
13+
<PackageReference Include="MSTest.TestFramework" Version="3.0.0" />
14+
<PackageReference Include="coverlet.collector" Version="3.2.0" />
15+
<ProjectReference Include="..\PerfDataExtension\PerfDataExtension.csproj" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<None Update="TestData\perf.data">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
169 KB
Binary file not shown.

README.md

Lines changed: 3 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/) CPU Sampling(cpu-clock)
11+
- [perf](https://perf.wiki.kernel.org/) (Generic events)
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,7 @@ 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](PerfUnitTest/PerfUnitTest.cs)
60+
- [Perf](PerfDataUnitTest/PerfDataUnitTest.cs)
6161
- [LinuxLogs](LinuxLogParsers/LinuxLogParsersUnitTest/LinuxLogParsersUnitTest.cs)
6262
- [Perfetto](PerfettoUnitTest/PerfettoUnitTest.cs)
6363
- With a driver program for example dumping to screen or text format
@@ -113,7 +113,7 @@ The tools can be run in several modes:
113113
- Unified (LTTng, Perfetto, or other multiple different logs files together)
114114
- 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)
115115
- 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 CPU Sampling, Dmesg
116+
- Example: You want to open in the same timeline: LTTng, Perf, Dmesg
117117
- Ensure that the Linux CTF folder/trace is zipped and renamed to .ctf in the same folder (hack so open Unified works)
118118
- WPA -> File -> Open -> Multi-select all files and choose "Open Unified"
119119

0 commit comments

Comments
 (0)