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

Unified Diff: runtime/vm/timeline_test.cc

Issue 1173333007: Refactor some Timeline interfaces to be simpler and support streaming (Closed) Base URL: git@github.com:dart-lang/sdk.git@timeline2
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/timeline.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/timeline_test.cc
diff --git a/runtime/vm/timeline_test.cc b/runtime/vm/timeline_test.cc
index 344b2070690f705b3d7017622037f288169f1d98..38f907be6bedddd423fff55a178cc0f740df91a7 100644
--- a/runtime/vm/timeline_test.cc
+++ b/runtime/vm/timeline_test.cc
@@ -12,18 +12,27 @@
namespace dart {
+class TimelineTestHelper : public AllStatic {
+ public:
+ static void SetStream(TimelineEvent* event, TimelineStream* stream) {
+ event->StreamInit(stream);
+ }
+};
+
+
TEST_CASE(TimelineEventIsValid) {
// Create a test stream.
TimelineStream stream;
stream.Init("testStream", true);
TimelineEvent event;
+ TimelineTestHelper::SetStream(&event, &stream);
// Starts invalid.
EXPECT(!event.IsValid());
// Becomes valid.
- event.Instant(&stream, "hello");
+ event.Instant("hello");
EXPECT(event.IsValid());
// Becomes invalid.
@@ -39,7 +48,8 @@ TEST_CASE(TimelineEventDuration) {
// Create a test event.
TimelineEvent event;
- event.DurationBegin(&stream, "apple");
+ TimelineTestHelper::SetStream(&event, &stream);
+ event.DurationBegin("apple");
// Measure the duration.
int64_t current_duration = event.TimeDuration();
event.DurationEnd();
@@ -55,7 +65,8 @@ TEST_CASE(TimelineEventDurationPrintJSON) {
// Create a test event.
TimelineEvent event;
- event.DurationBegin(&stream, "apple");
+ TimelineTestHelper::SetStream(&event, &stream);
+ event.DurationBegin("apple");
{
// Test printing to JSON.
JSONStream js;
@@ -82,13 +93,14 @@ TEST_CASE(TimelineEventArguments) {
// Create a test event.
TimelineEvent event;
+ TimelineTestHelper::SetStream(&event, &stream);
// Allocate room for four arguments.
event.SetNumArguments(4);
// Reset.
event.Reset();
- event.DurationBegin(&stream, "apple");
+ event.DurationBegin("apple");
event.SetNumArguments(2);
event.CopyArgument(0, "arg1", "value1");
event.CopyArgument(1, "arg2", "value2");
@@ -103,8 +115,9 @@ TEST_CASE(TimelineEventArgumentsPrintJSON) {
// Create a test event.
TimelineEvent event;
+ TimelineTestHelper::SetStream(&event, &stream);
- event.DurationBegin(&stream, "apple");
+ event.DurationBegin("apple");
event.SetNumArguments(2);
event.CopyArgument(0, "arg1", "value1");
event.CopyArgument(1, "arg2", "value2");
@@ -124,13 +137,92 @@ TEST_CASE(TimelineEventArgumentsPrintJSON) {
TEST_CASE(TimelineEventBufferPrintJSON) {
Isolate* isolate = Isolate::Current();
- TimelineEventBuffer* buffer = isolate->timeline_event_buffer();
+ TimelineEventRecorder* recorder = isolate->timeline_event_recorder();
JSONStream js;
- buffer->PrintJSON(&js);
+ recorder->PrintJSON(&js);
// Check the type. This test will fail if we ever make Timeline public.
EXPECT_SUBSTRING("\"type\":\"_Timeline\"", js.ToCString());
// Check that there is a traceEvents array.
EXPECT_SUBSTRING("\"traceEvents\":[", js.ToCString());
}
+
+// Count the number of each event type seen.
+class EventCounterRecorder : public TimelineEventStreamingRecorder {
+ public:
+ EventCounterRecorder() {
+ for (intptr_t i = 0; i < TimelineEvent::kNumEventTypes; i++) {
+ counts_[i] = 0;
+ }
+ }
+
+ void StreamEvent(TimelineEvent* event) {
+ counts_[event->event_type()]++;
+ }
+
+ intptr_t CountFor(TimelineEvent::EventType type) {
+ return counts_[type];
+ }
+
+ private:
+ intptr_t counts_[TimelineEvent::kNumEventTypes];
+};
+
+
+TEST_CASE(TimelineEventStreamingRecorderBasic) {
+ EventCounterRecorder* recorder = new EventCounterRecorder();
+
+ // Initial counts are all zero.
+ for (intptr_t i = TimelineEvent::kNone + 1;
+ i < TimelineEvent::kNumEventTypes;
+ i++) {
+ EXPECT_EQ(0, recorder->CountFor(static_cast<TimelineEvent::EventType>(i)));
+ }
+
+ // Create a test stream.
+ TimelineStream stream;
+ stream.Init("testStream", true);
+ stream.set_recorder(recorder);
+
+ TimelineEvent* event = NULL;
+
+ event = stream.StartEvent();
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kDuration));
+ event->DurationBegin("cabbage");
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kDuration));
+ event->DurationEnd();
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kDuration));
+ event->Complete();
+ EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kDuration));
+
+ event = stream.StartEvent();
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kInstant));
+ event->Instant("instantCabbage");
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kInstant));
+ event->Complete();
+ EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kInstant));
+
+ event = stream.StartEvent();
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncBegin));
+ int64_t async_id = event->AsyncBegin("asyncBeginCabbage");
+ EXPECT(async_id >= 0);
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncBegin));
+ event->Complete();
+ EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncBegin));
+
+ event = stream.StartEvent();
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncInstant));
+ event->AsyncInstant("asyncInstantCabbage", async_id);
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncInstant));
+ event->Complete();
+ EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncInstant));
+
+ event = stream.StartEvent();
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
+ event->AsyncEnd("asyncEndCabbage", async_id);
+ EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
+ event->Complete();
+ EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd));
+}
+
} // namespace dart
« no previous file with comments | « runtime/vm/timeline.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698