-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #841 from gmetais/cpu-tasks
Expose CPU related metrics from page.metrics() as phantomas metrics
- Loading branch information
Showing
3 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}; |