From 5d6c987818a33ac8cac5a69e6978d1fe7f677368 Mon Sep 17 00:00:00 2001 From: Jonathan Lee Date: Tue, 24 Jan 2017 23:18:10 -0500 Subject: [PATCH] #257 - implement whitelist option for userTimings --- lib/core/engine.js | 11 +++++++++++ lib/support/cli.js | 3 +++ 2 files changed, 14 insertions(+) diff --git a/lib/core/engine.js b/lib/core/engine.js index 5818377005..e44b84bda7 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -232,6 +232,17 @@ class Engine { merge({}, syncScripts, asyncScripts)); }) .then((result) => { + const userTimingWhitelistRegex = new RegExp(options.userTimingWhitelist); + if (userTimingWhitelistRegex) { + let userTimingMarks = result.timings.userTimings.marks; + result.timings.userTimings.marks = userTimingMarks.filter((mark) => { + return userTimingWhitelistRegex.exec(mark.name) !== null; + }, {}); + let userTimingMeasurements = result.timings.userTimings.measures; + result.timings.userTimings.measures = userTimingMeasurements.filter((measure) => { + return userTimingWhitelistRegex.exec(measure.name) !== null; + }, {}); + } return { browserScripts: result, extraJson: {} diff --git a/lib/support/cli.js b/lib/support/cli.js index d5826b8c9b..11863a2910 100644 --- a/lib/support/cli.js +++ b/lib/support/cli.js @@ -273,6 +273,9 @@ module.exports.parseCommandLine = function parseCommandLine() { .option('preURL', { describe: 'A URL that will be accessed first by the browser before the URL that you wanna analyze. Use it to fill the cache.' }) + .option('userTimingWhitelist', { + describe: 'A regex that will whitelist which userTimings to capture in results.' + }) .count('verbose') .string('_') .help('h')