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

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js

Issue 2244783004: DevTools: Refactor Profiler domain interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/sdk/CPUProfileDataModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js
index 26ed0e3eaab8a60e2e4116b65e34f6a588ba5c1d..0c98355352cd8fc8e8edc7d85f5df0cd1eb9793d 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js
@@ -42,7 +42,7 @@ WebInspector.CPUProfileDataModel = function(profile)
this.profileStartTime = profile.startTime * 1000;
this.profileEndTime = profile.endTime * 1000;
this.totalHitCount = 0;
- this.profileHead = this._translateProfileTree(profile.head);
+ this.profileHead = this._translateProfileTree(profile.nodes);
WebInspector.ProfileTreeModel.call(this, this.profileHead);
this._extractMetaNodes();
if (this.samples) {
@@ -54,20 +54,12 @@ WebInspector.CPUProfileDataModel = function(profile)
WebInspector.CPUProfileDataModel.prototype = {
/**
- * @param {!ProfilerAgent.CPUProfileNode} root
+ * @param {!Array<!ProfilerAgent.CPUProfileNode>} nodes
* @return {!WebInspector.CPUProfileNode}
*/
- _translateProfileTree: function(root)
+ _translateProfileTree: function(nodes)
{
/**
- * @param {!ProfilerAgent.CPUProfileNode} node
- * @return {number}
- */
- function computeHitCountForSubtree(node)
- {
- return node.children.reduce((acc, node) => acc + computeHitCountForSubtree(node), node.hitCount);
- }
- /**
* @param {!ProfilerAgent.CPUProfileNode} node
* @return {boolean}
*/
@@ -77,14 +69,21 @@ WebInspector.CPUProfileDataModel.prototype = {
return !!node.callFrame.url && node.callFrame.url.startsWith("native ");
return !!node.url && node.url.startsWith("native ");
}
- this.totalHitCount = computeHitCountForSubtree(root);
+ /** @type {!Map<number, !ProfilerAgent.CPUProfileNode>} */
+ var nodeByIdMap = new Map();
+ for (var i = 0; i < nodes.length; ++i) {
+ var node = nodes[i];
+ nodeByIdMap.set(node.id, node);
+ }
+ this.totalHitCount = nodes.reduce((acc, node) => acc + node.hitCount, 0);
var sampleTime = (this.profileEndTime - this.profileStartTime) / this.totalHitCount;
var keepNatives = !!WebInspector.moduleSetting("showNativeFunctionsInJSProfile").get();
+ var root = nodes[0];
/** @type {!Map<number, number>} */
var idMap = new Map([[root.id, root.id]]);
var resultRoot = new WebInspector.CPUProfileNode(root, sampleTime);
var parentNodeStack = root.children.map(() => resultRoot);
- var sourceNodeStack = root.children;
+ var sourceNodeStack = root.children.map(id => nodeByIdMap.get(id));
while (sourceNodeStack.length) {
var parentNode = parentNodeStack.pop();
var sourceNode = sourceNodeStack.pop();
@@ -97,7 +96,7 @@ WebInspector.CPUProfileDataModel.prototype = {
}
idMap.set(sourceNode.id, parentNode.id);
parentNodeStack.push.apply(parentNodeStack, sourceNode.children.map(() => parentNode));
- sourceNodeStack.push.apply(sourceNodeStack, sourceNode.children);
+ sourceNodeStack.push.apply(sourceNodeStack, sourceNode.children.map(id => nodeByIdMap.get(id)));
}
if (this.samples)
this.samples = this.samples.map(id => idMap.get(id));

Powered by Google App Engine
This is Rietveld 408576698