| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 9282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9293 TEST_CASE(Timeline_Dart_TimelineDuration) { | 9293 TEST_CASE(Timeline_Dart_TimelineDuration) { |
| 9294 Isolate* isolate = Isolate::Current(); | 9294 Isolate* isolate = Isolate::Current(); |
| 9295 // Grab embedder stream. | 9295 // Grab embedder stream. |
| 9296 TimelineStream* stream = isolate->GetEmbedderStream(); | 9296 TimelineStream* stream = isolate->GetEmbedderStream(); |
| 9297 // Make sure it is enabled. | 9297 // Make sure it is enabled. |
| 9298 stream->set_enabled(true); | 9298 stream->set_enabled(true); |
| 9299 // Add a duration event. | 9299 // Add a duration event. |
| 9300 Dart_TimelineDuration("testDurationEvent", 0, 1); | 9300 Dart_TimelineDuration("testDurationEvent", 0, 1); |
| 9301 // Check that it is in the output. | 9301 // Check that it is in the output. |
| 9302 TimelineEventRecorder* recorder = Timeline::recorder(); | 9302 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 9303 Timeline::ReclaimIsolateBlocks(); |
| 9303 JSONStream js; | 9304 JSONStream js; |
| 9304 IsolateTimelineEventFilter filter(isolate); | 9305 IsolateTimelineEventFilter filter(isolate); |
| 9305 recorder->PrintJSON(&js, &filter); | 9306 recorder->PrintJSON(&js, &filter); |
| 9306 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); | 9307 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); |
| 9307 } | 9308 } |
| 9308 | 9309 |
| 9309 | 9310 |
| 9310 TEST_CASE(Timeline_Dart_TimelineInstant) { | 9311 TEST_CASE(Timeline_Dart_TimelineInstant) { |
| 9311 Isolate* isolate = Isolate::Current(); | 9312 Isolate* isolate = Isolate::Current(); |
| 9312 // Grab embedder stream. | 9313 // Grab embedder stream. |
| 9313 TimelineStream* stream = isolate->GetEmbedderStream(); | 9314 TimelineStream* stream = isolate->GetEmbedderStream(); |
| 9314 // Make sure it is enabled. | 9315 // Make sure it is enabled. |
| 9315 stream->set_enabled(true); | 9316 stream->set_enabled(true); |
| 9316 Dart_TimelineInstant("testInstantEvent"); | 9317 Dart_TimelineInstant("testInstantEvent"); |
| 9317 // Check that it is in the output. | 9318 // Check that it is in the output. |
| 9318 TimelineEventRecorder* recorder = Timeline::recorder(); | 9319 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 9320 Timeline::ReclaimIsolateBlocks(); |
| 9319 JSONStream js; | 9321 JSONStream js; |
| 9320 IsolateTimelineEventFilter filter(isolate); | 9322 IsolateTimelineEventFilter filter(isolate); |
| 9321 recorder->PrintJSON(&js, &filter); | 9323 recorder->PrintJSON(&js, &filter); |
| 9322 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); | 9324 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); |
| 9323 } | 9325 } |
| 9324 | 9326 |
| 9325 | 9327 |
| 9326 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { | 9328 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { |
| 9327 Isolate* isolate = Isolate::Current(); | 9329 Isolate* isolate = Isolate::Current(); |
| 9328 // Grab embedder stream. | 9330 // Grab embedder stream. |
| 9329 TimelineStream* stream = isolate->GetEmbedderStream(); | 9331 TimelineStream* stream = isolate->GetEmbedderStream(); |
| 9330 // Make sure it is disabled. | 9332 // Make sure it is disabled. |
| 9331 stream->set_enabled(false); | 9333 stream->set_enabled(false); |
| 9332 int64_t async_id = -1; | 9334 int64_t async_id = -1; |
| 9333 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); | 9335 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); |
| 9334 // Expect that the |async_id| is negative because the stream is disabled. | 9336 // Expect that the |async_id| is negative because the stream is disabled. |
| 9335 EXPECT(async_id < 0); | 9337 EXPECT(async_id < 0); |
| 9336 // Call Dart_TimelineAsyncEnd with a negative async_id. | 9338 // Call Dart_TimelineAsyncEnd with a negative async_id. |
| 9337 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); | 9339 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); |
| 9338 // Check that testAsync is not in the output. | 9340 // Check that testAsync is not in the output. |
| 9339 TimelineEventRecorder* recorder = Timeline::recorder(); | 9341 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 9342 Timeline::ReclaimIsolateBlocks(); |
| 9340 JSONStream js; | 9343 JSONStream js; |
| 9341 TimelineEventFilter filter; | 9344 TimelineEventFilter filter; |
| 9342 recorder->PrintJSON(&js, &filter); | 9345 recorder->PrintJSON(&js, &filter); |
| 9343 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); | 9346 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); |
| 9344 } | 9347 } |
| 9345 | 9348 |
| 9346 | 9349 |
| 9347 TEST_CASE(Timeline_Dart_TimelineAsync) { | 9350 TEST_CASE(Timeline_Dart_TimelineAsync) { |
| 9348 Isolate* isolate = Isolate::Current(); | 9351 Isolate* isolate = Isolate::Current(); |
| 9349 // Grab embedder stream. | 9352 // Grab embedder stream. |
| 9350 TimelineStream* stream = isolate->GetEmbedderStream(); | 9353 TimelineStream* stream = isolate->GetEmbedderStream(); |
| 9351 // Make sure it is enabled. | 9354 // Make sure it is enabled. |
| 9352 stream->set_enabled(true); | 9355 stream->set_enabled(true); |
| 9353 int64_t async_id = -1; | 9356 int64_t async_id = -1; |
| 9354 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); | 9357 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); |
| 9355 // Expect that the |async_id| is >= 0. | 9358 // Expect that the |async_id| is >= 0. |
| 9356 EXPECT(async_id >= 0); | 9359 EXPECT(async_id >= 0); |
| 9357 | 9360 |
| 9358 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); | 9361 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); |
| 9359 | 9362 |
| 9360 // Check that it is in the output. | 9363 // Check that it is in the output. |
| 9361 TimelineEventRecorder* recorder = Timeline::recorder(); | 9364 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 9365 Timeline::ReclaimIsolateBlocks(); |
| 9362 JSONStream js; | 9366 JSONStream js; |
| 9363 IsolateTimelineEventFilter filter(isolate); | 9367 IsolateTimelineEventFilter filter(isolate); |
| 9364 recorder->PrintJSON(&js, &filter); | 9368 recorder->PrintJSON(&js, &filter); |
| 9365 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); | 9369 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); |
| 9366 } | 9370 } |
| 9367 | 9371 |
| 9368 | 9372 |
| 9369 struct AppendData { | 9373 struct AppendData { |
| 9370 uint8_t* buffer; | 9374 uint8_t* buffer; |
| 9371 intptr_t buffer_length; | 9375 intptr_t buffer_length; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9477 // Heartbeat test. | 9481 // Heartbeat test. |
| 9478 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9482 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9479 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9483 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9480 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9484 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9481 | 9485 |
| 9482 // Free buffer allocated by AppendStreamConsumer | 9486 // Free buffer allocated by AppendStreamConsumer |
| 9483 free(data.buffer); | 9487 free(data.buffer); |
| 9484 } | 9488 } |
| 9485 | 9489 |
| 9486 | 9490 |
| 9487 UNIT_TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { | 9491 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { |
| 9492 const char* kScriptChars = |
| 9493 "bar() => 'z';\n" |
| 9494 "foo() => 'a';\n" |
| 9495 "main() => foo();\n"; |
| 9496 |
| 9497 // Enable all streams. |
| 9498 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | |
| 9499 DART_TIMELINE_STREAM_VM); |
| 9500 Dart_Handle lib; |
| 9501 { |
| 9502 // Add something to the VM stream. |
| 9503 TimelineDurationScope tds(Timeline::GetVMStream(), |
| 9504 "TestVMDuration"); |
| 9505 lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 9506 } |
| 9507 |
| 9508 // Invoke main, which will be compiled resulting in a compiler event in |
| 9509 // the timeline. |
| 9510 Dart_Handle result = Dart_Invoke(lib, |
| 9511 NewString("main"), |
| 9512 0, |
| 9513 NULL); |
| 9514 EXPECT_VALID(result); |
| 9515 |
| 9488 const char* buffer = NULL; | 9516 const char* buffer = NULL; |
| 9489 intptr_t buffer_length = 0; | 9517 intptr_t buffer_length = 0; |
| 9490 bool success = false; | 9518 bool success = false; |
| 9491 | 9519 |
| 9492 // Enable all streams. | |
| 9493 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | | |
| 9494 DART_TIMELINE_STREAM_VM); | |
| 9495 { | |
| 9496 // Create isolate. | |
| 9497 TestIsolateScope __test_isolate__; | |
| 9498 Thread* __thread__ = Thread::Current(); | |
| 9499 ASSERT(__thread__->isolate() == __test_isolate__.isolate()); | |
| 9500 StackZone __zone__(__thread__); | |
| 9501 HandleScope __hs__(__thread__); | |
| 9502 | |
| 9503 // Load test script. | |
| 9504 const char* kScriptChars = | |
| 9505 "foo() => 'a';\n" | |
| 9506 "main() => foo();\n"; | |
| 9507 | |
| 9508 Dart_Handle lib = | |
| 9509 TestCase::LoadTestScript(kScriptChars, NULL); | |
| 9510 | |
| 9511 // Invoke main, which will be compiled resulting in a compiler event in | |
| 9512 // the timeline. | |
| 9513 Dart_Handle result = Dart_Invoke(lib, | |
| 9514 NewString("main"), | |
| 9515 0, | |
| 9516 NULL); | |
| 9517 EXPECT_VALID(result); | |
| 9518 } | |
| 9519 | |
| 9520 // Isolate is shutdown now. | |
| 9521 // Grab the global trace. | 9520 // Grab the global trace. |
| 9522 AppendData data; | 9521 AppendData data; |
| 9523 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9522 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
| 9524 EXPECT(success); | 9523 EXPECT(success); |
| 9525 buffer = reinterpret_cast<char*>(data.buffer); | 9524 buffer = reinterpret_cast<char*>(data.buffer); |
| 9526 buffer_length = data.buffer_length; | 9525 buffer_length = data.buffer_length; |
| 9527 EXPECT(buffer_length > 0); | 9526 EXPECT(buffer_length > 0); |
| 9528 EXPECT(buffer != NULL); | 9527 EXPECT(buffer != NULL); |
| 9529 | 9528 |
| 9530 // Heartbeat test. | 9529 // Heartbeat test. |
| 9531 EXPECT_SUBSTRING("\"name\":\"InitializeIsolate\"", buffer); | 9530 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); |
| 9531 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9532 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9533 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9534 EXPECT_NOTSUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9535 |
| 9536 // Free buffer allocated by AppendStreamConsumer |
| 9537 free(data.buffer); |
| 9538 data.buffer = NULL; |
| 9539 data.buffer_length = 0; |
| 9540 |
| 9541 // Retrieving the global trace resulted in all open blocks being reclaimed. |
| 9542 // Add some new events and verify that both sets of events are present |
| 9543 // in the resulting trace. |
| 9544 { |
| 9545 // Add something to the VM stream. |
| 9546 TimelineDurationScope tds(Timeline::GetVMStream(), |
| 9547 "TestVMDuration2"); |
| 9548 // Invoke bar, which will be compiled resulting in a compiler event in |
| 9549 // the timeline. |
| 9550 result = Dart_Invoke(lib, |
| 9551 NewString("bar"), |
| 9552 0, |
| 9553 NULL); |
| 9554 } |
| 9555 |
| 9556 // Grab the global trace. |
| 9557 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
| 9558 EXPECT(success); |
| 9559 buffer = reinterpret_cast<char*>(data.buffer); |
| 9560 buffer_length = data.buffer_length; |
| 9561 EXPECT(buffer_length > 0); |
| 9562 EXPECT(buffer != NULL); |
| 9563 |
| 9564 // Heartbeat test for old events. |
| 9565 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); |
| 9532 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9566 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9533 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9567 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9534 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9568 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9535 | 9569 |
| 9570 // Heartbeat test for new events. |
| 9571 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
| 9572 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9573 |
| 9536 // Free buffer allocated by AppendStreamConsumer | 9574 // Free buffer allocated by AppendStreamConsumer |
| 9537 free(data.buffer); | 9575 free(data.buffer); |
| 9538 } | 9576 } |
| 9539 | 9577 |
| 9540 } // namespace dart | 9578 } // namespace dart |
| OLD | NEW |