Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline_model/TimelineJSProfile.js

Issue 2729793003: DevTools: Support reading CPU profile format on Performance panel (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 TimelineModel.TimelineJSProfileProcessor = class { 5 TimelineModel.TimelineJSProfileProcessor = class {
6 /** 6 /**
7 * @param {!SDK.CPUProfileDataModel} jsProfileModel 7 * @param {!SDK.CPUProfileDataModel} jsProfileModel
8 * @param {!SDK.TracingModel.Thread} thread 8 * @param {!SDK.TracingModel.Thread} thread
9 * @return {!Array<!SDK.TracingModel.Event>} 9 * @return {!Array<!SDK.TracingModel.Event>}
10 */ 10 */
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 ['CompileIgnition', nativeGroups.Compile], ['CompilerDispatcher', native Groups.Compile], 224 ['CompileIgnition', nativeGroups.Compile], ['CompilerDispatcher', native Groups.Compile],
225 ['CompileSerialize', nativeGroups.Compile], ['ParseProgram', nativeGroup s.Parse], 225 ['CompileSerialize', nativeGroups.Compile], ['ParseProgram', nativeGroup s.Parse],
226 ['ParseFunction', nativeGroups.Parse], ['RecompileConcurrent', nativeGro ups.Compile], 226 ['ParseFunction', nativeGroups.Parse], ['RecompileConcurrent', nativeGro ups.Compile],
227 ['RecompileSynchronous', nativeGroups.Compile], ['ParseLazy', nativeGrou ps.Parse] 227 ['RecompileSynchronous', nativeGroups.Compile], ['ParseLazy', nativeGrou ps.Parse]
228 ]); 228 ]);
229 /** @type {!Map<string, !TimelineModel.TimelineJSProfileProcessor.NativeGr oups>} */ 229 /** @type {!Map<string, !TimelineModel.TimelineJSProfileProcessor.NativeGr oups>} */
230 TimelineModel.TimelineJSProfileProcessor.nativeGroup._map = map; 230 TimelineModel.TimelineJSProfileProcessor.nativeGroup._map = map;
231 } 231 }
232 return map.get(nativeName) || null; 232 return map.get(nativeName) || null;
233 } 233 }
234
235 /**
236 * @param {*} profile
caseq 2017/03/02 19:00:40 ?Object
alph 2017/03/02 19:20:00 This actually could be anything, as it comes out o
237 * @return {!Array<!SDK.TracingManager.EventPayload>}
238 */
239 static buildTraceProfileFromCpuProfile(profile) {
240 if (!profile)
241 return [];
242 var start = profile.startTime;
243 var events = [];
244 appendEvent('TracingStartedInPage', {'sessionId': '1'}, 0, 0, 'M');
245 var idToNode = new Map();
246 for (var i = 0; i < profile.nodes.length; ++i)
caseq 2017/03/02 19:00:40 profile['nodes']...
alph 2017/03/02 19:20:00 Done.
247 idToNode.set(profile.nodes[i].id, profile.nodes[i]);
248 var stateProgram = '(program)';
249 var stateIdle = '(idle)';
250 var stateFunction = '(function)';
251 var state = stateIdle;
252 var programEvent = null;
253 var functionEvent = null;
254 var nextTime = start;
255 for (var i = 0; i < profile.samples.length; ++i) {
256 var currentTime = nextTime;
257 nextTime += profile.timeDeltas[i];
258 var id = profile.samples[i];
259 var node = idToNode.get(id);
260 var name = node.callFrame.functionName;
261 if (state === name)
caseq 2017/03/02 19:00:40 Let's keep the state space separate from names spa
alph 2017/03/02 19:20:00 Done.
262 continue;
263 if (state === stateIdle) {
264 programEvent = appendEvent('MessageLoop::RunTask', {}, currentTime, 0, ' X', 'toplevel');
265 state = stateProgram;
266 if (name !== '(program)') {
267 functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, curren tTime, 0);
268 state = stateFunction;
269 }
270 continue;
271 }
272 if (name === stateIdle) {
273 if (programEvent)
274 programEvent.dur = currentTime - programEvent.ts;
275 if (functionEvent)
276 functionEvent.dur = currentTime - functionEvent.ts;
277 programEvent = null;
278 functionEvent = null;
279 state = stateIdle;
280 continue;
281 }
282 // Remaining cases program->function and function->program.
283 if (name === stateProgram) {
284 functionEvent.dur = currentTime - functionEvent.ts;
285 functionEvent = null;
286 state = stateProgram;
287 } else if (state === stateProgram) {
288 functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, currentT ime, 0);
289 state = stateFunction;
290 }
291 }
292 appendEvent('CpuProfile', {'cpuProfile': profile}, profile.endTime, 0, 'I');
293 events.sort((a, b) => a.startTime - b.startTime);
294 return events;
295
296 /**
297 * @param {string} name
298 * @param {*} data
299 * @param {number} ts
300 * @param {number=} dur
301 * @param {string=} ph
302 * @param {string=} cat
303 * @return {!SDK.TracingManager.EventPayload}
304 */
305 function appendEvent(name, data, ts, dur, ph, cat) {
306 var event = /** @type {!SDK.TracingManager.EventPayload} */ ({
307 cat: cat || 'disabled-by-default-devtools.timeline',
308 name: name,
309 ph: ph || 'X',
310 pid: 1,
311 tid: 1,
312 ts: ts,
313 args: {data: data}
314 });
315 if (dur)
316 event.dur = dur;
317 events.push(event);
318 return event;
319 }
320 }
234 }; 321 };
235 322
236 /** @enum {string} */ 323 /** @enum {string} */
237 TimelineModel.TimelineJSProfileProcessor.NativeGroups = { 324 TimelineModel.TimelineJSProfileProcessor.NativeGroups = {
238 'Compile': 'Compile', 325 'Compile': 'Compile',
239 'Parse': 'Parse' 326 'Parse': 'Parse'
240 }; 327 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698