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 9271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9282 return; | 9282 return; |
9283 } | 9283 } |
9284 AppendData* data = reinterpret_cast<AppendData*>(user_data); | 9284 AppendData* data = reinterpret_cast<AppendData*>(user_data); |
9285 if (state == Dart_StreamConsumer_kStart) { | 9285 if (state == Dart_StreamConsumer_kStart) { |
9286 // Initialize append data. | 9286 // Initialize append data. |
9287 data->buffer = NULL; | 9287 data->buffer = NULL; |
9288 data->buffer_length = 0; | 9288 data->buffer_length = 0; |
9289 return; | 9289 return; |
9290 } | 9290 } |
9291 ASSERT(state == Dart_StreamConsumer_kData); | 9291 ASSERT(state == Dart_StreamConsumer_kData); |
| 9292 |
9292 // Grow buffer. | 9293 // Grow buffer. |
9293 data->buffer = reinterpret_cast<uint8_t*>( | 9294 data->buffer = reinterpret_cast<uint8_t*>( |
9294 realloc(data->buffer, data->buffer_length + buffer_length)); | 9295 realloc(data->buffer, data->buffer_length + buffer_length)); |
9295 // Copy new data. | 9296 // Copy new data. |
9296 memmove(&data->buffer[data->buffer_length], | 9297 memmove(&data->buffer[data->buffer_length], |
9297 buffer, | 9298 buffer, |
9298 buffer_length); | 9299 buffer_length); |
9299 // Update length. | 9300 // Update length. |
9300 data->buffer_length += buffer_length; | 9301 data->buffer_length += buffer_length; |
9301 } | 9302 } |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9765 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); | 9766 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); |
9766 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9767 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9767 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9768 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9768 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9769 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9769 | 9770 |
9770 // Heartbeat test for new events. | 9771 // Heartbeat test for new events. |
9771 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9772 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
9772 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9773 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9773 } | 9774 } |
9774 | 9775 |
| 9776 static bool start_called = false; |
| 9777 static bool stop_called = false; |
| 9778 |
| 9779 static void StartRecording() { |
| 9780 start_called = true; |
| 9781 } |
| 9782 |
| 9783 static void StopRecording() { |
| 9784 stop_called = true; |
| 9785 } |
| 9786 |
| 9787 |
| 9788 TEST_CASE(Timeline_Dart_EmbedderTimelineStartStopRecording) { |
| 9789 Dart_SetEmbedderTimelineCallbacks(StartRecording, StopRecording, NULL); |
| 9790 |
| 9791 EXPECT(!start_called); |
| 9792 EXPECT(!stop_called); |
| 9793 Timeline::SetStreamEmbedderEnabled(true); |
| 9794 EXPECT(start_called); |
| 9795 EXPECT(!stop_called); |
| 9796 |
| 9797 start_called = false; |
| 9798 stop_called = false; |
| 9799 EXPECT(!start_called); |
| 9800 EXPECT(!stop_called); |
| 9801 Timeline::SetStreamEmbedderEnabled(false); |
| 9802 EXPECT(!start_called); |
| 9803 EXPECT(stop_called); |
| 9804 } |
| 9805 |
| 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,{\"name\":\"testDurationEvent\"", |
| 9831 data.buffer); |
| 9832 |
| 9833 // Free buffer allocated by AppendStreamConsumer |
| 9834 free(data.buffer); |
| 9835 } |
| 9836 |
9775 #endif // !PRODUCT | 9837 #endif // !PRODUCT |
9776 | 9838 |
9777 } // namespace dart | 9839 } // namespace dart |
OLD | NEW |