fix(benchpress): Use performance.mark() instead of console.time() (#24114)
Previously, benchpress would use `console.time()` and `console.timeEnd()` to measure the start and end of a test in the performance log. This used to work over navigations - if you called `console.time(id)` then navigated to a different page, calling `console.timeEnd(id)` would still insert an event in the performance log. As of Chrome 65, this is no longer the case. `console.timeEnd(id)` will simply not insert an event in the performance log unless `console.time(id)` was called on the same page. Likewise, using `performance.measure()` does not work if the starting mark was on a different page. This simple workaround uses `performance.mark()` to insert events in the performance log at the start and end of the test. Benchpress looks for '-bpstart' and '-bpend' in the name of the performance mark, and normalizes that to the start and end events expected by PerflogMetric PR Close #24114
This commit is contained in:

committed by
Misko Hevery

parent
6143da66b2
commit
06d04002fd
@ -61,16 +61,17 @@ import {TraceEventFactory} from '../trace_event_factory';
|
||||
});
|
||||
}));
|
||||
|
||||
it('should clear the perf logs and mark the timeline via console.time() on the first call',
|
||||
it('should clear the perf logs and mark the timeline via performance.mark() on the first call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension().timeBegin('someName').then(() => {
|
||||
expect(log).toEqual(
|
||||
[['logs', 'performance'], ['executeScript', `console.time('someName');`]]);
|
||||
expect(log).toEqual([
|
||||
['logs', 'performance'], ['executeScript', `performance.mark('someName-bpstart');`]
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via console.time() on the second call',
|
||||
it('should mark the timeline via performance.mark() on the second call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const ext = createExtension();
|
||||
ext.timeBegin('someName')
|
||||
@ -79,24 +80,25 @@ import {TraceEventFactory} from '../trace_event_factory';
|
||||
ext.timeBegin('someName');
|
||||
})
|
||||
.then(() => {
|
||||
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
|
||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpstart');`]]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via console.timeEnd()',
|
||||
it('should mark the timeline via performance.mark()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension().timeEnd('someName', null).then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
|
||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpend');`]]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via console.time() and console.timeEnd()',
|
||||
it('should mark the timeline via performance.mark() with start and end of a test',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||
expect(log).toEqual(
|
||||
[['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
||||
expect(log).toEqual([[
|
||||
'executeScript', `performance.mark('name1-bpend');performance.mark('name2-bpstart');`
|
||||
]]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
Reference in New Issue
Block a user