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

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

Issue 1283093004: Ensure TimelineEventRingRecorder outputs blocks in increasing time order (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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/timeline.cc ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 <cstring>
6
5 #include "platform/assert.h" 7 #include "platform/assert.h"
6 8
7 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
9 #include "vm/globals.h" 11 #include "vm/globals.h"
10 #include "vm/timeline.h" 12 #include "vm/timeline.h"
11 #include "vm/timeline_analysis.h" 13 #include "vm/timeline_analysis.h"
12 #include "vm/unit_test.h" 14 #include "vm/unit_test.h"
13 15
14 namespace dart { 16 namespace dart {
15 17
16 class TimelineTestHelper : public AllStatic { 18 class TimelineTestHelper : public AllStatic {
17 public: 19 public:
18 static void SetStream(TimelineEvent* event, TimelineStream* stream) { 20 static void SetStream(TimelineEvent* event, TimelineStream* stream) {
19 event->StreamInit(stream); 21 event->StreamInit(stream);
20 } 22 }
21 23
22 static TimelineEvent* FakeThreadEvent( 24 static TimelineEvent* FakeThreadEvent(
23 TimelineEventBlock* block, intptr_t ftid) { 25 TimelineEventBlock* block,
26 intptr_t ftid,
27 const char* label = "fake",
28 TimelineStream* stream = NULL) {
24 TimelineEvent* event = block->StartEvent(); 29 TimelineEvent* event = block->StartEvent();
25 ASSERT(event != NULL); 30 ASSERT(event != NULL);
26 event->DurationBegin("fake"); 31 event->DurationBegin(label);
27 event->thread_ = OSThread::ThreadIdFromIntPtr(ftid); 32 event->thread_ = OSThread::ThreadIdFromIntPtr(ftid);
33 if (stream != NULL) {
34 event->StreamInit(stream);
35 }
28 return event; 36 return event;
29 } 37 }
30 }; 38 };
31 39
32 40
33 TEST_CASE(TimelineEventIsValid) { 41 TEST_CASE(TimelineEventIsValid) {
34 // Create a test stream. 42 // Create a test stream.
35 TimelineStream stream; 43 TimelineStream stream;
36 stream.Init("testStream", true); 44 stream.Init("testStream", true);
37 45
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // Verify that block_1_1 has two events. 312 // Verify that block_1_1 has two events.
305 EXPECT_EQ(2, block_1_1->length()); 313 EXPECT_EQ(2, block_1_1->length());
306 314
307 // Thread '2" should have one block.' 315 // Thread '2" should have one block.'
308 EXPECT_EQ(1, thread_2->NumBlocks()); 316 EXPECT_EQ(1, thread_2->NumBlocks());
309 EXPECT_EQ(thread_2->At(0), block_2_0); 317 EXPECT_EQ(thread_2->At(0), block_2_0);
310 // Verify that block_2_0 has six events. 318 // Verify that block_2_0 has six events.
311 EXPECT_EQ(6, block_2_0->length()); 319 EXPECT_EQ(6, block_2_0->length());
312 } 320 }
313 321
322
323 TEST_CASE(TimelineRingRecorderJSONOrder) {
324 TimelineStream stream;
325 stream.Init("testStream", true);
326
327 TimelineEventRingRecorder* recorder =
328 new TimelineEventRingRecorder(TimelineEventBlock::kBlockSize * 2);
329
330 TimelineEventBlock* block_0 = recorder->GetNewBlock();
331 EXPECT(block_0 != NULL);
332 TimelineEventBlock* block_1 = recorder->GetNewBlock();
333 EXPECT(block_1 != NULL);
334 // Test that we wrapped.
335 EXPECT(block_0 == recorder->GetNewBlock());
336
337 // Emit the earlier event into block_1.
338 TimelineTestHelper::FakeThreadEvent(block_1, 2, "Alpha", &stream);
339 OS::Sleep(1);
340 // Emit the later event into block_0.
341 TimelineTestHelper::FakeThreadEvent(block_0, 2, "Beta", &stream);
342
343 JSONStream js;
344 recorder->PrintJSON(&js);
345 // trace-event has a requirement that events for a thread must have
346 // monotonically increasing timestamps.
347 // Verify that "Alpha" comes before "Beta" even though "Beta" is in the first
348 // block.
349 const char* alpha = strstr(js.ToCString(), "Alpha");
350 const char* beta = strstr(js.ToCString(), "Beta");
351 EXPECT(alpha < beta);
352 }
353
314 } // namespace dart 354 } // namespace dart
OLDNEW
« 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