Debian Codegraph @

js/src/jit-test/tests/profiler/interpreter-stacks.js

raw
1 // |jit-test| --no-blinterp
2 // Disable Baseline Interpreter and JITs because we only read information about
3 // C++ Interpreter profiling frames.
4
5 enableGeckoProfilingWithSlowAssertions();
6
7 function assertStack(stack, expected) {
8 assertEq(stack.length, expected.length);
9 for (let i = 0; i < stack.length; i++) {
10 // Use |split| to get rid of the file name.
11 assertEq(stack[i].dynamicString.split(" (")[0], expected[i]);
12 }
13 }
14
15 // We currently don't push entries for frames that were already on the stack
16 // when the profiler was enabled.
17 assertStack(readGeckoInterpProfilingStack(), []);
18
19 function testBasic() {
20 let g1 = function() {
21 return readGeckoInterpProfilingStack();
22 }
23 let f1 = () => g1();
24 assertStack(f1(), ["testBasic", "f1", "g1"]);
25
26 // Test non-function frames.
27 assertStack(evaluate("eval(`(function foo() { return readGeckoInterpProfilingStack(); })()`)"),
28 ["testBasic", "@evaluate", "@evaluate line 1 > eval:1:1", "foo"]);
29 }
30 testBasic();
31 testBasic();
32
33 function testThrow() {
34 let stacks = [];
35 let thrower = function() {
36 stacks.push(readGeckoInterpProfilingStack());
37 throw 1;
38 };
39 let catcher = function() {
40 try {
41 thrower();
42 } catch (e) {
43 stacks.push(readGeckoInterpProfilingStack());
44 }
45 };
46 catcher();
47 assertEq(stacks.length, 2);
48 assertStack(stacks[0], ["testThrow", "catcher", "thrower"]);
49 assertStack(stacks[1], ["testThrow", "catcher"]);
50 }
51 testThrow();
52 testThrow();
53
54 function testSelfHosted() {
55 let stacks = [1, 2, 3].map(function() {
56 return readGeckoInterpProfilingStack();
57 });
58 assertEq(stacks.length, 3);
59 for (var stack of stacks) {
60 assertStack(stack, ["testSelfHosted", "map", "testSelfHosted/stacks<"]);
61 }
62 }
63 testSelfHosted();
64 testSelfHosted();
65
66 function testGenerator() {
67 let stacks = [];
68 let generator = function*() {
69 stacks.push(readGeckoInterpProfilingStack());
70 yield 1;
71 stacks.push(readGeckoInterpProfilingStack());
72 yield 2;
73 stacks.push(readGeckoInterpProfilingStack());
74 };
75 for (let x of generator()) {}
76 assertStack(readGeckoInterpProfilingStack(), ["testGenerator"]);
77
78 assertEq(stacks.length, 3);
79 for (var stack of stacks) {
80 assertStack(stack, ["testGenerator", "next", "generator"]);
81 }
82 }
83 testGenerator();
84 testGenerator();
85
86 async function testAsync() {
87 let stacks = [];
88 let asyncFun = async function() {
89 stacks.push(readGeckoInterpProfilingStack());
90 await 1;
91 stacks.push(readGeckoInterpProfilingStack());
92 };
93 await asyncFun();
94 assertStack(readGeckoInterpProfilingStack(), ["AsyncFunctionNext", "testAsync"]);
95
96 assertEq(stacks.length, 2);
97 assertStack(stacks[0], ["testAsync", "asyncFun"]);
98 assertStack(stacks[1], ["AsyncFunctionNext", "asyncFun"]);
99 }
100 testAsync();
101 drainJobQueue();
102 testAsync();
103 drainJobQueue();
104
105 disableGeckoProfiling();