Skip to content

Commit 44af167

Browse files
committed
build,test: setup perfetto tests on windows build
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
1 parent 338686d commit 44af167

7 files changed

Lines changed: 90 additions & 43 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ tools/*/*.i.tmp
123123

124124
# === Rules for tools/perfetto ===
125125
/tools/perfetto/trace_processor_shell
126+
/tools/perfetto/trace_processor_shell.exe
126127

127128
# === Rules for test artifacts ===
128129
/*.tap

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ TRACE_PROCESSOR_SHELL_DEPS = deps/perfetto/VERSION
349349
endif
350350

351351
$(TRACE_PROCESSOR_SHELL_PATH): $(TRACE_PROCESSOR_SHELL_DEPS)
352-
@tools/perfetto/get_trace_processor $@
352+
@$(PYTHON) tools/perfetto/get_trace_processor.py $@
353353

354354
.PHONY: test
355355
# This does not run tests of third-party libraries inside deps.

‎test/common/trace_events.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// binary format.
55
// This depends on perfetto's `trace_processor_shell` converts to pftrace format
66
// to JSON format. Run `make tools/perfetto/trace_processor_shell` to download
7-
// it, or point `TRACE_PROCESSOR_SHELL_PATH` at an existing build of it.
7+
// it (`vcbuild test` does so on Windows), or point `TRACE_PROCESSOR_SHELL_PATH`
8+
// at an existing build of it.
89

910
const assert = require('assert');
1011
const { spawnSync } = require('child_process');
@@ -14,7 +15,8 @@ const common = require('./');
1415

1516
const traceProcessor = path.resolve(
1617
__dirname, '..', '..',
17-
process.env.TRACE_PROCESSOR_SHELL_PATH || 'tools/perfetto/trace_processor_shell');
18+
process.env.TRACE_PROCESSOR_SHELL_PATH ||
19+
`tools/perfetto/trace_processor_shell${common.isWindows ? '.exe' : ''}`);
1820

1921
// The JSON form of a trace runs about three times the size of the trace it was
2022
// converted from, and the traces these tests produce are a few hundred KiB at
@@ -29,7 +31,7 @@ const defaultTraceFileName = `node_trace.1.${traceFileExt}`;
2931
function checkTraceProcessor() {
3032
if (common.hasPerfetto && !fs.existsSync(traceProcessor)) {
3133
assert.fail('trace_processor_shell is missing, ' +
32-
'run `make tools/perfetto/trace_processor_shell` to download it');
34+
'run `python3 tools/perfetto/get_trace_processor.py` to download it');
3335
}
3436
}
3537

‎test/trace_events/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
When the `node` binary is built with configure flag `--with-perfetto`,
44
the tests in this folder depends on `tools/perfetto/trace_processor_shell`,
5-
which is downloaded with `tools/perfetto/get_trace_processor` via
5+
which is downloaded with `tools/perfetto/get_trace_processor.py` via
66
`make tools/perfetto/trace_processor_shell`, to convert Perfetto binary trace
7-
files to JSON format. Set `TRACE_PROCESSOR_SHELL_PATH` to use an existing build
8-
of the tool instead of downloading a release.
7+
files to JSON format. On Windows, `vcbuild.bat` downloads
8+
`tools/perfetto/trace_processor_shell.exe` with the same script before running
9+
the tests. Set `TRACE_PROCESSOR_SHELL_PATH` to use an existing build of the
10+
tool instead of downloading a release.
911

1012
Refer to <https://perfetto.dev/docs/reference/trace-processor-cli>
1113
for help of the `trace_processor_shell` CLI.

‎tools/perfetto/get_trace_processor‎

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
# Downloads perfetto's trace_processor_shell, matching the SDK version vendored
3+
# in deps/perfetto. The trace events tests read back the binary traces that
4+
# perfetto builds write through this tool.
5+
6+
import os
7+
import platform
8+
import shutil
9+
import stat
10+
import sys
11+
import tempfile
12+
import urllib.request
13+
import zipfile
14+
15+
script_dir = os.path.dirname(os.path.abspath(__file__))
16+
version_file = os.path.join(script_dir, '..', '..', 'deps', 'perfetto', 'VERSION')
17+
is_windows = platform.system() == 'Windows'
18+
19+
# Perfetto names its release archives <os>-<arch>, which does not match what
20+
# platform reports.
21+
OS_NAMES = {'Darwin': 'mac', 'Linux': 'linux'}
22+
ARCH_NAMES = {'x86_64': 'amd64', 'amd64': 'amd64', 'arm64': 'arm64', 'aarch64': 'arm64'}
23+
24+
25+
def release_name():
26+
# Perfetto releases only an x64 build for Windows. Windows on arm64 runs it
27+
# under emulation.
28+
if is_windows:
29+
return 'windows-amd64'
30+
31+
os_name = OS_NAMES.get(platform.system())
32+
arch = ARCH_NAMES.get(platform.machine().lower())
33+
if os_name is None or arch is None:
34+
sys.exit(f'No perfetto release for {platform.system()} {platform.machine()}')
35+
return f'{os_name}-{arch}'
36+
37+
38+
def main():
39+
exe = 'trace_processor_shell.exe' if is_windows else 'trace_processor_shell'
40+
trace_processor = sys.argv[1] if len(sys.argv) > 1 else os.path.join(script_dir, exe)
41+
42+
# The tool is current when it is newer than the version file it was
43+
# downloaded for, so a version bump re-downloads it.
44+
if (os.path.exists(trace_processor) and
45+
os.path.getmtime(trace_processor) > os.path.getmtime(version_file)):
46+
return
47+
48+
with open(version_file) as f:
49+
version = f.read().strip()
50+
name = release_name()
51+
url = f'https://github.com/google/perfetto/releases/download/v{version}/{name}.zip'
52+
53+
print(f'Downloading {url}')
54+
with tempfile.TemporaryFile() as archive:
55+
with urllib.request.urlopen(url) as response:
56+
shutil.copyfileobj(response, archive)
57+
with zipfile.ZipFile(archive) as zf, \
58+
zf.open(f'{name}/{exe}') as src, \
59+
open(trace_processor, 'wb') as dst:
60+
shutil.copyfileobj(src, dst)
61+
62+
if not is_windows:
63+
mode = os.stat(trace_processor).st_mode
64+
os.chmod(trace_processor, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
65+
66+
67+
if __name__ == '__main__':
68+
main()

‎vcbuild.bat‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set compile_commands=
8585
set cfg=
8686
set v8temporal=
8787
set v8windbg=
88+
set with_perfetto=
8889
set exit_code=0
8990

9091
:next-arg
@@ -116,6 +117,7 @@ if /i "%1"=="pgo-generate" set pgo_generate=1&goto arg-ok
116117
if /i "%1"=="pgo-use" set pgo_use=1&goto arg-ok
117118
if /i "%1"=="v8temporal" set v8temporal=1&goto arg-ok
118119
if /i "%1"=="v8windbg" set v8windbg=1&goto arg-ok
120+
if /i "%1"=="with-perfetto" set with_perfetto=1&goto arg-ok
119121
if /i "%1"=="licensertf" set licensertf=1&goto arg-ok
120122
if /i "%1"=="test" set test_args=%test_args% %common_test_suites%&set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok
121123
if /i "%1"=="test-ci-native" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap %CI_NATIVE_SUITES% %CI_DOC%&set build_addons=1&set build_js_native_api_tests=1&set build_node_api_tests=1&set build_ffi_tests=1&set cctest_args=%cctest_args% --gtest_output=xml:cctest.junit.xml&goto arg-ok
@@ -272,6 +274,7 @@ if defined compile_commands set configure_flags=%configure_flags% -C
272274
if defined cfg set configure_flags=%configure_flags% --control-flow-guard
273275
if defined v8temporal set configure_flags=%configure_flags% --v8-enable-temporal-support
274276
if defined v8windbg set configure_flags=%configure_flags% --enable-v8windbg
277+
if defined with_perfetto set configure_flags=%configure_flags% --with-perfetto
275278

276279
if "%target_arch%"=="x86" (
277280
echo "32-bit Windows builds are not supported anymore."
@@ -826,6 +829,13 @@ echo running 'cctest %cctest_args%'
826829
"%config%\cctest" %cctest_args%
827830
if %errorlevel% neq 0 set exit_code=%errorlevel%
828831
:run-test-py
832+
@rem Download trace_processor_shell for perfetto builds.
833+
if defined TRACE_PROCESSOR_SHELL_PATH goto run-test-py-start
834+
findstr /r /c:"v8_use_perfetto.: 1," config.gypi >nul 2>&1
835+
if errorlevel 1 goto run-test-py-start
836+
python tools\perfetto\get_trace_processor.py
837+
if errorlevel 1 exit /b 1
838+
:run-test-py-start
829839
echo running 'python tools\test.py %test_args%'
830840
python tools\test.py %test_args%
831841
if %errorlevel% neq 0 set exit_code=%errorlevel%

0 commit comments

Comments
 (0)