From 7b1473e49c6059d7b9a3d433f2571cb4766992d0 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Sun, 22 Dec 2024 15:19:16 +0100 Subject: [PATCH] Add --userTimingBlockList https://github.com/sitespeedio/sitespeed.io/issues/4344 --- lib/core/engine/command/measure.js | 13 ++++++++++++- lib/support/cli.js | 4 ++++ lib/support/userTiming.js | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/core/engine/command/measure.js b/lib/core/engine/command/measure.js index a196e295b2..538bba853e 100644 --- a/lib/core/engine/command/measure.js +++ b/lib/core/engine/command/measure.js @@ -6,7 +6,10 @@ import { timestamp as _timestamp } from '../../../support/engineUtils.js'; import { Video } from '../../../video/video.js'; import { pathToFolder } from '../../../support/pathToFolder.js'; import { setOrangeBackground } from '../../../video/screenRecording/setOrangeBackground.js'; -import { filterAllowlisted } from '../../../support/userTiming.js'; +import { + filterAllowlisted, + filterBlocklisted +} from '../../../support/userTiming.js'; import { isAndroidConfigured, Android } from '../../../android/index.js'; import { TCPDump } from '../../../support/tcpdump.js'; import { lcpHighlightScript as highlightLargestContentfulPaint } from './util/lcpHighlightScript.js'; @@ -643,6 +646,14 @@ export class Measure { ); } + if (this.options.userTimingBlockList) { + filterBlocklisted( + this.result[this.numberOfMeasuredPages].browserScripts.timings + .userTimings, + this.options.userTimingAllowList + ); + } + if (isAndroidConfigured(this.options) && this.options.processStartTime) { const packageName = this.options.browser === 'firefox' diff --git a/lib/support/cli.js b/lib/support/cli.js index a7ec288d3e..40873deee1 100644 --- a/lib/support/cli.js +++ b/lib/support/cli.js @@ -1255,6 +1255,10 @@ export function parseCommandLine() { describe: 'All userTimings are captured by default this option takes a regex that will allow which userTimings to capture in the results.' }) + .option('userTimingBlockList', { + describe: + 'All userTimings are captured by default this option takes a regex that will block some usertimings in the results.' + }) .option('headless', { type: 'boolean', default: false, diff --git a/lib/support/userTiming.js b/lib/support/userTiming.js index 509d28504b..5d00b769c9 100644 --- a/lib/support/userTiming.js +++ b/lib/support/userTiming.js @@ -5,3 +5,13 @@ export function filterAllowlisted(userTimings, allowlistRegex) { allowed.test(measure.name) ); } + +export function filterBlocklisted(userTimings, blocklistRegex) { + const blocked = new RegExp(blocklistRegex); + userTimings.marks = userTimings.marks.filter( + mark => !blocked.test(mark.name) + ); + userTimings.measures = userTimings.measures.filter( + measure => !blocked.test(measure.name) + ); +}