sitespeedio / sitespeed.io

sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your website’s speed using real browsers in various environments.
https://www.sitespeed.io/
MIT License
4.76k stars 603 forks source link

CPU power measurement causes type error #4314

Closed jannekalliola closed 2 days ago

jannekalliola commented 2 weeks ago

Have you read the documentation?

URL

https://hs.fi

What are you trying to accomplish

Measure the energy consumption of an example site, but the system crashes to a JavaScript type error. The same error happens also with number of other sites, but not all. For example, replacing www.hs.fi with websummit.com works ok.

What browser did you use?

Firefox

How to reproduce

The command I run is:

sitespeed.io -b firefox -n 1 --firefox.geckoProfiler --firefox.geckoProfilerParams.features "power" --firefox.powerConsumption scroll.mjs --multi

scroll.mjs is the following

export default async function (context, commands) {
  const delayTime = 250;

  await commands.measure.start();
  await commands.navigate(
      'https://www.hs.fi'
  );
  await commands.scroll.toBottom(delayTime);
  return commands.measure.stop();
};

Log output

Memento:sitespeed plastic$ sitespeed.io -b firefox -n 1 --firefox.geckoProfiler --firefox.geckoProfilerParams.features "power" --firefox.powerConsumption scroll.mjs --multi
[2024-11-11 14:08:10] INFO: Versions OS: darwin 23.6.0 nodejs: v20.11.0 sitespeed.io: 35.4.1 browsertime: 23.2.0 coach: 8.0.2
[2024-11-11 14:08:10] INFO: Running tests using Firefox - 1 iteration(s)
[2024-11-11 14:08:12] INFO: Start to measure
[2024-11-11 14:08:12] INFO: Start GeckoProfiler with features: ["power"] and threads: ["GeckoMain","Compositor","Renderer"]
[2024-11-11 14:08:15] INFO: Navigating to url https://www.hs.fi iteration 1
[2024-11-11 14:08:57] INFO: Collecting Gecko profile from /Users/plastic/Code/phd/sitespeed/sitespeed-result/scroll_mjs/2024-11-11-14-08-10/pages/www_hs_fi/data/geckoProfile-1.json to /Users/plastic/Code/phd/sitespeed/sitespeed-result/scroll_mjs/2024-11-11-14-08-10/pages/www_hs_fi/data/geckoProfile-1.json
[2024-11-11 14:08:57] INFO: Stop GeckoProfiler.
[2024-11-11 14:08:57] INFO: Collecting CPU power consumtion
[2024-11-11 14:08:58] INFO: Gzip file the profile.
[2024-11-11 14:08:59] INFO: Done stopping GeckoProfiler.
[2024-11-11 14:08:59] INFO: Take after page complete check screenshot
[2024-11-11 14:09:00] INFO: Take largest contentful paint screenshot
[2024-11-11 14:09:03] ERROR: There is an page without an URL in the HAR. Please inspect the HAR file and check whats wrong
[2024-11-11 14:09:03] ERROR: There is an page without an URL in the HAR. Please inspect the HAR file and check whats wrong
[2024-11-11 14:09:03] ERROR: There is an page without an URL in the HAR. Please inspect the HAR file and check whats wrong
[2024-11-11 14:09:03] INFO: https://www.hs.fi/ 3 requests, TTFB: 174ms, firstPaint: 278ms, FCP: 278ms, DOMContentLoaded: 642ms, LCP: 322ms, CPUBenchmark: 25ms, Load: 726ms
[2024-11-11 14:09:03] INFO: The server responded with a 400 status code for https://dsp.360yield.com/ul_cb/dsp_match/275?ssp=76&gdpr=1&g...
[2024-11-11 14:09:03] ERROR: Could not generate url/iteration/index, /usr/local/lib/node_modules/sitespeed.io/lib/plugins/html/templates/url/cpu/index.pug:1
  > 1| - const browsertime = medianRun ? (pageInfo.data.browsertime ? pageInfo.data.browsertime.pageSummary.browserScripts[medianRun.runIndex - 1]: undefined) : pageInfo.data.browsertime.run 
    2| 
    3| - const cpu = medianRun ? (pageInfo.data.browsertime ? pageInfo.data.browsertime.pageSummary.cpu[medianRun.runIndex - 1]: undefined) : pageInfo.data.browsertime.run.cpu
    4| 

Cannot read properties of undefined (reading 'run')
node:internal/fs/utils:916
    throw new ERR_INVALID_ARG_TYPE(
          ^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at writeFile (node:fs:2295:5)
    at node:internal/util:442:7
    at new Promise (<anonymous>)
    at writeFile (node:internal/util:428:12)
    at write (file:///usr/local/lib/node_modules/sitespeed.io/lib/core/resultsStorage/storageManager.js:26:10)
    at file:///usr/local/lib/node_modules/sitespeed.io/lib/core/resultsStorage/storageManager.js:113:9 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v20.11.0
jannekalliola commented 2 weeks ago

Laptop info

image
soulgalore commented 2 weeks ago

Hi @jannekalliola thanks for creating the issue, yes it looks like something is broken, let me have a look tonight.

soulgalore commented 2 weeks ago

I could reproduce and something strange here going on, I could see that the HAR generator for Firefox generates multiple pages (but it should be one), I pickups the start data URL that we use before we start to navigate. I created an issue in that lib.

jannekalliola commented 2 weeks ago

Hello @soulgalore and thank you for reacting so quickly. Hopefully the root cause is found and fixed in a timely fashion.

soulgalore commented 2 weeks ago

Hi @jannekalliola they are usually really fast. So I wonder though, I did try out the power feature when it was released Mozilla, but I got really high variation in the metric so I didn't use it. However I never tried it on a standalone bare metal server. But maybe Mozilla uses it internally I'm not sure.

soulgalore commented 2 weeks ago

Hi @jannekalliola the Mozilla team did an update yesterday and I updated the code this morning so if you run a fresh install to get the newest version, you can test again. I did a quick test and it seemed to work but want to check that it works for you.

jannekalliola commented 2 weeks ago

Thanks @soulgalore, that was a fast fix. Should I download a Firefox nightly build to test it?

soulgalore commented 2 weeks ago

No it should work directly if you use latest sitespeed.io with Firefox 132. So Mozilla has their own library for generating a HAR file in Firefox using Bidi webdriver, and it's in that code that needed the change. I updated that dependency in Browsertime/sitespeed.io

jannekalliola commented 2 days ago

Sorry for the silence, quite hectic weeks. I finally got time to check it and now it works. Thanks.