README.chromium
README.md
1# Crossbench
2
3Crossbench is a cross-browser/cross-benchmark runner to extract performance
4numbers.
5
6Mailing list: <crossbench@chromium.org>
7
8Issues/Bugs: [Tests > CrossBench](https://bugs.chromium.org/p/chromium/issues/list?q=component%3ATest%3ECrossBench)
9
10Supported Browsers: Chrome/Chromium, Firefox, Safari and Edge.
11
12Supported OS: MacOS, Android, Linux and Windows.
13
14## Basic usage:
15### Chromium Devs (with a full chromium checkout)
16Use the `./cb.py` script directly to run benchmarks (requires chrome's
17[vpython3](https://chromium.googlesource.com/infra/infra/+/main/doc/users/vpython.md))
18
19### Standalone installation
20- Use `pip install crossbench`,
21- or use the "poetry" package manager, see the [development section](#development).
22
23### Running Workloads Examples
24Run the latest [speedometer benchmark](https://browserbench.org/Speedometer/)
2520 times with the system default browser (chrome-stable):
26```bash
27# Run chrome-stable by default:
28./cb.py speedometer --repeat=3
29
30# Compare chrome browser versions and a local chrome build on jetstream:
31./cb.py jetstream --browser=chrome-stable --browser=chrome-m90 --browser=$PATH
32```
33
34Profile individual line items (with pprof on linux):
35```bash
36./cb.py speedometer --probe='profiling' --separate
37```
38
39Use a custom chrome build and only run a subset of the stories:
40```bash
41./cb.py speedometer --browser=$PATH --probe='profiling' --story='jQuery.*'
42```
43
44Profile a website for 17 seconds on Chrome M100 (auto-downloading on macOS and linux):
45```bash
46./cb.py loading --browser=chrome-m100 --probe='profiling' --url=www.cnn.com,17s
47```
48
49Collect perfetto data from loading separate websites on multiple attached
50android devices using the device ID or unique device names
51(see `adb devices -l`):
52
53```bash
54./cb.py loading --probe-config=./config/probe/perfetto/default.config.hjson \
55 --browser='Pixel_4:chrome-stable' --browser='AA00BB11:chrome-stable' \
56 --parallel=platform \
57 --url=https://theverge.com,15s,https://cnn.com,15s --separate
58```
59
60
61## Main Components
62
63### Browsers
64Crossbench supports running benchmarks on one or multiple browser configurations.
65The main implementation uses selenium for maximum system independence.
66
67You can specify a browser with `--browser=<name>`. You can repeat the
68`--browser` argument to run multiple browser. If you need custom flags for
69multiple browsers use `--browser-config` (or pass simple flags after `--` to
70the browser).
71
72```bash
73./cb.py speedometer --browser=$BROWSER -- --enable-field-trial-config
74```
75#### `--browser` flag on desktop:
76
77| Flag | Description |
78|------|-------------|
79|`--browser=chrome-stable`| Use the installed Chrome stable on the host. Also works with `beta`, `dev` and `canary` versions. |
80|`--browser=edge-stable`| Use the installed Edge stable on the host. Also works with `beta`, `dev` and `canary` versions. |
81|`--browser=safari-stable`| Use the installed Safari stable version on the host. Also works with `technology-preview` |
82|`--browser=firefox-stable`| Use the installed Firefox stable version on the host. Also works with `dev` and `nightly` versions. |
83|`--browser=./out/Release/chrome`| Use a locally compiled chrome version. Any path to a chrome binary will work. |
84|`--browser=chrome-m123`| Download the latest M123 chrome release and install it locally |
85|`--browser=chrome-125.0.6422.112`| Download and install a specific chrome version. |
86|`--browser=chrome-M100...M123`| Download and install a range of 24 different chrome milestones. |
87
88#### `--browser` flag on mobile:
89You can directly run on attached android devices using the device ID or unique device names.
90They need to have [developer mode and usb-debugging enabled](https://developer.android.com/studio/debug/dev-options#Enable-debugging).
91
92| Flag | Description |
93|------|-------------|
94| `--browser=adb:chrome-stable` | Use Chrome stable on a single attached adb device. Note this will fail if there is more than one attached device. |
95| `--browser=Pixel_7_pro:chrome-canary` | Use Chrome canary on an attached Pixel 7 Pro device. Note this will fail if there is more than one Pixel 7 pro attached.|
96| `--browser=2900FF00BB:chrome-dev` | Use Chrome dev on an attached adb device with the serial id `2900FF00BB`. Use `adb devices -l` to find the serial id.|
97
98#### Browser Config File
99For more complex scenarios you can use a
100[browser.config.hjson](config/doc/browser.config.hjson) file.
101It allows you to specify multiple browser and multiple flag configurations in
102a single file and produce performance numbers with a single invocation.
103
104```bash
105./cb.py speedometer --browser-config=config.hjson
106```
107
108The [example file](config/doc/browser.config.hjson) lists and explains all
109configuration details.
110
111#### Remote WebDriver Interface
112Crossbench also supports benchmarking browsers on remote machines
113running Linux or ChromeOS, via SSH.
114The remote machine is expected to have at least two ports open to the host:
115(a) the SSH port (typically `22`), and
116(b) the WebDriver port (typically `9515`).
117The [remote browser example](config/doc/remote_browser.config.hjson)
118describes the configuration details for both Linux and ChromeOS.
119
120On ChromeOS, Crossbench requires
121[ChromeDriver](https://developer.chrome.com/docs/chromedriver/get-started/chromeos/)
122to interact with Chrome,
123and [Autotest](https://chromium.googlesource.com/chromiumos/third_party/autotest/+/HEAD/docs/user-doc.md)
124for creating ephemeral sessions for testing.
125Both ChromeDriver and Autotest are pre-installed on ChromeOS test images.
126Detailed instructions for flashing Chromebooks with test images are provided at:
127go/arc-setup-dev-mode-dut#usb-cros-test-image.
128
129### Probes
130Probes define a way to extract arbitrary (performance) numbers from a
131host or running browser. This can reach from running simple JS-snippets to
132extract page-specific numbers to system-wide profiling.
133
134Multiple probes can be added with repeated `--probe='XXX'` options.
135You can use the `describe probes` subcommand to list all probes:
136
137```bash
138# List all probes:
139./cb.py describe probes
140
141# List help for an individual probe:
142./cb.py describe probe v8.log
143```
144
145#### Inline Probe Config
146Some probes can be configured, either with inline JSON when using `--probe` or
147in a separate `--probe-config` HJSON file. Use the `describe` command to list
148all options. The inline JSON or HJSON is the same format as used in the separate
149probe config files (see below).
150
151```bash
152# Get probe config details:
153./cb.py describe probe v8.log
154
155# Use inline HJSON to configure a probe:
156./cb.py speedometer --probe='v8.log:{prof:true}'
157```
158
159#### Probe Config File
160For complex probe setups you can use `--probe-config=<file>`.
161The [example file](config/doc/probe.config.hjson) lists and explains all
162configuration details. For the specific probe configuration properties consult
163the `describe` command.
164
165### Benchmarks
166Use the `describe` command to list all benchmark details:
167
168```bash
169# List all benchmark info:
170./cb.py describe benchmarks
171
172# List an individual benchmark info:
173./cb.py describe benchmark speedometer_3.0
174
175# List a benchmark's command line options:
176./cb.py speedometer_3.0 --help
177```
178
179### Stories
180Stories define sequences of browser interactions. This can be simply
181loading a URL and waiting for a given period of time, or in more complex
182scenarios, actively interact with a page and navigate multiple times.
183
184Use `--help` or describe to list all stories for a benchmark:
185
186```bash
187./cb.py speedometer --help
188```
189
190Use `--stories` to list individual story names, or use regular expression
191as filter.
192
193```bash
194./cb.py speedometer --browser=$BROWSER --stories='.*Angular.*'
195```
196
197
198## Development
199
200### Checking Out Code
201Don't just `git clone` the crossbench repo! Use depot_tools to set everything
202up correctly for you.
203
204- Install [Chromium depot_tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up).
205- Get the crossbench code with all dependencies:
206```
207mkdir code
208cd code
209fetch crossbench
210cd crossbench
211```
212- Don't forget to run `gclient sync` every time you pull new changes from the
213crossbench repo.
214
215### Poetry Setup
216This project uses [poetry](https://python-poetry.org/) deps and package scripts
217to setup the correct environment for testing and debugging.
218
219```bash
220# a) On debian:
221sudo apt-get install python3.10 python3-poetry
222# b) With python 3.9 to 3.11 installed already:
223pip3 install poetry
224```
225
226Check that you have poetry on your path and make sure you have the right
227`$PATH` settings.
228```bash
229poetry --help || echo "Please update your \$PATH to include poetry bin location";
230# Depending on your setup, add one of the following to your $PATH:
231echo "`python3 -m site --user-base`/bin";
232python3 -c "import sysconfig; print(sysconfig.get_path('scripts'))";
233```
234
235Install the necessary dependencies from the lock file using poetry:
236
237```bash
238# Select the python version you want to use (3.9 to 3.10):
239poetry env use 3.10
240poetry install
241
242# For windows you have to skip pytype support:
243poetry env use 3.11
244poetry install --without=dev-pytype
245```
246
247### Crossbench
248For local development / non-chromium installation you should
249use `poetry run cb ...` instead of `./cb.py ...`.
250
251Side-note, beware that poetry eats up an empty `--`:
252
253```bash
254# With cb.py:
255./cb.py speedometer ... -- --custom-chrome-flag ...
256# With poetry:
257poetry run cb speedometer ... -- -- --custom-chrome-flag ...
258```
259
260### Tests
261```
262poetry run pytest
263```
264
265Run detailed test coverage:
266```bash
267poetry run pytest --cov=crossbench --cov-report=html
268```
269
270Run [pytype](https://github.com/google/pytype) type checker:
271```bash
272poetry run pytype -j auto .
273```
274