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 9242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9253 0, | 9253 0, |
| 9254 NULL); | 9254 NULL); |
| 9255 EXPECT_VALID(result); | 9255 EXPECT_VALID(result); |
| 9256 | 9256 |
| 9257 const char* buffer = NULL; | 9257 const char* buffer = NULL; |
| 9258 intptr_t buffer_length = 0; | 9258 intptr_t buffer_length = 0; |
| 9259 bool success = false; | 9259 bool success = false; |
| 9260 | 9260 |
| 9261 // Grab the global trace. | 9261 // Grab the global trace. |
| 9262 AppendData data; | 9262 AppendData data; |
| 9263 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9263 { |
| 9264 EXPECT(success); | 9264 Thread* T = Thread::Current(); |
| 9265 StackZone zone(T); | |
| 9266 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | |
| 9267 EXPECT(success); | |
| 9268 // The call should do no zone allocation. | |
| 9269 EXPECT(zone.SizeInBytes() == 0); | |
| 9270 } | |
| 9265 buffer = reinterpret_cast<char*>(data.buffer); | 9271 buffer = reinterpret_cast<char*>(data.buffer); |
| 9266 buffer_length = data.buffer_length; | 9272 buffer_length = data.buffer_length; |
| 9267 EXPECT(buffer_length > 0); | 9273 EXPECT(buffer_length > 0); |
| 9268 EXPECT(buffer != NULL); | 9274 EXPECT(buffer != NULL); |
| 9269 | 9275 |
| 9270 // Response starts with a '{' character and not a '['. | 9276 // Response starts with a '{' character and not a '['. |
| 9271 EXPECT(buffer[0] == '{'); | 9277 EXPECT(buffer[0] == '{'); |
| 9272 // Response ends with a '}' character and not a ']'. | 9278 // Response ends with a '}' character and not a ']'. |
| 9273 EXPECT(buffer[buffer_length - 1] == '\0'); | 9279 EXPECT(buffer[buffer_length - 1] == '\0'); |
| 9274 EXPECT(buffer[buffer_length - 2] == '}'); | 9280 EXPECT(buffer[buffer_length - 2] == '}'); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 9294 "TestVMDuration2"); | 9300 "TestVMDuration2"); |
| 9295 // Invoke bar, which will be compiled resulting in a compiler event in | 9301 // Invoke bar, which will be compiled resulting in a compiler event in |
| 9296 // the timeline. | 9302 // the timeline. |
| 9297 result = Dart_Invoke(lib, | 9303 result = Dart_Invoke(lib, |
| 9298 NewString("bar"), | 9304 NewString("bar"), |
| 9299 0, | 9305 0, |
| 9300 NULL); | 9306 NULL); |
| 9301 } | 9307 } |
| 9302 | 9308 |
| 9303 // Grab the global trace. | 9309 // Grab the global trace. |
| 9304 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | 9310 { |
| 9305 EXPECT(success); | 9311 Thread* T = Thread::Current(); |
| 9312 StackZone zone(T); | |
| 9313 success = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); | |
| 9314 EXPECT(success); | |
| 9315 EXPECT(zone.SizeInBytes() == 0); | |
| 9316 } | |
| 9306 buffer = reinterpret_cast<char*>(data.buffer); | 9317 buffer = reinterpret_cast<char*>(data.buffer); |
| 9307 buffer_length = data.buffer_length; | 9318 buffer_length = data.buffer_length; |
| 9308 EXPECT(buffer_length > 0); | 9319 EXPECT(buffer_length > 0); |
| 9309 EXPECT(buffer != NULL); | 9320 EXPECT(buffer != NULL); |
| 9310 // Response starts with a '{' character and not a '['. | 9321 // Response starts with a '{' character and not a '['. |
| 9311 EXPECT(buffer[0] == '{'); | 9322 EXPECT(buffer[0] == '{'); |
| 9312 // Response ends with a '}' character and not a ']'. | 9323 // Response ends with a '}' character and not a ']'. |
| 9313 EXPECT(buffer[buffer_length - 1] == '\0'); | 9324 EXPECT(buffer[buffer_length - 1] == '\0'); |
| 9314 EXPECT(buffer[buffer_length - 2] == '}'); | 9325 EXPECT(buffer[buffer_length - 2] == '}'); |
| 9315 | 9326 |
| 9316 // Heartbeat test for old events. | 9327 // Heartbeat test for old events. |
| 9317 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); | 9328 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); |
| 9318 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9329 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9319 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9330 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9320 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9331 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9321 | 9332 |
| 9322 // Heartbeat test for new events. | 9333 // Heartbeat test for new events. |
| 9323 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9334 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
| 9324 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9335 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9325 | 9336 |
| 9326 // Free buffer allocated by AppendStreamConsumer | 9337 // Free buffer allocated by AppendStreamConsumer |
| 9327 free(data.buffer); | 9338 free(data.buffer); |
| 9328 } | 9339 } |
| 9329 | 9340 |
| 9341 | |
| 9342 struct GlobalTimelineThreadData { | |
|
Ivan Posva
2015/12/01 18:00:51
How about making this a class with a destructor an
zra
2015/12/01 18:51:51
Done.
| |
| 9343 explicit GlobalTimelineThreadData(Monitor* m) | |
| 9344 : monitor(m), | |
| 9345 running(true), | |
| 9346 join_id(OSThread::kInvalidThreadJoinId) { | |
| 9347 } | |
| 9348 | |
| 9349 Monitor* monitor; | |
| 9350 AppendData data; | |
| 9351 bool running; | |
| 9352 ThreadJoinId join_id; | |
| 9353 }; | |
| 9354 | |
| 9355 | |
| 9356 static void GlobalTimelineThread(uword parameter) { | |
| 9357 GlobalTimelineThreadData* data = | |
| 9358 reinterpret_cast<GlobalTimelineThreadData*>(parameter); | |
| 9359 Thread* T = Thread::Current(); | |
| 9360 // When there is no current Thread, then Zone allocation will fail. | |
| 9361 EXPECT(T == NULL); | |
| 9362 { | |
| 9363 MonitorLocker ml(data->monitor); | |
| 9364 bool success = Dart_GlobalTimelineGetTrace( | |
| 9365 AppendStreamConsumer, &data->data); | |
| 9366 EXPECT(success); | |
| 9367 data->running = false; | |
| 9368 data->join_id = OSThread::Current()->join_id(); | |
| 9369 ml.Notify(); | |
| 9370 } | |
| 9371 } | |
| 9372 | |
| 9373 | |
| 9374 // This test is the same as the one above except that the calls to | |
| 9375 // Dart_GlobalTimelineGetTrace are made from a fresh thread. This ensures that | |
| 9376 // we can call the function from a thread for which we have not set up a | |
| 9377 // Thread object. | |
| 9378 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace_Threaded) { | |
| 9379 const char* kScriptChars = | |
| 9380 "bar() => 'z';\n" | |
| 9381 "foo() => 'a';\n" | |
| 9382 "main() => foo();\n"; | |
| 9383 | |
| 9384 // Enable all streams. | |
| 9385 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL | | |
| 9386 DART_TIMELINE_STREAM_VM); | |
| 9387 Dart_Handle lib; | |
| 9388 { | |
| 9389 // Add something to the VM stream. | |
| 9390 TimelineDurationScope tds(Timeline::GetVMStream(), | |
| 9391 "TestVMDuration"); | |
| 9392 lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 9393 } | |
| 9394 | |
| 9395 // Invoke main, which will be compiled resulting in a compiler event in | |
| 9396 // the timeline. | |
| 9397 Dart_Handle result = Dart_Invoke(lib, | |
|
Ivan Posva
2015/12/01 18:00:51
Single line?
zra
2015/12/01 18:51:51
Done.
| |
| 9398 NewString("main"), | |
| 9399 0, | |
| 9400 NULL); | |
| 9401 EXPECT_VALID(result); | |
| 9402 | |
| 9403 const char* buffer = NULL; | |
| 9404 intptr_t buffer_length = 0; | |
| 9405 | |
| 9406 // Run Dart_GlobalTimelineGetTrace on a fresh thread. | |
| 9407 Monitor monitor; | |
| 9408 GlobalTimelineThreadData data(&monitor); | |
| 9409 int err = OSThread::Start("Timeline test thread", | |
| 9410 GlobalTimelineThread, reinterpret_cast<uword>(&data)); | |
| 9411 EXPECT(err == 0); | |
| 9412 { | |
| 9413 MonitorLocker ml(&monitor); | |
| 9414 while (data.running) { | |
| 9415 ml.Wait(); | |
| 9416 } | |
| 9417 buffer = reinterpret_cast<char*>(data.data.buffer); | |
| 9418 buffer_length = data.data.buffer_length; | |
| 9419 OSThread::Join(data.join_id); | |
| 9420 } | |
| 9421 EXPECT(buffer_length > 0); | |
| 9422 EXPECT(buffer != NULL); | |
| 9423 | |
| 9424 // Response starts with a '{' character and not a '['. | |
| 9425 EXPECT(buffer[0] == '{'); | |
| 9426 // Response ends with a '}' character and not a ']'. | |
| 9427 EXPECT(buffer[buffer_length - 1] == '\0'); | |
| 9428 EXPECT(buffer[buffer_length - 2] == '}'); | |
| 9429 | |
| 9430 // Heartbeat test. | |
| 9431 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); | |
| 9432 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | |
| 9433 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | |
| 9434 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | |
| 9435 EXPECT_NOTSUBSTRING("\"function\":\"::_bar\"", buffer); | |
| 9436 | |
| 9437 // Free buffer allocated by AppendStreamConsumer | |
| 9438 free(data.data.buffer); | |
| 9439 data.data.buffer = NULL; | |
| 9440 data.data.buffer_length = 0; | |
| 9441 | |
| 9442 // Retrieving the global trace resulted in all open blocks being reclaimed. | |
| 9443 // Add some new events and verify that both sets of events are present | |
| 9444 // in the resulting trace. | |
| 9445 { | |
| 9446 // Add something to the VM stream. | |
| 9447 TimelineDurationScope tds(Timeline::GetVMStream(), | |
| 9448 "TestVMDuration2"); | |
| 9449 // Invoke bar, which will be compiled resulting in a compiler event in | |
| 9450 // the timeline. | |
| 9451 result = Dart_Invoke(lib, | |
| 9452 NewString("bar"), | |
| 9453 0, | |
| 9454 NULL); | |
| 9455 } | |
| 9456 | |
| 9457 // Grab the global trace. | |
| 9458 GlobalTimelineThreadData data2(&monitor); | |
| 9459 err = OSThread::Start("Timeline test thread", | |
| 9460 GlobalTimelineThread, reinterpret_cast<uword>(&data2)); | |
| 9461 EXPECT(err == 0); | |
| 9462 { | |
| 9463 MonitorLocker ml(&monitor); | |
| 9464 while (data2.running) { | |
| 9465 ml.Wait(); | |
| 9466 } | |
| 9467 buffer = reinterpret_cast<char*>(data2.data.buffer); | |
| 9468 buffer_length = data2.data.buffer_length; | |
| 9469 OSThread::Join(data2.join_id); | |
| 9470 } | |
| 9471 | |
| 9472 EXPECT(buffer_length > 0); | |
| 9473 EXPECT(buffer != NULL); | |
| 9474 // Response starts with a '{' character and not a '['. | |
| 9475 EXPECT(buffer[0] == '{'); | |
| 9476 // Response ends with a '}' character and not a ']'. | |
| 9477 EXPECT(buffer[buffer_length - 1] == '\0'); | |
| 9478 EXPECT(buffer[buffer_length - 2] == '}'); | |
| 9479 | |
| 9480 // Heartbeat test for old events. | |
| 9481 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); | |
| 9482 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | |
| 9483 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | |
| 9484 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | |
| 9485 | |
| 9486 // Heartbeat test for new events. | |
| 9487 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | |
| 9488 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | |
| 9489 | |
| 9490 // Free buffer allocated by AppendStreamConsumer | |
| 9491 free(data2.data.buffer); | |
| 9492 } | |
| 9493 | |
| 9330 } // namespace dart | 9494 } // namespace dart |
| OLD | NEW |