diff --git a/packages/benchpress/src/metric/perflog_metric.ts b/packages/benchpress/src/metric/perflog_metric.ts index f31fc6186d..033c1b6da5 100644 --- a/packages/benchpress/src/metric/perflog_metric.ts +++ b/packages/benchpress/src/metric/perflog_metric.ts @@ -19,18 +19,21 @@ import {PerfLogEvent, PerfLogFeatures, WebDriverExtension} from '../web_driver_e @Injectable() export class PerflogMetric extends Metric { static SET_TIMEOUT = new InjectionToken('PerflogMetric.setTimeout'); + static IGNORE_NAVIGATION = new InjectionToken('PerflogMetric.ignoreNavigation'); static PROVIDERS = [ { provide: PerflogMetric, deps: [ WebDriverExtension, PerflogMetric.SET_TIMEOUT, Options.MICRO_METRICS, Options.FORCE_GC, - Options.CAPTURE_FRAMES, Options.RECEIVED_DATA, Options.REQUEST_COUNT + Options.CAPTURE_FRAMES, Options.RECEIVED_DATA, Options.REQUEST_COUNT, + PerflogMetric.IGNORE_NAVIGATION ] }, { provide: PerflogMetric.SET_TIMEOUT, useValue: (fn: Function, millis: number) => setTimeout(fn, millis) - } + }, + {provide: PerflogMetric.IGNORE_NAVIGATION, useValue: false} ]; private _remainingEvents: PerfLogEvent[]; @@ -41,6 +44,8 @@ export class PerflogMetric extends Metric { * @param driverExtension * @param setTimeout * @param microMetrics Name and description of metrics provided via console.time / console.timeEnd + * @param ignoreNavigation If true, don't measure from navigationStart events. These events are + * usually triggered by a page load, but can also be triggered when adding iframes to the DOM. **/ constructor( private _driverExtension: WebDriverExtension, @@ -49,7 +54,8 @@ export class PerflogMetric extends Metric { @Inject(Options.FORCE_GC) private _forceGc: boolean, @Inject(Options.CAPTURE_FRAMES) private _captureFrames: boolean, @Inject(Options.RECEIVED_DATA) private _receivedData: boolean, - @Inject(Options.REQUEST_COUNT) private _requestCount: boolean) { + @Inject(Options.REQUEST_COUNT) private _requestCount: boolean, + @Inject(PerflogMetric.IGNORE_NAVIGATION) private _ignoreNavigation: boolean) { super(); this._remainingEvents = []; @@ -231,7 +237,7 @@ export class PerflogMetric extends Metric { const name = event['name']; if (ph === 'B' && name === markName) { markStartEvent = event; - } else if (ph === 'I' && name === 'navigationStart') { + } else if (ph === 'I' && name === 'navigationStart' && !this._ignoreNavigation) { // if a benchmark measures reload of a page, use the last // navigationStart as begin event markStartEvent = event; diff --git a/packages/benchpress/test/metric/perflog_metric_spec.ts b/packages/benchpress/test/metric/perflog_metric_spec.ts index 68822092f9..a8ad908d50 100644 --- a/packages/benchpress/test/metric/perflog_metric_spec.ts +++ b/packages/benchpress/test/metric/perflog_metric_spec.ts @@ -18,12 +18,13 @@ export function main() { function createMetric( perfLogs: PerfLogEvent[], perfLogFeatures: PerfLogFeatures, - {microMetrics, forceGc, captureFrames, receivedData, requestCount}: { + {microMetrics, forceGc, captureFrames, receivedData, requestCount, ignoreNavigation}: { microMetrics?: {[key: string]: string}, forceGc?: boolean, captureFrames?: boolean, receivedData?: boolean, - requestCount?: boolean + requestCount?: boolean, + ignoreNavigation?: boolean } = {}): Metric { commandLog = []; if (!perfLogFeatures) { @@ -59,6 +60,9 @@ export function main() { if (requestCount != null) { providers.push({provide: Options.REQUEST_COUNT, useValue: requestCount}); } + if (ignoreNavigation != null) { + providers.push({provide: PerflogMetric.IGNORE_NAVIGATION, useValue: ignoreNavigation}); + } return Injector.create(providers).get(PerflogMetric); } @@ -185,6 +189,22 @@ export function main() { }); })); + it('should ignore navigationStart if ignoreNavigation is set', + inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + const events = [[ + eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4), + eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7), + eventFactory.start('script', 8), eventFactory.end('script', 9), + eventFactory.markEnd('benchpress0', 10) + ]]; + const metric = createMetric(events, null !, {ignoreNavigation: true}); + metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => { + expect(data['scriptTime']).toBe(3); + + async.done(); + }); + })); + it('should restart timing', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const events = [ [