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

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

Issue 1873973002: DevTools: extract CPU profile independent part of CPUProfileNode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @implements {RuntimeAgent.CallFrame}
caseq 2016/04/13 17:21:12 WAT?
alph 2016/04/13 19:05:07 Fixed. Encapsulated it instead and added getters t
8 */
9 WebInspector.ProfileNode = function()
10 {
11 /** @type {string} */
12 this.functionName;
13 /** @type {string} */
14 this.scriptId;
15 /** @type {string} */
16 this.url;
17 /** @type {number} */
18 this.lineNumber;
19 /** @type {number} */
20 this.columnNumber;
21 /** @type {number} */
22 this.callUID;
23 /** @type {number} */
24 this.self = 0;
25 /** @type {number} */
26 this.total = 0;
27 /** @type {number} */
28 this.id = 0;
29 /** @type {?WebInspector.ProfileNode} */
30 this.parent = null;
31 /** @type {!Array<!WebInspector.ProfileNode>} */
32 this.children = [];
33 }
34
35 /**
36 * @constructor
37 * @param {!WebInspector.ProfileNode} head
caseq 2016/04/13 17:21:12 nit: s/head/root/ everywhere?
alph 2016/04/13 19:05:07 Renamed local variables. Left the rest for now to
38 * @param {number} begin
39 * @param {number} end
40 */
41 WebInspector.ProfileTreeModel = function(head, begin, end)
42 {
43 this.head = head;
44 this.begin = begin;
45 this.end = end;
46 this._assignInfo();
47 this._calculateTotal(this.head);
48 }
49
50 WebInspector.ProfileTreeModel.prototype = {
51 _assignInfo: function()
caseq 2016/04/13 17:21:12 _updateDepthAndParent?
alph 2016/04/13 19:05:07 Done.
52 {
53 var head = this.head;
54 head.depth = -1;
55 head.parent = null;
56 this.maxDepth = 0;
57 var nodesToTraverse = [ head ];
58 while (nodesToTraverse.length) {
59 var parent = nodesToTraverse.pop();
60 var depth = parent.depth + 1;
61 if (depth > this.maxDepth)
62 this.maxDepth = depth;
63 var children = parent.children;
64 var length = children.length;
65 for (var i = 0; i < length; ++i) {
66 var child = children[i];
67 child.depth = depth;
68 child.parent = parent;
69 if (child.children.length)
70 nodesToTraverse.push(child);
71 }
72 }
73 },
74
75 /**
76 * @param {!WebInspector.ProfileNode} node
77 * @return {number}
78 */
79 _calculateTotal: function(node)
80 {
81 node.total = node.children.reduce((acc, child) => acc + this._calculateT otal(child), node.self);
82 return node.total;
83 }
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698