3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
5 function collectProfiles()
7 console
.profile("outer");
8 console
.profile("inner");
9 console
.profileEnd("outer");
10 console
.profileEnd("inner");
15 InspectorTest
.fail = function(message
)
17 InspectorTest
.log("FAIL: " + message
);
18 InspectorTest
.completeTest();
21 InspectorTest
.sendCommand("Profiler.enable", {});
22 InspectorTest
.sendCommand("Runtime.evaluate", { expression
: "collectProfiles()"}, didCollectProfiles
);
25 InspectorTest
.eventHandler
["Profiler.consoleProfileFinished"] = function(messageObject
)
28 profile
: messageObject
["params"]["profile"],
29 title
: messageObject
["params"]["title"]
33 function didCollectProfiles(messageObject
)
35 if (headers
.length
!== 2)
36 return InspectorTest
.fail("Cannot retrive headers: " + JSON
.stringify(messageObject
, null, 4));
37 for (var i
= 0; i
< headers
.length
; i
++) {
38 if (headers
[i
].title
=== "inner") {
39 checkInnerProfile(headers
[i
].profile
);
43 InspectorTest
.fail("Cannot find 'inner' profile header");
46 function checkInnerProfile(profile
)
48 InspectorTest
.log("SUCCESS: retrieved 'inner' profile");
49 var root
= profile
.head
;
50 if (!findFunctionInProfile(root
, "collectProfiles"))
51 return InspectorTest
.fail("collectProfiles function not found in the profile: " + JSON
.stringify(profile
, null, 4));
52 InspectorTest
.log("SUCCESS: found 'collectProfiles' function in the profile");
53 InspectorTest
.completeTest();
56 function findFunctionInProfile(node
, functionName
)
58 if (node
.functionName
=== functionName
)
60 var children
= node
.children
;
61 for (var i
= 0; i
< children
.length
; ++i
)
62 if (findFunctionInProfile(children
[i
], functionName
))
69 <body onload=
"runTest()">
71 Tests that console.profile/profileEnd will record CPU profile when inspector front-end is connected.
<br>