fix(benchpress): Allow ignoring navigationStart events in perflog metric. (#20312)

PR Close #20312
This commit is contained in:
Michael Giambalvo 2017-11-09 12:51:17 -08:00 committed by Miško Hevery
parent 4064cbe945
commit 717ac5ac4d
2 changed files with 32 additions and 6 deletions

View File

@ -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) => <any>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;

View File

@ -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 = [
[