Skip to content

Commit a71bee3

Browse files
committed
Add tracing
1 parent 33bb97c commit a71bee3

File tree

6 files changed

+149
-2
lines changed

6 files changed

+149
-2
lines changed

.azure-pipelines/steps/run-tests-windows.yml

+37-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,48 @@ steps:
88
versionSpec: '$(python.version)'
99
architecture: '$(python.architecture)'
1010

11+
- powershell: |
12+
Invoke-WebRequest -Uri https://go.microsoft.com/fwlink/?linkid=2026036 -OutFile adksetup.exe
13+
./adksetup.exe /features OptionId.WindowsPerformanceToolkit /log adk-setup.log /ceip off /installpath "C:\Program Files (x86)\Windows Kits\10\"
14+
# Wait for install to complete.
15+
python -c "
16+
import os, time
17+
start = time.time()
18+
last = start
19+
while last - start < 60:
20+
if os.path.exists('C:/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/wpr.exe'):
21+
break
22+
print('Waiting...')
23+
time.sleep(2)
24+
last = time.time()
25+
"
26+
Get-Content adk-setup.log
27+
displayName: ADK Setup
28+
1129
- bash: pip install --upgrade setuptools tox
1230
displayName: Install Tox
1331

14-
- script: tox -e py -- -m unit -n 3 --junit-xml=junit/unit-test.xml
32+
- script:
33+
mkdir traces
34+
tox -e py -- -m unit --junit-xml=junit/unit-test.xml
35+
--use-wpr
36+
--wpr-path="C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\wpr.exe"
37+
--wpr-profile=GeneralProfile.verbose
38+
--wpr-profile=CPU.verbose
39+
--wpr-output=traces/wpr-result.etl
1540
displayName: Tox run unit tests
1641

42+
- script:
43+
tracerpt -l traces/wpr-result.etl -export traces/providers.man
44+
displayName: Generate trace provider manifest
45+
46+
- task: PublishBuildArtifacts@1
47+
displayName: 'Publish trace results'
48+
inputs:
49+
pathtoPublish: traces
50+
artifactName: wpr-result-$(python.version)-$(python.architecture).etl
51+
condition: succeededOrFailed()
52+
1753
- ${{ if eq(parameters.runIntegrationTests, 'true') }}:
1854
- powershell: |
1955
# Fix Git SSL errors

tests/conftest.py

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
from tests.lib.venv import VirtualEnvironment
1919

2020

21+
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
22+
23+
24+
pytest_plugins = "tests.plugins.wpr"
25+
26+
2127
def pytest_addoption(parser):
2228
parser.addoption(
2329
"--keep-tmpdir", action="store_true",

tests/plugins/__init__.py

Whitespace-only changes.

tests/plugins/wpr.py

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import os
2+
import re
3+
import subprocess
4+
import sys
5+
from itertools import chain, repeat
6+
7+
8+
def pytest_addoption(parser):
9+
group = parser.getgroup('wpr')
10+
group.addoption(
11+
'--use-wpr',
12+
action='store_true',
13+
)
14+
group.addoption(
15+
'--wpr-path',
16+
default=None,
17+
)
18+
group.addoption(
19+
'--wpr-output',
20+
default=None,
21+
)
22+
group.addoption(
23+
'--wpr-profile',
24+
action='append',
25+
)
26+
27+
28+
class Plugin(object):
29+
def __init__(self, config):
30+
self.config = config
31+
32+
def pytest_runtest_logstart(self, nodeid, location):
33+
wpr_path = self.config.getoption('--wpr-path')
34+
if not wpr_path:
35+
return
36+
msg = "{} ({}) - begin".format(nodeid, os.getpid())
37+
create_mark(wpr_path, msg)
38+
39+
def pytest_runtest_logfinish(self, nodeid, location):
40+
wpr_path = self.config.getoption('--wpr-path')
41+
if not wpr_path:
42+
return
43+
msg = "{} ({}) - end".format(nodeid, os.getpid())
44+
create_mark(wpr_path, msg)
45+
46+
47+
def pytest_configure(config):
48+
if sys.platform != 'win32':
49+
return
50+
51+
if not config.getoption('--use-wpr'):
52+
return
53+
54+
config.pluginmanager.register(Plugin(config))
55+
56+
wpr_path = config.getoption('--wpr-path')
57+
wpr_profiles = config.getoption('--wpr-profile')
58+
59+
start_wpr(wpr_path, wpr_profiles)
60+
61+
62+
def pytest_unconfigure(config):
63+
if sys.platform != 'win32':
64+
return
65+
66+
if not config.getoption('--use-wpr'):
67+
return
68+
69+
wpr_path = config.getoption('--wpr-path')
70+
wpr_output = config.getoption('--wpr-output')
71+
72+
stop_wpr(wpr_path, wpr_output)
73+
74+
75+
_name_re = re.compile(r"(?P<file>.+?)::(?P<name>.+?) \(.*\)$")
76+
77+
78+
def current_test_name():
79+
try:
80+
name = os.environ["PYTEST_CURRENT_TEST"]
81+
except KeyError:
82+
return "<outside test>"
83+
m = _name_re.match(name)
84+
if not m:
85+
raise RuntimeError(
86+
"Could not extract test name from {}".format(name)
87+
)
88+
return m.group("name")
89+
90+
91+
def start_wpr(executable, profiles):
92+
# type: (str, List[str]) -> None
93+
args = [executable]
94+
args.extend(chain.from_iterable(zip(repeat('-start'), profiles)))
95+
subprocess.check_call(args)
96+
97+
98+
def stop_wpr(executable, output_path):
99+
# type: (str, str) -> None
100+
subprocess.check_call([executable, '-stop', output_path])
101+
102+
103+
def create_mark(executable, message):
104+
# type: (str, str) -> None
105+
subprocess.check_call([executable, '-marker', message])

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ deps = -r{toxinidir}/tools/requirements/tests.txt
2020
commands_pre =
2121
python -c 'import shutil, sys; shutil.rmtree(sys.argv[1], ignore_errors=True)' {toxinidir}/tests/data/common_wheels
2222
{[helpers]pip} wheel -w {toxinidir}/tests/data/common_wheels -r {toxinidir}/tools/requirements/tests-common_wheels.txt
23-
commands = pytest --timeout 300 --suppress-no-test-exit-code [] tests/unit/test_build_env.py
23+
commands = pytest --timeout 300 --suppress-no-test-exit-code [] -k test_build_env_allow_only_one_install tests/unit/test_build_env.py
2424
install_command = {[helpers]pip} install {opts} {packages}
2525
list_dependencies_command = {[helpers]pip} freeze --all
2626

wpr-result-37.etl

28 MB
Binary file not shown.

0 commit comments

Comments
 (0)