fix(benchpress): Allow ignoring navigationStart events in perflog metric. (#20312)
PR Close #20312
This commit is contained in:
parent
4064cbe945
commit
717ac5ac4d
@ -19,18 +19,21 @@ import {PerfLogEvent, PerfLogFeatures, WebDriverExtension} from '../web_driver_e
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class PerflogMetric extends Metric {
|
export class PerflogMetric extends Metric {
|
||||||
static SET_TIMEOUT = new InjectionToken('PerflogMetric.setTimeout');
|
static SET_TIMEOUT = new InjectionToken('PerflogMetric.setTimeout');
|
||||||
|
static IGNORE_NAVIGATION = new InjectionToken('PerflogMetric.ignoreNavigation');
|
||||||
static PROVIDERS = [
|
static PROVIDERS = [
|
||||||
{
|
{
|
||||||
provide: PerflogMetric,
|
provide: PerflogMetric,
|
||||||
deps: [
|
deps: [
|
||||||
WebDriverExtension, PerflogMetric.SET_TIMEOUT, Options.MICRO_METRICS, Options.FORCE_GC,
|
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,
|
provide: PerflogMetric.SET_TIMEOUT,
|
||||||
useValue: (fn: Function, millis: number) => <any>setTimeout(fn, millis)
|
useValue: (fn: Function, millis: number) => <any>setTimeout(fn, millis)
|
||||||
}
|
},
|
||||||
|
{provide: PerflogMetric.IGNORE_NAVIGATION, useValue: false}
|
||||||
];
|
];
|
||||||
|
|
||||||
private _remainingEvents: PerfLogEvent[];
|
private _remainingEvents: PerfLogEvent[];
|
||||||
@ -41,6 +44,8 @@ export class PerflogMetric extends Metric {
|
|||||||
* @param driverExtension
|
* @param driverExtension
|
||||||
* @param setTimeout
|
* @param setTimeout
|
||||||
* @param microMetrics Name and description of metrics provided via console.time / console.timeEnd
|
* @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(
|
constructor(
|
||||||
private _driverExtension: WebDriverExtension,
|
private _driverExtension: WebDriverExtension,
|
||||||
@ -49,7 +54,8 @@ export class PerflogMetric extends Metric {
|
|||||||
@Inject(Options.FORCE_GC) private _forceGc: boolean,
|
@Inject(Options.FORCE_GC) private _forceGc: boolean,
|
||||||
@Inject(Options.CAPTURE_FRAMES) private _captureFrames: boolean,
|
@Inject(Options.CAPTURE_FRAMES) private _captureFrames: boolean,
|
||||||
@Inject(Options.RECEIVED_DATA) private _receivedData: 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();
|
super();
|
||||||
|
|
||||||
this._remainingEvents = [];
|
this._remainingEvents = [];
|
||||||
@ -231,7 +237,7 @@ export class PerflogMetric extends Metric {
|
|||||||
const name = event['name'];
|
const name = event['name'];
|
||||||
if (ph === 'B' && name === markName) {
|
if (ph === 'B' && name === markName) {
|
||||||
markStartEvent = event;
|
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
|
// if a benchmark measures reload of a page, use the last
|
||||||
// navigationStart as begin event
|
// navigationStart as begin event
|
||||||
markStartEvent = event;
|
markStartEvent = event;
|
||||||
|
@ -18,12 +18,13 @@ export function main() {
|
|||||||
|
|
||||||
function createMetric(
|
function createMetric(
|
||||||
perfLogs: PerfLogEvent[], perfLogFeatures: PerfLogFeatures,
|
perfLogs: PerfLogEvent[], perfLogFeatures: PerfLogFeatures,
|
||||||
{microMetrics, forceGc, captureFrames, receivedData, requestCount}: {
|
{microMetrics, forceGc, captureFrames, receivedData, requestCount, ignoreNavigation}: {
|
||||||
microMetrics?: {[key: string]: string},
|
microMetrics?: {[key: string]: string},
|
||||||
forceGc?: boolean,
|
forceGc?: boolean,
|
||||||
captureFrames?: boolean,
|
captureFrames?: boolean,
|
||||||
receivedData?: boolean,
|
receivedData?: boolean,
|
||||||
requestCount?: boolean
|
requestCount?: boolean,
|
||||||
|
ignoreNavigation?: boolean
|
||||||
} = {}): Metric {
|
} = {}): Metric {
|
||||||
commandLog = [];
|
commandLog = [];
|
||||||
if (!perfLogFeatures) {
|
if (!perfLogFeatures) {
|
||||||
@ -59,6 +60,9 @@ export function main() {
|
|||||||
if (requestCount != null) {
|
if (requestCount != null) {
|
||||||
providers.push({provide: Options.REQUEST_COUNT, useValue: requestCount});
|
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);
|
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) => {
|
it('should restart timing', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const events = [
|
const events = [
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user