Skip to content

Commit e58100d

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[stack_trace] Add scaffolding and some types for the fragment trie
Get the boiler plate out of the way to keep CL size small. The root node of the trie holds on to it's children via WeakRef. This allows the GC to cleanup unused stack trace fragments. In theory, we could use WeakRefs for all child references, to allow the GC pruning of unused branches. But WeakRefs are not cheap from a GC perspective so WeakRef-ing the whole Trie would come at a significant performance cost with questionable benefit. [email protected] Bug: 433162438 Change-Id: If57cf52301c958ebb3cedbd27bb9fef807fbb5ee Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6837823 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Philip Pfaffe <[email protected]>
1 parent b48b4d1 commit e58100d

File tree

7 files changed

+110
-0
lines changed

7 files changed

+110
-0
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ grd_files_bundled_sources = [
592592
"front_end/models/project_settings/project_settings.js",
593593
"front_end/models/source_map_scopes/source_map_scopes.js",
594594
"front_end/models/stack_trace/stack_trace.js",
595+
"front_end/models/stack_trace/stack_trace_impl.js",
595596
"front_end/models/text_utils/text_utils.js",
596597
"front_end/models/trace/extras/extras.js",
597598
"front_end/models/trace/handlers/handlers.js",
@@ -1121,6 +1122,7 @@ grd_files_unbundled_sources = [
11211122
"front_end/models/source_map_scopes/ScopeChainModel.js",
11221123
"front_end/models/source_map_scopes/ScopeTreeCache.js",
11231124
"front_end/models/stack_trace/StackTrace.js",
1125+
"front_end/models/stack_trace/Trie.js",
11241126
"front_end/models/text_utils/CodeMirrorUtils.js",
11251127
"front_end/models/text_utils/ContentData.js",
11261128
"front_end/models/text_utils/ContentProvider.js",

front_end/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ group("unittests") {
143143
"models/persistence:unittests",
144144
"models/project_settings:unittests",
145145
"models/source_map_scopes:unittests",
146+
"models/stack_trace:unittests",
146147
"models/text_utils:unittests",
147148
"models/trace:unittests",
148149
"models/trace/extras:unittests",

front_end/models/bindings/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ devtools_module("bindings") {
3737
"../../core/sdk:bundle",
3838
"../../generated:protocol",
3939
"../../models/stack_trace:bundle",
40+
"../../models/stack_trace:impl",
4041
"../../models/text_utils:bundle",
4142
"../../models/workspace:bundle",
4243
]

front_end/models/stack_trace/BUILD.gn

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,37 @@ devtools_entrypoint("bundle") {
2323

2424
visibility = [ "*" ]
2525
}
26+
27+
devtools_module("stack_trace_impl") {
28+
sources = [ "Trie.ts" ]
29+
30+
deps = [
31+
":bundle",
32+
"../../generated",
33+
]
34+
}
35+
36+
devtools_entrypoint("impl") {
37+
entrypoint = "stack_trace_impl.ts"
38+
39+
deps = [ ":stack_trace_impl" ]
40+
41+
# IMPORTANT: Besides tests and bindings, no other module is allowed access.
42+
# If you have a use-case where you need access to stack trace internals,
43+
# consult one of the OWNERS before drilling holes.
44+
visibility = [
45+
":unittests",
46+
"../bindings",
47+
]
48+
}
49+
50+
ts_library("unittests") {
51+
testonly = true
52+
53+
sources = [ "Trie.test.ts" ]
54+
55+
deps = [
56+
":bundle",
57+
":impl",
58+
]
59+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2025 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+
import * as StackTraceImpl from './stack_trace_impl.js';
6+
7+
describe('Trie', () => {
8+
describe('insert', () => {
9+
it('throws for empty stack traces', () => {
10+
const trie = new StackTraceImpl.Trie.Trie();
11+
12+
assert.throws(() => trie.insert([]));
13+
});
14+
});
15+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2025 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+
import type * as Protocol from '../../generated/protocol.js';
6+
7+
import type * as StackTrace from './stack_trace.js';
8+
9+
/**
10+
* Intentionally very close to a {@link Protocol.Runtime.CallFrame} but with optional `scriptId`.
11+
*/
12+
export interface RawFrame {
13+
readonly scriptId?: Protocol.Runtime.ScriptId;
14+
readonly url?: string;
15+
readonly functionName?: string;
16+
readonly lineNumber: number;
17+
readonly columnNumber: number;
18+
}
19+
20+
interface FrameNodeBase<ChildT, ParentT> {
21+
readonly parent: ParentT;
22+
readonly children: ChildT[];
23+
}
24+
25+
type RootFrameNode = FrameNodeBase<WeakRef<FrameNode>, null>;
26+
type AnyFrameNode = FrameNode|RootFrameNode;
27+
28+
export interface FrameNode extends FrameNodeBase<FrameNode, AnyFrameNode> {
29+
readonly rawFrame: RawFrame;
30+
frames: StackTrace.StackTrace.Frame[];
31+
}
32+
33+
/**
34+
* Stores stack trace fragments in a trie, but does not own them/keep them alive.
35+
*/
36+
export class Trie {
37+
// eslint-disable-next-line no-unused-private-class-members
38+
readonly #root: RootFrameNode = {parent: null, children: []};
39+
40+
insert(frames: RawFrame[]): FrameNode {
41+
if (frames.length === 0) {
42+
throw new Error('Trie.insert called with an empty frames array.');
43+
}
44+
45+
// TODO(crbug.com/433162438): Implement it.
46+
throw new Error('Not implemented');
47+
}
48+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2025 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+
import * as Trie from './Trie.js';
6+
7+
export {
8+
Trie,
9+
};

0 commit comments

Comments
 (0)