Chromium Code Reviews| 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 9360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9371 | 9371 |
| 9372 | 9372 |
| 9373 struct AppendData { | 9373 struct AppendData { |
| 9374 uint8_t* buffer; | 9374 uint8_t* buffer; |
| 9375 intptr_t buffer_length; | 9375 intptr_t buffer_length; |
| 9376 }; | 9376 }; |
| 9377 | 9377 |
| 9378 | 9378 |
| 9379 static void AppendStreamConsumer(Dart_StreamConsumer_State state, | 9379 static void AppendStreamConsumer(Dart_StreamConsumer_State state, |
| 9380 const char* stream_name, | 9380 const char* stream_name, |
| 9381 uint8_t* buffer, | 9381 const uint8_t* buffer, |
| 9382 intptr_t buffer_length, | 9382 intptr_t buffer_length, |
| 9383 void* user_data) { | 9383 void* user_data) { |
| 9384 if (state == Dart_StreamConsumer_kFinish) { | 9384 if (state == Dart_StreamConsumer_kFinish) { |
| 9385 return; | 9385 return; |
| 9386 } | 9386 } |
| 9387 AppendData* data = reinterpret_cast<AppendData*>(user_data); | 9387 AppendData* data = reinterpret_cast<AppendData*>(user_data); |
| 9388 if (state == Dart_StreamConsumer_kStart) { | 9388 if (state == Dart_StreamConsumer_kStart) { |
| 9389 // Initialize append data. | 9389 // Initialize append data. |
| 9390 data->buffer = NULL; | 9390 data->buffer = NULL; |
| 9391 data->buffer_length = 0; | 9391 data->buffer_length = 0; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9439 // Heartbeat test. | 9439 // Heartbeat test. |
| 9440 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9440 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9441 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9441 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9442 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9442 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9443 | 9443 |
| 9444 // Free buffer allocated by AppendStreamConsumer | 9444 // Free buffer allocated by AppendStreamConsumer |
| 9445 free(data.buffer); | 9445 free(data.buffer); |
| 9446 } | 9446 } |
| 9447 | 9447 |
| 9448 | 9448 |
| 9449 TEST_CASE(Timeline_Dart_TimelineGetTraceOnlyDartEvents) { | |
| 9450 const char* kScriptChars = | |
| 9451 "import 'dart:developer';\n" | |
| 9452 "" | |
| 9453 "main() => Timeline.openSync('DART_CATEGORY', 'DART_NAME')..close();\n"; | |
|
rmacnak
2015/09/29 22:36:41
cascade doesn't add anything here.
Cutch
2015/09/30 14:42:29
Done.
| |
| 9454 | |
| 9455 Dart_Handle lib = | |
| 9456 TestCase::LoadTestScript(kScriptChars, NULL); | |
| 9457 | |
| 9458 const char* buffer = NULL; | |
| 9459 intptr_t buffer_length = 0; | |
| 9460 bool success = false; | |
| 9461 | |
| 9462 // Enable recording of the Dart stream. | |
| 9463 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART); | |
| 9464 | |
| 9465 // Invoke main, which will add a new timeline event from Dart. | |
| 9466 Dart_Handle result = Dart_Invoke(lib, | |
| 9467 NewString("main"), | |
| 9468 0, | |
| 9469 NULL); | |
| 9470 EXPECT_VALID(result); | |
| 9471 | |
| 9472 // Grab the trace. | |
| 9473 AppendData data; | |
| 9474 data.buffer = NULL; | |
| 9475 data.buffer_length = 0; | |
| 9476 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data); | |
| 9477 EXPECT(success); | |
| 9478 buffer = reinterpret_cast<char*>(data.buffer); | |
| 9479 buffer_length = data.buffer_length; | |
| 9480 EXPECT(buffer_length > 0); | |
| 9481 EXPECT(buffer != NULL); | |
| 9482 | |
| 9483 // Heartbeat test. | |
| 9484 EXPECT_SUBSTRING("\"cat\":\"DART_CATEGORY\"", buffer); | |
| 9485 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); | |
| 9486 | |
| 9487 // Free buffer allocated by AppendStreamConsumer | |
| 9488 free(data.buffer); | |
| 9489 } | |
| 9490 | |
| 9491 | |
| 9492 TEST_CASE(Timeline_Dart_TimelineGetTraceWithDartEvents) { | |
| 9493 const char* kScriptChars = | |
| 9494 "import 'dart:developer';\n" | |
| 9495 "\n" | |
| 9496 "main() => Timeline.openSync('DART_CATEGORY', 'DART_NAME')..close();\n"; | |
|
rmacnak
2015/09/29 22:36:41
"
Cutch
2015/09/30 14:42:29
Done.
| |
| 9497 | |
| 9498 Dart_Handle lib = | |
| 9499 TestCase::LoadTestScript(kScriptChars, NULL); | |
| 9500 | |
| 9501 const char* buffer = NULL; | |
| 9502 intptr_t buffer_length = 0; | |
| 9503 bool success = false; | |
| 9504 | |
| 9505 // Enable recording of all streams. | |
| 9506 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); | |
| 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 | |
| 9516 // Grab the trace. | |
| 9517 AppendData data; | |
| 9518 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data); | |
| 9519 EXPECT(success); | |
| 9520 buffer = reinterpret_cast<char*>(data.buffer); | |
| 9521 buffer_length = data.buffer_length; | |
| 9522 EXPECT(buffer_length > 0); | |
| 9523 EXPECT(buffer != NULL); | |
| 9524 | |
| 9525 // Heartbeat test. | |
| 9526 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | |
| 9527 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | |
| 9528 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | |
| 9529 EXPECT_SUBSTRING("\"cat\":\"DART_CATEGORY\"", buffer); | |
| 9530 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer); | |
| 9531 | |
| 9532 // Free buffer allocated by AppendStreamConsumer | |
| 9533 free(data.buffer); | |
| 9534 } | |
| 9535 | |
| 9449 TEST_CASE(Timeline_Dart_TimelineGetTraceGlobalOverride) { | 9536 TEST_CASE(Timeline_Dart_TimelineGetTraceGlobalOverride) { |
| 9450 const char* kScriptChars = | 9537 const char* kScriptChars = |
| 9451 "foo() => 'a';\n" | 9538 "foo() => 'a';\n" |
| 9452 "main() => foo();\n"; | 9539 "main() => foo();\n"; |
| 9453 | 9540 |
| 9454 Dart_Handle lib = | 9541 Dart_Handle lib = |
| 9455 TestCase::LoadTestScript(kScriptChars, NULL); | 9542 TestCase::LoadTestScript(kScriptChars, NULL); |
| 9456 | 9543 |
| 9457 const char* buffer = NULL; | 9544 const char* buffer = NULL; |
| 9458 intptr_t buffer_length = 0; | 9545 intptr_t buffer_length = 0; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9569 | 9656 |
| 9570 // Heartbeat test for new events. | 9657 // Heartbeat test for new events. |
| 9571 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9658 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
| 9572 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9659 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9573 | 9660 |
| 9574 // Free buffer allocated by AppendStreamConsumer | 9661 // Free buffer allocated by AppendStreamConsumer |
| 9575 free(data.buffer); | 9662 free(data.buffer); |
| 9576 } | 9663 } |
| 9577 | 9664 |
| 9578 } // namespace dart | 9665 } // namespace dart |
| OLD | NEW |