Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
| 237 * @return {!Array<!SDK.TracingManager.EventPayload>} | |
| 238 */ | |
| 239 static buildTraceProfileFromCpuProfile(profile) { | |
| 240 if (!profile) | |
| 241 return []; | |
| 242 var start = profile.startTime; | |
|
caseq
2017/03/02 21:27:05
remove start, assign directly?
alph
2017/03/02 22:17:25
Done.
| |
| 243 var events = []; | |
| 244 appendEvent('TracingStartedInPage', {'sessionId': '1'}, 0, 0, 'M'); | |
| 245 var idToNode = new Map(); | |
| 246 var nodes = profile['nodes']; | |
| 247 for (var i = 0; i < nodes.length; ++i) | |
| 248 idToNode.set(nodes[i].id, nodes[i]); | |
| 249 var stateProgram = Symbol('program'); | |
| 250 var stateIdle = Symbol('idle'); | |
| 251 var stateFunction = Symbol('function'); | |
| 252 var state = stateIdle; | |
| 253 var programEvent = null; | |
| 254 var functionEvent = null; | |
| 255 var nextTime = start; | |
| 256 var samples = profile['samples']; | |
| 257 var timeDeltas = profile['timeDeltas']; | |
| 258 for (var i = 0; i < samples.length; ++i) { | |
| 259 var currentTime = nextTime; | |
| 260 nextTime += timeDeltas[i]; | |
| 261 var id = samples[i]; | |
| 262 var node = idToNode.get(id); | |
| 263 var name = node.callFrame.functionName; | |
|
caseq
2017/03/02 21:27:05
topFunctionName?
alph
2017/03/02 22:17:25
Let me keep it. It's not important that it's a top
| |
| 264 if (state === stateIdle) { | |
| 265 if (name === '(idle)') | |
| 266 continue; | |
| 267 programEvent = appendEvent('MessageLoop::RunTask', {}, currentTime, 0, ' X', 'toplevel'); | |
| 268 state = stateProgram; | |
| 269 if (name !== '(program)') { | |
| 270 functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, curren tTime, 0); | |
| 271 state = stateFunction; | |
| 272 } | |
| 273 continue; | |
| 274 } | |
| 275 if (name === '(idle)') { | |
| 276 if (programEvent) | |
| 277 programEvent.dur = currentTime - programEvent.ts; | |
| 278 if (functionEvent) | |
| 279 functionEvent.dur = currentTime - functionEvent.ts; | |
| 280 programEvent = null; | |
| 281 functionEvent = null; | |
| 282 state = stateIdle; | |
| 283 continue; | |
| 284 } | |
| 285 // Remaining cases program->function and function->program. | |
| 286 if (name === '(program)') { | |
| 287 if (state === stateProgram) | |
| 288 continue; | |
| 289 functionEvent.dur = currentTime - functionEvent.ts; | |
| 290 functionEvent = null; | |
| 291 state = stateProgram; | |
| 292 } else if (state === stateProgram) { | |
| 293 functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, currentT ime, 0); | |
| 294 state = stateFunction; | |
| 295 } | |
| 296 } | |
| 297 appendEvent('CpuProfile', {'cpuProfile': profile}, profile.endTime, 0, 'I'); | |
| 298 events.sort((a, b) => a.startTime - b.startTime); | |
| 299 return events; | |
| 300 | |
| 301 /** | |
| 302 * @param {string} name | |
| 303 * @param {*} data | |
| 304 * @param {number} ts | |
| 305 * @param {number=} dur | |
| 306 * @param {string=} ph | |
| 307 * @param {string=} cat | |
| 308 * @return {!SDK.TracingManager.EventPayload} | |
| 309 */ | |
| 310 function appendEvent(name, data, ts, dur, ph, cat) { | |
| 311 var event = /** @type {!SDK.TracingManager.EventPayload} */ ({ | |
| 312 cat: cat || 'disabled-by-default-devtools.timeline', | |
| 313 name: name, | |
| 314 ph: ph || 'X', | |
| 315 pid: 1, | |
| 316 tid: 1, | |
| 317 ts: ts, | |
| 318 args: {data: data} | |
| 319 }); | |
| 320 if (dur) | |
| 321 event.dur = dur; | |
| 322 events.push(event); | |
| 323 return event; | |
| 324 } | |
| 325 } | |
| 234 }; | 326 }; |
| 235 | 327 |
| 236 /** @enum {string} */ | 328 /** @enum {string} */ |
| 237 TimelineModel.TimelineJSProfileProcessor.NativeGroups = { | 329 TimelineModel.TimelineJSProfileProcessor.NativeGroups = { |
| 238 'Compile': 'Compile', | 330 'Compile': 'Compile', |
| 239 'Parse': 'Parse' | 331 'Parse': 'Parse' |
| 240 }; | 332 }; |
| OLD | NEW |