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 9261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9272 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); | 9272 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); |
9273 | 9273 |
9274 // Check that it is in the output. | 9274 // Check that it is in the output. |
9275 TimelineEventRecorder* recorder = isolate->timeline_event_recorder(); | 9275 TimelineEventRecorder* recorder = isolate->timeline_event_recorder(); |
9276 JSONStream js; | 9276 JSONStream js; |
9277 recorder->PrintJSON(&js); | 9277 recorder->PrintJSON(&js); |
9278 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); | 9278 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); |
9279 } | 9279 } |
9280 | 9280 |
9281 | 9281 |
| 9282 struct AppendData { |
| 9283 uint8_t* buffer; |
| 9284 intptr_t buffer_length; |
| 9285 }; |
| 9286 |
| 9287 |
| 9288 static void AppendStreamConsumer(intptr_t state, |
| 9289 const char* stream_name, |
| 9290 uint8_t* buffer, |
| 9291 intptr_t buffer_length, |
| 9292 void* user_data) { |
| 9293 if (state == DART_STREAM_CONSUMER_STATE_FINISH) { |
| 9294 return; |
| 9295 } |
| 9296 AppendData* data = reinterpret_cast<AppendData*>(user_data); |
| 9297 if (state == DART_STREAM_CONSUMER_STATE_START) { |
| 9298 // Initialize append data. |
| 9299 data->buffer = NULL; |
| 9300 data->buffer_length = 0; |
| 9301 return; |
| 9302 } |
| 9303 ASSERT(state == DART_STREAM_CONSUMER_STATE_DATA); |
| 9304 // Grow buffer. |
| 9305 data->buffer = reinterpret_cast<uint8_t*>( |
| 9306 realloc(data->buffer, data->buffer_length + buffer_length)); |
| 9307 // Copy new data. |
| 9308 memmove(&data->buffer[data->buffer_length], |
| 9309 buffer, |
| 9310 buffer_length); |
| 9311 // Update length. |
| 9312 data->buffer_length += buffer_length; |
| 9313 } |
| 9314 |
| 9315 |
9282 TEST_CASE(Timeline_Dart_TimelineGetTrace) { | 9316 TEST_CASE(Timeline_Dart_TimelineGetTrace) { |
9283 const char* kScriptChars = | 9317 const char* kScriptChars = |
9284 "foo() => 'a';\n" | 9318 "foo() => 'a';\n" |
9285 "main() => foo();\n"; | 9319 "main() => foo();\n"; |
9286 | 9320 |
9287 Dart_Handle lib = | 9321 Dart_Handle lib = |
9288 TestCase::LoadTestScript(kScriptChars, NULL); | 9322 TestCase::LoadTestScript(kScriptChars, NULL); |
9289 | 9323 |
9290 const char* buffer = NULL; | 9324 const char* buffer = NULL; |
9291 intptr_t buffer_length = 0; | 9325 intptr_t buffer_length = 0; |
9292 bool success = false; | 9326 bool success = false; |
9293 | 9327 |
9294 // Enable recording of all streams. | 9328 // Enable recording of all streams. |
9295 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); | 9329 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL); |
9296 | 9330 |
9297 // Invoke main, which will be compiled resulting in a compiler event in | 9331 // Invoke main, which will be compiled resulting in a compiler event in |
9298 // the timeline. | 9332 // the timeline. |
9299 Dart_Handle result = Dart_Invoke(lib, | 9333 Dart_Handle result = Dart_Invoke(lib, |
9300 NewString("main"), | 9334 NewString("main"), |
9301 0, | 9335 0, |
9302 NULL); | 9336 NULL); |
9303 EXPECT_VALID(result); | 9337 EXPECT_VALID(result); |
9304 | 9338 |
9305 // Grab the trace. | 9339 // Grab the trace. |
9306 success = Dart_TimelineGetTrace(&buffer, &buffer_length); | 9340 AppendData data; |
| 9341 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data); |
9307 EXPECT(success); | 9342 EXPECT(success); |
| 9343 buffer = reinterpret_cast<char*>(data.buffer); |
| 9344 buffer_length = data.buffer_length; |
9308 EXPECT(buffer_length > 0); | 9345 EXPECT(buffer_length > 0); |
9309 EXPECT(buffer != NULL); | 9346 EXPECT(buffer != NULL); |
| 9347 |
9310 // Heartbeat test. | 9348 // Heartbeat test. |
9311 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9349 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9312 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9350 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9313 EXPECT_SUBSTRING("\"function\":\"main\"", buffer); | 9351 EXPECT_SUBSTRING("\"function\":\"main\"", buffer); |
9314 // Free buffer acquired by Dart_TimelineGetTrace call. | 9352 |
9315 free(const_cast<char*>(buffer)); | 9353 // Free buffer allocated by AppendStreamConsumer |
| 9354 free(data.buffer); |
9316 } | 9355 } |
9317 | 9356 |
9318 } // namespace dart | 9357 } // namespace dart |
OLD | NEW |