fix(benchpress): support nested intervals
Chrome sometimes reports nested `FunctionCall` intervals in the timeline, which should be ignored for measuring the `script` metric. Might solve #2116
This commit is contained in:
parent
b071b66b45
commit
c280fe816c
|
@ -168,7 +168,8 @@ export class PerflogMetric extends Metric {
|
|||
var gcTimeInScript = 0;
|
||||
var renderTimeInScript = 0;
|
||||
|
||||
var intervalStarts = {};
|
||||
var intervalStarts: StringMap<string, any> = {};
|
||||
var intervalStartCount: StringMap<string, number> = {};
|
||||
events.forEach((event) => {
|
||||
var ph = event['ph'];
|
||||
var name = event['name'];
|
||||
|
@ -187,9 +188,16 @@ export class PerflogMetric extends Metric {
|
|||
if (isPresent(markStartEvent) && isBlank(markEndEvent) &&
|
||||
event['pid'] === markStartEvent['pid']) {
|
||||
if (StringWrapper.equals(ph, 'B') || StringWrapper.equals(ph, 'b')) {
|
||||
if (isBlank(intervalStarts[name])) {
|
||||
intervalStartCount[name] = 1;
|
||||
intervalStarts[name] = event;
|
||||
} else {
|
||||
intervalStartCount[name]++;
|
||||
}
|
||||
} else if ((StringWrapper.equals(ph, 'E') || StringWrapper.equals(ph, 'e')) &&
|
||||
isPresent(intervalStarts[name])) {
|
||||
intervalStartCount[name]--;
|
||||
if (intervalStartCount[name] === 0) {
|
||||
var startEvent = intervalStarts[name];
|
||||
var duration = (event['ts'] - startEvent['ts']);
|
||||
intervalStarts[name] = null;
|
||||
|
@ -217,6 +225,7 @@ export class PerflogMetric extends Metric {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
result['pureScriptTime'] = result['scriptTime'] - gcTimeInScript - renderTimeInScript;
|
||||
return isPresent(markStartEvent) && isPresent(markEndEvent) ? result : null;
|
||||
|
|
|
@ -343,6 +343,19 @@ export function main() {
|
|||
});
|
||||
}));
|
||||
|
||||
it('should ignore nested intervals', inject([AsyncTestCompleter], (async) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0),
|
||||
eventFactory.start('script', 5),
|
||||
eventFactory.end('script', 10),
|
||||
eventFactory.end('script', 17)
|
||||
])
|
||||
.then((data) => {
|
||||
expect(data['scriptTime']).toBe(17);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore events from different processed as the start mark',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||
|
|
Loading…
Reference in New Issue