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 if (!Runtime.experiments.isEnabled("lineLevelProfile")) | |
| 501 return; | |
| 502 var nodesToGo = [profile.profileHead]; | |
| 503 var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / p rofile.totalHitCount; | |
| 504 /** @type {!Map<string, !Map<number,number>>} */ | |
| 505 var files = new Map(); | |
| 506 while (nodesToGo.length) { | |
| 507 var nodes = nodesToGo.pop().children; | |
| 508 for (var i = 0; i < nodes.length; ++i) { | |
| 509 var node = nodes[i]; | |
| 510 if (!node.url) | |
| 511 continue; | |
| 512 var fileInfo = files.get(node.url); | |
| 513 if (!fileInfo) { | |
| 514 fileInfo = new Map(); | |
| 515 files.set(node.url, fileInfo); | |
| 516 } | |
| 517 for (var j = 0; j < node.positionTicks.length; ++j) { | |
| 518 var lineInfo = node.positionTicks[j]; | |
| 519 var line = lineInfo.line - 1; | |
| 520 var time = lineInfo.ticks * sampleDuration; | |
| 521 fileInfo.set(line, (fileInfo.get(line) || 0) + time); | |
| 522 } | |
| 523 nodesToGo.push(node); | |
| 524 } | |
| 525 } | |
| 526 for (var fileInfo of files) { | |
| 527 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(fileInfo[0] ); | |
| 528 if (!uiSourceCode) | |
| 529 continue; | |
| 530 var decorator = profileInfoDecorator.bind(null, fileInfo[1]); | |
| 531 for (var line of fileInfo[1].keys()) | |
| 532 uiSourceCode.addLineMarker(line, decorator); | |
|
pfeldman
2016/03/02 19:48:59
addLineMarker(line, "performance", fileInfo[1]);
alph
2016/03/03 02:02:52
Done.
| |
| 533 } | |
| 534 files.clear(); | |
| 535 | |
| 536 /** | |
| 537 * @param {!Map<number, number>} fileInfo | |
| 538 * @param {number} lineNumber | |
| 539 * @return {!{text: string, color: string}} | |
| 540 */ | |
| 541 function profileInfoDecorator(fileInfo, lineNumber) | |
| 542 { | |
| 543 var time = fileInfo.get(lineNumber) || 0; | |
| 544 var text = WebInspector.UIString("%.1f\xa0ms", time); | |
| 545 var intensity = Number.constrain(Math.log10(1 + 2 * time) / 5, 0.02, 1); | |
| 546 var color = `rgba(255, 0, 0, ${intensity.toFixed(3)})`; | |
| 547 return { text: text, color: color }; | |
| 548 } | |
| 549 } | |
| 550 | |
| 551 WebInspector.TimelineJSProfileProcessor.resetLineLevelProfiles = function() | |
| 552 { | |
| 553 if (!Runtime.experiments.isEnabled("lineLevelProfile")) | |
| 554 return; | |
| 555 WebInspector.workspace.uiSourceCodes().forEach(uiSourceCode => uiSourceCode. removeAllLineMarkers()); | |
| 556 } | |
| OLD | NEW |