fix(benchpress): Update types for TypeScript nullability support
This commit is contained in:
parent
075f3f8c9f
commit
14669f20bf
|
@ -4,6 +4,7 @@
|
||||||
"description": "Benchpress - a framework for e2e performance tests",
|
"description": "Benchpress - a framework for e2e performance tests",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"typings": "./index.d.ts",
|
"typings": "./index.d.ts",
|
||||||
|
"strictNullChecks": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/core": "^2.0.0-rc.7",
|
"@angular/core": "^2.0.0-rc.7",
|
||||||
"reflect-metadata": "^0.1.2",
|
"reflect-metadata": "^0.1.2",
|
||||||
|
|
|
@ -16,7 +16,7 @@ export function convertPerfProfileToEvents(perfProfile: any): any[] {
|
||||||
const finishedEvents: {[key: string]: any}[] = []; // Event[] finished events
|
const finishedEvents: {[key: string]: any}[] = []; // Event[] finished events
|
||||||
const addFinishedEvent = function(eventName: string, startTime: number, endTime: number) {
|
const addFinishedEvent = function(eventName: string, startTime: number, endTime: number) {
|
||||||
const categorizedEventName = categorizeEvent(eventName);
|
const categorizedEventName = categorizeEvent(eventName);
|
||||||
let args: {[key: string]: any} = undefined;
|
let args: {[key: string]: any}|undefined = undefined;
|
||||||
if (categorizedEventName == 'gc') {
|
if (categorizedEventName == 'gc') {
|
||||||
// TODO: We cannot measure heap size at the moment
|
// TODO: We cannot measure heap size at the moment
|
||||||
args = {usedHeapSize: 0};
|
args = {usedHeapSize: 0};
|
||||||
|
|
|
@ -140,11 +140,11 @@ export class PerflogMetric extends Metric {
|
||||||
const markName = this._markName(this._measureCount - 1);
|
const markName = this._markName(this._measureCount - 1);
|
||||||
const nextMarkName = restart ? this._markName(this._measureCount++) : null;
|
const nextMarkName = restart ? this._markName(this._measureCount++) : null;
|
||||||
return this._driverExtension.timeEnd(markName, nextMarkName)
|
return this._driverExtension.timeEnd(markName, nextMarkName)
|
||||||
.then((_) => this._readUntilEndMark(markName));
|
.then((_: any) => this._readUntilEndMark(markName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private _readUntilEndMark(
|
private _readUntilEndMark(
|
||||||
markName: string, loopCount: number = 0, startEvent: PerfLogEvent = null) {
|
markName: string, loopCount: number = 0, startEvent: PerfLogEvent|null = null) {
|
||||||
if (loopCount > _MAX_RETRY_COUNT) {
|
if (loopCount > _MAX_RETRY_COUNT) {
|
||||||
throw new Error(`Tried too often to get the ending mark: ${loopCount}`);
|
throw new Error(`Tried too often to get the ending mark: ${loopCount}`);
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ export class PerflogMetric extends Metric {
|
||||||
}
|
}
|
||||||
startEvent['ph'] = 'B';
|
startEvent['ph'] = 'B';
|
||||||
endEvent['ph'] = 'E';
|
endEvent['ph'] = 'E';
|
||||||
endEvent['ts'] = startEvent['ts'] + startEvent['dur'];
|
endEvent['ts'] = startEvent['ts'] ! + startEvent['dur'] !;
|
||||||
this._remainingEvents.push(startEvent);
|
this._remainingEvents.push(startEvent);
|
||||||
this._remainingEvents.push(endEvent);
|
this._remainingEvents.push(endEvent);
|
||||||
} else {
|
} else {
|
||||||
|
@ -185,13 +185,13 @@ export class PerflogMetric extends Metric {
|
||||||
if (needSort) {
|
if (needSort) {
|
||||||
// Need to sort because of the ph==='X' events
|
// Need to sort because of the ph==='X' events
|
||||||
this._remainingEvents.sort((a, b) => {
|
this._remainingEvents.sort((a, b) => {
|
||||||
const diff = a['ts'] - b['ts'];
|
const diff = a['ts'] ! - b['ts'] !;
|
||||||
return diff > 0 ? 1 : diff < 0 ? -1 : 0;
|
return diff > 0 ? 1 : diff < 0 ? -1 : 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _aggregateEvents(events: PerfLogEvent[], markName: string): {[key: string]: number} {
|
private _aggregateEvents(events: PerfLogEvent[], markName: string): {[key: string]: number}|null {
|
||||||
const result: {[key: string]: number} = {'scriptTime': 0, 'pureScriptTime': 0};
|
const result: {[key: string]: number} = {'scriptTime': 0, 'pureScriptTime': 0};
|
||||||
if (this._perfLogFeatures.gc) {
|
if (this._perfLogFeatures.gc) {
|
||||||
result['gcTime'] = 0;
|
result['gcTime'] = 0;
|
||||||
|
@ -217,8 +217,8 @@ export class PerflogMetric extends Metric {
|
||||||
result['requestCount'] = 0;
|
result['requestCount'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let markStartEvent: PerfLogEvent = null;
|
let markStartEvent: PerfLogEvent = null !;
|
||||||
let markEndEvent: PerfLogEvent = null;
|
let markEndEvent: PerfLogEvent = null !;
|
||||||
events.forEach((event) => {
|
events.forEach((event) => {
|
||||||
const ph = event['ph'];
|
const ph = event['ph'];
|
||||||
const name = event['name'];
|
const name = event['name'];
|
||||||
|
@ -242,8 +242,8 @@ export class PerflogMetric extends Metric {
|
||||||
|
|
||||||
const frameTimestamps: number[] = [];
|
const frameTimestamps: number[] = [];
|
||||||
const frameTimes: number[] = [];
|
const frameTimes: number[] = [];
|
||||||
let frameCaptureStartEvent: PerfLogEvent = null;
|
let frameCaptureStartEvent: PerfLogEvent|null = null;
|
||||||
let frameCaptureEndEvent: PerfLogEvent = null;
|
let frameCaptureEndEvent: PerfLogEvent|null = null;
|
||||||
|
|
||||||
const intervalStarts: {[key: string]: PerfLogEvent} = {};
|
const intervalStarts: {[key: string]: PerfLogEvent} = {};
|
||||||
const intervalStartCount: {[key: string]: number} = {};
|
const intervalStartCount: {[key: string]: number} = {};
|
||||||
|
@ -251,7 +251,7 @@ export class PerflogMetric extends Metric {
|
||||||
let inMeasureRange = false;
|
let inMeasureRange = false;
|
||||||
events.forEach((event) => {
|
events.forEach((event) => {
|
||||||
const ph = event['ph'];
|
const ph = event['ph'];
|
||||||
let name = event['name'];
|
let name = event['name'] !;
|
||||||
let microIterations = 1;
|
let microIterations = 1;
|
||||||
const microIterationsMatch = name.match(_MICRO_ITERATIONS_REGEX);
|
const microIterationsMatch = name.match(_MICRO_ITERATIONS_REGEX);
|
||||||
if (microIterationsMatch) {
|
if (microIterationsMatch) {
|
||||||
|
@ -270,7 +270,7 @@ export class PerflogMetric extends Metric {
|
||||||
if (this._requestCount && name === 'sendRequest') {
|
if (this._requestCount && name === 'sendRequest') {
|
||||||
result['requestCount'] += 1;
|
result['requestCount'] += 1;
|
||||||
} else if (this._receivedData && name === 'receivedData' && ph === 'I') {
|
} else if (this._receivedData && name === 'receivedData' && ph === 'I') {
|
||||||
result['receivedData'] += event['args']['encodedDataLength'];
|
result['receivedData'] += event['args'] !['encodedDataLength'] !;
|
||||||
}
|
}
|
||||||
if (ph === 'B' && name === _MARK_NAME_FRAME_CAPTURE) {
|
if (ph === 'B' && name === _MARK_NAME_FRAME_CAPTURE) {
|
||||||
if (frameCaptureStartEvent) {
|
if (frameCaptureStartEvent) {
|
||||||
|
@ -289,7 +289,7 @@ export class PerflogMetric extends Metric {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ph === 'I' && frameCaptureStartEvent && !frameCaptureEndEvent && name === 'frame') {
|
if (ph === 'I' && frameCaptureStartEvent && !frameCaptureEndEvent && name === 'frame') {
|
||||||
frameTimestamps.push(event['ts']);
|
frameTimestamps.push(event['ts'] !);
|
||||||
if (frameTimestamps.length >= 2) {
|
if (frameTimestamps.length >= 2) {
|
||||||
frameTimes.push(
|
frameTimes.push(
|
||||||
frameTimestamps[frameTimestamps.length - 1] -
|
frameTimestamps[frameTimestamps.length - 1] -
|
||||||
|
@ -308,14 +308,14 @@ export class PerflogMetric extends Metric {
|
||||||
intervalStartCount[name]--;
|
intervalStartCount[name]--;
|
||||||
if (intervalStartCount[name] === 0) {
|
if (intervalStartCount[name] === 0) {
|
||||||
const startEvent = intervalStarts[name];
|
const startEvent = intervalStarts[name];
|
||||||
const duration = (event['ts'] - startEvent['ts']);
|
const duration = (event['ts'] ! - startEvent['ts'] !);
|
||||||
intervalStarts[name] = null;
|
intervalStarts[name] = null !;
|
||||||
if (name === 'gc') {
|
if (name === 'gc') {
|
||||||
result['gcTime'] += duration;
|
result['gcTime'] += duration;
|
||||||
const amount =
|
const amount =
|
||||||
(startEvent['args']['usedHeapSize'] - event['args']['usedHeapSize']) / 1000;
|
(startEvent['args'] !['usedHeapSize'] ! - event['args'] !['usedHeapSize'] !) / 1000;
|
||||||
result['gcAmount'] += amount;
|
result['gcAmount'] += amount;
|
||||||
const majorGc = event['args']['majorGc'];
|
const majorGc = event['args'] !['majorGc'];
|
||||||
if (majorGc && majorGc) {
|
if (majorGc && majorGc) {
|
||||||
result['majorGcTime'] += duration;
|
result['majorGcTime'] += duration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ export class Sampler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _iterate(lastState: SampleState): Promise<SampleState> {
|
private _iterate(lastState: SampleState): Promise<SampleState> {
|
||||||
let resultPromise: Promise<SampleState>;
|
let resultPromise: Promise<SampleState|null>;
|
||||||
if (this._prepare !== Options.NO_PREPARE) {
|
if (this._prepare !== Options.NO_PREPARE) {
|
||||||
resultPromise = this._driver.waitFor(this._prepare);
|
resultPromise = this._driver.waitFor(this._prepare);
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,5 +76,5 @@ export class Sampler {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SampleState {
|
export class SampleState {
|
||||||
constructor(public completeSample: MeasureValues[], public validSample: MeasureValues[]) {}
|
constructor(public completeSample: MeasureValues[], public validSample: MeasureValues[]|null) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ export abstract class Validator {
|
||||||
/**
|
/**
|
||||||
* Calculates a valid sample out of the complete sample
|
* Calculates a valid sample out of the complete sample
|
||||||
*/
|
*/
|
||||||
validate(completeSample: MeasureValues[]): MeasureValues[] { throw new Error('NYI'); }
|
validate(completeSample: MeasureValues[]): MeasureValues[]|null { throw new Error('NYI'); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Map that describes the properties of the validator
|
* Returns a Map that describes the properties of the validator
|
||||||
|
|
|
@ -35,7 +35,7 @@ export class RegressionSlopeValidator extends Validator {
|
||||||
return {'sampleSize': this._sampleSize, 'regressionSlopeMetric': this._metric};
|
return {'sampleSize': this._sampleSize, 'regressionSlopeMetric': this._metric};
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(completeSample: MeasureValues[]): MeasureValues[] {
|
validate(completeSample: MeasureValues[]): MeasureValues[]|null {
|
||||||
if (completeSample.length >= this._sampleSize) {
|
if (completeSample.length >= this._sampleSize) {
|
||||||
const latestSample =
|
const latestSample =
|
||||||
completeSample.slice(completeSample.length - this._sampleSize, completeSample.length);
|
completeSample.slice(completeSample.length - this._sampleSize, completeSample.length);
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class SizeValidator extends Validator {
|
||||||
|
|
||||||
describe(): {[key: string]: any} { return {'sampleSize': this._sampleSize}; }
|
describe(): {[key: string]: any} { return {'sampleSize': this._sampleSize}; }
|
||||||
|
|
||||||
validate(completeSample: MeasureValues[]): MeasureValues[] {
|
validate(completeSample: MeasureValues[]): MeasureValues[]|null {
|
||||||
if (completeSample.length >= this._sampleSize) {
|
if (completeSample.length >= this._sampleSize) {
|
||||||
return completeSample.slice(completeSample.length - this._sampleSize, completeSample.length);
|
return completeSample.slice(completeSample.length - this._sampleSize, completeSample.length);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -43,7 +43,7 @@ export abstract class WebDriverExtension {
|
||||||
{
|
{
|
||||||
provide: WebDriverExtension,
|
provide: WebDriverExtension,
|
||||||
useFactory: (children: WebDriverExtension[], capabilities: {[key: string]: any}) => {
|
useFactory: (children: WebDriverExtension[], capabilities: {[key: string]: any}) => {
|
||||||
let delegate: WebDriverExtension;
|
let delegate: WebDriverExtension = undefined !;
|
||||||
children.forEach(extension => {
|
children.forEach(extension => {
|
||||||
if (extension.supports(capabilities)) {
|
if (extension.supports(capabilities)) {
|
||||||
delegate = extension;
|
delegate = extension;
|
||||||
|
@ -64,7 +64,7 @@ export abstract class WebDriverExtension {
|
||||||
|
|
||||||
timeBegin(name: string): Promise<any> { throw new Error('NYI'); }
|
timeBegin(name: string): Promise<any> { throw new Error('NYI'); }
|
||||||
|
|
||||||
timeEnd(name: string, restartName: string): Promise<any> { throw new Error('NYI'); }
|
timeEnd(name: string, restartName: string|null): Promise<any> { throw new Error('NYI'); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format:
|
* Format:
|
||||||
|
|
|
@ -51,7 +51,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
|
||||||
return this._driver.executeScript(`console.time('${name}');`);
|
return this._driver.executeScript(`console.time('${name}');`);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeEnd(name: string, restartName: string = null): Promise<any> {
|
timeEnd(name: string, restartName: string|null = null): Promise<any> {
|
||||||
let script = `console.timeEnd('${name}');`;
|
let script = `console.timeEnd('${name}');`;
|
||||||
if (restartName) {
|
if (restartName) {
|
||||||
script += `console.time('${restartName}');`;
|
script += `console.time('${restartName}');`;
|
||||||
|
@ -82,14 +82,14 @@ export class ChromeDriverExtension extends WebDriverExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _convertPerfRecordsToEvents(
|
private _convertPerfRecordsToEvents(
|
||||||
chromeEvents: Array<{[key: string]: any}>, normalizedEvents: PerfLogEvent[] = null) {
|
chromeEvents: Array<{[key: string]: any}>, normalizedEvents: PerfLogEvent[]|null = null) {
|
||||||
if (!normalizedEvents) {
|
if (!normalizedEvents) {
|
||||||
normalizedEvents = [];
|
normalizedEvents = [];
|
||||||
}
|
}
|
||||||
chromeEvents.forEach((event) => {
|
chromeEvents.forEach((event) => {
|
||||||
const categories = this._parseCategories(event['cat']);
|
const categories = this._parseCategories(event['cat']);
|
||||||
const normalizedEvent = this._convertEvent(event, categories);
|
const normalizedEvent = this._convertEvent(event, categories);
|
||||||
if (normalizedEvent != null) normalizedEvents.push(normalizedEvent);
|
if (normalizedEvent != null) normalizedEvents !.push(normalizedEvent);
|
||||||
});
|
});
|
||||||
return normalizedEvents;
|
return normalizedEvents;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
|
||||||
|
|
||||||
private _isEvent(
|
private _isEvent(
|
||||||
eventCategories: string[], eventName: string, expectedCategories: string[],
|
eventCategories: string[], eventName: string, expectedCategories: string[],
|
||||||
expectedName: string = null): boolean {
|
expectedName: string|null = null): boolean {
|
||||||
const hasCategories = expectedCategories.reduce(
|
const hasCategories = expectedCategories.reduce(
|
||||||
(value, cat) => value && eventCategories.indexOf(cat) !== -1, true);
|
(value, cat) => value && eventCategories.indexOf(cat) !== -1, true);
|
||||||
return !expectedName ? hasCategories : hasCategories && eventName === expectedName;
|
return !expectedName ? hasCategories : hasCategories && eventName === expectedName;
|
||||||
|
|
|
@ -32,7 +32,7 @@ export class FirefoxDriverExtension extends WebDriverExtension {
|
||||||
return this._driver.executeScript('window.markStart("' + name + '");');
|
return this._driver.executeScript('window.markStart("' + name + '");');
|
||||||
}
|
}
|
||||||
|
|
||||||
timeEnd(name: string, restartName: string = null): Promise<any> {
|
timeEnd(name: string, restartName: string|null = null): Promise<any> {
|
||||||
let script = 'window.markEnd("' + name + '");';
|
let script = 'window.markEnd("' + name + '");';
|
||||||
if (restartName != null) {
|
if (restartName != null) {
|
||||||
script += 'window.markStart("' + restartName + '");';
|
script += 'window.markStart("' + restartName + '");';
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class IOsDriverExtension extends WebDriverExtension {
|
||||||
return this._driver.executeScript(`console.time('${name}');`);
|
return this._driver.executeScript(`console.time('${name}');`);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeEnd(name: string, restartName: string = null): Promise<any> {
|
timeEnd(name: string, restartName: string|null = null): Promise<any> {
|
||||||
let script = `console.timeEnd('${name}');`;
|
let script = `console.timeEnd('${name}');`;
|
||||||
if (restartName != null) {
|
if (restartName != null) {
|
||||||
script += `console.time('${restartName}');`;
|
script += `console.time('${restartName}');`;
|
||||||
|
@ -50,28 +50,28 @@ export class IOsDriverExtension extends WebDriverExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
private _convertPerfRecordsToEvents(records: any[], events: PerfLogEvent[] = null) {
|
private _convertPerfRecordsToEvents(records: any[], events: PerfLogEvent[]|null = null) {
|
||||||
if (!events) {
|
if (!events) {
|
||||||
events = [];
|
events = [];
|
||||||
}
|
}
|
||||||
records.forEach((record) => {
|
records.forEach((record) => {
|
||||||
let endEvent: PerfLogEvent = null;
|
let endEvent: PerfLogEvent|null = null;
|
||||||
const type = record['type'];
|
const type = record['type'];
|
||||||
const data = record['data'];
|
const data = record['data'];
|
||||||
const startTime = record['startTime'];
|
const startTime = record['startTime'];
|
||||||
const endTime = record['endTime'];
|
const endTime = record['endTime'];
|
||||||
|
|
||||||
if (type === 'FunctionCall' && (data == null || data['scriptName'] !== 'InjectedScript')) {
|
if (type === 'FunctionCall' && (data == null || data['scriptName'] !== 'InjectedScript')) {
|
||||||
events.push(createStartEvent('script', startTime));
|
events !.push(createStartEvent('script', startTime));
|
||||||
endEvent = createEndEvent('script', endTime);
|
endEvent = createEndEvent('script', endTime);
|
||||||
} else if (type === 'Time') {
|
} else if (type === 'Time') {
|
||||||
events.push(createMarkStartEvent(data['message'], startTime));
|
events !.push(createMarkStartEvent(data['message'], startTime));
|
||||||
} else if (type === 'TimeEnd') {
|
} else if (type === 'TimeEnd') {
|
||||||
events.push(createMarkEndEvent(data['message'], startTime));
|
events !.push(createMarkEndEvent(data['message'], startTime));
|
||||||
} else if (
|
} else if (
|
||||||
type === 'RecalculateStyles' || type === 'Layout' || type === 'UpdateLayerTree' ||
|
type === 'RecalculateStyles' || type === 'Layout' || type === 'UpdateLayerTree' ||
|
||||||
type === 'Paint' || type === 'Rasterize' || type === 'CompositeLayers') {
|
type === 'Paint' || type === 'Rasterize' || type === 'CompositeLayers') {
|
||||||
events.push(createStartEvent('render', startTime));
|
events !.push(createStartEvent('render', startTime));
|
||||||
endEvent = createEndEvent('render', endTime);
|
endEvent = createEndEvent('render', endTime);
|
||||||
}
|
}
|
||||||
// Note: ios used to support GCEvent up until iOS 6 :-(
|
// Note: ios used to support GCEvent up until iOS 6 :-(
|
||||||
|
@ -79,7 +79,7 @@ export class IOsDriverExtension extends WebDriverExtension {
|
||||||
this._convertPerfRecordsToEvents(record['children'], events);
|
this._convertPerfRecordsToEvents(record['children'], events);
|
||||||
}
|
}
|
||||||
if (endEvent != null) {
|
if (endEvent != null) {
|
||||||
events.push(endEvent);
|
events !.push(endEvent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return events;
|
return events;
|
||||||
|
|
|
@ -80,7 +80,7 @@ export function main() {
|
||||||
sortedKeys(createMetric([[]], new PerfLogFeatures({render: true, gc: false})).describe()))
|
sortedKeys(createMetric([[]], new PerfLogFeatures({render: true, gc: false})).describe()))
|
||||||
.toEqual(['pureScriptTime', 'renderTime', 'scriptTime']);
|
.toEqual(['pureScriptTime', 'renderTime', 'scriptTime']);
|
||||||
|
|
||||||
expect(sortedKeys(createMetric([[]], null).describe())).toEqual([
|
expect(sortedKeys(createMetric([[]], null !).describe())).toEqual([
|
||||||
'gcAmount', 'gcTime', 'majorGcTime', 'pureScriptTime', 'renderTime', 'scriptTime'
|
'gcAmount', 'gcTime', 'majorGcTime', 'pureScriptTime', 'renderTime', 'scriptTime'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ export function main() {
|
||||||
|
|
||||||
it('should describe itself based on micro metrics', () => {
|
it('should describe itself based on micro metrics', () => {
|
||||||
const description =
|
const description =
|
||||||
createMetric([[]], null, {microMetrics: {'myMicroMetric': 'someDesc'}}).describe();
|
createMetric([[]], null !, {microMetrics: {'myMicroMetric': 'someDesc'}}).describe();
|
||||||
expect(description['myMicroMetric']).toEqual('someDesc');
|
expect(description['myMicroMetric']).toEqual('someDesc');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ export function main() {
|
||||||
|
|
||||||
it('should not force gc and mark the timeline',
|
it('should not force gc and mark the timeline',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const metric = createMetric([[]], null);
|
const metric = createMetric([[]], null !);
|
||||||
metric.beginMeasure().then((_) => {
|
metric.beginMeasure().then((_) => {
|
||||||
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
|
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ export function main() {
|
||||||
|
|
||||||
it('should force gc and mark the timeline',
|
it('should force gc and mark the timeline',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const metric = createMetric([[]], null, {forceGc: true});
|
const metric = createMetric([[]], null !, {forceGc: true});
|
||||||
metric.beginMeasure().then((_) => {
|
metric.beginMeasure().then((_) => {
|
||||||
expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]);
|
expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]);
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ export function main() {
|
||||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||||
eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10)
|
eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10)
|
||||||
]];
|
]];
|
||||||
const metric = createMetric(events, null);
|
const metric = createMetric(events, null !);
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
expect(commandLog).toEqual([
|
expect(commandLog).toEqual([
|
||||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog'
|
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog'
|
||||||
|
@ -177,7 +177,7 @@ export function main() {
|
||||||
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
||||||
eventFactory.markEnd('benchpress0', 10)
|
eventFactory.markEnd('benchpress0', 10)
|
||||||
]];
|
]];
|
||||||
const metric = createMetric(events, null);
|
const metric = createMetric(events, null !);
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
expect(data['scriptTime']).toBe(1);
|
expect(data['scriptTime']).toBe(1);
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ export function main() {
|
||||||
],
|
],
|
||||||
[eventFactory.markEnd('benchpress1', 3)]
|
[eventFactory.markEnd('benchpress1', 3)]
|
||||||
];
|
];
|
||||||
const metric = createMetric(events, null);
|
const metric = createMetric(events, null !);
|
||||||
metric.beginMeasure()
|
metric.beginMeasure()
|
||||||
.then((_) => metric.endMeasure(true))
|
.then((_) => metric.endMeasure(true))
|
||||||
.then((_) => metric.endMeasure(true))
|
.then((_) => metric.endMeasure(true))
|
||||||
|
@ -218,7 +218,7 @@ export function main() {
|
||||||
eventFactory.markEnd('benchpress0', 10)
|
eventFactory.markEnd('benchpress0', 10)
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
const metric = createMetric(events, null);
|
const metric = createMetric(events, null !);
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
expect(commandLog).toEqual([
|
expect(commandLog).toEqual([
|
||||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog',
|
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog',
|
||||||
|
@ -243,7 +243,7 @@ export function main() {
|
||||||
eventFactory.markEnd('benchpress1', 6)
|
eventFactory.markEnd('benchpress1', 6)
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
const metric = createMetric(events, null);
|
const metric = createMetric(events, null !);
|
||||||
metric.beginMeasure()
|
metric.beginMeasure()
|
||||||
.then((_) => metric.endMeasure(true))
|
.then((_) => metric.endMeasure(true))
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
@ -275,7 +275,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should measure forced gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should measure forced gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const metric = createMetric(events, null, {forceGc: true});
|
const metric = createMetric(events, null !, {forceGc: true});
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
expect(commandLog).toEqual([
|
expect(commandLog).toEqual([
|
||||||
['gc'], ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
['gc'], ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||||
|
@ -290,7 +290,7 @@ export function main() {
|
||||||
|
|
||||||
it('should restart after the forced gc if needed',
|
it('should restart after the forced gc if needed',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const metric = createMetric(events, null, {forceGc: true});
|
const metric = createMetric(events, null !, {forceGc: true});
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => {
|
metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => {
|
||||||
expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']);
|
expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']);
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ export function main() {
|
||||||
} = {}) {
|
} = {}) {
|
||||||
events.unshift(eventFactory.markStart('benchpress0', 0));
|
events.unshift(eventFactory.markStart('benchpress0', 0));
|
||||||
events.push(eventFactory.markEnd('benchpress0', 10));
|
events.push(eventFactory.markEnd('benchpress0', 10));
|
||||||
const metric = createMetric([events], null, {
|
const metric = createMetric([events], null !, {
|
||||||
microMetrics: microMetrics,
|
microMetrics: microMetrics,
|
||||||
captureFrames: captureFrames,
|
captureFrames: captureFrames,
|
||||||
receivedData: receivedData,
|
receivedData: receivedData,
|
||||||
|
@ -510,7 +510,7 @@ export function main() {
|
||||||
otherProcessEventFactory.end('script', 17, null),
|
otherProcessEventFactory.end('script', 17, null),
|
||||||
eventFactory.markEnd('benchpress0', 20)
|
eventFactory.markEnd('benchpress0', 20)
|
||||||
]],
|
]],
|
||||||
null);
|
null !);
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
expect(data['scriptTime']).toBe(5);
|
expect(data['scriptTime']).toBe(5);
|
||||||
async.done();
|
async.done();
|
||||||
|
@ -674,7 +674,7 @@ class MockDriverExtension extends WebDriverExtension {
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeEnd(name: string, restartName: string): Promise<any> {
|
timeEnd(name: string, restartName: string|null): Promise<any> {
|
||||||
this._commandLog.push(['timeEnd', name, restartName]);
|
this._commandLog.push(['timeEnd', name, restartName]);
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ export function main() {
|
||||||
const providers: Provider[] = [
|
const providers: Provider[] = [
|
||||||
ConsoleReporter.PROVIDERS, {
|
ConsoleReporter.PROVIDERS, {
|
||||||
provide: SampleDescription,
|
provide: SampleDescription,
|
||||||
useValue: new SampleDescription(sampleId, descriptions, metrics)
|
useValue: new SampleDescription(sampleId, descriptions, metrics !)
|
||||||
},
|
},
|
||||||
{provide: ConsoleReporter.PRINT, useValue: (line: string) => log.push(line)}
|
{provide: ConsoleReporter.PRINT, useValue: (line: string) => log.push(line)}
|
||||||
];
|
];
|
||||||
|
|
|
@ -15,7 +15,7 @@ export function main() {
|
||||||
let injector: ReflectiveInjector;
|
let injector: ReflectiveInjector;
|
||||||
let runner: Runner;
|
let runner: Runner;
|
||||||
|
|
||||||
function createRunner(defaultProviders: any[] = null): Runner {
|
function createRunner(defaultProviders?: any[]): Runner {
|
||||||
if (!defaultProviders) {
|
if (!defaultProviders) {
|
||||||
defaultProviders = [];
|
defaultProviders = [];
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ export function main() {
|
||||||
|
|
||||||
class MockWebDriverAdapter extends WebDriverAdapter {
|
class MockWebDriverAdapter extends WebDriverAdapter {
|
||||||
executeScript(script: string): Promise<string> { return Promise.resolve('someUserAgent'); }
|
executeScript(script: string): Promise<string> { return Promise.resolve('someUserAgent'); }
|
||||||
capabilities(): Promise<Map<string, any>> { return null; }
|
capabilities(): Promise<Map<string, any>> { return null !; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockValidator extends Validator {
|
class MockValidator extends Validator {
|
||||||
|
@ -135,6 +135,6 @@ class MockMetric extends Metric {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockSampler extends Sampler {
|
class MockSampler extends Sampler {
|
||||||
constructor() { super(null, null, null, null, null, null, null); }
|
constructor() { super(null !, null !, null !, null !, null !, null !, null !); }
|
||||||
sample(): Promise<SampleState> { return Promise.resolve(new SampleState([], [])); }
|
sample(): Promise<SampleState> { return Promise.resolve(new SampleState([], [])); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ export function main() {
|
||||||
it('should call the validator for every execution and store the valid sample',
|
it('should call the validator for every execution and store the valid sample',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const log: any[] = [];
|
const log: any[] = [];
|
||||||
const validSample = [mv(null, null, {})];
|
const validSample = [mv(null !, null !, {})];
|
||||||
|
|
||||||
createSampler({
|
createSampler({
|
||||||
metric: createCountingMetric(),
|
metric: createCountingMetric(),
|
||||||
|
@ -174,7 +174,7 @@ export function main() {
|
||||||
it('should report the metric values',
|
it('should report the metric values',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const log: any[] = [];
|
const log: any[] = [];
|
||||||
const validSample = [mv(null, null, {})];
|
const validSample = [mv(null !, null !, {})];
|
||||||
createSampler({
|
createSampler({
|
||||||
validator: createCountingValidator(2, validSample),
|
validator: createCountingValidator(2, validSample),
|
||||||
metric: createCountingMetric(),
|
metric: createCountingMetric(),
|
||||||
|
@ -206,8 +206,7 @@ function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
||||||
return new MeasureValues(runIndex, new Date(time), values);
|
return new MeasureValues(runIndex, new Date(time), values);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCountingValidator(
|
function createCountingValidator(count: number, validSample?: MeasureValues[], log: any[] = []) {
|
||||||
count: number, validSample: MeasureValues[] = null, log: any[] = []) {
|
|
||||||
return new MockValidator(log, (completeSample: MeasureValues[]) => {
|
return new MockValidator(log, (completeSample: MeasureValues[]) => {
|
||||||
count--;
|
count--;
|
||||||
if (count === 0) {
|
if (count === 0) {
|
||||||
|
@ -224,7 +223,7 @@ function createCountingMetric(log: any[] = []) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockDriverAdapter extends WebDriverAdapter {
|
class MockDriverAdapter extends WebDriverAdapter {
|
||||||
constructor(private _log: any[] = [], private _waitFor: Function = null) { super(); }
|
constructor(private _log: any[] = [], private _waitFor: Function|null = null) { super(); }
|
||||||
waitFor(callback: Function): Promise<any> {
|
waitFor(callback: Function): Promise<any> {
|
||||||
if (this._waitFor != null) {
|
if (this._waitFor != null) {
|
||||||
return this._waitFor(callback);
|
return this._waitFor(callback);
|
||||||
|
@ -236,7 +235,7 @@ class MockDriverAdapter extends WebDriverAdapter {
|
||||||
|
|
||||||
|
|
||||||
class MockValidator extends Validator {
|
class MockValidator extends Validator {
|
||||||
constructor(private _log: any[] = [], private _validate: Function = null) { super(); }
|
constructor(private _log: any[] = [], private _validate: Function|null = null) { super(); }
|
||||||
validate(completeSample: MeasureValues[]): MeasureValues[] {
|
validate(completeSample: MeasureValues[]): MeasureValues[] {
|
||||||
const stableSample = this._validate != null ? this._validate(completeSample) : completeSample;
|
const stableSample = this._validate != null ? this._validate(completeSample) : completeSample;
|
||||||
this._log.push(['validate', completeSample, stableSample]);
|
this._log.push(['validate', completeSample, stableSample]);
|
||||||
|
@ -245,7 +244,7 @@ class MockValidator extends Validator {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockMetric extends Metric {
|
class MockMetric extends Metric {
|
||||||
constructor(private _log: any[] = [], private _endMeasure: Function = null) { super(); }
|
constructor(private _log: any[] = [], private _endMeasure: Function|null = null) { super(); }
|
||||||
beginMeasure() {
|
beginMeasure() {
|
||||||
this._log.push(['beginMeasure']);
|
this._log.push(['beginMeasure']);
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
|
|
|
@ -32,7 +32,7 @@ export function main() {
|
||||||
const normEvents = new TraceEventFactory('timeline', 'pid0');
|
const normEvents = new TraceEventFactory('timeline', 'pid0');
|
||||||
|
|
||||||
function createExtension(
|
function createExtension(
|
||||||
perfRecords: any[] = null, userAgent: string = null,
|
perfRecords: any[] | null = null, userAgent: string | null = null,
|
||||||
messageMethod = 'Tracing.dataCollected'): WebDriverExtension {
|
messageMethod = 'Tracing.dataCollected'): WebDriverExtension {
|
||||||
if (!perfRecords) {
|
if (!perfRecords) {
|
||||||
perfRecords = [];
|
perfRecords = [];
|
||||||
|
@ -392,7 +392,7 @@ class MockDriverAdapter extends WebDriverAdapter {
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
logs(type: string) {
|
logs(type: string): Promise<any[]> {
|
||||||
this._log.push(['logs', type]);
|
this._log.push(['logs', type]);
|
||||||
if (type === 'performance') {
|
if (type === 'performance') {
|
||||||
return Promise.resolve(this._events.map(
|
return Promise.resolve(this._events.map(
|
||||||
|
@ -401,7 +401,7 @@ class MockDriverAdapter extends WebDriverAdapter {
|
||||||
{'message': {'method': this._messageMethod, 'params': event}}, null, 2)
|
{'message': {'method': this._messageMethod, 'params': event}}, null, 2)
|
||||||
})));
|
})));
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null !;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function main() {
|
||||||
|
|
||||||
const normEvents = new TraceEventFactory('timeline', 'pid0');
|
const normEvents = new TraceEventFactory('timeline', 'pid0');
|
||||||
|
|
||||||
function createExtension(perfRecords: any[] = null): WebDriverExtension {
|
function createExtension(perfRecords: any[] | null = null): WebDriverExtension {
|
||||||
if (!perfRecords) {
|
if (!perfRecords) {
|
||||||
perfRecords = [];
|
perfRecords = [];
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,8 @@ function timeEndRecord(name: string, time: number) {
|
||||||
return {'type': 'TimeEnd', 'startTime': time, 'data': {'message': name}};
|
return {'type': 'TimeEnd', 'startTime': time, 'data': {'message': name}};
|
||||||
}
|
}
|
||||||
|
|
||||||
function durationRecord(type: string, startTime: number, endTime: number, children: any[] = null) {
|
function durationRecord(
|
||||||
|
type: string, startTime: number, endTime: number, children: any[] | null = null) {
|
||||||
if (!children) {
|
if (!children) {
|
||||||
children = [];
|
children = [];
|
||||||
}
|
}
|
||||||
|
@ -178,7 +179,7 @@ class MockDriverAdapter extends WebDriverAdapter {
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
logs(type: string) {
|
logs(type: string): Promise<any[]> {
|
||||||
this._log.push(['logs', type]);
|
this._log.push(['logs', type]);
|
||||||
if (type === 'performance') {
|
if (type === 'performance') {
|
||||||
return Promise.resolve(this._perfRecords.map(function(record) {
|
return Promise.resolve(this._perfRecords.map(function(record) {
|
||||||
|
@ -189,7 +190,7 @@ class MockDriverAdapter extends WebDriverAdapter {
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null !;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue