Skip to content

Commit 7116806

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[trace] Document behavior of setHasChildren on BottomUpNode
This code had no bugs, but it threw me (and Gemini) for a loop because it wasn't clear that "setHasChildren" here was being called correctly. Fixed: 454088373 Change-Id: I3e01f12b46a4cf5f249301cfccb1be1e5a5474c1 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7240306 Reviewed-by: Paul Irish <paulirish@chromium.org> Auto-Submit: Connor Clark <cjamcl@chromium.org> Commit-Queue: Connor Clark <cjamcl@chromium.org>
1 parent d44ed9d commit 7116806

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

front_end/models/trace/extras/TraceTree.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,7 @@ describeWithEnvironment('TraceTree', () => {
475475
assert.lengthOf(second.events, 3);
476476
});
477477

478-
// TODO: Gemini noticed that "setHasChildren" may not be called correctly ... I think
479-
// it's right, but fixing it has proven difficult. So here's a test case for a later day.
480-
it.skip('[crbug.com/454088373] correctly identifies which nodes have children in a nested structure', () => {
478+
it('correctly identifies which nodes have children in a nested structure', () => {
481479
// This builds the following simple tree:
482480
// |----Parent Task----|
483481
// |--Child Task--|
@@ -505,8 +503,10 @@ describeWithEnvironment('TraceTree', () => {
505503
assert.exists(parentNode, 'Parent node was not found');
506504
assert.exists(childNode, 'Child node was not found');
507505

508-
assert.isTrue(parentNode.hasChildren(), 'Parent node should have children');
509-
assert.isFalse(childNode.hasChildren(), 'Child node should not have children');
506+
// Since this is bottom-up, a node with callers should have children.
507+
// A node with no callers (a top-level node) has no children.
508+
assert.isFalse(parentNode.hasChildren(), 'Parent node (the root) should NOT have children in bottom-up');
509+
assert.isTrue(childNode.hasChildren(), 'Child node (the nested event) SHOULD have children in bottom-up');
510510
});
511511
});
512512

front_end/models/trace/extras/TraceTree.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,10 @@ export class BottomUpRootNode extends Node {
493493
node.totalTime += totalTimeById.get(id) || 0;
494494
totalTimeById.delete(id);
495495
}
496-
// TODO: this may be wrong. See the skipped test in TraceTree.test.ts.
497-
if (firstNodeStack.length) {
496+
497+
// An item on this stack means that this current node has a caller. Therefore,
498+
// in a bottom-up view it has children.
499+
if (idStack.length > 0) {
498500
node.setHasChildren(true);
499501
}
500502
}

0 commit comments

Comments
 (0)