sitespeed.io icon indicating copy to clipboard operation
sitespeed.io copied to clipboard

Understanding power measurement better

Open Jones-S opened this issue 1 month ago • 5 comments

Your question

Hi I am currently trying to get a more or less accurate power consumption value from browsertime. Following this example: https://github.com/sitespeedio/sitespeed.io/issues/3944#issuecomment-1874409458 I get the initial info in my terminal: INFO: CPU / Power usage: 7334 which I guess is in µWh.

If I open the browsertime.json I see this: "powerConsumption":[0.003353606209] and "powerConsumption":{"median":0.0034, ...

Now the numbers are pretty close to each other. But what is the difference? I also had the case that they differed quite a bit. The first [0].info.powerConsumption and the second is [0].info.statistics.powerConsumption.

Also I don't understand the key cpu which is the number from before 7334. So is this just the Power used by the CPU? What about GPU for example? Is GPU taken into account in one of the powerConsumption keys?

If I then open the saved profile (attached) I see in the parent process → process power: 2.1mWh in the full range. How is that value linked to the powerConsumption in the browsertime summary?

In the process github.com itself I see 967 µWh for the full range.

I also wonder: Which number would go up if I had power intensive tasks running in the background on my machine? Would all be affected?

Maybe somebody could help me out to understand which of the values would be most accurate number to measure if I want to find out about the power consumption of one page.

🙏

Image

geckoProfile-1.json.gz

browsertime.json

Jones-S avatar Nov 18 '25 13:11 Jones-S

Hi @Jones-S !

For the actual number and what Firefox exactly measures I think Nazim from Mozilla has better knowledge or could point you in the right direction. I think the goal is to measure the consumption used when accessing the page, but I'm not 100% sure what's more included and how precise it is.

For the metrics in the JSON file: The info.powerConsumption should be an array of each run. So for example if you run browsertime with 5 iterations, you should have five numbers there. The statistics use https://www.npmjs.com/package/fast-stats to calculate median, different percentiles etc (useful when you do many runs).

soulgalore avatar Nov 19 '25 04:11 soulgalore

@soulgalore Thanks for your quick reply! I did get that with the powerConsumption Array, but do you know the difference between the two? It would also help me which numbers you take from the profile json to mix them into the browsertime.json calculation. I was not able to find the numbers or even keys in the geckoProfile-1.json. That would be of great help if I could match the numbers I see in my profiler interface with the summarized numbers of the browsertime.json.

🙏

Jones-S avatar Nov 19 '25 08:11 Jones-S

I don't know how the numbers stored in browsertime.json are computed. It's likely a subset of the profile, based on a start time and stop time for an interesting range (maybe between the page load was requested, and finished?).

So is this just the Power used by the CPU? What about GPU for example?

On Apple Silicon hardware we don't have the CPU vs GPU breakdown. We have it on Intel CPUs.

If I then open the saved profile (attached) I see in the parent process → process power: 2.1mWh in the full range. How is that value linked to the powerConsumption in the browsertime summary?

In the process github.com itself I see 967 µWh for the full range.

I also see these 2 numbers in the profile.

I also wonder: Which number would go up if I had power intensive tasks running in the background on my machine? Would all be affected?

Hopefully neither, because you are power profiling on an Apple Silicon machine where we have power information per process.

Maybe somebody could help me out to understand which of the values would be most accurate number to measure if I want to find out about the power consumption of one page.

Parent process + content process is a reasonable thing to look at on Mac. One thing you need to pay attention to is if there is unrelated CPU activity in the profile. In your profile in the parent process I see about 750ms of activity in the parent process that might not be related to your page load (might be the browser finishing font loading from the OS a few seconds after startup is over).

geckoProfile-1.json.gz

It's easier to look at your profile if you upload it from the profiler UI and paste a share.firefox.dev link.

fqueze avatar Dec 05 '25 13:12 fqueze

thanks for the hints. this already helps a lot. Here is the profiler link: https://share.firefox.dev/4pqMrsY

Jones-S avatar Dec 05 '25 15:12 Jones-S

The powerConsumption values in browsertime json is coming from here: https://github.com/sitespeedio/browsertime/blob/88501b651908459fdc7f7a3490bc929f7d67bd6d/lib/firefox/geckoProfiler.js#L267 and https://github.com/sitespeedio/browsertime/blob/88501b651908459fdc7f7a3490bc929f7d67bd6d/lib/firefox/geckoProfiler.js#L44-L72

So it sums up all the power values in the whole "profile". If you look at it in the Firefox Profiler UI, you'll see the power consumption of that process only. So that's the main difference between the values coming from the profiler UI vs browsertime.

If you sum up all these values and if they don't match, then it's probably a bug and we should fix it. You can write a function that sums up all the power values in the DevTools console.

When I was working on this, I wanted to report the whole Firefox instance since when we use browsertime, the only that that's open is the tab that we created. And reporting the whole Firefox made sense at that time. I'm not too attached to it, but I assume that there is going to be some idle content processes that increase that number.


About the INFO: CPU / Power usage: 7334 thing, Apparently it gets the total CPU time from Glean, and it's CPU time in ms: https://github.com/sitespeedio/browsertime/blob/88501b651908459fdc7f7a3490bc929f7d67bd6d/lib/firefox/webdriver/firefox.js#L265-L274

Which is not a power usage value at all. I think it's very misleading, and we should either remove it completely or rename it better so it's not confusing to people. (I don't know why that was added initially, maybe for perf testing inside mozilla?) @fqueze might know more.

canova avatar Dec 05 '25 17:12 canova

Ok that helps a lot. @canova I will ignore the INFO: CPU / Power usage: 7334 and focus on the the sum of all the samples with categorey === "power". I would still wonder though what the numbers in the data array mean:

        {
          "name": "Process Power",
          "category": "power",
          "description": "Power utilization",
          "samples": {
            "schema": {"time": 0, "count": 1},
            "data": [
              [ 1479.471833, 134577200],
              [ 1480.700833,    130566],
              [ 1481.66225,      10120],

Is one of the numbers the sample time and the other the sampled value? If so, what would the units be?

I came to this question because I was wondering where I would see this information from this screenshot:

Image

In the profilers data. I would have expected to find the 358 somewhere in my data. Maybe even with a relation to a number which would mark my 2ms. But so far I could not find that.

Oh and also: What unit is the powerConsumption? µWh or Ws? As I don't know what the counters are which are summed up I also don't understand the final result.

If you could clarify this even more, that would be of great help! Thanks a lot!

Jones-S avatar Dec 17 '25 10:12 Jones-S

Is one of the numbers the sample time and the other the sampled value? If so, what would the units be?

the schema object right above it is there to tell you which field corresponds to which array index.

            "schema": {"time": 0, "count": 1},

means that the first index is time and the second index is count (power usage values).

If so, what would the units be?

For the value units, I had to refresh my memory by reading some code, but it looks like we are storing picowatt-hour in the samples data array. See here: https://github.com/firefox-devtools/profiler/blob/eedf6466d4075cc63e39d45c8baedd34d970d38d/src/components/tooltip/TrackPower.tsx#L175

I would have expected to find the 358 somewhere in my data. Maybe even with a relation to a number which would mark my 2ms. But so far I could not find that.

In the tooltips we do some calculation to find that power value. You can see that calculation here: https://github.com/firefox-devtools/profiler/blob/eedf6466d4075cc63e39d45c8baedd34d970d38d/src/components/tooltip/TrackPower.tsx#L181-L184 It's this:

const power =
  ((powerUsageInPwh * 1e-12) /* pWh->Wh */ / sampleTimeDeltaInMs) *
  1000 * // ms->s
  3600; // s->h

Note that the unit of power is not watt-hour, it's in watt. That's why we do the conversion there. I would expect that because of this calculation, you can't see the numbers directly there.

Oh and also: What unit is the powerConsumption? µWh or Ws? As I don't know what the counters are which are summed up I also don't understand the final result.

This comment mentions that the returned value is in Wh: https://github.com/sitespeedio/browsertime/blob/88501b651908459fdc7f7a3490bc929f7d67bd6d/lib/firefox/geckoProfiler.js#L44-L45

Hope that helps!

canova avatar Dec 18 '25 22:12 canova