2016-08-03 15:00:07 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-03 12:32:26 -07:00
|
|
|
import {BaseException, WrappedException} from '@angular/facade/src/exceptions';
|
2016-08-05 09:50:49 -07:00
|
|
|
import {Json, StringWrapper, isBlank, isPresent} from '@angular/facade/src/lang';
|
2015-02-18 14:39:52 -08:00
|
|
|
|
2015-05-27 14:57:54 -07:00
|
|
|
import {WebDriverAdapter} from '../web_driver_adapter';
|
2016-08-03 15:00:07 -07:00
|
|
|
import {PerfLogFeatures, WebDriverExtension} from '../web_driver_extension';
|
2015-02-18 14:39:52 -08:00
|
|
|
|
|
|
|
export class IOsDriverExtension extends WebDriverExtension {
|
|
|
|
// TODO(tbosch): use static values when our transpiler supports them
|
2016-06-02 17:30:40 -07:00
|
|
|
static get PROVIDERS(): any[] { return _PROVIDERS; }
|
2015-02-18 14:39:52 -08:00
|
|
|
|
2015-05-27 14:57:54 -07:00
|
|
|
constructor(private _driver: WebDriverAdapter) { super(); }
|
2015-02-18 14:39:52 -08:00
|
|
|
|
2015-05-27 14:57:54 -07:00
|
|
|
gc(): Promise<any> { throw new BaseException('Force GC is not supported on iOS'); }
|
2015-02-18 14:39:52 -08:00
|
|
|
|
2015-05-27 14:57:54 -07:00
|
|
|
timeBegin(name: string): Promise<any> {
|
2015-02-18 14:39:52 -08:00
|
|
|
return this._driver.executeScript(`console.time('${name}');`);
|
|
|
|
}
|
|
|
|
|
2015-05-27 14:57:54 -07:00
|
|
|
timeEnd(name: string, restartName: string = null): Promise<any> {
|
2015-02-18 14:39:52 -08:00
|
|
|
var script = `console.timeEnd('${name}');`;
|
|
|
|
if (isPresent(restartName)) {
|
2016-08-03 15:00:07 -07:00
|
|
|
script += `console.time('${restartName}');`;
|
2015-02-18 14:39:52 -08:00
|
|
|
}
|
|
|
|
return this._driver.executeScript(script);
|
|
|
|
}
|
|
|
|
|
2015-02-20 13:32:54 -08:00
|
|
|
// See https://github.com/WebKit/webkit/tree/master/Source/WebInspectorUI/Versions
|
2015-02-18 14:39:52 -08:00
|
|
|
readPerfLog() {
|
|
|
|
// TODO(tbosch): Bug in IOsDriver: Need to execute at least one command
|
|
|
|
// so that the browser logs can be read out!
|
|
|
|
return this._driver.executeScript('1+1')
|
2015-05-27 14:57:54 -07:00
|
|
|
.then((_) => this._driver.logs('performance'))
|
|
|
|
.then((entries) => {
|
|
|
|
var records = [];
|
2015-10-07 09:09:43 -07:00
|
|
|
entries.forEach(entry => {
|
2015-05-27 14:57:54 -07:00
|
|
|
var message = Json.parse(entry['message'])['message'];
|
|
|
|
if (StringWrapper.equals(message['method'], 'Timeline.eventRecorded')) {
|
2015-06-17 11:17:21 -07:00
|
|
|
records.push(message['params']['record']);
|
2015-05-27 14:57:54 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return this._convertPerfRecordsToEvents(records);
|
2015-02-18 14:39:52 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-03 15:00:07 -07:00
|
|
|
/** @internal */
|
|
|
|
private _convertPerfRecordsToEvents(records: any[], events: any[] = null) {
|
2015-02-18 14:39:52 -08:00
|
|
|
if (isBlank(events)) {
|
|
|
|
events = [];
|
|
|
|
}
|
2015-05-27 14:57:54 -07:00
|
|
|
records.forEach((record) => {
|
2015-02-18 14:39:52 -08:00
|
|
|
var endEvent = null;
|
|
|
|
var type = record['type'];
|
|
|
|
var data = record['data'];
|
|
|
|
var startTime = record['startTime'];
|
|
|
|
var endTime = record['endTime'];
|
|
|
|
|
|
|
|
if (StringWrapper.equals(type, 'FunctionCall') &&
|
|
|
|
(isBlank(data) || !StringWrapper.equals(data['scriptName'], 'InjectedScript'))) {
|
2015-06-17 11:17:21 -07:00
|
|
|
events.push(createStartEvent('script', startTime));
|
2015-02-18 14:39:52 -08:00
|
|
|
endEvent = createEndEvent('script', endTime);
|
|
|
|
} else if (StringWrapper.equals(type, 'Time')) {
|
2015-06-17 11:17:21 -07:00
|
|
|
events.push(createMarkStartEvent(data['message'], startTime));
|
2015-02-18 14:39:52 -08:00
|
|
|
} else if (StringWrapper.equals(type, 'TimeEnd')) {
|
2015-06-17 11:17:21 -07:00
|
|
|
events.push(createMarkEndEvent(data['message'], startTime));
|
2016-08-03 15:00:07 -07:00
|
|
|
} else if (
|
|
|
|
StringWrapper.equals(type, 'RecalculateStyles') || StringWrapper.equals(type, 'Layout') ||
|
|
|
|
StringWrapper.equals(type, 'UpdateLayerTree') || StringWrapper.equals(type, 'Paint') ||
|
|
|
|
StringWrapper.equals(type, 'Rasterize') ||
|
|
|
|
StringWrapper.equals(type, 'CompositeLayers')) {
|
2015-06-17 11:17:21 -07:00
|
|
|
events.push(createStartEvent('render', startTime));
|
2015-02-18 14:39:52 -08:00
|
|
|
endEvent = createEndEvent('render', endTime);
|
|
|
|
}
|
2015-03-06 17:34:27 -08:00
|
|
|
// Note: ios used to support GCEvent up until iOS 6 :-(
|
2015-02-18 14:39:52 -08:00
|
|
|
if (isPresent(record['children'])) {
|
|
|
|
this._convertPerfRecordsToEvents(record['children'], events);
|
|
|
|
}
|
|
|
|
if (isPresent(endEvent)) {
|
2015-06-17 11:17:21 -07:00
|
|
|
events.push(endEvent);
|
2015-02-18 14:39:52 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return events;
|
|
|
|
}
|
2015-02-20 13:32:54 -08:00
|
|
|
|
2015-05-27 14:57:54 -07:00
|
|
|
perfLogFeatures(): PerfLogFeatures { return new PerfLogFeatures({render: true}); }
|
2015-03-06 17:34:27 -08:00
|
|
|
|
2015-10-02 16:47:54 -07:00
|
|
|
supports(capabilities: {[key: string]: any}): boolean {
|
2015-02-20 13:32:54 -08:00
|
|
|
return StringWrapper.equals(capabilities['browserName'].toLowerCase(), 'safari');
|
|
|
|
}
|
2015-02-18 14:39:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function createEvent(ph, name, time, args = null) {
|
|
|
|
var result = {
|
|
|
|
'cat': 'timeline',
|
|
|
|
'name': name,
|
|
|
|
'ts': time,
|
|
|
|
'ph': ph,
|
|
|
|
// The ios protocol does not support the notions of multiple processes in
|
|
|
|
// the perflog...
|
|
|
|
'pid': 'pid0'
|
|
|
|
};
|
|
|
|
if (isPresent(args)) {
|
|
|
|
result['args'] = args;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createStartEvent(name, time, args = null) {
|
|
|
|
return createEvent('B', name, time, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createEndEvent(name, time, args = null) {
|
|
|
|
return createEvent('E', name, time, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMarkStartEvent(name, time) {
|
|
|
|
return createEvent('b', name, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMarkEndEvent(name, time) {
|
|
|
|
return createEvent('e', name, time);
|
|
|
|
}
|
|
|
|
|
2016-08-03 15:00:07 -07:00
|
|
|
var _PROVIDERS = [{
|
|
|
|
provide: IOsDriverExtension,
|
|
|
|
useFactory: (driver) => new IOsDriverExtension(driver),
|
|
|
|
deps: [WebDriverAdapter]
|
|
|
|
}];
|