refactor(benchpress): normalize phase `b` into `B` and `e` into `E`
This simplifies the perflog metrics and prevents future errors.
This commit is contained in:
parent
838d4bbf6c
commit
32aeb1052d
|
@ -42,11 +42,11 @@ class Profiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
addStartEvent(name: string, timeStarted: number) {
|
addStartEvent(name: string, timeStarted: number) {
|
||||||
this._markerEvents.push({ph: 'b', ts: timeStarted - this._profilerStartTime, name: name});
|
this._markerEvents.push({ph: 'B', ts: timeStarted - this._profilerStartTime, name: name});
|
||||||
}
|
}
|
||||||
|
|
||||||
addEndEvent(name: string, timeEnded: number) {
|
addEndEvent(name: string, timeEnded: number) {
|
||||||
this._markerEvents.push({ph: 'e', ts: timeEnded - this._profilerStartTime, name: name});
|
this._markerEvents.push({ph: 'E', ts: timeEnded - this._profilerStartTime, name: name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,13 +222,13 @@ export class PerflogMetric extends Metric {
|
||||||
events.forEach((event) => {
|
events.forEach((event) => {
|
||||||
var ph = event['ph'];
|
var ph = event['ph'];
|
||||||
var name = event['name'];
|
var 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') {
|
||||||
// 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;
|
||||||
} else if (ph === 'e' && name === markName) {
|
} else if (ph === 'E' && name === markName) {
|
||||||
markEndEvent = event;
|
markEndEvent = event;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -272,7 +272,7 @@ export class PerflogMetric extends Metric {
|
||||||
} 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_CAPUTRE) {
|
if (ph === 'B' && name === _MARK_NAME_FRAME_CAPUTRE) {
|
||||||
if (frameCaptureStartEvent) {
|
if (frameCaptureStartEvent) {
|
||||||
throw new Error('can capture frames only once per benchmark run');
|
throw new Error('can capture frames only once per benchmark run');
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ export class PerflogMetric extends Metric {
|
||||||
'found start event for frame capture, but frame capture was not requested in benchpress');
|
'found start event for frame capture, but frame capture was not requested in benchpress');
|
||||||
}
|
}
|
||||||
frameCaptureStartEvent = event;
|
frameCaptureStartEvent = event;
|
||||||
} else if (ph === 'e' && name === _MARK_NAME_FRAME_CAPUTRE) {
|
} else if (ph === 'E' && name === _MARK_NAME_FRAME_CAPUTRE) {
|
||||||
if (!frameCaptureStartEvent) {
|
if (!frameCaptureStartEvent) {
|
||||||
throw new Error('missing start event for frame capture');
|
throw new Error('missing start event for frame capture');
|
||||||
}
|
}
|
||||||
|
@ -297,14 +297,14 @@ export class PerflogMetric extends Metric {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ph === 'B' || ph === 'b') {
|
if (ph === 'B') {
|
||||||
if (!intervalStarts[name]) {
|
if (!intervalStarts[name]) {
|
||||||
intervalStartCount[name] = 1;
|
intervalStartCount[name] = 1;
|
||||||
intervalStarts[name] = event;
|
intervalStarts[name] = event;
|
||||||
} else {
|
} else {
|
||||||
intervalStartCount[name]++;
|
intervalStartCount[name]++;
|
||||||
}
|
}
|
||||||
} else if ((ph === 'E' || ph === 'e') && intervalStarts[name]) {
|
} else if ((ph === 'E') && intervalStarts[name]) {
|
||||||
intervalStartCount[name]--;
|
intervalStartCount[name]--;
|
||||||
if (intervalStartCount[name] === 0) {
|
if (intervalStartCount[name] === 0) {
|
||||||
var startEvent = intervalStarts[name];
|
var startEvent = intervalStarts[name];
|
||||||
|
|
|
@ -14,13 +14,18 @@ import {isBlank, isPresent} from './facade/lang';
|
||||||
export type PerfLogEvent = {
|
export type PerfLogEvent = {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
} & {
|
} & {
|
||||||
cat?: string,
|
ph?: 'X' | 'B' | 'E' | 'I',
|
||||||
ph?: 'X' | 'B' | 'E' | 'b' | 'e' | 'I',
|
|
||||||
ts?: number,
|
ts?: number,
|
||||||
dur?: number,
|
dur?: number,
|
||||||
name?: string,
|
name?: string,
|
||||||
pid?: string,
|
pid?: string,
|
||||||
args?: {encodedDataLength?: number, usedHeapSize?: number, majorGc?: number}
|
args?: {
|
||||||
|
encodedDataLength?: number,
|
||||||
|
usedHeapSize?: number,
|
||||||
|
majorGc?: boolean,
|
||||||
|
url?: string,
|
||||||
|
method?: string
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,8 +71,7 @@ export abstract class WebDriverExtension {
|
||||||
* Format:
|
* Format:
|
||||||
* - cat: category of the event
|
* - cat: category of the event
|
||||||
* - name: event name: 'script', 'gc', 'render', ...
|
* - name: event name: 'script', 'gc', 'render', ...
|
||||||
* - ph: phase: 'B' (begin), 'E' (end), 'b' (nestable start), 'e' (nestable end), 'X' (Complete
|
* - ph: phase: 'B' (begin), 'E' (end), 'X' (Complete event), 'I' (Instant event)
|
||||||
*event)
|
|
||||||
* - ts: timestamp in ms, e.g. 12345
|
* - ts: timestamp in ms, e.g. 12345
|
||||||
* - pid: process id
|
* - pid: process id
|
||||||
* - args: arguments, e.g. {heapSize: 1234}
|
* - args: arguments, e.g. {heapSize: 1234}
|
||||||
|
|
|
@ -158,7 +158,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
|
||||||
let normArgs = {'url': data['url'], 'method': data['requestMethod']};
|
let normArgs = {'url': data['url'], 'method': data['requestMethod']};
|
||||||
return normalizeEvent(event, {'name': 'sendRequest', 'args': normArgs});
|
return normalizeEvent(event, {'name': 'sendRequest', 'args': normArgs});
|
||||||
} else if (this._isEvent(categories, name, ['blink.user_timing'], 'navigationStart')) {
|
} else if (this._isEvent(categories, name, ['blink.user_timing'], 'navigationStart')) {
|
||||||
return normalizeEvent(event, {'name': name});
|
return normalizeEvent(event, {'name': 'navigationStart'});
|
||||||
}
|
}
|
||||||
return null; // nothing useful in this event
|
return null; // nothing useful in this event
|
||||||
}
|
}
|
||||||
|
@ -182,23 +182,19 @@ export class ChromeDriverExtension extends WebDriverExtension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeEvent(
|
function normalizeEvent(chromeEvent: {[key: string]: any}, data: PerfLogEvent): PerfLogEvent {
|
||||||
chromeEvent: {[key: string]: any}, data: {[key: string]: any}): PerfLogEvent {
|
var ph = chromeEvent['ph'].toUpperCase();
|
||||||
var ph = chromeEvent['ph'];
|
|
||||||
if (ph === 'S') {
|
if (ph === 'S') {
|
||||||
ph = 'b';
|
ph = 'B';
|
||||||
} else if (ph === 'F') {
|
} else if (ph === 'F') {
|
||||||
ph = 'e';
|
ph = 'E';
|
||||||
} else if (ph === 'R') {
|
} else if (ph === 'R') {
|
||||||
// mark events from navigation timing
|
// mark events from navigation timing
|
||||||
ph = 'I';
|
ph = 'I';
|
||||||
} else if (ph === 'i') {
|
|
||||||
// legacy support
|
|
||||||
ph = 'I';
|
|
||||||
}
|
}
|
||||||
var result: {[key: string]: any} =
|
var result: {[key: string]: any} =
|
||||||
{'pid': chromeEvent['pid'], 'ph': ph, 'cat': 'timeline', 'ts': chromeEvent['ts'] / 1000};
|
{'pid': chromeEvent['pid'], 'ph': ph, 'cat': 'timeline', 'ts': chromeEvent['ts'] / 1000};
|
||||||
if (chromeEvent['ph'] === 'X') {
|
if (ph === 'X') {
|
||||||
var dur = chromeEvent['dur'];
|
var dur = chromeEvent['dur'];
|
||||||
if (dur === undefined) {
|
if (dur === undefined) {
|
||||||
dur = chromeEvent['tdur'];
|
dur = chromeEvent['tdur'];
|
||||||
|
|
|
@ -97,7 +97,7 @@ export class IOsDriverExtension extends WebDriverExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEvent(
|
function createEvent(
|
||||||
ph: 'X' | 'B' | 'E' | 'b' | 'e', name: string, time: number, args: any = null) {
|
ph: 'X' | 'B' | 'E' | 'B' | 'E', name: string, time: number, args: any = null) {
|
||||||
var result: PerfLogEvent = {
|
var result: PerfLogEvent = {
|
||||||
'cat': 'timeline',
|
'cat': 'timeline',
|
||||||
'name': name,
|
'name': name,
|
||||||
|
@ -122,9 +122,9 @@ function createEndEvent(name: string, time: number, args: any = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMarkStartEvent(name: string, time: number) {
|
function createMarkStartEvent(name: string, time: number) {
|
||||||
return createEvent('b', name, time);
|
return createEvent('B', name, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMarkEndEvent(name: string, time: number) {
|
function createMarkEndEvent(name: string, time: number) {
|
||||||
return createEvent('e', name, time);
|
return createEvent('E', name, time);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ export class TraceEventFactory {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
markStart(name: string, time: number) { return this.create('b', name, time); }
|
markStart(name: string, time: number) { return this.create('B', name, time); }
|
||||||
|
|
||||||
markEnd(name: string, time: number) { return this.create('e', name, time); }
|
markEnd(name: string, time: number) { return this.create('E', name, time); }
|
||||||
|
|
||||||
start(name: string, time: number, args: any = null) { return this.create('B', name, time, args); }
|
start(name: string, time: number, args: any = null) { return this.create('B', name, time, args); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue