Skip to content

Commit 49957c9

Browse files
committed
test: setup perfetto tests on windows build
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
1 parent 04fb145 commit 49957c9

7 files changed

Lines changed: 89 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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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', 'Windows': 'windows'}
22+
ARCH_NAMES = {'x86_64': 'amd64', 'amd64': 'amd64', 'arm64': 'arm64', 'aarch64': 'arm64'}
23+
24+
25+
def release_name():
26+
os_name = OS_NAMES.get(platform.system())
27+
arch = ARCH_NAMES.get(platform.machine().lower())
28+
if os_name is None or arch is None:
29+
sys.exit(f'No perfetto release for {platform.system()} {platform.machine()}')
30+
# Perfetto releases only an x64 build for Windows. Windows on arm64 runs it
31+
# under emulation.
32+
if is_windows:
33+
arch = 'amd64'
34+
return f'{os_name}-{arch}'
35+
36+
37+
def main():
38+
exe = 'trace_processor_shell.exe' if is_windows else 'trace_processor_shell'
39+
trace_processor = sys.argv[1] if len(sys.argv) > 1 else os.path.join(script_dir, exe)
40+
41+
# The tool is current when it is newer than the version file it was
42+
# downloaded for, so a version bump re-downloads it.
43+
if (os.path.exists(trace_processor) and
44+
os.path.getmtime(trace_processor) > os.path.getmtime(version_file)):
45+
return
46+
47+
with open(version_file) as f:
48+
version = f.read().strip()
49+
name = release_name()
50+
url = f'https://github.com/google/perfetto/releases/download/v{version}/{name}.zip'
51+
52+
print(f'Downloading {url}')
53+
with tempfile.TemporaryFile() as archive:
54+
with urllib.request.urlopen(url) as response:
55+
shutil.copyfileobj(response, archive)
56+
with zipfile.ZipFile(archive) as zf, \
57+
zf.open(f'{name}/{exe}') as src, \
58+
open(trace_processor, 'wb') as dst:
59+
shutil.copyfileobj(src, dst)
60+
61+
if not is_windows:
62+
mode = os.stat(trace_processor).st_mode
63+
os.chmod(trace_processor, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
64+
65+
66+
if __name__ == '__main__':
67+
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."
@@ -814,6 +817,13 @@ echo running 'cctest %cctest_args%'
814817
"%config%\cctest" %cctest_args%
815818
if %errorlevel% neq 0 set exit_code=%errorlevel%
816819
:run-test-py
820+
@rem Download trace_processor_shell for perfetto builds.
821+
if defined TRACE_PROCESSOR_SHELL_PATH goto run-test-py-start
822+
findstr /r /c:"v8_use_perfetto.: 1," config.gypi >nul 2>&1
823+
if errorlevel 1 goto run-test-py-start
824+
python tools\perfetto\get_trace_processor.py
825+
if errorlevel 1 exit /b 1
826+
:run-test-py-start
817827
echo running 'python tools\test.py %test_args%'
818828
python tools\test.py %test_args%
819829
if %errorlevel% neq 0 set exit_code=%errorlevel%

0 commit comments

Comments
 (0)