Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/timeline/TimelineJSProfile.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineJSProfile.js b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineJSProfile.js |
| index ea1e23a3123759c3492dfe581a30c41828784ed1..1daabd70849453dc0bb53d4ca887dbb51feb511b 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineJSProfile.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineJSProfile.js |
| @@ -6,15 +6,12 @@ |
| WebInspector.TimelineJSProfileProcessor = { }; |
| /** |
| - * @param {!ProfilerAgent.CPUProfile} jsProfile |
| + * @param {!WebInspector.CPUProfileDataModel} jsProfileModel |
| * @param {!WebInspector.TracingModel.Thread} thread |
| * @return {!Array<!WebInspector.TracingModel.Event>} |
| */ |
| -WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile = function(jsProfile, thread) |
| +WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile = function(jsProfileModel, thread) |
| { |
| - if (!jsProfile.samples) |
| - return []; |
| - var jsProfileModel = new WebInspector.CPUProfileDataModel(jsProfile); |
| var idleNode = jsProfileModel.idleNode; |
| var programNode = jsProfileModel.programNode; |
| var gcNode = jsProfileModel.gcNode; |
| @@ -494,3 +491,66 @@ WebInspector.TimelineJSProfileProcessor.processRawV8Samples = function(events) |
| return samples; |
| } |
| + |
| +/** |
| + * @param {!WebInspector.CPUProfileDataModel} profile |
| + */ |
| +WebInspector.TimelineJSProfileProcessor.buildLineLevelProfiles = function(profile) |
| +{ |
| + if (!Runtime.experiments.isEnabled("lineLevelProfile")) |
| + return; |
| + var nodesToGo = [profile.profileHead]; |
| + var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / profile.totalHitCount; |
| + /** @type {!Map<string, !Map<number,number>>} */ |
| + var files = new Map(); |
| + while (nodesToGo.length) { |
| + var nodes = nodesToGo.pop().children; |
| + for (var i = 0; i < nodes.length; ++i) { |
| + var node = nodes[i]; |
| + if (!node.url) |
| + continue; |
| + var fileInfo = files.get(node.url); |
| + if (!fileInfo) { |
| + fileInfo = new Map(); |
| + files.set(node.url, fileInfo); |
| + } |
| + for (var j = 0; j < node.positionTicks.length; ++j) { |
| + var lineInfo = node.positionTicks[j]; |
| + var line = lineInfo.line - 1; |
| + var time = lineInfo.ticks * sampleDuration; |
| + fileInfo.set(line, (fileInfo.get(line) || 0) + time); |
| + } |
| + nodesToGo.push(node); |
| + } |
| + } |
| + for (var fileInfo of files) { |
| + var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(fileInfo[0]); |
| + if (!uiSourceCode) |
| + continue; |
| + var decorator = profileInfoDecorator.bind(null, fileInfo[1]); |
| + for (var line of fileInfo[1].keys()) |
| + uiSourceCode.addLineMarker(line, decorator); |
|
pfeldman
2016/03/02 19:48:59
addLineMarker(line, "performance", fileInfo[1]);
alph
2016/03/03 02:02:52
Done.
|
| + } |
| + files.clear(); |
| + |
| + /** |
| + * @param {!Map<number, number>} fileInfo |
| + * @param {number} lineNumber |
| + * @return {!{text: string, color: string}} |
| + */ |
| + function profileInfoDecorator(fileInfo, lineNumber) |
| + { |
| + var time = fileInfo.get(lineNumber) || 0; |
| + var text = WebInspector.UIString("%.1f\xa0ms", time); |
| + var intensity = Number.constrain(Math.log10(1 + 2 * time) / 5, 0.02, 1); |
| + var color = `rgba(255, 0, 0, ${intensity.toFixed(3)})`; |
| + return { text: text, color: color }; |
| + } |
| +} |
| + |
| +WebInspector.TimelineJSProfileProcessor.resetLineLevelProfiles = function() |
| +{ |
| + if (!Runtime.experiments.isEnabled("lineLevelProfile")) |
| + return; |
| + WebInspector.workspace.uiSourceCodes().forEach(uiSourceCode => uiSourceCode.removeAllLineMarkers()); |
| +} |