browsertime.rst (20612B)
1 ################## 2 Raptor Browsertime 3 ################## 4 5 .. contents:: 6 :depth: 2 7 :local: 8 9 Browsertime is a harness for running performance tests, similar to Mozilla's Raptor testing framework. Browsertime is written in Node.js and uses Selenium WebDriver to drive multiple browsers including Safari, Safari Technology Preview, Chrome, Chrome for Android, Firefox, and Firefox for Android and GeckoView-based browsers. 10 11 Source code: 12 13 - Our current Browsertime version uses the canonical repo. 14 - In-tree: https://searchfox.org/mozilla-central/source/tools/browsertime and https://searchfox.org/mozilla-central/source/taskcluster/scripts/misc/browsertime.sh 15 16 Running Locally 17 --------------- 18 19 **Prerequisites** 20 21 - A local Mozilla Repository clone with a `successful Firefox build </setup>`_ completed 22 23 Running on Firefox Desktop 24 -------------------------- 25 26 Vanilla Browsertime tests 27 ------------------------- 28 29 If you want to run highly customized tests, you can make use of our customizable ``browsertime`` test. 30 31 With this test, you can customize the page to test, test script to use, and anything else required. It will make use of default settings that Raptor uses in browsertime but these can be overridden with ``--browsertime-arg`` settings. 32 33 For example, here's a test on ``https://www.sitespeed.io`` using this custom test: 34 35 :: 36 37 ./mach raptor -t browsertime --browsertime-arg test_script=pageload --browsertime-arg browsertime.url=https://www.sitespeed.io --browsertime-arg iterations=3 38 39 That test will perform 3 iterations of the given url. Note also that we can use simplified names to make use of test scripts that are built into raptor. You can use ``pageload``, ``interactive``, or provide a path to another test script. 40 41 This custom test is only available locally. 42 43 Page-load tests 44 --------------- 45 There are two ways to run performance tests through browsertime listed below. 46 47 **Note that** ``./mach browsertime`` **should not be used when debugging performance issues with profiles as it does not do symbolication.** 48 49 * Raptor-Browsertime (recommended): 50 51 :: 52 53 ./mach raptor -t google-search 54 55 * Browsertime-"native": 56 57 :: 58 59 ./mach browsertime https://www.sitespeed.io --firefox.binaryPath '/Users/{userdir}/moz_src/mozilla-unified/obj-x86_64-apple-darwin18.7.0/dist/Nightly.app/Contents/MacOS/firefox' 60 61 Benchmark tests 62 --------------- 63 * Raptor-wrapped: 64 65 :: 66 67 ./mach raptor -t speedometer 68 69 Running on Android 70 ------------------ 71 To run on Android, the device needs to have Geckoview or Fenix installed on it. Our tests will only work with physical devices, and `bug 1881570 <https://bugzilla.mozilla.org/show_bug.cgi?id=1881570>`__ tracks progress for enabling virtual devices (emulators). Running either of the commands below will attempt to install locally built APKs to the device **while uninstalling/removing any existing APKs of the package on the device**, but this can be skipped by setting ``MOZ_DISABLE_ADB_INSTALL=1`` in your environment. When that environment variable exists, we expect the APK to be pre-installed on the device. 72 73 Running on Raptor-Browsertime (recommended): 74 75 * Running on Fenix 76 77 :: 78 79 ./mach raptor -t amazon --app fenix --binary org.mozilla.fenix 80 81 * Running on Geckoview 82 83 :: 84 85 ./mach raptor -t amazon --app geckoview --binary org.mozilla.geckoview_example 86 87 Running on vanilla Browsertime: 88 89 * Running on Fenix/Firefox Preview 90 91 :: 92 93 ./mach browsertime --android --browser firefox --firefox.android.package org.mozilla.fenix.debug --firefox.android.activity org.mozilla.fenix.IntentReceiverActivity https://www.sitespeed.io 94 95 * Running on the GeckoView Example app 96 97 :: 98 99 ./mach browsertime --android --browser firefox https://www.sitespeed.io 100 101 Running Power Usage tests on Mobile 102 ----------------------------------- 103 To gather power usage tests on mobile, you can pass ``--power-test`` to ``./mach raptor``. This will only work if the phone is hooked up to a `supported USB power meter <https://github.com/fqueze/usb-power-profiling/tree/5a6fc823ea4dd0553f810f29a04c43a3c9c49147?tab=readme-ov-file#supported-devices>`_. 104 105 The data output is originally in picoWattHours, but are converted to microWattHours for the Perfherder Data JSON. The power usage is from the start of the pageload until the pageComplete check in browsertime completes. 106 107 Running on Google Chrome 108 ------------------------ 109 Chrome releases are tied to a specific version of ChromeDriver -- you will need to ensure the two are aligned. 110 111 There are two ways of doing this: 112 113 * Download the ChromeDriver that matches the chrome you wish to run from https://chromedriver.chromium.org/ and specify the path: 114 115 :: 116 117 ./mach browsertime https://www.sitespeed.io -b chrome --chrome.chromedriverPath <PATH/TO/VERSIONED/CHROMEDRIVER> 118 119 * Upgrade the ChromeDriver version in ``tools/browsertime/package-lock.json`` (see https://www.npmjs.com/package/@sitespeed.io/chromedriver for versions). 120 121 Run ``npm install``. 122 123 Launch vanilla Browsertime as follows: 124 125 :: 126 127 ./mach browsertime https://www.sitespeed.io -b chrome 128 129 Or for Raptor-Browsertime (use ``chrome`` for desktop, and ``chrome-m`` for mobile): 130 131 :: 132 133 ./mach raptor -t amazon --app chrome --browsertime-chromedriver <PATH/TO/CHROMEDRIVER> 134 135 Running on Safari Technology Preview 136 ------------------------------------ 137 138 Safari Technology Preview comes bundled with an appropriate ``safaridriver`` binary, and browsertime (via selenium) automatically launches this. 139 140 You will need to have installed the most up-to-date application version either by updating an existing installation on your MacOS or downloading it from https://developer.apple.com/safari/resources/ and ensure you download the one appropriate to your MacOS version 141 142 You can launch vanilla Browsertime with Safari Technology Preview as follows: 143 144 :: 145 146 ./mach browsertime https://www.sitespeed.io -b safari --safari.useTechnologyPreview 147 148 149 Or with Raptor-Browsertime 150 151 :: 152 153 ./mach raptor -t speedometer3 --app safari-tp --binary "/Applications/Safari Technology Preview.app/Contents/MacOS/Safari Technology Preview" 154 155 Running Page-load tests with third party WebExtensions 156 ------------------------------------------------------ 157 Page-load tests can also be executed on both Firefox Desktop and Firefox for Android builds with a set of popular 158 third party extensions installed (similarly to talos-realworld-webextensions, which runs tp5 tests with a set of third 159 party extensions installed). 160 161 Any of the page-load tests can be executed locally with the pre-selected set of third party extensions installed by just 162 adding to the base raptor command the additional ``--conditioned-profile settled-webext`` command line option. 163 164 Launch amazon tp6 page-load test on Firefox Desktop: 165 166 :: 167 168 ./mach raptor -t amazon --conditioned-profile settled-webext 169 170 Launch amazon tp6 mobile page-load test on Firefox for Android (the apk has to be pre-installed, mach raptor does detect if already installed but 171 it does not install it): 172 173 :: 174 175 ./mach raptor -t amazon --app fenix --binary org.mozilla.fenix --conditioned-profile settled-webext 176 177 To run these jobs on try, make sure to select the tp6 jobs that include the string `webextensions`, as an example (add ``--no-push`` to force try perf to only 178 list the jobs selected by the try perf query) to run all tp6 page-load webextensons jobs currently defined: 179 180 :: 181 182 ./mach try perf --full -q "'tp6 'webextensions" 183 184 Similarly for running tp6m (equivalent to tp6 but for mobile) on Firefox for Android builds: 185 186 :: 187 188 ./mach try perf --full -q "'tp6m 'webextensions" 189 190 The set of extensions installed are the ones listed in the ``"addons"`` property of the condprof customization file 191 `webext.json`_ from the ``testing/condprofile/condprof/customization/`` directory. 192 193 All extensions listed in the ``webext.json`` file are expected to have been predownloaded and included in the ``firefox-addons.tar`` archive 194 defined in the CI fetch config named `firefox-addons`_, but they will be automatically downloaded from the url specified in the ``webext.json`` 195 file if they are not. 196 197 In a try push we allow to run jobs on new extension XPI files not part of the firefox-addons.tar archive, the new extension needs to be just 198 added in the `webext.json`_ condprof customization file in a patch part of the same stack of patches being pushed to try. 199 200 On the contrary new extensions added to the `webext.json`_ condprof customization file on mozilla-central patches will require the XPI file to be 201 added to the ``firefox-addons.tar`` archive and the `firefox-addons`_ CI fetch config updated accordingly (missing to update the archive will 202 trigger explicit linter errors, :doc:`see condprof-addons linter docs </code-quality/lint/linters/condprof-addons>`). 203 204 .. _webext.json: https://searchfox.org/mozilla-central/rev/bc6a50e6f08db0bb371ef7197c472555499e82c0/testing/condprofile/condprof/customization/webext.json 205 .. _firefox-addons: https://searchfox.org/mozilla-central/rev/bc6a50e6f08db0bb371ef7197c472555499e82c0/taskcluster/ci/fetch/browsertime.yml#169-176 206 207 TP6-Bench Test 208 -------------- 209 210 The ``tp6-bench`` can either be run on desktop, or locally using the following command: 211 212 :: 213 214 ./mach raptor -t tp6-bench 215 216 This test runs through a selection of our tp6 pageload tests as quickly as possible while only measuring loadtime, FCP (First Contentful Paint), and LCP (Largest Contentful Paint). It does not measure visual metrics like our standard tp6 pageload tests do. The test produces 3 overall metrics (fcp, lcp, and loadtime) across all the pages tested that are summarized in two ways: geomean, and mean. The subtests for each of those metrics are the individual metrics produced in each of the pages tested. 217 218 To run this test on try and get a compare view link, run the following 219 220 :: 221 222 ./mach try perf -q "'Pageload 'Lite" 223 224 225 226 More Examples 227 ------------- 228 229 `Browsertime docs <https://www.sitespeed.io/documentation/sitespeed.io/scripting/>`_ 230 231 Passing Additional Arguments to Browsertime 232 ------------------------------------------- 233 234 Browsertime has many command line flags to configure its usage, see `Browsertime configuration <https://www.sitespeed.io/documentation/browsertime/configuration/>`_. 235 236 There are multiple ways of adding additional arguments to Browsertime from Raptor. The primary method is to use ``--browsertime-arg``. For example: ``./mach raptor -t amazon --browsertime-arg iterations=10`` 237 238 Other methods for adding additional arguments are: 239 240 * Define additional arguments in `testing/raptor/raptor/browsertime/base.py <https://searchfox.org/mozilla-central/source/testing/raptor/raptor/browsertime/base.py#220-252>`_. 241 242 * Add a ``browsertime_args`` entry to the appropriate manifest with the desired arguments, i.e. `browsertime-tp6.ini <https://searchfox.org/mozilla-central/source/testing/raptor/raptor/tests/tp6/desktop/browsertime-tp6.ini>`_ for desktop page load tests. `Example of browsertime_args format <https://searchfox.org/mozilla-central/source/testing/raptor/raptor/tests/custom/browsertime-process-switch.ini#27>`_. 243 244 Running Browsertime on Try 245 -------------------------- 246 247 You can run all of our browsertime pageload tests through ``./mach try perf`` by selecting the ``Pageload`` category. We use chimera mode in these tests which means that both cold and warm pageload variants are running at the same time. There are a lot of other tests/categories available as well. Documentation about this tool can be found in :ref:`Mach Try Perf`. 248 249 For example, the following will select all ``Pageload`` categories to run on desktop: 250 251 :: 252 253 ./mach try perf -q "'Pageload 'desktop" 254 255 If you exclude the ``-q "..."`` option, an interface similar to the fuzzy interface will open, and show all available categories. 256 257 Visual Metrics 258 -------------- 259 260 The following visual metrics are collected in all page load tests: ``ContentfulSpeedIndex, PerceptualSpeedIndex, SpeedIndex, FirstVisualChange, LastVisualChange`` 261 262 Further information regarding these metrics can be viewed at `visual-metrics <https://www.sitespeed.io/documentation/sitespeed.io/metrics/#visual-metrics>`_ 263 264 Gecko Profiling with Browsertime 265 -------------------------------- 266 267 To run gecko profiling using Raptor-Browsertime you can add the ``--gecko-profile`` flag to any command and you will get profiles from the test (with the profiler page opening in the browser automatically). This method also performs symbolication for you. For example: 268 269 :: 270 271 ./mach raptor -t amazon --gecko-profile 272 273 It's also possible to specify more configuration such as the profiled threads, the sampling interval or the profiler features being enabled. The parameters used in a profiling run can be copied directly from the about:profiling page in any Nightly build: click the button at the top of the page, then pick the option "Copy parameters for performance tests". 274 275 Note that vanilla Browsertime does support Gecko Profiling but **it does not symbolicate the profiles** so it is **not recommended** to use for debugging performance regressions/improvements. 276 277 Gathering a Chrome trace with Raptor-Browsertime 278 ------------------------------------------------ 279 280 Browsertime supports the ability to profile Chrome applications and this functionality is now available in Raptor. 281 282 If running a Chrome/Chromium/Chromium-as-release test locally, simply add the ``--extra-profiler-run`` flag to your command line. By default the Chrome trace is run in CI now, and can be opened in the Firefox profiler UI. 283 284 Equivalent functionality to the ``--gecko-profile`` flag, i.e. something like ``--chrome-trace``, is not yet supported. That is currently tracked in `Bug 1848390 <https://bugzilla.mozilla.org/show_bug.cgi?id=1848390>`_ 285 286 Custom profiling with Raptor-Browsertime 287 ---------------------------------------- 288 289 With browsertime you can now use the exposed start/stop commands of the gecko profiler **and** chrome trace. First, one needs to define the ``expose_browser_profiler`` and ``apps`` variables appropriately in the `test's configuration file <https://searchfox.org/mozilla-central/rev/11d085b63cf74b35737d9c036be80434883dd3f6/testing/raptor/raptor/tests/benchmarks/speedometer-desktop.ini#9,12>`_ 290 291 If you want to run the test in CI then you will want to ensure you set the ``--extra-profiler-run`` flag in the mozharness extra options for where your test is defined in the `browsertime-desktop yaml file <https://searchfox.org/mozilla-central/rev/2e06f92ba068e32a9a7213ee726e8171f91605c7/taskcluster/ci/test/browsertime-desktop.yml#404-406>`_. Otherwise you can just pass the ``--extra-profiler-run`` flag locally in your command line. 292 293 Both of these steps are required to satisfy the ``_expose_browser_profiler()`` `method <https://searchfox.org/mozilla-central/rev/11d085b63cf74b35737d9c036be80434883dd3f6/testing/raptor/raptor/browsertime/base.py#241>`_ so that the option, `expose_profiler <https://searchfox.org/mozilla-central/rev/11d085b63cf74b35737d9c036be80434883dd3f6/testing/raptor/raptor/browsertime/base.py#383-386>`_, is passed into your browsertime script. Finally, it should be as simple as calling the ``start()`` & ``stop()`` commands in your `script <https://searchfox.org/mozilla-central/rev/11d085b63cf74b35737d9c036be80434883dd3f6/testing/raptor/browsertime/speedometer3.js#14,30-37,58-65>`_. 294 295 For the gecko profiler, you should also keep in mind these `default parameters <https://searchfox.org/mozilla-central/rev/2e06f92ba068e32a9a7213ee726e8171f91605c7/testing/raptor/raptor/browsertime/base.py#474-495>`_, which you may or may not want to change yourself in your tests configuration file. 296 297 Likewise, for chrome trace you will want to be aware of `these defaults. <https://searchfox.org/mozilla-central/rev/11d085b63cf74b35737d9c036be80434883dd3f6/testing/raptor/raptor/browsertime/base.py#646-658>`_ 298 299 Upgrading Browsertime In-Tree 300 ----------------------------- 301 302 To upgrade the browsertime version used in-tree you can run, then commit the changes made to ``package.json`` and ``package-lock.json``: 303 304 :: 305 306 ./mach browsertime --update-upstream-url <TARBALL-URL> 307 308 Here is a sample URL that we can update to: https://github.com/sitespeedio/browsertime/tarball/89771a1d6be54114db190427dbc281582cba3d47 309 310 To test the upgrade, run a raptor test locally (with and without visual-metrics ``--browsertime-visualmetrics`` if possible) and test it on try with at least one test on desktop and mobile. 311 312 Updating Benchmark Tests 313 ------------------------ 314 315 To upgrade any of our benchmark tests, you will need to change the revision used in the test manifest. There are three fields that you have available to use there: ``repository_revision`` to denote the revision, ``repository_branch`` to denote the branch name, and ``repository`` to provide the link of the Github repo that contains the benchmark. 316 317 For instance, with Speedometer 3 (sp3), we can update the revision `by changing the repository_revision field found here <https://searchfox.org/mozilla-central/rev/aa3ccd258b64abfd4c5ce56c1f512bc7f65b844c/testing/raptor/raptor/tests/benchmarks/speedometer-desktop.ini#29>`_. If the change isn't found on the default branch (master/main branch), then you will need to add an entry for ``repository_branch`` to specify this. 318 319 If the path to the test file changes (the file that is invoked to run the test), then the ``test_url`` will need to be changed. 320 321 Finding the Geckodriver Being Used 322 ---------------------------------- 323 324 If you're looking for the latest geckodriver being used there are two ways: 325 * Find the latest one from here: https://treeherder.mozilla.org/jobs?repo=mozilla-central&searchStr=geckodriver 326 * Alternatively, if you're trying to figure out which geckodriver a given CI task is using, you can click on the browsertime task in treeherder, and then click on the ``Task`` id in the bottom left of the pop-up interface. Then in the window that opens up, click on `See more` in the task details tab on the left, this will show you the dependent tasks with the latest toolchain-geckodriver being used. There's an Artifacts drop down on the right hand side for the toolchain-geckodriver task that you can find the latest geckodriver in. 327 328 If you're trying to test Browsertime with a new geckodriver, you can do either of the following: 329 * Request a new geckodriver build in your try run (i.e. through ``./mach try perf --show-all``). 330 * Trigger a new geckodriver in a try push, then trigger the browsertime tests which will then use the newly built version in the try push. 331 332 Comparing Before/After Browsertime Videos 333 ----------------------------------------- 334 335 We have some scripts that can produce side-by-side comparison videos for you of the worst pairing of videos. You can find the script here: https://github.com/mozilla/mozperftest-tools#browsertime-side-by-side-video-comparisons 336 337 Once the side-by-side comparison is produced, the video on the left is the old/base video, and the video on the right is the new video. 338 339 Mach Browsertime Setup 340 ---------------------- 341 342 **WARNING** 343 Raptor-Browsertime (i.e. ``./mach raptor -t <TEST>``) is currently required to be ran first in order to acquire the Node-16 binary. In general, it is also not recommended to use ``./mach browsertime`` for testing as it will be deprecated soon. 344 345 Note that if you are running Raptor-Browsertime then it will get installed automatically and also update itself. Otherwise, you can run: 346 347 - ``./mach browsertime --clobber --setup --install-vismet-reqs`` 348 349 This will automatically check your setup and install the necessary dependencies if required. If successful, the output should read as something similar to: 350 351 :: 352 353 browsertime installed successfully! 354 355 NOTE: Your local browsertime binary is at <...>/mozilla-unified/tools/browsertime/node_modules/.bin/browsertime 356 357 - To manually check your setup, you can also run ``./mach browsertime --check`` 358 359 Known Issues 360 ^^^^^^^^^^^^ 361 362 With the replacement of ImageMagick, former cross platform installation issues have been resolved. The details of this can be viewed in the meta bug tracker 363 `Bug 1735410 <https://bugzilla.mozilla.org/show_bug.cgi?id=1735410>`_ 364 365 366 367 - For other issues, try deleting the ``~/.mozbuild/browsertime`` folder and re-running the browsertime setup command or a Raptor-Browsertime test. Alternatively, you may need to delete the ``tools/browsertime/node_modules`` folder. 368 369 - If you plan on running Browsertime on Android, your Android device must already be set up (see more above in the :ref: `Running on Android` section) 370 371 - **If you encounter any issues not mentioned here, please** `file a bug <https://bugzilla.mozilla.org/enter_bug.cgi?product=Testing&component=Raptor>`_ **in the** ``Testing::Raptor`` **component.**