Bug 1147143 - Inverted call tree times are now based on the context of their position in the tree, non-leaf frames do not have self costs, and total costs add up to their parent. r=shu

This commit is contained in:
Jordan Santell 2015-05-23 15:58:56 -07:00
parent d90ddbc18f
commit 24aff4397c
4 changed files with 236 additions and 24 deletions

View File

@ -175,6 +175,7 @@ ThreadNode.prototype = {
let prevCalls = this.calls;
let prevFrameKey;
let isLeaf = mutableFrameKeyOptions.isLeaf = true;
let skipRoot = options.invertTree;
// Inflate the stack and build the FrameNode call tree directly.
//
@ -213,6 +214,13 @@ ThreadNode.prototype = {
// Fetch the stack prefix (i.e. older frames) index.
stackIndex = stackEntry[STACK_PREFIX_SLOT];
// Do not include the (root) node in this sample, as the costs of each frame
// will make it clear to differentiate (root)->B vs (root)->A->B
// when a tree is inverted, a revert of bug 1147604
if (stackIndex === null && skipRoot) {
break;
}
// Inflate the frame.
let inflatedFrame = getOrAddInflatedFrame(inflatedFrameCache, frameIndex, frameTable,
stringTable, allocationsTable);
@ -496,7 +504,7 @@ FrameNode.prototype = {
return null;
}
return new JITOptimizations(this._optimizations, this._stringTable);
}
},
};
exports.ThreadNode = ThreadNode;

View File

@ -21,9 +21,14 @@ const CALL_TREE_INDENTATION = 16; // px
const DEFAULT_SORTING_PREDICATE = (frameA, frameB) => {
let dataA = frameA.getDisplayedData();
let dataB = frameB.getDisplayedData();
return this.inverted
? (dataA.selfPercentage < dataB.selfPercentage ? 1 : -1)
: (dataA.samples < dataB.samples ? 1 : -1);
if (this.inverted) {
// Invert trees, sort by selfPercentage, and then totalPercentage
if (dataA.selfPercentage === dataB.selfPercentage) {
return dataA.totalPercentage < dataB.totalPercentage ? 1 : -1;
}
return dataA.selfPercentage < dataB.selfPercentage ? 1 : - 1;
}
return dataA.samples < dataB.samples ? 1 : -1;
};
const DEFAULT_AUTO_EXPAND_DEPTH = 3; // depth
@ -241,7 +246,7 @@ CallView.prototype = Heritage.extend(AbstractTreeItem.prototype, {
cell.className = "plain call-tree-cell";
cell.setAttribute("type", "samples");
cell.setAttribute("crop", "end");
cell.setAttribute("value", count || "");
cell.setAttribute("value", count || 0);
return cell;
},
_createFunctionCell: function(doc, arrowNode, frameName, frameInfo, frameLevel) {
@ -335,6 +340,52 @@ CallView.prototype = Heritage.extend(AbstractTreeItem.prototype, {
let data = this._cachedDisplayedData = Object.create(null);
let frameInfo = this.frame.getInfo();
/**
* When inverting call tree, the costs and times are dependent on position
* in the tree. We must only count leaf nodes with self cost, and total costs
* dependent on how many times the leaf node was found with a full stack path.
*
* Total | Self | Calls | Function
* ============================================================================
* 100% | 100% | 100 | C
* 50% | 0% | 50 | B
* 50% | 0% | 50 | A
* 50% | 0% | 50 | B
*
* Every instance of a `CallView` represents a row in the call tree. The same
* container node is used for all rows.
*/
// Leaf nodes in an inverted tree don't have to do anything special.
let isLeaf = this._level === 0;
if (this.inverted && !isLeaf && this.parent != null) {
let calleeData = this.parent.getDisplayedData();
// Percentage of time that this frame called the callee
// in this branch
let callerPercentage = this.frame.samples / calleeData.samples;
// Self/total duration.
if (this.visibleCells.duration) {
data.totalDuration = calleeData.totalDuration * callerPercentage;
}
if (this.visibleCells.selfDuration) {
data.selfDuration = 0;
}
// Self/total samples percentage.
if (this.visibleCells.percentage) {
data.totalPercentage = calleeData.totalPercentage * callerPercentage;
}
if (this.visibleCells.selfPercentage) {
data.selfPercentage = 0;
}
// Raw samples.
if (this.visibleCells.samples) {
data.samples = this.frame.samples;
}
} else {
// Self/total duration.
if (this.visibleCells.duration) {
data.totalDuration = this.frame.duration;
@ -351,6 +402,12 @@ CallView.prototype = Heritage.extend(AbstractTreeItem.prototype, {
data.selfPercentage = this.root.frame.selfCount[this.frame.key] / this.root.frame.samples * 100;
}
// Raw samples.
if (this.visibleCells.samples) {
data.samples = this.frame.samples;
}
}
// Self/total allocations count.
if (this.visibleCells.allocations) {
let childrenAllocations = this.frame.calls.reduce((acc, node) => acc + node.allocations, 0);
@ -360,11 +417,6 @@ CallView.prototype = Heritage.extend(AbstractTreeItem.prototype, {
data.selfAllocations = this.frame.allocations;
}
// Raw samples.
if (this.visibleCells.samples) {
data.samples = this.frame.samples;
}
// Frame name (function location or some meta information).
data.name = frameInfo.isMetaCategory
? frameInfo.categoryData.label
@ -396,7 +448,7 @@ CallView.prototype = Heritage.extend(AbstractTreeItem.prototype, {
e.preventDefault();
e.stopPropagation();
this.root.emit("link", this);
}
},
});
exports.CallView = CallView;

View File

@ -140,6 +140,7 @@ skip-if = e10s # GC events seem unreliable in multiprocess
[browser_profiler_tree-view-07.js]
[browser_profiler_tree-view-08.js]
[browser_profiler_tree-view-09.js]
[browser_profiler_tree-view-10.js]
[browser_profiler-frame-utils-01.js]
[browser_timeline-blueprint.js]
[browser_timeline-filters.js]

View File

@ -0,0 +1,151 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if the profiler's tree view, when inverted, displays the self and
* total costs correctly.
*/
function test() {
let { ThreadNode } = devtools.require("devtools/performance/tree-model");
let { CallView } = devtools.require("devtools/performance/tree-view");
let threadNode = new ThreadNode(gThread, { invertTree: true });
let treeRoot = new CallView({ frame: threadNode, inverted: true, hidden: true });
let container = document.createElement("vbox");
treeRoot.attachTo(container);
// Add 1 to each index to skip the hidden root node
let $$fun = i => container.querySelectorAll(".call-tree-cell[type=function]")[i+1];
let $$name = i => container.querySelectorAll(".call-tree-cell[type=function] > .call-tree-name")[i+1];
let $$percentage = i => container.querySelectorAll(".call-tree-cell[type=percentage]")[i+1];
let $$selfpercentage = i => container.querySelectorAll(".call-tree-cell[type='self-percentage']")[i+1];
/**
* Samples
*
* A->C
* A->B
* A->B->C x4
* A->B->D x4
*
* Expected Tree
* +--total--+--self--+--tree-------------+
* | 50% | 50% | C
* | 40% | 0 | -> B
* | 30% | 0 | -> A
* | 10% | 0 | -> A
*
* | 40% | 40% | D
* | 40% | 0 | -> B
* | 40% | 0 | -> A
*
* | 10% | 10% | B
* | 10% | 0 | -> A
*/
is(container.childNodes.length, 10,
"The container node should have all children available.");
[ // total, self, indent + name
[ 50, 50, "C"],
[ 40, 0, " B"],
[ 30, 0, " A"],
[ 10, 0, " A"],
[ 40, 40, "D"],
[ 40, 0, " B"],
[ 40, 0, " A"],
[ 10, 10, "B"],
[ 10, 0, " A"],
].forEach(function (def, i) {
info(`Checking ${i}th tree item`);
let [total, self, name] = def;
name = name.trim();
is($$name(i).getAttribute("value"), name, `${name} has correct name.`);
is($$percentage(i).getAttribute("value"), `${total}%`, `${name} has correct total percent.`);
is($$selfpercentage(i).getAttribute("value"), `${self}%`, `${name} has correct self percent.`);
});
finish();
}
let gThread = synthesizeProfileForTest([{
time: 5,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
{ location: "C" }
]
}, {
time: 10,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
{ location: "D" }
]
}, {
time: 15,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "C" },
]
}, {
time: 20,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
]
}, {
time: 25,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
{ location: "C" }
]
}, {
time: 30,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
{ location: "C" }
]
}, {
time: 35,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
{ location: "D" }
]
}, {
time: 40,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
{ location: "D" }
]
}, {
time: 45,
frames: [
{ location: "(root)" },
{ location: "B" },
{ location: "C" }
]
}, {
time: 50,
frames: [
{ location: "(root)" },
{ location: "A" },
{ location: "B" },
{ location: "D" }
]
}]);