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 | 5 |
| 6 WebInspector.TimelineJSProfileProcessor = { }; | 6 WebInspector.TimelineJSProfileProcessor = { }; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * @param {!ProfilerAgent.CPUProfile} jsProfile | 9 * @param {!WebInspector.CPUProfileDataModel} jsProfileModel |
| 10 * @param {!WebInspector.TracingModel.Thread} thread | 10 * @param {!WebInspector.TracingModel.Thread} thread |
| 11 * @return {!Array<!WebInspector.TracingModel.Event>} | 11 * @return {!Array<!WebInspector.TracingModel.Event>} |
| 12 */ | 12 */ |
| 13 WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile = fu nction(jsProfile, thread) | 13 WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile = fu nction(jsProfileModel, thread) |
| 14 { | 14 { |
| 15 if (!jsProfile.samples) | |
| 16 return []; | |
| 17 var jsProfileModel = new WebInspector.CPUProfileDataModel(jsProfile); | |
| 18 var idleNode = jsProfileModel.idleNode; | 15 var idleNode = jsProfileModel.idleNode; |
| 19 var programNode = jsProfileModel.programNode; | 16 var programNode = jsProfileModel.programNode; |
| 20 var gcNode = jsProfileModel.gcNode; | 17 var gcNode = jsProfileModel.gcNode; |
| 21 var samples = jsProfileModel.samples; | 18 var samples = jsProfileModel.samples; |
| 22 var timestamps = jsProfileModel.timestamps; | 19 var timestamps = jsProfileModel.timestamps; |
| 23 var jsEvents = []; | 20 var jsEvents = []; |
| 24 /** @type {!Map<!Object, !Array<!RuntimeAgent.CallFrame>>} */ | 21 /** @type {!Map<!Object, !Array<!RuntimeAgent.CallFrame>>} */ |
| 25 var nodeToStackMap = new Map(); | 22 var nodeToStackMap = new Map(); |
| 26 nodeToStackMap.set(programNode, []); | 23 nodeToStackMap.set(programNode, []); |
| 27 for (var i = 0; i < samples.length; ++i) { | 24 for (var i = 0; i < samples.length; ++i) { |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 WebInspector.TracingModel.Phase.Instant, e.startTime, e.thread); | 484 WebInspector.TracingModel.Phase.Instant, e.startTime, e.thread); |
| 488 sampleEvent.ordinal = e.ordinal; | 485 sampleEvent.ordinal = e.ordinal; |
| 489 sampleEvent.args = {"data": {"stackTrace": stack }}; | 486 sampleEvent.args = {"data": {"stackTrace": stack }}; |
| 490 samples.push(sampleEvent); | 487 samples.push(sampleEvent); |
| 491 break; | 488 break; |
| 492 } | 489 } |
| 493 } | 490 } |
| 494 | 491 |
| 495 return samples; | 492 return samples; |
| 496 } | 493 } |
| 494 | |
| 495 /** | |
| 496 * @param {!WebInspector.CPUProfileDataModel} profile | |
| 497 */ | |
| 498 WebInspector.TimelineJSProfileProcessor.buildLineLevelProfiles = function(profil e) | |
| 499 { | |
| 500 var nodesToGo = [profile.profileHead]; | |
| 501 var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / p rofile.totalHitCount; | |
| 502 /** @type {!Map<string, !Map<number,number>>} */ | |
| 503 var files = new Map(); | |
| 504 while (nodesToGo.length) { | |
| 505 var nodes = nodesToGo.pop().children; | |
| 506 for (var i = 0; i < nodes.length; ++i) { | |
| 507 var node = nodes[i]; | |
| 508 if (!node.url || !node.positionTicks) | |
| 509 continue; | |
| 510 var fileInfo = files.get(node.url); | |
| 511 if (!fileInfo) { | |
| 512 fileInfo = new Map(); | |
| 513 files.set(node.url, fileInfo); | |
| 514 } | |
| 515 for (var j = 0; j < node.positionTicks.length; ++j) { | |
| 516 var lineInfo = node.positionTicks[j]; | |
| 517 var line = lineInfo.line - 1; | |
| 518 var time = lineInfo.ticks * sampleDuration; | |
| 519 fileInfo.set(line, (fileInfo.get(line) || 0) + time); | |
| 520 } | |
| 521 nodesToGo.push(node); | |
| 522 } | |
| 523 } | |
| 524 for (var fileInfo of files) { | |
| 525 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(/** @type { string} */ (fileInfo[0])); | |
| 526 if (!uiSourceCode) | |
| 527 continue; | |
| 528 for (var lineInfo of fileInfo[1]) { | |
| 529 var line = lineInfo[0]; | |
| 530 var time = lineInfo[1]; | |
| 531 var text = WebInspector.UIString("%.1f\xa0ms", time); | |
|
caseq
2016/03/11 22:52:05
Can we get UI stuff out of model classes?
alph
2016/03/12 00:47:54
Done.
| |
| 532 var intensity = Number.constrain(Math.log10(1 + 2 * time) / 5, 0.02, 1); | |
| 533 var object = { | |
| 534 text: text, | |
| 535 intensity: intensity | |
| 536 }; | |
| 537 uiSourceCode.addLineDecoration(line, "performance", object); | |
|
caseq
2016/03/11 22:52:05
ditto.
alph
2016/03/12 00:47:54
Done.
| |
| 538 } | |
| 539 } | |
| 540 } | |
| 541 | |
| 542 WebInspector.TimelineJSProfileProcessor.resetLineLevelProfiles = function() | |
| 543 { | |
| 544 WebInspector.workspace.uiSourceCodes().forEach(uiSourceCode => uiSourceCode. removeAllLineDecorations("performance")); | |
| 545 } | |
| OLD | NEW |