Index: test/inspector/sessions/cpu-profile.js |
diff --git a/test/inspector/sessions/cpu-profile.js b/test/inspector/sessions/cpu-profile.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c0be6544943138ea46c901f14960bc65091614b6 |
--- /dev/null |
+++ b/test/inspector/sessions/cpu-profile.js |
@@ -0,0 +1,62 @@ |
+// Copyright 2017 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+InspectorTest.log('Tests that multiple sessions can record profiles concurrently.'); |
+ |
+var contextGroup = new InspectorTest.ContextGroup(); |
+contextGroup.addScript(` |
+function foo() { |
+ var doSomeWork = 1; |
+ for (var i = 0; i < 10000000; i++) |
+ doSomeWork += i; |
+ return doSomeWork; |
+} |
+//# sourceURL=test.js`, 7, 26); |
+ |
+function checkProfile(profile) { |
+ var foundFoo = profile.nodes.some(node => node.callFrame.functionName === 'foo'); |
alph
2017/06/05 21:10:41
FYI: This has some probability of flaking, as ther
dgozman
2017/06/05 21:50:47
Thanks! I'm staying positive though :)
|
+ InspectorTest.log(`Found foo() call in profile: ${foundFoo}`); |
+} |
+ |
+(async function test() { |
+ var session1 = await connect(contextGroup, 1); |
+ var session2 = await connect(contextGroup, 2); |
+ |
+ InspectorTest.log('console.profile in 1'); |
+ await session1.Protocol.Runtime.evaluate({expression: 'console.profile("one"); foo(); console.profileEnd("one");'}); |
+ InspectorTest.log('console.profile in 2'); |
+ await session2.Protocol.Runtime.evaluate({expression: 'console.profile("two"); foo(); console.profileEnd("two");'}); |
+ |
+ InspectorTest.log('starting in 1'); |
+ session1.Protocol.Profiler.start(); |
+ InspectorTest.log('starting in 2'); |
+ session2.Protocol.Profiler.start(); |
+ await session1.Protocol.Runtime.evaluate({expression: 'foo();'}); |
+ |
+ InspectorTest.log('stopping in 1'); |
+ var message = await session1.Protocol.Profiler.stop(); |
+ InspectorTest.log('stopped in 1'); |
+ checkProfile((message).result.profile); |
alph
2017/06/05 21:10:41
drop ()
dgozman
2017/06/05 21:50:48
Done.
|
+ |
+ InspectorTest.log('stopping in 2'); |
+ var message = await session2.Protocol.Profiler.stop(); |
+ InspectorTest.log('stopped in 2'); |
+ checkProfile((message).result.profile); |
alph
2017/06/05 21:10:40
drop ()
dgozman
2017/06/05 21:50:48
Done.
|
+ |
+ InspectorTest.completeTest(); |
+})(); |
+ |
+async function connect(contextGroup, num) { |
+ var session = contextGroup.connect(); |
+ session.Protocol.Profiler.onConsoleProfileStarted(message => { |
+ InspectorTest.log(`console profile started from ${num}: ${message.params.title}`); |
+ }); |
+ session.Protocol.Profiler.onConsoleProfileFinished(message => { |
+ InspectorTest.log(`console profile finished from ${num}: ${message.params.title}`); |
+ checkProfile(message.params.profile); |
+ }); |
+ await session.Protocol.Profiler.enable(); |
+ await session.Protocol.Profiler.setSamplingInterval({interval: 100}); |
+ return session; |
+} |