Skip to content

Commit

Permalink
fix(benchpress): chrome - prevent trace buffer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tbosch authored and mhevery committed Apr 21, 2017
1 parent 0ea4a13 commit d216f94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/benchpress/src/webdriver/chrome_driver_extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
static PROVIDERS = [ChromeDriverExtension];

private _majorChromeVersion: number;
private _firstRun = true;

constructor(private _driver: WebDriverAdapter, @Inject(Options.USER_AGENT) userAgent: string) {
super();
Expand All @@ -48,6 +49,12 @@ export class ChromeDriverExtension extends WebDriverExtension {
gc() { return this._driver.executeScript('window.gc()'); }

timeBegin(name: string): Promise<any> {
if (this._firstRun) {
this._firstRun = false;
// Before the first run, read out the existing performance logs
// so that the chrome buffer does not fill up.
this._driver.logs('performance');
}
return this._driver.executeScript(`console.time('${name}');`);
}

Expand Down
23 changes: 19 additions & 4 deletions packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
import {AsyncTestCompleter, describe, expect, iit, inject, it} from '@angular/core/testing/src/testing_internal';

import {ChromeDriverExtension, Options, ReflectiveInjector, WebDriverAdapter, WebDriverExtension} from '../../index';
import {TraceEventFactory} from '../trace_event_factory';
Expand Down Expand Up @@ -61,14 +61,29 @@ export function main() {
});
}));

it('should mark the timeline via console.time()',
it('should clear the perf logs and mark the timeline via console.time() on the first call',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension().timeBegin('someName').then((_) => {
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
createExtension().timeBegin('someName').then(() => {
expect(log).toEqual(
[['logs', 'performance'], ['executeScript', `console.time('someName');`]]);
async.done();
});
}));

it('should mark the timeline via console.time() on the second call',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const ext = createExtension();
ext.timeBegin('someName')
.then((_) => {
log.splice(0, log.length);
ext.timeBegin('someName');
})
.then(() => {
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
async.done();
});
}));

it('should mark the timeline via console.timeEnd()',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension().timeEnd('someName', null).then((_) => {
Expand Down

0 comments on commit d216f94

Please sign in to comment.