| 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 events = []; |
| 243 appendEvent('TracingStartedInPage', {'sessionId': '1'}, 0, 0, 'M'); |
| 244 var idToNode = new Map(); |
| 245 var nodes = profile['nodes']; |
| 246 for (var i = 0; i < nodes.length; ++i) |
| 247 idToNode.set(nodes[i].id, nodes[i]); |
| 248 var programEvent = null; |
| 249 var functionEvent = null; |
| 250 var nextTime = profile.startTime; |
| 251 var currentTime; |
| 252 var samples = profile['samples']; |
| 253 var timeDeltas = profile['timeDeltas']; |
| 254 for (var i = 0; i < samples.length; ++i) { |
| 255 currentTime = nextTime; |
| 256 nextTime += timeDeltas[i]; |
| 257 var node = idToNode.get(samples[i]); |
| 258 var name = node.callFrame.functionName; |
| 259 if (name === '(idle)') { |
| 260 closeEvents(); |
| 261 continue; |
| 262 } |
| 263 if (!programEvent) |
| 264 programEvent = appendEvent('MessageLoop::RunTask', {}, currentTime, 0, '
X', 'toplevel'); |
| 265 if (name === '(program)') { |
| 266 if (functionEvent) { |
| 267 functionEvent.dur = currentTime - functionEvent.ts; |
| 268 functionEvent = null; |
| 269 } |
| 270 } else { |
| 271 // A JS function. |
| 272 if (!functionEvent) |
| 273 functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, curren
tTime); |
| 274 } |
| 275 } |
| 276 closeEvents(); |
| 277 appendEvent('CpuProfile', {'cpuProfile': profile}, profile.endTime, 0, 'I'); |
| 278 return events; |
| 279 |
| 280 function closeEvents() { |
| 281 if (programEvent) |
| 282 programEvent.dur = currentTime - programEvent.ts; |
| 283 if (functionEvent) |
| 284 functionEvent.dur = currentTime - functionEvent.ts; |
| 285 programEvent = null; |
| 286 functionEvent = null; |
| 287 } |
| 288 |
| 289 /** |
| 290 * @param {string} name |
| 291 * @param {*} data |
| 292 * @param {number} ts |
| 293 * @param {number=} dur |
| 294 * @param {string=} ph |
| 295 * @param {string=} cat |
| 296 * @return {!SDK.TracingManager.EventPayload} |
| 297 */ |
| 298 function appendEvent(name, data, ts, dur, ph, cat) { |
| 299 var event = /** @type {!SDK.TracingManager.EventPayload} */ ({ |
| 300 cat: cat || 'disabled-by-default-devtools.timeline', |
| 301 name: name, |
| 302 ph: ph || 'X', |
| 303 pid: 1, |
| 304 tid: 1, |
| 305 ts: ts, |
| 306 args: {data: data} |
| 307 }); |
| 308 if (dur) |
| 309 event.dur = dur; |
| 310 events.push(event); |
| 311 return event; |
| 312 } |
| 313 } |
| 234 }; | 314 }; |
| 235 | 315 |
| 236 /** @enum {string} */ | 316 /** @enum {string} */ |
| 237 TimelineModel.TimelineJSProfileProcessor.NativeGroups = { | 317 TimelineModel.TimelineJSProfileProcessor.NativeGroups = { |
| 238 'Compile': 'Compile', | 318 'Compile': 'Compile', |
| 239 'Parse': 'Parse' | 319 'Parse': 'Parse' |
| 240 }; | 320 }; |
| OLD | NEW |