Skip to content

Commit f60e1bc

Browse files
committed
Start of review of WindowsPerf with SPE
1 parent c6493e2 commit f60e1bc

File tree

2 files changed

+71
-54
lines changed

2 files changed

+71
-54
lines changed

content/learning-paths/cross-platform/windowsperf_sampling_cpython_spe/_index.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
---
22
title: Sampling CPython with Arm SPE with WindowsPerf
3+
draft: true
4+
cascade:
5+
draft: true
36

47
minutes_to_complete: 30
58

6-
who_is_this_for: This is an introductory topic for developers keen to understand sampling with ARM SPE extension.
9+
who_is_this_for: This is an introductory topic for developers keen to understand sampling with the Arm Statistical Profiling Extension (SPE).
710

811
learning_objectives:
9-
- Use WindowsPerf with native Windows on Arm workload
10-
- Understand the basics of sampling with Arm SPE
11-
- Explore the WindowsPerf command line
12-
- Build CPython from sources for Windows on Arm ARM64 target
12+
- Use WindowsPerf with a native Windows on Arm workload.
13+
- Understand the basics of sampling with Arm SPE.
14+
- Explore the WindowsPerf command line.
15+
- Build CPython from sources for Windows on Arm (ARM64).
1316

1417
prerequisites:
15-
- Windows on Arm desktop or development machine with [WindowsPerf installed](/install-guides/wperf)
16-
- CPU with Arm Statistical Profiling Extension (SPE) support
18+
- Windows on Arm desktop or development machine with [WindowsPerf](/install-guides/wperf), [Visual Studio](/install-guides/vs-woa/), and [Git](/install-guides/git-woa/) installed.
19+
- The system must also have an Arm CPU with SPE support.
1720

1821
author_primary: Przemyslaw Wirkus
1922

@@ -30,6 +33,12 @@ tools_software_languages:
3033
- Python
3134
- perf
3235

36+
## Cross-platform metadata only
37+
shared_path: true
38+
shared_between:
39+
- servers-and-cloud-computing
40+
- laptops-and-desktops
41+
3342
### FIXED, DO NOT MODIFY
3443
# ================================================================================
3544
weight: 1 # _index.md always has weight of 1 to order correctly
Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,60 @@
11
---
22
layout: learningpathall
3-
title: CPython Sampling with SPE Example Overview
3+
title: An overview of CPython sampling with SPE
44
weight: 2
55
---
66

7-
# CPython Sampling with SPE Example
7+
In this example, you will build a debug build of CPython from sources and execute simple instructions in the Python interactive mode to obtain WindowsPerf sampling results from the CPython runtime image.
88

9-
In this example, you will build a debug build of CPython from sources and then execute simple instructions in the Python interactive mode to obtain WindowsPerf sampling results from a CPython runtime image.
10-
11-
## The Arm Statistical Profiling Extension Introduction
9+
## Introduction to the Arm Statistical Profiling Extension (SPE)
1210

1311
The Arm Statistical Profiling Extension (SPE) is a feature defined as part of the Armv8-A architecture, starting from version 8.2. It provides non-invasive, hardware-based statistical sampling for CPUs. Unlike the Performance Monitor Unit (PMU), SPE is a different module that integrates the sampling process into the instruction execution process within the CPU's pipelines.
1412

1513
SPE is particularly useful for performance analysis and optimization, as it provides detailed insights into the behavior of the CPU during execution. This can help identify performance bottlenecks and optimize software for better efficiency.
1614

17-
## Introduction
15+
## Overview
16+
17+
You will use sampling to determine the CPython program "hot" locations as provided by the Arm Statistical Profiling Extension (SPE).
1818

19-
You will use sampling to determine CPython program "hot" locations provided by Arm Statistical Profiling Extension (SPE).
19+
WindowsPerf includes `record` support for the Arm Statistical Profiling Extension (SPE).
2020

21-
WindowsPerf added support (in `record` command) for the [Arm Statistical Profiling Extension (SPE)](https://developer.arm.com/documentation/101136/22-1-3/MAP/Arm-Statistical-Profiling-Extension--SPE-). SPE is an optional feature in ARMv8.2 hardware that allows CPU instructions to be sampled and associated with the source code location where that instruction occurred.
21+
SPE is an optional feature in ARMv8.2 hardware that allows CPU instructions to be sampled and associated with the source code location where that instruction occurred.
2222

2323
{{% notice Note %}}
24-
Currently SPE is available on Windows On Arm in Test Mode only!
24+
Currently SPE is available on Windows On Arm in Test Mode only!
2525
{{% /notice %}}
2626

2727
## Before you begin
2828

29-
For this learning path you will need:
30-
* A Windows on Arm (ARM64) native machine with pre-installed WindowsPerf (both driver and `wperf` CLI tool). See [WindowsPerf Install Guide](/install-guides/wperf/) for more details.
29+
For this Learning Path you will need:
30+
31+
* A Windows on Arm (ARM64) native machine with pre-installed WindowsPerf (both driver and `wperf` CLI tool). Refer to the [WindowsPerf Install Guide](/install-guides/wperf/) for more details.
3132
* Note: The [WindowsPerf release 3.8.0](https://github.com/arm-developer-tools/windowsperf/releases/tag/3.8.0) includes a separate build with Arm SPE (Statistical Profiling Extension) support enabled. To install this version download release asset and you will find WindowsPerf SPE build in the `SPE/` subdirectory.
32-
* CPU must support Arm SPE extension, an optional feature in ARMv8.2 hardware - we will show you how to check your CPU compatibility using WindowsPerf command-line tool.
33-
* Basic knowledge of git and Python.
34-
* See [Install Git on Windows](https://github.com/git-guides/install-git#install-git-on-windows) for more details.
33+
* [Visual Studio](/install-guides/vs-woa/) and [Git](/install-guides/git-woa/) installed.
34+
* The CPU must support the Arm SPE extension, an optional feature in ARMv8.2 hardware. You can check your CPU compatibility using the WindowsPerf command-line tool (explained below).
3535

36-
### How to check if your ARM64 CPU supports Arm SPE extension
36+
### How do I check if my Arm CPU supports the Arm SPE extension?
3737

3838
#### SPE hardware support detection:
3939

40-
You can check if your system supports SPE or if WindowsPerf can detect SPE with `wperf test` command. See below an example of `spe_device.version_name property` value on system with SPE:
40+
You can check if WindowsPerf detects SPE support with the `wperf test` command.
41+
42+
Run the command below and if the `spe_device.version_name` property shows `FEAT_SPE` it means WindowsPerf can use the SPE features.
4143

4244
```console
4345
wperf test
4446
```
4547

48+
Here is the output for a system with SPE support:
49+
4650
```output
4751
Test Name Result
4852
========= ======
4953
...
5054
spe_device.version_name FEAT_SPE
5155
```
5256

53-
#### How do I know if your WindowsPerf binaries and driver support optional SPE?
57+
#### How do I know if my WindowsPerf binaries and driver support optional SPE?
5458

5559
{{% notice Note %}}
5660
Currently WindowsPerf support of SPE is in development, not all versions of WindowsPerf enable SPE support. Some WindowsPerf releases may contain separate binaries with SPE support enables.
@@ -62,26 +66,28 @@ You can check feature string `FeatureString` of both `wperf` and `wperf-driver`
6266
wperf --version
6367
```
6468

69+
The output is similar to:
70+
6571
```output
6672
Component Version GitVer FeatureString
6773
========= ======= ====== =============
6874
wperf 3.8.0 6d15ddfc +etw-app+spe
6975
wperf-driver 3.8.0 6d15ddfc +trace+spe
7076
```
7177

72-
If `FeatureString` for both components (`wperf` and `wperf-driver`) contains `+spe` (and `spe_device.version_name` contains `FEAT_SPE`) you are good to go!
78+
If the `FeatureString` for both `wperf` and `wperf-driver` contains `+spe` you can use the SPE features of WindowsPerf.
7379

74-
### Build CPython targeting ARM64
80+
### Build CPython for ARM64
7581

76-
Note: all steps are done on Windows on Arm system with ARM64 CPU.
82+
Perform the build steps below on your Windows on Arm system.
7783

78-
CPython is an open-source project. There is native support in CPython for Windows on Arm starting with version 3.11. In this learning path you will use a debug build of CPython. For this, you will build [CPython](https://github.com/python/cpython) locally from sources in the debug mode on an x86_64 machine and cross-compile it for an ARM64 target.
84+
CPython is an open-source project which includes native support for Windows on Arm starting with version 3.11.
7985

80-
{{% notice Note %}}
81-
Use the Visual Studio `Developer Command Prompt for VS 2022` which is already set up in the VS environment. Go to Start and search for "Developer Command Prompt for VS 2022".
82-
{{% /notice %}}
86+
The SPE features are demonstrated with a debug build of CPython. You can build [CPython](https://github.com/python/cpython) locally from sources in debug mode.
87+
88+
Open a Visual Studio `Developer Command Prompt for VS 2022` command prompt. You can find this from Windows Start by searching for "Developer Command Prompt for VS 2022".
8389

84-
You should see a prompt as shown below:
90+
When you open the command prompt, you will see output similar to:
8591

8692
```output
8793
**********************************************************************
@@ -93,20 +99,20 @@ C:\Program Files\Microsoft Visual Studio\2022\Community>
9399
```
94100

95101
{{% notice Note %}}
96-
Please use `Developer Command Prompt for VS 2022` with all of the next steps.
102+
Please use the `Developer Command Prompt for VS 2022` command prompt for the remainder of the steps.
97103
{{% /notice %}}
98104

99-
---
100-
101-
Let's build CPython locally in debug mode using the `build.bat` script. You have the option to build CPython directly on your ARM64 machine or cross-compile it on an x64 machine. Below is an example demonstrating how to build it on an ARM64 machine.
105+
You can build CPython locally in debug mode using the `build.bat` script using the steps below.
102106

103107
#### Clone CPython source code
104108

109+
Get the CPython source code from GitHub:
110+
105111
```command
106112
git clone https://github.com/python/cpython.git
107113
```
108114

109-
The output from this command will be similar to:
115+
The output from this command is similar to:
110116

111117
```output
112118
Cloning into 'cpython'...
@@ -119,19 +125,19 @@ Resolving deltas: 100% (792463/792463), done.
119125
Updating files: 100% (4647/4647), done.
120126
```
121127

122-
#### Checkout CPython at specific SHA
128+
#### Checkout CPython with a specific SHA
123129

124130
{{% notice Note %}}
125-
This step is optional, but please remember that you may encounter build issues unrelated to this example as the CPython mainline source code that you've just checked out is not stable. Therefore, we recommend that you check out SHA to avoid any unexpected issues and to ensure you are working off the same code base.
131+
This step is optional, but you may encounter build issues unrelated to this example if the CPython mainline source code is not stable. It's best to check out a specific SHA to avoid any unexpected issues and to ensure you are working off the same code base.
126132
{{% /notice %}}
127133

128-
Use a specific CPython commit to match the sampling output in this example:
134+
Use a specific CPython commit to match the output for this example:
129135

130136
```console
131137
cd cpython
132138
git checkout 1ff81c0cb67215694f084e51c4d35ae53b9f5cf9
133139
```
134-
The output will be similar to:
140+
The output is similar to:
135141

136142
```output
137143
Updating files: 100% (2774/2774), done.
@@ -141,17 +147,18 @@ Note: switching to '1ff81c0cb67215694f084e51c4d35ae53b9f5cf9'.
141147

142148
#### Build CPython from sources
143149

144-
The folder `cpython\PCbuild` contains the `build.bat` script you will use to build CPython from sources. Build CPython with debug symbols by invoking the `-d` command line option and select the ARM64 target with `-p ARM64`.
150+
The `build.bat` script builds CPython from sources. Build CPython with debug symbols by invoking the `-d` command line option and select the ARM64 target with `-p ARM64`.
145151

146-
{{% notice Note %}}
147152
Make sure you are using `Developer Command Prompt for VS 2022`.
148-
{{% /notice %}}
153+
154+
Change to the `PCbuild` directory and run the build command:
149155

150156
```console
151157
cd PCbuild
152158
build.bat -d -p ARM64
153159
```
154-
The output will be similar to:
160+
161+
The output is similar to:
155162

156163
```output
157164
Downloading nuget...
@@ -172,26 +179,27 @@ Build succeeded.
172179
Time Elapsed 00:00:59.50
173180
```
174181

175-
{{% notice Note %}}
176-
The folder `cpython\PCbuild\arm64` should contain all the executables built in this process. You will use `python_d.exe` in this example.
177-
{{% /notice %}}
182+
The folder `cpython\PCbuild\arm64` contains the executables built in this process.
183+
184+
You will use `python_d.exe` to run Python.
178185

179186
##### Execute interactive mode to make sure all the CPython dependencies and libraries are loaded
180187

181-
On your Windows ARM64 machine, open a command prompt and run:
188+
Continue at the same command prompt, and test that Python runs correctly:
182189

183190
```console
184-
cd c:\path\to\cpython\PCbuild\arm64
191+
cd arm64
185192
python_d.exe
186193
```
187-
You should see CPython being invoked in interactive mode:
194+
195+
You see CPython being invoked in interactive mode:
188196

189197
```output
190198
Python 3.12.0a6+ (heads/main:1ff81c0cb6, Mar 14 2023, 16:26:50) [MSC v.1935 64 bit (ARM64)] on win32
191199
Type "help", "copyright", "credits" or "license" for more information.
192200
>>>
193201
```
194202

195-
{{% notice Note %}}
196-
Your environment should now be fully set up and you are ready to move on to the next step.
197-
{{% /notice %}}
203+
Type `quit()` to exit CPython.
204+
205+
Your environment s now ready to use WindowsPerf with SPE on CPython.

0 commit comments

Comments
 (0)