| 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" |
| 11 #include "platform/text_buffer.h" | 11 #include "platform/text_buffer.h" |
| 12 #include "platform/utils.h" | 12 #include "platform/utils.h" |
| 13 #include "vm/class_finalizer.h" | 13 #include "vm/class_finalizer.h" |
| 14 #include "vm/dart_api_impl.h" | 14 #include "vm/dart_api_impl.h" |
| 15 #include "vm/dart_api_state.h" | 15 #include "vm/dart_api_state.h" |
| 16 #include "vm/lockers.h" | 16 #include "vm/lockers.h" |
| 17 #include "vm/timeline.h" |
| 17 #include "vm/unit_test.h" | 18 #include "vm/unit_test.h" |
| 18 #include "vm/verifier.h" | 19 #include "vm/verifier.h" |
| 19 | 20 |
| 20 namespace dart { | 21 namespace dart { |
| 21 | 22 |
| 22 DECLARE_FLAG(bool, verify_acquired_data); | 23 DECLARE_FLAG(bool, verify_acquired_data); |
| 23 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); | 24 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); |
| 24 | 25 |
| 25 #ifndef PRODUCT | 26 #ifndef PRODUCT |
| 26 | 27 |
| (...skipping 9156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9183 } | 9184 } |
| 9184 } | 9185 } |
| 9185 | 9186 |
| 9186 | 9187 |
| 9187 #ifndef PRODUCT | 9188 #ifndef PRODUCT |
| 9188 | 9189 |
| 9189 | 9190 |
| 9190 TEST_CASE(Timeline_Dart_TimelineDuration) { | 9191 TEST_CASE(Timeline_Dart_TimelineDuration) { |
| 9191 Isolate* isolate = Isolate::Current(); | 9192 Isolate* isolate = Isolate::Current(); |
| 9192 // Grab embedder stream. | 9193 // Grab embedder stream. |
| 9193 TimelineStream* stream = isolate->GetEmbedderStream(); | 9194 TimelineStream* stream = Timeline::GetEmbedderStream(); |
| 9194 // Make sure it is enabled. | 9195 // Make sure it is enabled. |
| 9195 stream->set_enabled(true); | 9196 stream->set_enabled(true); |
| 9196 // Add a duration event. | 9197 // Add a duration event. |
| 9197 Dart_TimelineDuration("testDurationEvent", 0, 1); | 9198 Dart_TimelineDuration("testDurationEvent", 0, 1); |
| 9198 // Check that it is in the output. | 9199 // Check that it is in the output. |
| 9199 TimelineEventRecorder* recorder = Timeline::recorder(); | 9200 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 9200 Timeline::ReclaimCachedBlocksFromThreads(); | 9201 Timeline::ReclaimCachedBlocksFromThreads(); |
| 9201 JSONStream js; | 9202 JSONStream js; |
| 9202 IsolateTimelineEventFilter filter(isolate->main_port()); | 9203 IsolateTimelineEventFilter filter(isolate->main_port()); |
| 9203 recorder->PrintJSON(&js, &filter); | 9204 recorder->PrintJSON(&js, &filter); |
| 9204 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); | 9205 EXPECT_SUBSTRING("testDurationEvent", js.ToCString()); |
| 9205 } | 9206 } |
| 9206 | 9207 |
| 9207 | 9208 |
| 9208 TEST_CASE(Timeline_Dart_TimelineInstant) { | 9209 TEST_CASE(Timeline_Dart_TimelineInstant) { |
| 9209 Isolate* isolate = Isolate::Current(); | 9210 Isolate* isolate = Isolate::Current(); |
| 9210 // Grab embedder stream. | 9211 // Grab embedder stream. |
| 9211 TimelineStream* stream = isolate->GetEmbedderStream(); | 9212 TimelineStream* stream = Timeline::GetEmbedderStream(); |
| 9212 // Make sure it is enabled. | 9213 // Make sure it is enabled. |
| 9213 stream->set_enabled(true); | 9214 stream->set_enabled(true); |
| 9214 Dart_TimelineInstant("testInstantEvent"); | 9215 Dart_TimelineInstant("testInstantEvent"); |
| 9215 // Check that it is in the output. | 9216 // Check that it is in the output. |
| 9216 TimelineEventRecorder* recorder = Timeline::recorder(); | 9217 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 9217 Timeline::ReclaimCachedBlocksFromThreads(); | 9218 Timeline::ReclaimCachedBlocksFromThreads(); |
| 9218 JSONStream js; | 9219 JSONStream js; |
| 9219 IsolateTimelineEventFilter filter(isolate->main_port()); | 9220 IsolateTimelineEventFilter filter(isolate->main_port()); |
| 9220 recorder->PrintJSON(&js, &filter); | 9221 recorder->PrintJSON(&js, &filter); |
| 9221 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); | 9222 EXPECT_SUBSTRING("testInstantEvent", js.ToCString()); |
| 9222 } | 9223 } |
| 9223 | 9224 |
| 9224 | 9225 |
| 9225 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { | 9226 TEST_CASE(Timeline_Dart_TimelineAsyncDisabled) { |
| 9226 Isolate* isolate = Isolate::Current(); | |
| 9227 // Grab embedder stream. | 9227 // Grab embedder stream. |
| 9228 TimelineStream* stream = isolate->GetEmbedderStream(); | 9228 TimelineStream* stream = Timeline::GetEmbedderStream(); |
| 9229 // Make sure it is disabled. | 9229 // Make sure it is disabled. |
| 9230 stream->set_enabled(false); | 9230 stream->set_enabled(false); |
| 9231 int64_t async_id = -1; | 9231 int64_t async_id = -1; |
| 9232 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); | 9232 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); |
| 9233 // Expect that the |async_id| is negative because the stream is disabled. | 9233 // Expect that the |async_id| is negative because the stream is disabled. |
| 9234 EXPECT(async_id < 0); | 9234 EXPECT(async_id < 0); |
| 9235 // Call Dart_TimelineAsyncEnd with a negative async_id. | 9235 // Call Dart_TimelineAsyncEnd with a negative async_id. |
| 9236 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); | 9236 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); |
| 9237 // Check that testAsync is not in the output. | 9237 // Check that testAsync is not in the output. |
| 9238 TimelineEventRecorder* recorder = Timeline::recorder(); | 9238 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 9239 Timeline::ReclaimCachedBlocksFromThreads(); | 9239 Timeline::ReclaimCachedBlocksFromThreads(); |
| 9240 JSONStream js; | 9240 JSONStream js; |
| 9241 TimelineEventFilter filter; | 9241 TimelineEventFilter filter; |
| 9242 recorder->PrintJSON(&js, &filter); | 9242 recorder->PrintJSON(&js, &filter); |
| 9243 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); | 9243 EXPECT_NOTSUBSTRING("testAsyncEvent", js.ToCString()); |
| 9244 } | 9244 } |
| 9245 | 9245 |
| 9246 | 9246 |
| 9247 TEST_CASE(Timeline_Dart_TimelineAsync) { | 9247 TEST_CASE(Timeline_Dart_TimelineAsync) { |
| 9248 Isolate* isolate = Isolate::Current(); | 9248 Isolate* isolate = Isolate::Current(); |
| 9249 // Grab embedder stream. | 9249 // Grab embedder stream. |
| 9250 TimelineStream* stream = isolate->GetEmbedderStream(); | 9250 TimelineStream* stream = Timeline::GetEmbedderStream(); |
| 9251 // Make sure it is enabled. | 9251 // Make sure it is enabled. |
| 9252 stream->set_enabled(true); | 9252 stream->set_enabled(true); |
| 9253 int64_t async_id = -1; | 9253 int64_t async_id = -1; |
| 9254 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); | 9254 Dart_TimelineAsyncBegin("testAsyncEvent", &async_id); |
| 9255 // Expect that the |async_id| is >= 0. | 9255 // Expect that the |async_id| is >= 0. |
| 9256 EXPECT(async_id >= 0); | 9256 EXPECT(async_id >= 0); |
| 9257 | 9257 |
| 9258 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); | 9258 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); |
| 9259 | 9259 |
| 9260 // Check that it is in the output. | 9260 // Check that it is in the output. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9308 "main() => foo();\n"; | 9308 "main() => foo();\n"; |
| 9309 | 9309 |
| 9310 Dart_Handle lib = | 9310 Dart_Handle lib = |
| 9311 TestCase::LoadTestScript(kScriptChars, NULL); | 9311 TestCase::LoadTestScript(kScriptChars, NULL); |
| 9312 | 9312 |
| 9313 const char* buffer = NULL; | 9313 const char* buffer = NULL; |
| 9314 intptr_t buffer_length = 0; | 9314 intptr_t buffer_length = 0; |
| 9315 bool success = false; | 9315 bool success = false; |
| 9316 | 9316 |
| 9317 // Enable recording of all streams. | 9317 // Enable recording of all streams. |
| 9318 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); | 9318 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); |
| 9319 | 9319 |
| 9320 // Invoke main, which will be compiled resulting in a compiler event in | 9320 // Invoke main, which will be compiled resulting in a compiler event in |
| 9321 // the timeline. | 9321 // the timeline. |
| 9322 Dart_Handle result = Dart_Invoke(lib, | 9322 Dart_Handle result = Dart_Invoke(lib, |
| 9323 NewString("main"), | 9323 NewString("main"), |
| 9324 0, | 9324 0, |
| 9325 NULL); | 9325 NULL); |
| 9326 EXPECT_VALID(result); | 9326 EXPECT_VALID(result); |
| 9327 | 9327 |
| 9328 // Grab the trace. | 9328 // Grab the trace. |
| 9329 AppendData data; | 9329 AppendData data; |
| 9330 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data); | 9330 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
| 9331 EXPECT(success); | 9331 EXPECT(success); |
| 9332 buffer = reinterpret_cast<char*>(data.buffer); | 9332 buffer = reinterpret_cast<char*>(data.buffer); |
| 9333 buffer_length = data.buffer_length; | 9333 buffer_length = data.buffer_length; |
| 9334 EXPECT(buffer_length > 0); | 9334 EXPECT(buffer_length > 0); |
| 9335 EXPECT(buffer != NULL); | 9335 EXPECT(buffer != NULL); |
| 9336 | 9336 |
| 9337 // Response starts with a '{' character and not a '['. | 9337 // Response starts with a '{' character and not a '['. |
| 9338 EXPECT(buffer[0] == '{'); | 9338 EXPECT(buffer[0] == '{'); |
| 9339 // Response ends with a '}' character and not a ']'. | 9339 // Response ends with a '}' character and not a ']'. |
| 9340 EXPECT(buffer[buffer_length - 1] == '\0'); | 9340 EXPECT(buffer[buffer_length - 1] == '\0'); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 9360 "}\n"; | 9360 "}\n"; |
| 9361 | 9361 |
| 9362 Dart_Handle lib = | 9362 Dart_Handle lib = |
| 9363 TestCase::LoadTestScript(kScriptChars, NULL); | 9363 TestCase::LoadTestScript(kScriptChars, NULL); |
| 9364 | 9364 |
| 9365 const char* buffer = NULL; | 9365 const char* buffer = NULL; |
| 9366 intptr_t buffer_length = 0; | 9366 intptr_t buffer_length = 0; |
| 9367 bool success = false; | 9367 bool success = false; |
| 9368 | 9368 |
| 9369 // Enable recording of the Dart stream. | 9369 // Enable recording of the Dart stream. |
| 9370 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART); | 9370 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART); |
| 9371 | 9371 |
| 9372 // Invoke main, which will add a new timeline event from Dart. | 9372 // Invoke main, which will add a new timeline event from Dart. |
| 9373 Dart_Handle result = Dart_Invoke(lib, | 9373 Dart_Handle result = Dart_Invoke(lib, |
| 9374 NewString("main"), | 9374 NewString("main"), |
| 9375 0, | 9375 0, |
| 9376 NULL); | 9376 NULL); |
| 9377 EXPECT_VALID(result); | 9377 EXPECT_VALID(result); |
| 9378 | 9378 |
| 9379 // Grab the trace. | 9379 // Grab the trace. |
| 9380 AppendData data; | 9380 AppendData data; |
| 9381 data.buffer = NULL; | 9381 data.buffer = NULL; |
| 9382 data.buffer_length = 0; | 9382 data.buffer_length = 0; |
| 9383 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data); | 9383 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
| 9384 EXPECT(success); | 9384 EXPECT(success); |
| 9385 buffer = reinterpret_cast<char*>(data.buffer); | 9385 buffer = reinterpret_cast<char*>(data.buffer); |
| 9386 buffer_length = data.buffer_length; | 9386 buffer_length = data.buffer_length; |
| 9387 EXPECT(buffer_length > 0); | 9387 EXPECT(buffer_length > 0); |
| 9388 EXPECT(buffer != NULL); | 9388 EXPECT(buffer != NULL); |
| 9389 | 9389 |
| 9390 // Response starts with a '{' character and not a '['. | 9390 // Response starts with a '{' character and not a '['. |
| 9391 EXPECT(buffer[0] == '{'); | 9391 EXPECT(buffer[0] == '{'); |
| 9392 // Response ends with a '}' character and not a ']'. | 9392 // Response ends with a '}' character and not a ']'. |
| 9393 EXPECT(buffer[buffer_length - 1] == '\0'); | 9393 EXPECT(buffer[buffer_length - 1] == '\0'); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 9412 "}\n"; | 9412 "}\n"; |
| 9413 | 9413 |
| 9414 Dart_Handle lib = | 9414 Dart_Handle lib = |
| 9415 TestCase::LoadTestScript(kScriptChars, NULL); | 9415 TestCase::LoadTestScript(kScriptChars, NULL); |
| 9416 | 9416 |
| 9417 const char* buffer = NULL; | 9417 const char* buffer = NULL; |
| 9418 intptr_t buffer_length = 0; | 9418 intptr_t buffer_length = 0; |
| 9419 bool success = false; | 9419 bool success = false; |
| 9420 | 9420 |
| 9421 // Enable recording of all streams. | 9421 // Enable recording of all streams. |
| 9422 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); | 9422 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); |
| 9423 | 9423 |
| 9424 // Invoke main, which will be compiled resulting in a compiler event in | 9424 // Invoke main, which will be compiled resulting in a compiler event in |
| 9425 // the timeline. | 9425 // the timeline. |
| 9426 Dart_Handle result = Dart_Invoke(lib, | 9426 Dart_Handle result = Dart_Invoke(lib, |
| 9427 NewString("main"), | 9427 NewString("main"), |
| 9428 0, | 9428 0, |
| 9429 NULL); | 9429 NULL); |
| 9430 EXPECT_VALID(result); | 9430 EXPECT_VALID(result); |
| 9431 | 9431 |
| 9432 // Grab the trace. | 9432 // Grab the trace. |
| 9433 AppendData data; | 9433 AppendData data; |
| 9434 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data); | 9434 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
| 9435 EXPECT(success); | 9435 EXPECT(success); |
| 9436 buffer = reinterpret_cast<char*>(data.buffer); | 9436 buffer = reinterpret_cast<char*>(data.buffer); |
| 9437 buffer_length = data.buffer_length; | 9437 buffer_length = data.buffer_length; |
| 9438 EXPECT(buffer_length > 0); | 9438 EXPECT(buffer_length > 0); |
| 9439 EXPECT(buffer != NULL); | 9439 EXPECT(buffer != NULL); |
| 9440 | 9440 |
| 9441 // Response starts with a '{' character and not a '['. | 9441 // Response starts with a '{' character and not a '['. |
| 9442 EXPECT(buffer[0] == '{'); | 9442 EXPECT(buffer[0] == '{'); |
| 9443 // Response ends with a '}' character and not a ']'. | 9443 // Response ends with a '}' character and not a ']'. |
| 9444 EXPECT(buffer[buffer_length - 1] == '\0'); | 9444 EXPECT(buffer[buffer_length - 1] == '\0'); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 9473 // Invoke main, which will be compiled resulting in a compiler event in | 9473 // Invoke main, which will be compiled resulting in a compiler event in |
| 9474 // the timeline. | 9474 // the timeline. |
| 9475 Dart_Handle result = Dart_Invoke(lib, | 9475 Dart_Handle result = Dart_Invoke(lib, |
| 9476 NewString("main"), | 9476 NewString("main"), |
| 9477 0, | 9477 0, |
| 9478 NULL); | 9478 NULL); |
| 9479 EXPECT_VALID(result); | 9479 EXPECT_VALID(result); |
| 9480 | 9480 |
| 9481 // Grab the trace. | 9481 // Grab the trace. |
| 9482 AppendData data; | 9482 AppendData data; |
| 9483 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data); | 9483 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); |
| 9484 EXPECT(success); | 9484 EXPECT(success); |
| 9485 buffer = reinterpret_cast<char*>(data.buffer); | 9485 buffer = reinterpret_cast<char*>(data.buffer); |
| 9486 buffer_length = data.buffer_length; | 9486 buffer_length = data.buffer_length; |
| 9487 EXPECT(buffer_length > 0); | 9487 EXPECT(buffer_length > 0); |
| 9488 EXPECT(buffer != NULL); | 9488 EXPECT(buffer != NULL); |
| 9489 | 9489 |
| 9490 // Response starts with a '{' character and not a '['. | 9490 // Response starts with a '{' character and not a '['. |
| 9491 EXPECT(buffer[0] == '{'); | 9491 EXPECT(buffer[0] == '{'); |
| 9492 // Response ends with a '}' character and not a ']'. | 9492 // Response ends with a '}' character and not a ']'. |
| 9493 EXPECT(buffer[buffer_length - 1] == '\0'); | 9493 EXPECT(buffer[buffer_length - 1] == '\0'); |
| 9494 EXPECT(buffer[buffer_length - 2] == '}'); | 9494 EXPECT(buffer[buffer_length - 2] == '}'); |
| 9495 | 9495 |
| 9496 // Heartbeat test. | 9496 // Heartbeat test. |
| 9497 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9497 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9498 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9498 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9499 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9499 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9500 | 9500 |
| 9501 // Free buffer allocated by AppendStreamConsumer | 9501 // Free buffer allocated by AppendStreamConsumer |
| 9502 free(data.buffer); | 9502 free(data.buffer); |
| 9503 } | 9503 } |
| 9504 | 9504 |
| 9505 | 9505 |
| 9506 static const char* arg_names[] = { |
| 9507 "arg0" |
| 9508 }; |
| 9509 |
| 9510 |
| 9511 static const char* arg_values[] = { |
| 9512 "value0" |
| 9513 }; |
| 9514 |
| 9515 |
| 9506 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { | 9516 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace) { |
| 9507 const char* kScriptChars = | 9517 const char* kScriptChars = |
| 9508 "bar() => 'z';\n" | 9518 "bar() => 'z';\n" |
| 9509 "foo() => 'a';\n" | 9519 "foo() => 'a';\n" |
| 9510 "main() => foo();\n"; | 9520 "main() => foo();\n"; |
| 9511 | 9521 |
| 9512 // Enable all streams. | 9522 // Enable all streams. |
| 9513 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | | 9523 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | |
| 9514 DART_TIMELINE_STREAM_VM); | 9524 DART_TIMELINE_STREAM_VM); |
| 9515 Dart_Handle lib; | 9525 Dart_Handle lib; |
| 9516 { | 9526 { |
| 9517 // Add something to the VM stream. | 9527 // Add something to the VM stream. |
| 9518 TimelineDurationScope tds(Timeline::GetVMStream(), | 9528 TimelineDurationScope tds(Timeline::GetVMStream(), |
| 9519 "TestVMDuration"); | 9529 "TestVMDuration"); |
| 9520 lib = TestCase::LoadTestScript(kScriptChars, NULL); | 9530 lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 9521 } | 9531 } |
| 9522 | 9532 |
| 9533 { |
| 9534 // Add something to the embedder stream. |
| 9535 Dart_TimelineEvent("TRACE_EVENT", |
| 9536 Dart_TimelineGetMicros(), |
| 9537 0, |
| 9538 Dart_Timeline_Event_Begin, |
| 9539 1, |
| 9540 &arg_names[0], |
| 9541 &arg_values[0]); |
| 9542 } |
| 9543 |
| 9523 // Invoke main, which will be compiled resulting in a compiler event in | 9544 // Invoke main, which will be compiled resulting in a compiler event in |
| 9524 // the timeline. | 9545 // the timeline. |
| 9525 Dart_Handle result = Dart_Invoke(lib, | 9546 Dart_Handle result = Dart_Invoke(lib, |
| 9526 NewString("main"), | 9547 NewString("main"), |
| 9527 0, | 9548 0, |
| 9528 NULL); | 9549 NULL); |
| 9529 EXPECT_VALID(result); | 9550 EXPECT_VALID(result); |
| 9530 | 9551 |
| 9531 const char* buffer = NULL; | 9552 const char* buffer = NULL; |
| 9532 intptr_t buffer_length = 0; | 9553 intptr_t buffer_length = 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 9552 // Response ends with a '}' character and not a ']'. | 9573 // Response ends with a '}' character and not a ']'. |
| 9553 EXPECT(buffer[buffer_length - 1] == '\0'); | 9574 EXPECT(buffer[buffer_length - 1] == '\0'); |
| 9554 EXPECT(buffer[buffer_length - 2] == '}'); | 9575 EXPECT(buffer[buffer_length - 2] == '}'); |
| 9555 | 9576 |
| 9556 // Heartbeat test. | 9577 // Heartbeat test. |
| 9557 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); | 9578 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); |
| 9558 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9579 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9559 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9580 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9560 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9581 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9561 EXPECT_NOTSUBSTRING("\"function\":\"::_bar\"", buffer); | 9582 EXPECT_NOTSUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9583 EXPECT_SUBSTRING("TRACE_EVENT", buffer); |
| 9584 EXPECT_SUBSTRING("arg0", buffer); |
| 9585 EXPECT_SUBSTRING("value0", buffer); |
| 9562 | 9586 |
| 9563 // Free buffer allocated by AppendStreamConsumer | 9587 // Free buffer allocated by AppendStreamConsumer |
| 9564 free(data.buffer); | 9588 free(data.buffer); |
| 9565 data.buffer = NULL; | 9589 data.buffer = NULL; |
| 9566 data.buffer_length = 0; | 9590 data.buffer_length = 0; |
| 9567 | 9591 |
| 9568 // Retrieving the global trace resulted in all open blocks being reclaimed. | 9592 // Retrieving the global trace resulted in all open blocks being reclaimed. |
| 9569 // Add some new events and verify that both sets of events are present | 9593 // Add some new events and verify that both sets of events are present |
| 9570 // in the resulting trace. | 9594 // in the resulting trace. |
| 9571 { | 9595 { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9779 static void StartRecording() { | 9803 static void StartRecording() { |
| 9780 start_called = true; | 9804 start_called = true; |
| 9781 } | 9805 } |
| 9782 | 9806 |
| 9783 static void StopRecording() { | 9807 static void StopRecording() { |
| 9784 stop_called = true; | 9808 stop_called = true; |
| 9785 } | 9809 } |
| 9786 | 9810 |
| 9787 | 9811 |
| 9788 TEST_CASE(Timeline_Dart_EmbedderTimelineStartStopRecording) { | 9812 TEST_CASE(Timeline_Dart_EmbedderTimelineStartStopRecording) { |
| 9789 Dart_SetEmbedderTimelineCallbacks(StartRecording, StopRecording, NULL); | 9813 Dart_SetEmbedderTimelineCallbacks(StartRecording, StopRecording); |
| 9790 | 9814 |
| 9791 EXPECT(!start_called); | 9815 EXPECT(!start_called); |
| 9792 EXPECT(!stop_called); | 9816 EXPECT(!stop_called); |
| 9793 Timeline::SetStreamEmbedderEnabled(true); | 9817 Timeline::SetStreamEmbedderEnabled(true); |
| 9794 EXPECT(start_called); | 9818 EXPECT(start_called); |
| 9795 EXPECT(!stop_called); | 9819 EXPECT(!stop_called); |
| 9796 | 9820 |
| 9797 start_called = false; | 9821 start_called = false; |
| 9798 stop_called = false; | 9822 stop_called = false; |
| 9799 EXPECT(!start_called); | 9823 EXPECT(!start_called); |
| 9800 EXPECT(!stop_called); | 9824 EXPECT(!stop_called); |
| 9801 Timeline::SetStreamEmbedderEnabled(false); | 9825 Timeline::SetStreamEmbedderEnabled(false); |
| 9802 EXPECT(!start_called); | 9826 EXPECT(!start_called); |
| 9803 EXPECT(stop_called); | 9827 EXPECT(stop_called); |
| 9804 } | 9828 } |
| 9805 | 9829 |
| 9806 static bool GetTimeline(Dart_StreamConsumer stream_consumer, | |
| 9807 void* user_data) { | |
| 9808 ASSERT(stream_consumer != NULL); | |
| 9809 ASSERT(user_data != NULL); | |
| 9810 | |
| 9811 const char* test_string = "HELLO FROM EMBEDDER"; | |
| 9812 stream_consumer(Dart_StreamConsumer_kData, | |
| 9813 "embedder.timeline", | |
| 9814 reinterpret_cast<const uint8_t*>(test_string), | |
| 9815 strlen(test_string), | |
| 9816 user_data); | |
| 9817 return true; | |
| 9818 } | |
| 9819 | |
| 9820 TEST_CASE(Timeline_Dart_EmbedderTimelineGetTimeline) { | |
| 9821 Dart_SetEmbedderTimelineCallbacks(NULL, NULL, GetTimeline); | |
| 9822 | |
| 9823 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_EMBEDDER); | |
| 9824 Dart_TimelineDuration("testDurationEvent", 0, 1); | |
| 9825 | |
| 9826 AppendData data; | |
| 9827 bool success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | |
| 9828 EXPECT(success); | |
| 9829 | |
| 9830 EXPECT_SUBSTRING("}},HELLO FROM EMBEDDER", | |
| 9831 data.buffer); | |
| 9832 | |
| 9833 // Free buffer allocated by AppendStreamConsumer | |
| 9834 free(data.buffer); | |
| 9835 } | |
| 9836 | |
| 9837 #endif // !PRODUCT | 9830 #endif // !PRODUCT |
| 9838 | 9831 |
| 9839 } // namespace dart | 9832 } // namespace dart |
| OLD | NEW |