Commit 86bdb457 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Make DevTools performance work for ndb

Do not generate multiple TracingStatedInPage events. It was causing N^2 passes
over CPU profiles slowing down execution and consuming lots of memory.

Change-Id: Id8c3293a7cc92a2cc611746f68c92a2c9a0b63f6
Reviewed-on: https://chromium-review.googlesource.com/1179239
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583940}
parent 125e3706
......@@ -302,16 +302,12 @@ Timeline.TimelineController = class {
} else {
// Or there was no tracing manager in the main target at all, in this case build the model full
// of cpu profiles.
// Assign tids equal to the target ordinals for the thread name lookup.
// This is a little shaky because targets can disappear, but we will read these tids sooner than
// that.
// TODO(pfeldman): resolve this.
let counter = 1000;
let tid = 0;
for (const pair of this._cpuProfiles) {
const target = SDK.targetManager.targetById(pair[0]);
const tid = target ? SDK.targetManager.targets().indexOf(target) : ++counter;
this._tracingModel.addEvents(
TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(pair[1], tid));
const name = target && target.name();
this._tracingModel.addEvents(TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(
pair[1], ++tid, /* injectPageEvent */ tid === 1, name));
}
}
}
......
......@@ -221,7 +221,8 @@ Timeline.TimelineLoader = class {
let traceEvents;
try {
const profile = JSON.parse(text);
traceEvents = TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(profile, 1);
traceEvents = TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(
profile, /* tid */ 1, /* injectPageEvent */ true);
} catch (e) {
this._reportErrorAndCancelLoading(Common.UIString('Malformed CPU profile format'));
return;
......
......@@ -228,13 +228,19 @@ TimelineModel.TimelineJSProfileProcessor = class {
/**
* @param {*} profile
* @param {number} tid
* @param {boolean} injectPageEvent
* @param {?string=} name
* @return {!Array<!SDK.TracingManager.EventPayload>}
*/
static buildTraceProfileFromCpuProfile(profile, tid) {
if (!profile)
return [];
static buildTraceProfileFromCpuProfile(profile, tid, injectPageEvent, name) {
const events = [];
appendEvent('TracingStartedInPage', {'sessionId': '1'}, 0, 0, 'M');
if (injectPageEvent)
appendEvent('TracingStartedInPage', {data: {'sessionId': '1'}}, 0, 0, 'M');
if (!name)
name = ls`Thread ${tid}`;
appendEvent(SDK.TracingModel.MetadataEvent.ThreadName, {name}, 0, 0, 'M', '__metadata');
if (!profile)
return events;
const idToNode = new Map();
const nodes = profile['nodes'];
for (let i = 0; i < nodes.length; ++i)
......@@ -264,11 +270,11 @@ TimelineModel.TimelineJSProfileProcessor = class {
} else {
// A JS function.
if (!functionEvent)
functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, currentTime);
functionEvent = appendEvent('FunctionCall', {data: {'sessionId': '1'}}, currentTime);
}
}
closeEvents();
appendEvent('CpuProfile', {'cpuProfile': profile}, profile.endTime, 0, 'I');
appendEvent('CpuProfile', {data: {'cpuProfile': profile}}, profile.endTime, 0, 'I');
return events;
function closeEvents() {
......@@ -282,23 +288,16 @@ TimelineModel.TimelineJSProfileProcessor = class {
/**
* @param {string} name
* @param {*} data
* @param {*} args
* @param {number} ts
* @param {number=} dur
* @param {string=} ph
* @param {string=} cat
* @return {!SDK.TracingManager.EventPayload}
*/
function appendEvent(name, data, ts, dur, ph, cat) {
const event = /** @type {!SDK.TracingManager.EventPayload} */ ({
cat: cat || 'disabled-by-default-devtools.timeline',
name: name,
ph: ph || 'X',
pid: 1,
tid,
ts: ts,
args: {data: data}
});
function appendEvent(name, args, ts, dur, ph, cat) {
const event = /** @type {!SDK.TracingManager.EventPayload} */ (
{cat: cat || 'disabled-by-default-devtools.timeline', name, ph: ph || 'X', pid: 1, tid, ts, args});
if (dur)
event.dur = dur;
events.push(event);
......
......@@ -201,6 +201,8 @@ TimelineModel.TimelineModel = class {
const metaEvent = metadataEvents.page[i];
const process = metaEvent.thread.process();
const endTime = i + 1 < length ? metadataEvents.page[i + 1].startTime : Infinity;
if (startTime === endTime)
continue;
this._legacyCurrentPage = metaEvent.args['data'] && metaEvent.args['data']['page'];
for (const thread of process.sortedThreads()) {
let workerUrl = null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment