mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 21:54:47 +08:00
Move and rename files. NOAUTOREVERT=true NOPRESUBMIT=true NOTREECHECKS=true Bug: 768828 TBR=darin@chromium.org NOTRY=true Change-Id: I66d3b155808bc5bdbf237b80208e1e552bcf7f28 Reviewed-on: https://chromium-review.googlesource.com/1001153 Reviewed-by: Blink Reformat <blink-reformat@chromium.org> Commit-Queue: Blink Reformat <blink-reformat@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#549061} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 0aee4434a4dba42a42abaea9bfbc0cd196a63bc1
121 lines
2.6 KiB
JavaScript
121 lines
2.6 KiB
JavaScript
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
SDK.ProfileNode = class {
|
|
/**
|
|
* @param {!Protocol.Runtime.CallFrame} callFrame
|
|
*/
|
|
constructor(callFrame) {
|
|
/** @type {!Protocol.Runtime.CallFrame} */
|
|
this.callFrame = callFrame;
|
|
/** @type {string} */
|
|
this.callUID = `${this.callFrame.functionName}@${this.callFrame.scriptId}:${this.callFrame.lineNumber}`;
|
|
/** @type {number} */
|
|
this.self = 0;
|
|
/** @type {number} */
|
|
this.total = 0;
|
|
/** @type {number} */
|
|
this.id = 0;
|
|
/** @type {?SDK.ProfileNode} */
|
|
this.parent = null;
|
|
/** @type {!Array<!SDK.ProfileNode>} */
|
|
this.children = [];
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
get functionName() {
|
|
return this.callFrame.functionName;
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
get scriptId() {
|
|
return this.callFrame.scriptId;
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
get url() {
|
|
return this.callFrame.url;
|
|
}
|
|
|
|
/**
|
|
* @return {number}
|
|
*/
|
|
get lineNumber() {
|
|
return this.callFrame.lineNumber;
|
|
}
|
|
|
|
/**
|
|
* @return {number}
|
|
*/
|
|
get columnNumber() {
|
|
return this.callFrame.columnNumber;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
SDK.ProfileTreeModel = class {
|
|
/**
|
|
* @param {!SDK.ProfileNode} root
|
|
* @protected
|
|
*/
|
|
initialize(root) {
|
|
this.root = root;
|
|
this._assignDepthsAndParents();
|
|
this.total = this._calculateTotals(this.root);
|
|
}
|
|
|
|
_assignDepthsAndParents() {
|
|
const root = this.root;
|
|
root.depth = -1;
|
|
root.parent = null;
|
|
this.maxDepth = 0;
|
|
const nodesToTraverse = [root];
|
|
while (nodesToTraverse.length) {
|
|
const parent = nodesToTraverse.pop();
|
|
const depth = parent.depth + 1;
|
|
if (depth > this.maxDepth)
|
|
this.maxDepth = depth;
|
|
const children = parent.children;
|
|
const length = children.length;
|
|
for (let i = 0; i < length; ++i) {
|
|
const child = children[i];
|
|
child.depth = depth;
|
|
child.parent = parent;
|
|
if (child.children.length)
|
|
nodesToTraverse.push(child);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {!SDK.ProfileNode} root
|
|
* @return {number}
|
|
*/
|
|
_calculateTotals(root) {
|
|
const nodesToTraverse = [root];
|
|
const dfsList = [];
|
|
while (nodesToTraverse.length) {
|
|
const node = nodesToTraverse.pop();
|
|
node.total = node.self;
|
|
dfsList.push(node);
|
|
nodesToTraverse.push(...node.children);
|
|
}
|
|
while (dfsList.length > 1) {
|
|
const node = dfsList.pop();
|
|
node.parent.total += node.total;
|
|
}
|
|
return root.total;
|
|
}
|
|
};
|