Skip to content

Commit

Permalink
Port ETW eventing to 0.64 (#7727)
Browse files Browse the repository at this point in the history
  • Loading branch information
asklar committed May 6, 2021
1 parent 04b4004 commit e7efb40
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 1,423 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Initialize ETW provider only once",
"packageName": "react-native-windows",
"email": "asklar@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Last year, we had plumbed the Systrace sections and events in the core react native to windows code and fired ETW events. But, it was hard for people to use because we used manifest based ETW events. This change converts the event triggering code to use Tracelogging APIs (aka self describing events) which doesn't require the manifest to be registered on the host machine to inspect traces.\n Post this change, the systrace events can be inspected on any windows machines where the RNW based apps are running by issuing the following commands, \nwpr.exe -start rnw.wprp\nwpr.exe -stop rnw.etl\nwpa.exe rnw.etl\n\nThis works for Win32 apps too, say Office.",
"packageName": "react-native-windows",
"email": "mganandraj@outlook.com",
"dependentChangeType": "patch"
}
35 changes: 35 additions & 0 deletions docs/tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Event Tracing in ReactNative for Windows

React native for Windows implements an event provider using [Event Tracing for Windows (ETW)](https://docs.microsoft.com/en-us/windows/win32/etw/event-tracing-portal) framework, to enable instrumenting and analyzing performance critical source code. Events generated by an ETW provider can be observed and analyzed using tools available through [Windows Performance Toolkit (WPT)](https://docs.microsoft.com/en-us/windows-hardware/test/wpt/).

Currently, we have implemented the [Systrace APIs](https://stuff.mit.edu/afs/sipb/project/android/docs/tools/help/systrace.html) on Windows to generate ETW events. Systrace APIs are used to instrument the core React Native source code. In future, we will instrument more of the React Native Windows source code with ETW events.

Tracing sessions can be managed as described below,

## Start a tracing session

1. Trace only events generated by React Native For Windows providers,

```powershell
& .\vnext\Scripts\Tracing\Start-Tracing.ps1
```

2. Trace events generated by React Native For Windows as well as the general system providers,

```powershell
& .\vnext\Scripts\Tracing\Start-Tracing.ps1 -IncludeGeneralTrace=$True
```

## Stop a tracing session and anayze the traces

1. Stop the session and start anaylizing the traces,

```powershell
& .\vnext\Scripts\Tracing\Stop-Tracing.ps1
```

2. Stop the session only,

```powershell
& .\vnext\Scripts\Tracing\Stop-Tracing.ps1 -NoAnalysis=$True
```
28 changes: 28 additions & 0 deletions vnext/Scripts/Tracing/Start-Tracing.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
param(
[bool]$IncludeGeneralTrace = $False
)

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$wprpPath = Join-Path -Path $scriptPath -ChildPath "rnw.wprp"

if (!(Get-Command "wpr.exe" -ErrorAction SilentlyContinue)) {
throw "
################################################################
wpr.exe (Windows Performance Recorder) unavailable !
Ensure that WPT (Windows Performance Toolkit) is installed and its tools are added to the path
################################################################"
}

$wprArgs = "-start", $wprpPath

if ($IncludeGeneralTrace) {
$wprArgs += "-start", "GeneralProfile"
}


Write-Host "wpr.exe $wprArgs"
& Start-Process -Verb RunAs "wpr.exe" -ArgumentList $wprArgs -PassThru -Wait

Write-Host "To stop this trace and start analysis, run .\Stop-Tracing.ps1"
Write-Host "To stop this trace only, run .\Stop-Tracing.ps1 -NoAnalysis $True"
Write-Host
46 changes: 46 additions & 0 deletions vnext/Scripts/Tracing/Stop-Tracing.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
param(
[bool]$NoAnalysis = $False
)

$mypath = split-path -parent $MyInvocation.MyCommand.Definition
$timestamp = [DateTime]::Now.ToString("yyyyMMdd_HHmmss")
$fileName = "rnw_" + $timestamp + ".etl"
$etlPath = Join-Path -Path $mypath -ChildPath $fileName

if (!(Get-Command "wpr.exe" -ErrorAction SilentlyContinue)) {
throw "
################################################################
wpr.exe (Windows Performance Recorder) unavailable !
Ensure that WPT (Windows Performance Toolkit) is installed and its tools are added to the path
################################################################"
}

$wprArgs = "-stop", $etlPath

Write-Host "wpr.exe $wprArgs"
& Start-Process -Verb RunAs "wpr.exe" -ArgumentList $wprArgs -PassThru -Wait

if (!(Get-Command "wpa.exe" -ErrorAction SilentlyContinue)) {
Write-Host "wpa.exe (Windows Performance Analyzer) unavailable !"
Write-Host "Ensure that WPT (Windows Performance Toolkit) is installed and its tools are added to the path "
}

if ($NoAnalysis) {
Write-Host "To analys this trace, install WPT and run: 'wpa $etlPath'"
}
else {

if (!(Get-Command "wpa.exe" -ErrorAction SilentlyContinue)) {
throw "
################################################################
wpa.exe (Windows Performance Analyzer) unavailable !
Ensure that WPT (Windows Performance Toolkit) is installed and its tools are added to the path
################################################################"
}

$wpaArgs = $etlPath
Write-Host "wpa.exe $wpaArgs"
& Start-Process -Verb RunAs "wpa.exe" -ArgumentList $wpaArgs
}


40 changes: 40 additions & 0 deletions vnext/Scripts/Tracing/rnw.wprp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO:
1. Find and replace "RNWTraceLoggingProvider" with the name of your provider.
2. See TODO below to update GUID for your event provider
-->
<WindowsPerformanceRecorder Version="1.0" Author="Microsoft Corporation" Copyright="Microsoft Corporation" Company="Microsoft Corporation">
<Profiles>
<EventCollector Id="EventCollector_RNWTraceLoggingProvider" Name="RNWTraceLoggingProvider">
<BufferSize Value="64" />
<Buffers Value="4" />
</EventCollector>

<!-- TODO:
1. Update Name attribute in EventProvider xml element with your provider GUID, eg: Name="3970F9cf-2c0c-4f11-b1cc-e3a1e9958833". Or
if you specify an EventSource C# provider or call TraceLoggingRegister(...) without a GUID, use star (*) before your provider
name, eg: Name="*MyEventSourceProvider" which will enable your provider appropriately.
2. This sample lists one EventProvider xml element and references it in a Profile with EventProviderId xml element.
For your component wprp, enable the required number of providers and fix the Profile xml element appropriately
-->
<EventProvider Id="EventProvider_RNWTraceLoggingProvider" Name="910fb9a1-75dd-4cf4-beec-da21341f20c8" />

<Profile Id="RNWTraceLoggingProvider.Verbose.File" Name="RNWTraceLoggingProvider" Description="RNWTraceLoggingProvider" LoggingMode="File" DetailLevel="Verbose">
<Collectors>
<EventCollectorId Value="EventCollector_RNWTraceLoggingProvider">
<EventProviders>
<!-- TODO:
1. Fix your EventProviderId with Value same as the Id attribute on EventProvider xml element above
-->
<EventProviderId Value="EventProvider_RNWTraceLoggingProvider" />
</EventProviders>
</EventCollectorId>
</Collectors>
</Profile>

<Profile Id="RNWTraceLoggingProvider.Light.File" Name="RNWTraceLoggingProvider" Description="RNWTraceLoggingProvider" Base="RNWTraceLoggingProvider.Verbose.File" LoggingMode="File" DetailLevel="Light" />
<Profile Id="RNWTraceLoggingProvider.Verbose.Memory" Name="RNWTraceLoggingProvider" Description="RNWTraceLoggingProvider" Base="RNWTraceLoggingProvider.Verbose.File" LoggingMode="Memory" DetailLevel="Verbose" />
<Profile Id="RNWTraceLoggingProvider.Light.Memory" Name="RNWTraceLoggingProvider" Description="RNWTraceLoggingProvider" Base="RNWTraceLoggingProvider.Verbose.File" LoggingMode="Memory" DetailLevel="Light" />

</Profiles>
</WindowsPerformanceRecorder>
6 changes: 1 addition & 5 deletions vnext/Shared/Shared.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)CxxMessageQueue.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)DevServerHelper.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)DevSettings.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)etw\react_native_windows.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Executors\WebSocketJSExecutor.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)HermesRuntimeHolder.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)IDevSupportManager.h" />
Expand Down Expand Up @@ -118,9 +117,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)WinRTWebSocketResource.h" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)etw\build.bat" />
<None Include="$(MSBuildThisFileDirectory)etw\react_native_windows.man" />
<None Include="$(MSBuildThisFileDirectory)etw\react_native_windows_etw_res.dll" />
<None Include="$(MSBuildThisFileDirectory)etw\register.bat" />
<None Include="$(MSBuildThisFileDirectory)tracing\rnw.wprp" />
</ItemGroup>
</Project>
22 changes: 2 additions & 20 deletions vnext/Shared/Shared.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@
<Filter Include="Source Files\AsyncStorage">
<UniqueIdentifier>{ee633764-9967-4233-8848-81edf1488790}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\etw">
<UniqueIdentifier>{5862fbd1-2e67-4c90-9e58-24a66d71aec4}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Modules">
<UniqueIdentifier>{37d57028-146d-45f3-a56d-2ce7625a3449}</UniqueIdentifier>
</Filter>
Expand All @@ -141,9 +138,6 @@
<Filter Include="Header Files\tracing">
<UniqueIdentifier>{87b365df-267b-4c00-860a-53d129a65a4e}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\etw">
<UniqueIdentifier>{6008bddc-9f23-4190-9eea-662fb1ab2467}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\tracing">
<UniqueIdentifier>{6d6b7412-d407-4ee3-be2a-addd9dba140a}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -179,9 +173,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)AsyncStorage\KeyValueStorage.h">
<Filter>Header Files\AsyncStorage</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)etw\react_native_windows.h">
<Filter>Header Files\etw</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\ExceptionsManagerModule.h">
<Filter>Header Files\Modules</Filter>
</ClInclude>
Expand Down Expand Up @@ -334,17 +325,8 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)etw\build.bat">
<Filter>Source Files\etw</Filter>
</None>
<None Include="$(MSBuildThisFileDirectory)etw\react_native_windows.man">
<Filter>Source Files\etw</Filter>
</None>
<None Include="$(MSBuildThisFileDirectory)etw\react_native_windows_etw_res.dll">
<Filter>Source Files\etw</Filter>
</None>
<None Include="$(MSBuildThisFileDirectory)etw\register.bat">
<Filter>Source Files\etw</Filter>
<None Include="$(MSBuildThisFileDirectory)tracing\rnw.wprp">
<Filter>Source Files\tracing</Filter>
</None>
</ItemGroup>
</Project>
4 changes: 0 additions & 4 deletions vnext/Shared/etw/build.bat

This file was deleted.

0 comments on commit e7efb40

Please sign in to comment.