Skip to content

Commit

Permalink
Merge pull request #841 from gmetais/cpu-tasks
Browse files Browse the repository at this point in the history
Expose CPU related metrics from page.metrics() as phantomas metrics
  • Loading branch information
macbre authored Dec 23, 2020
2 parents 5389c16 + 1438f7f commit 133cca1
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
31 changes: 30 additions & 1 deletion docs/metrics.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Modules and metrics
===================

This file describes all [`phantomas` modules](https://github.com/macbre/phantomas/tree/devel/modules) (35 of them) and 181 metrics that they emit.
This file describes all [`phantomas` modules](https://github.com/macbre/phantomas/tree/devel/modules) (36 of them) and 187 metrics that they emit.

When applicable, [offender](https://github.com/macbre/phantomas/issues/140) example is provided.

Expand Down Expand Up @@ -473,6 +473,35 @@ length of document.cookie (bytes)
number of domains with cookies set (number, with offenders)


## [cpuTasks](https://github.com/macbre/phantomas/tree/devel/modules/cpuTasks/cpuTasks.js)

>
##### `layoutCount`

total number of full or partial page layout (number)

##### `layoutDuration`

combined durations in seconds of all page layouts (ms)

##### `recalcStyleCount`

total number of page style recalculations (number)

##### `recalcStyleDuration`

combined duration in seconds of all page style recalculations (ms)

##### `scriptDuration`

combined duration in seconds of JavaScript execution (ms)

##### `taskDuration`

combined duration in seconds of all tasks performed by the browser (ms)


## [documentHeight](https://github.com/macbre/phantomas/tree/devel/modules/documentHeight/documentHeight.js)

> Measure document height
Expand Down
53 changes: 51 additions & 2 deletions lib/metadata/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@
"documentCookiesCount"
]
},
"cpuTasks": {
"file": "/modules/cpuTasks/cpuTasks.js",
"desc": "",
"events": [],
"metrics": [
"layoutCount",
"layoutDuration",
"recalcStyleCount",
"recalcStyleDuration",
"scriptDuration",
"taskDuration"
]
},
"documentHeight": {
"file": "/modules/documentHeight/documentHeight.js",
"desc": "Measure document height",
Expand Down Expand Up @@ -1174,6 +1187,42 @@
"module": "cookies",
"testsCovered": false
},
"layoutCount": {
"desc": "total number of full or partial page layout",
"unit": "number",
"module": "cpuTasks",
"testsCovered": false
},
"layoutDuration": {
"desc": "combined durations of all page layouts",
"unit": "ms",
"module": "cpuTasks",
"testsCovered": false
},
"recalcStyleCount": {
"desc": "total number of page style recalculations",
"unit": "number",
"module": "cpuTasks",
"testsCovered": false
},
"recalcStyleDuration": {
"desc": "combined duration of all page style recalculations",
"unit": "ms",
"module": "cpuTasks",
"testsCovered": false
},
"scriptDuration": {
"desc": "combined duration of JavaScript execution",
"unit": "ms",
"module": "cpuTasks",
"testsCovered": false
},
"taskDuration": {
"desc": "combined duration of all tasks performed by the browser",
"unit": "ms",
"module": "cpuTasks",
"testsCovered": false
},
"documentHeight": {
"desc": "the page height",
"unit": "px",
Expand Down Expand Up @@ -1817,8 +1866,8 @@
"testsCovered": false
}
},
"metricsCount": 181,
"modulesCount": 35,
"metricsCount": 187,
"modulesCount": 36,
"extensionsCount": 12,
"version": "2.0.0"
}
22 changes: 22 additions & 0 deletions modules/cpuTasks/cpuTasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Retrieves stats about layouts, style recalcs and JS execution
*
* Metrics from https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagemetrics
*/
"use strict";

module.exports = function (phantomas) {
// Converts seconds into milliseconds
function ms(value) {
return Math.round(value * 1000);
}

phantomas.on("metrics", (metrics) => {
phantomas.setMetric("layoutCount", metrics.LayoutCount); // @desc total number of full or partial page layout
phantomas.setMetric("layoutDuration", ms(metrics.LayoutDuration)); // @desc combined durations of all page layouts
phantomas.setMetric("recalcStyleCount", metrics.RecalcStyleCount); // @desc total number of page style recalculations
phantomas.setMetric("recalcStyleDuration", ms(metrics.RecalcStyleDuration)); // @desc combined duration of style recalculations
phantomas.setMetric("scriptDuration", ms(metrics.ScriptDuration)); // @desc combined duration of JavaScript execution
phantomas.setMetric("taskDuration", ms(metrics.TaskDuration)); // @desc combined duration of all tasks performed by the browser
});
};

0 comments on commit 133cca1

Please sign in to comment.