npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

playwright-performance-reporter

v2.1.2

Published

Measure and publish performance metrics from browser dev-tools when running playwright

Downloads

279

Readme

playwright-performance-reporter

Release codecov version

Metrics from the dev tools to measure performance

[!CAUTION] This library is work in progress. The measurement is limited to Chromium and to a primitive test suite. Complex test suites/cases were not considered, which will be supported down the line. On the long run the goal is to

  • Support Firefox and Webkit
  • Useful amount of metrics to choose from
  • Insightful visualization of the results

Install

npm install playwright-performance-reporter --save-dev

Usage

Disable parallelism:

export default defineConfig({
  ...
  fullyParallel: false,
  workers: 1,
  ...
})

Setup Reporter

To register the reporter, include the code blow in your playwright config. Please see the subsections for more details about browser specific cases.

If you want to extend it with custom metrics, an entry exists for customMetrics, where the callback will get the accumulator and CDP client. Please see the example below how to use it.

For ease of implementation, the passed object can implement the interface MetricObserver.

import type { CDP, Options, Metric } from 'playwright-performance-reporter';

const PlayWrightPerformanceReporterOptions: Options = {
  outputDir: '/your/path/to/dir',
  outputFile: 'output.json',
  browsers: {
    chromium: {
      onTestStep: {
        metrics: ['usedJsHeapSize', 'totalJsHeapSize'],
        customMetrics: {
          someMetric: {
            name: 'someMetric',
            onStart: (accumulator: Metric[], client: CDP.Client) => new Promise(resolve => {
                client.send('Performance.getMetrics', (error, response) => { accumulator.push(response); resolve(); });
            }),
            onStop: (accumulator: Metric[], client: CDP.Client) => new Promise(resolve => {
                client.send('Performance.getMetrics', (error, response) => { accumulator.push(response); resolve(); });
            })
          }
        }
      }
    }
  }
}

export default defineConfig({
  ...
  reporter: [
    ['playwright-performance-reporter', PlayWrightPerformanceReporterOptions]
  ],
 ...
});

Chromium

Following metrics are supported out of the box:

  • usedJsHeapSize
  • totalJsHeapSize
  • allPerformanceMetrics

The MetricsEngine relies on the Chrome DevTool Protocol (CDP), which can be accessed through HTTP and WebSocket. To allow for a connection, make sure to expose a port for the remote debugging. The reporter will try to extract that port during start-up.

Setup Browser

{
  name: 'chromium',
  use: {
      ...devices['Desktop Chrome'],
    launchOptions: {
      args: [
        '--remote-debugging-port=9222'
      ]
    }
  }
},

Output

The top level is hooked into test().

{
  ...
  "4dde6239d9ac8c9468f3-82e3094b06379c51b729": {
    "TEST_CASE_PARENT": {
      "name": " > chromium > scenarios/profile.spec.ts > Profile",
      ...
    }
    ...
  }
  ...
}

The content consists of steps of the test suite. Please keep in mind that the metric request is async and is not awaited by Playwright. This means that the browser API might still in the process of collecting the metrics, even though Playwright instructed the browser to continue to the next step. This could lead to wrong output. To check if the output is invalid, the values startMeasurementOffset and endMeasurementOffset are provided, which measure the time delta in milliseconds between the request until the browser provides all metrics.

{
  ...
  "08e5cdf7227924757e4a8f402ac2167d": {
    "name": "click login",
    "startMetrics": [
      {
        "usedJsHeapSize": 8653828
      },
      {
        "totalJsHeapSize": 12611584
      }
    ],
    "stopMetrics": [
      {
        "usedJsHeapSize": 8863700
      },
      {
        "totalJsHeapSize": 12873728
      }
    ],
    "startMeasurement": 1724001218666,
    "endMeasurement": 1724001218914,
    "startMeasurementOffset": 4,
    "endMeasurementOffset": 3
  },
  "f957b5d47615b372c20ea69a16f5f344": {
    "name": "fill mock data",
    "startMetrics": [
      {
        "usedJsHeapSize": 8863700
      },
      {
        "totalJsHeapSize": 12873728
      }
    ],
    "stopMetrics": [
      {
        "usedJsHeapSize": 9055816
      },
      {
        "totalJsHeapSize": 12873728
      }
    ],
    "startMeasurement": 1724001218914,
    "endMeasurement": 1724001218947,
    "startMeasurementOffset": 2,
    "endMeasurementOffset": 2
  },
 ...
}