Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Unified Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelineModel.js

Issue 1748993002: DevTools: Initial implementation of line-level CPU profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/timeline/TimelineModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineModel.js b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineModel.js
index 3a47aec5c1f3dda19bb816c34635b982732b2f1b..f2762eaca7fb652b9d98bd20060855d214c4d957 100644
--- a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineModel.js
@@ -729,8 +729,11 @@ WebInspector.TimelineModel.prototype = {
var cpuProfileEvent = events.peekLast();
if (cpuProfileEvent && cpuProfileEvent.name === WebInspector.TimelineModel.RecordType.CpuProfile) {
var cpuProfile = cpuProfileEvent.args["data"]["cpuProfile"];
- if (cpuProfile)
- jsSamples = WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile(cpuProfile, thread);
+ if (cpuProfile) {
+ var jsProfileModel = new WebInspector.CPUProfileDataModel(cpuProfile);
+ this._lineLevelCPUProfile.appendCPUProfile(jsProfileModel);
+ jsSamples = WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile(jsProfileModel, thread);
+ }
}
}
@@ -1061,6 +1064,7 @@ WebInspector.TimelineModel.prototype = {
reset: function()
{
+ this._lineLevelCPUProfile = new WebInspector.TimelineModel.LineLevelProfile();
this._virtualThreads = [];
/** @type {!Array.<!WebInspector.TracingModel.Event>} */
this._mainThreadEvents = [];
@@ -1085,6 +1089,14 @@ WebInspector.TimelineModel.prototype = {
},
/**
+ * @return {!WebInspector.TimelineModel.LineLevelProfile}
+ */
+ lineLevelCPUProfile: function()
+ {
+ return this._lineLevelCPUProfile;
+ },
+
+ /**
* @return {number}
*/
minimumRecordTime: function()
@@ -1723,3 +1735,51 @@ WebInspector.TimelineAsyncEventTracker.prototype = {
event.initiator = initiatorMap.get(id) || null;
}
}
+
+/**
+ * @constructor
+ */
+WebInspector.TimelineModel.LineLevelProfile = function()
+{
+ /** @type {!Map<string, !Map<number, number>>} */
+ this._files = new Map();
+}
+
+WebInspector.TimelineModel.LineLevelProfile.prototype = {
+ /**
+ * @param {!WebInspector.CPUProfileDataModel} profile
+ */
+ appendCPUProfile: function(profile)
+ {
+ var nodesToGo = [profile.profileHead];
+ var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / profile.totalHitCount;
+ while (nodesToGo.length) {
+ var nodes = nodesToGo.pop().children;
+ for (var i = 0; i < nodes.length; ++i) {
+ var node = nodes[i];
+ nodesToGo.push(node);
+ if (!node.url || !node.positionTicks)
+ continue;
+ var fileInfo = this._files.get(node.url);
+ if (!fileInfo) {
+ fileInfo = new Map();
+ this._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);
+ }
+ }
+ }
+ },
+
+ /**
+ * @return {!Map<string, !Map<number, number>>}
+ */
+ files: function()
+ {
+ return this._files;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698