Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 1377663002: Add Timeline to dart:developer (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/timeline.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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() {\n"
9454 " Timeline.startSync('DART_NAME');\n"
9455 " Timeline.finishSync();\n"
9456 "}\n";
9457
9458 Dart_Handle lib =
9459 TestCase::LoadTestScript(kScriptChars, NULL);
9460
9461 const char* buffer = NULL;
9462 intptr_t buffer_length = 0;
9463 bool success = false;
9464
9465 // Enable recording of the Dart stream.
9466 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART);
9467
9468 // Invoke main, which will add a new timeline event from Dart.
9469 Dart_Handle result = Dart_Invoke(lib,
9470 NewString("main"),
9471 0,
9472 NULL);
9473 EXPECT_VALID(result);
9474
9475 // Grab the trace.
9476 AppendData data;
9477 data.buffer = NULL;
9478 data.buffer_length = 0;
9479 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data);
9480 EXPECT(success);
9481 buffer = reinterpret_cast<char*>(data.buffer);
9482 buffer_length = data.buffer_length;
9483 EXPECT(buffer_length > 0);
9484 EXPECT(buffer != NULL);
9485
9486 // Heartbeat test.
9487 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer);
9488 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer);
9489
9490 // Free buffer allocated by AppendStreamConsumer
9491 free(data.buffer);
9492 }
9493
9494
9495 TEST_CASE(Timeline_Dart_TimelineGetTraceWithDartEvents) {
9496 const char* kScriptChars =
9497 "import 'dart:developer';\n"
9498 "\n"
9499 "main() {\n"
9500 " Timeline.startSync('DART_NAME');\n"
9501 " Timeline.finishSync();\n"
9502 "}\n";
9503
9504 Dart_Handle lib =
9505 TestCase::LoadTestScript(kScriptChars, NULL);
9506
9507 const char* buffer = NULL;
9508 intptr_t buffer_length = 0;
9509 bool success = false;
9510
9511 // Enable recording of all streams.
9512 Dart_TimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL);
9513
9514 // Invoke main, which will be compiled resulting in a compiler event in
9515 // the timeline.
9516 Dart_Handle result = Dart_Invoke(lib,
9517 NewString("main"),
9518 0,
9519 NULL);
9520 EXPECT_VALID(result);
9521
9522 // Grab the trace.
9523 AppendData data;
9524 success = Dart_TimelineGetTrace(AppendStreamConsumer, &data);
9525 EXPECT(success);
9526 buffer = reinterpret_cast<char*>(data.buffer);
9527 buffer_length = data.buffer_length;
9528 EXPECT(buffer_length > 0);
9529 EXPECT(buffer != NULL);
9530
9531 // Heartbeat test.
9532 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer);
9533 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer);
9534 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer);
9535 EXPECT_SUBSTRING("\"cat\":\"Dart\"", buffer);
9536 EXPECT_SUBSTRING("\"name\":\"DART_NAME\"", buffer);
9537
9538 // Free buffer allocated by AppendStreamConsumer
9539 free(data.buffer);
9540 }
9541
9449 TEST_CASE(Timeline_Dart_TimelineGetTraceGlobalOverride) { 9542 TEST_CASE(Timeline_Dart_TimelineGetTraceGlobalOverride) {
9450 const char* kScriptChars = 9543 const char* kScriptChars =
9451 "foo() => 'a';\n" 9544 "foo() => 'a';\n"
9452 "main() => foo();\n"; 9545 "main() => foo();\n";
9453 9546
9454 Dart_Handle lib = 9547 Dart_Handle lib =
9455 TestCase::LoadTestScript(kScriptChars, NULL); 9548 TestCase::LoadTestScript(kScriptChars, NULL);
9456 9549
9457 const char* buffer = NULL; 9550 const char* buffer = NULL;
9458 intptr_t buffer_length = 0; 9551 intptr_t buffer_length = 0;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
9569 9662
9570 // Heartbeat test for new events. 9663 // Heartbeat test for new events.
9571 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); 9664 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer);
9572 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); 9665 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer);
9573 9666
9574 // Free buffer allocated by AppendStreamConsumer 9667 // Free buffer allocated by AppendStreamConsumer
9575 free(data.buffer); 9668 free(data.buffer);
9576 } 9669 }
9577 9670
9578 } // namespace dart 9671 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/timeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698