Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: test/inspector/cpu-profiler/coverage.js

Issue 2766573003: [debug] introduce precise binary code coverage. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --allow-natives-syntax
6
5 var source = 7 var source =
6 ` 8 `
7 function fib(x) { 9 function fib(x) {
8 if (x < 2) return 1; 10 if (x < 2) return 1;
9 return fib(x-1) + fib(x-2); 11 return fib(x-1) + fib(x-2);
10 } 12 }
13 function is_optimized(f) {
14 return (%GetOptimizationStatus(f) & 16) ? "optimized" : "unoptimized";
15 }
11 (function iife() { 16 (function iife() {
12 return 1; 17 return 1;
13 })(); 18 })();
14 fib(5); 19 fib(5);
15 `; 20 `;
16 21
17 var break_source = 22 var break_source =
18 ` 23 `
19 function g() { 24 function g() {
20 debugger; 25 debugger;
21 } 26 }
22 function f(x) { 27 function f(x) {
23 if (x == 0) g(); 28 if (x == 0) g();
24 else f(x - 1); 29 else f(x - 1);
25 } 30 }
26 function h() { 31 function h() {
27 g(); 32 g();
28 } 33 }
29 f(3); 34 f(3);
30 `; 35 `;
31 36
32 InspectorTest.log("Test collecting code coverage data with Profiler.collectCover age."); 37 InspectorTest.log("Test collecting code coverage data with Profiler.collectCover age.");
33 38
34 function ClearAndGC() { 39 function ClearAndGC() {
35 return Protocol.Runtime.evaluate({ expression: "fib = null;" }).then(GC); 40 return Protocol.Runtime.evaluate({ expression: "fib = g = f = h = is_optimized = null;" })
41 .then(GC);
36 } 42 }
37 43
38 function GC() { 44 function GC() {
39 return Protocol.HeapProfiler.enable() 45 return Protocol.HeapProfiler.enable()
40 .then(() => Protocol.HeapProfiler.collectGarbage()) 46 .then(() => Protocol.HeapProfiler.collectGarbage())
41 .then(() => Protocol.HeapProfiler.disable()); 47 .then(() => Protocol.HeapProfiler.disable());
42 } 48 }
43 49
44 function LogSorted(message) { 50 function LogSorted(message) {
45 message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptI d)); 51 message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptI d));
46 return InspectorTest.logMessage(message); 52 return InspectorTest.logMessage(message);
47 } 53 }
48 54
49 InspectorTest.runTestSuite([ 55 InspectorTest.runTestSuite([
50 function testPreciseBaseline(next) 56 function testPreciseBaseline(next)
51 { 57 {
52 Protocol.Runtime.enable() 58 Protocol.Runtime.enable()
53 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "0", persistScript: true })) 59 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "0", persistScript: true }))
54 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 60 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
55 .then(GC) 61 .then(GC)
56 .then(Protocol.Profiler.enable) 62 .then(Protocol.Profiler.enable)
57 .then(Protocol.Profiler.startPreciseCoverage) 63 .then(Protocol.Profiler.startPreciseCoverage)
58 .then(Protocol.Profiler.takePreciseCoverage) 64 .then(Protocol.Profiler.takePreciseCoverage)
59 .then(LogSorted) 65 .then(LogSorted)
60 .then(Protocol.Profiler.takePreciseCoverage) 66 .then(Protocol.Profiler.takePreciseCoverage)
61 .then(LogSorted) 67 .then(LogSorted)
62 .then(Protocol.Profiler.stopPreciseCoverage) 68 .then(Protocol.Profiler.stopPreciseCoverage)
63 .then(ClearAndGC)
64 .then(Protocol.Profiler.disable) 69 .then(Protocol.Profiler.disable)
65 .then(Protocol.Runtime.disable) 70 .then(Protocol.Runtime.disable)
71 .then(ClearAndGC)
66 .then(next); 72 .then(next);
67 }, 73 },
68 function testPreciseCoverage(next) 74 function testPreciseCoverage(next)
69 { 75 {
70 Protocol.Runtime.enable() 76 Protocol.Runtime.enable()
71 .then(Protocol.Profiler.enable) 77 .then(Protocol.Profiler.enable)
72 .then(Protocol.Profiler.startPreciseCoverage) 78 .then(Protocol.Profiler.startPreciseCoverage)
73 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "1", persistScript: true })) 79 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "1", persistScript: true }))
74 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 80 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
75 .then(ClearAndGC) 81 .then(ClearAndGC)
76 .then(InspectorTest.logMessage) 82 .then(InspectorTest.logMessage)
77 .then(Protocol.Profiler.takePreciseCoverage) 83 .then(Protocol.Profiler.takePreciseCoverage)
78 .then(LogSorted) 84 .then(LogSorted)
79 .then(Protocol.Profiler.takePreciseCoverage) 85 .then(Protocol.Profiler.takePreciseCoverage)
80 .then(LogSorted) 86 .then(LogSorted)
81 .then(ClearAndGC)
82 .then(Protocol.Profiler.stopPreciseCoverage) 87 .then(Protocol.Profiler.stopPreciseCoverage)
83 .then(Protocol.Profiler.disable) 88 .then(Protocol.Profiler.disable)
84 .then(Protocol.Runtime.disable) 89 .then(Protocol.Runtime.disable)
90 .then(ClearAndGC)
85 .then(next); 91 .then(next);
86 }, 92 },
87 function testPreciseCoverageFail(next) 93 function testPreciseCoverageFail(next)
88 { 94 {
89 Protocol.Runtime.enable() 95 Protocol.Runtime.enable()
90 .then(Protocol.Profiler.enable) 96 .then(Protocol.Profiler.enable)
91 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "2", persistScript: true })) 97 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "2", persistScript: true }))
92 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 98 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
93 .then(InspectorTest.logMessage) 99 .then(InspectorTest.logMessage)
94 .then(ClearAndGC) 100 .then(ClearAndGC)
95 .then(Protocol.Profiler.takePreciseCoverage) 101 .then(Protocol.Profiler.takePreciseCoverage)
96 .then(InspectorTest.logMessage) 102 .then(InspectorTest.logMessage)
97 .then(ClearAndGC)
98 .then(Protocol.Profiler.disable) 103 .then(Protocol.Profiler.disable)
99 .then(Protocol.Runtime.disable) 104 .then(Protocol.Runtime.disable)
105 .then(ClearAndGC)
100 .then(next); 106 .then(next);
101 }, 107 },
102 function testBestEffortCoverage(next) 108 function testBestEffortCoverage(next)
103 { 109 {
104 Protocol.Runtime.enable() 110 Protocol.Runtime.enable()
105 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "3", persistScript: true })) 111 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "3", persistScript: true }))
106 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 112 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
107 .then(InspectorTest.logMessage) 113 .then(InspectorTest.logMessage)
108 .then(ClearAndGC) 114 .then(ClearAndGC)
109 .then(Protocol.Profiler.getBestEffortCoverage) 115 .then(Protocol.Profiler.getBestEffortCoverage)
110 .then(LogSorted) 116 .then(LogSorted)
111 .then(Protocol.Profiler.getBestEffortCoverage) 117 .then(Protocol.Profiler.getBestEffortCoverage)
112 .then(LogSorted) 118 .then(LogSorted)
119 .then(Protocol.Runtime.disable)
113 .then(ClearAndGC) 120 .then(ClearAndGC)
114 .then(Protocol.Runtime.disable)
115 .then(next); 121 .then(next);
116 }, 122 },
117 function testBestEffortCoveragePrecise(next) 123 function testBestEffortCoveragePrecise(next)
118 { 124 {
119 Protocol.Runtime.enable() 125 Protocol.Runtime.enable()
120 .then(Protocol.Profiler.enable) 126 .then(Protocol.Profiler.enable)
121 .then(Protocol.Profiler.startPreciseCoverage) 127 .then(Protocol.Profiler.startPreciseCoverage)
122 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "4", persistScript: true })) 128 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "4", persistScript: true }))
123 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 129 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
124 .then(InspectorTest.logMessage) 130 .then(InspectorTest.logMessage)
125 .then(ClearAndGC) 131 .then(ClearAndGC)
126 .then(Protocol.Profiler.getBestEffortCoverage) 132 .then(Protocol.Profiler.getBestEffortCoverage)
127 .then(LogSorted) 133 .then(LogSorted)
128 .then(Protocol.Profiler.getBestEffortCoverage) 134 .then(Protocol.Profiler.getBestEffortCoverage)
129 .then(LogSorted) 135 .then(LogSorted)
130 .then(ClearAndGC) 136 .then(ClearAndGC)
131 .then(Protocol.Profiler.stopPreciseCoverage) 137 .then(Protocol.Profiler.stopPreciseCoverage)
132 .then(Protocol.Profiler.disable) 138 .then(Protocol.Profiler.disable)
133 .then(Protocol.Runtime.disable) 139 .then(Protocol.Runtime.disable)
140 .then(ClearAndGC)
134 .then(next); 141 .then(next);
135 }, 142 },
136 function testEnablePreciseCoverageAtPause(next) 143 function testEnablePreciseCoverageAtPause(next)
137 { 144 {
138 function handleDebuggerPause() { 145 function handleDebuggerPause() {
139 Protocol.Profiler.enable() 146 Protocol.Profiler.enable()
140 .then(Protocol.Profiler.startPreciseCoverage) 147 .then(Protocol.Profiler.startPreciseCoverage)
141 .then(Protocol.Debugger.resume) 148 .then(Protocol.Debugger.resume)
142 } 149 }
143 Protocol.Debugger.enable(); 150 Protocol.Debugger.enable();
144 Protocol.Debugger.oncePaused().then(handleDebuggerPause); 151 Protocol.Debugger.oncePaused().then(handleDebuggerPause);
145 Protocol.Runtime.enable() 152 Protocol.Runtime.enable()
146 .then(() => Protocol.Runtime.compileScript({ expression: break_source, sou rceURL: "5", persistScript: true })) 153 .then(() => Protocol.Runtime.compileScript({ expression: break_source, sou rceURL: "5", persistScript: true }))
147 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 154 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
148 .then(InspectorTest.logMessage) 155 .then(InspectorTest.logMessage)
149 .then(ClearAndGC) 156 .then(ClearAndGC)
150 .then(Protocol.Profiler.takePreciseCoverage) 157 .then(Protocol.Profiler.takePreciseCoverage)
151 .then(LogSorted) 158 .then(LogSorted)
159 .then(ClearAndGC)
160 .then(Protocol.Profiler.stopPreciseCoverage)
161 .then(Protocol.Profiler.disable)
162 .then(Protocol.Runtime.disable)
163 .then(Protocol.Debugger.disable)
164 .then(ClearAndGC)
165 .then(next);
166 },
167 function testPreciseCoverageBinary(next)
168 {
169 Protocol.Runtime.enable()
170 .then(Protocol.Profiler.enable)
171 .then(() => Protocol.Profiler.startPreciseCoverage({binary: true}))
172 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "6", persistScript: true }))
173 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
174 .then(InspectorTest.logMessage)
175 .then(Protocol.Profiler.takePreciseCoverage)
176 .then(LogSorted)
177 .then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }) )
178 .then(message => InspectorTest.logMessage(message))
179 .then(() => Protocol.Runtime.evaluate({ expression: "fib(20)" }))
180 .then(message => InspectorTest.logMessage(message))
181 .then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }) )
182 .then(message => InspectorTest.logMessage(message))
183 .then(Protocol.Profiler.takePreciseCoverage)
184 .then(LogSorted)
152 .then(Protocol.Profiler.stopPreciseCoverage) 185 .then(Protocol.Profiler.stopPreciseCoverage)
153 .then(Protocol.Profiler.disable) 186 .then(Protocol.Profiler.disable)
154 .then(Protocol.Runtime.disable) 187 .then(Protocol.Runtime.disable)
188 .then(ClearAndGC)
155 .then(next); 189 .then(next);
156 }, 190 },
157 ]); 191 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698