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

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

Issue 2321163003: DevTools: Support profile trees encoded with parents rather than children. (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/profiler/cpu-profiler-bottom-up-times.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * @constructor 6 * @constructor
7 * @extends {WebInspector.ProfileNode} 7 * @extends {WebInspector.ProfileNode}
8 * @param {!ProfilerAgent.ProfileNode} node 8 * @param {!ProfilerAgent.ProfileNode} node
9 * @param {number} sampleTime 9 * @param {number} sampleTime
10 */ 10 */
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 /** 113 /**
114 * @param {!ProfilerAgent.ProfileNode} node 114 * @param {!ProfilerAgent.ProfileNode} node
115 * @return {boolean} 115 * @return {boolean}
116 */ 116 */
117 function isNativeNode(node) 117 function isNativeNode(node)
118 { 118 {
119 if (node.callFrame) 119 if (node.callFrame)
120 return !!node.callFrame.url && node.callFrame.url.startsWith("na tive "); 120 return !!node.callFrame.url && node.callFrame.url.startsWith("na tive ");
121 return !!node.url && node.url.startsWith("native "); 121 return !!node.url && node.url.startsWith("native ");
122 } 122 }
123 /**
124 * @param {!Array<!ProfilerAgent.ProfileNode>} nodes
125 */
126 function buildChildrenFromParents(nodes)
127 {
128 if (nodes[0].children)
129 return;
130 nodes[0].children = [];
131 for (var i = 1; i < nodes.length; ++i) {
132 var node = nodes[i];
133 var parentNode = nodeByIdMap.get(node.parent);
134 if (parentNode.children)
135 parentNode.children.push(node.id);
136 else
137 parentNode.children = [node.id];
138 }
139 }
123 /** @type {!Map<number, !ProfilerAgent.ProfileNode>} */ 140 /** @type {!Map<number, !ProfilerAgent.ProfileNode>} */
124 var nodeByIdMap = new Map(); 141 var nodeByIdMap = new Map();
125 for (var i = 0; i < nodes.length; ++i) { 142 for (var i = 0; i < nodes.length; ++i) {
126 var node = nodes[i]; 143 var node = nodes[i];
127 nodeByIdMap.set(node.id, node); 144 nodeByIdMap.set(node.id, node);
128 } 145 }
146 buildChildrenFromParents(nodes);
129 this.totalHitCount = nodes.reduce((acc, node) => acc + node.hitCount, 0) ; 147 this.totalHitCount = nodes.reduce((acc, node) => acc + node.hitCount, 0) ;
130 var sampleTime = (this.profileEndTime - this.profileStartTime) / this.to talHitCount; 148 var sampleTime = (this.profileEndTime - this.profileStartTime) / this.to talHitCount;
131 var keepNatives = !!WebInspector.moduleSetting("showNativeFunctionsInJSP rofile").get(); 149 var keepNatives = !!WebInspector.moduleSetting("showNativeFunctionsInJSP rofile").get();
132 var root = nodes[0]; 150 var root = nodes[0];
133 /** @type {!Map<number, number>} */ 151 /** @type {!Map<number, number>} */
134 var idMap = new Map([[root.id, root.id]]); 152 var idMap = new Map([[root.id, root.id]]);
135 var resultRoot = new WebInspector.CPUProfileNode(root, sampleTime); 153 var resultRoot = new WebInspector.CPUProfileNode(root, sampleTime);
136 var parentNodeStack = root.children.map(() => resultRoot); 154 var parentNodeStack = root.children.map(() => resultRoot);
137 var sourceNodeStack = root.children.map(id => nodeByIdMap.get(id)); 155 var sourceNodeStack = root.children.map(id => nodeByIdMap.get(id));
138 while (sourceNodeStack.length) { 156 while (sourceNodeStack.length) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 * @param {number} index 368 * @param {number} index
351 * @return {?WebInspector.CPUProfileNode} 369 * @return {?WebInspector.CPUProfileNode}
352 */ 370 */
353 nodeByIndex: function(index) 371 nodeByIndex: function(index)
354 { 372 {
355 return this._idToNode.get(this.samples[index]) || null; 373 return this._idToNode.get(this.samples[index]) || null;
356 }, 374 },
357 375
358 __proto__: WebInspector.ProfileTreeModel.prototype 376 __proto__: WebInspector.ProfileTreeModel.prototype
359 } 377 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/profiler/cpu-profiler-bottom-up-times.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698