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

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

Issue 1297443002: Improve timeline iterators and tests (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_analysis.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> 5 #include <cstring>
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 event = stream.StartEvent(); 238 event = stream.StartEvent();
239 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd)); 239 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
240 event->AsyncEnd("asyncEndCabbage", async_id); 240 event->AsyncEnd("asyncEndCabbage", async_id);
241 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd)); 241 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
242 event->Complete(); 242 event->Complete();
243 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd)); 243 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd));
244 } 244 }
245 245
246 246
247 static bool LabelMatch(TimelineEvent* event, const char* label) {
248 ASSERT(event != NULL);
249 return strcmp(event->label(), label) == 0;
250 }
251
252
247 TEST_CASE(TimelineAnalysis_ThreadBlockCount) { 253 TEST_CASE(TimelineAnalysis_ThreadBlockCount) {
248 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder(); 254 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder();
249 ASSERT(recorder != NULL); 255 ASSERT(recorder != NULL);
250 // Blocks owned by thread "1". 256 // Blocks owned by thread "1".
251 TimelineEventBlock* block_1_0 = recorder->GetNewBlock(); 257 TimelineEventBlock* block_1_0 = recorder->GetNewBlock();
252 TimelineEventBlock* block_1_1 = recorder->GetNewBlock(); 258 TimelineEventBlock* block_1_1 = recorder->GetNewBlock();
253 TimelineEventBlock* block_1_2 = recorder->GetNewBlock(); 259 TimelineEventBlock* block_1_2 = recorder->GetNewBlock();
254 // Blocks owned by thread "2". 260 // Blocks owned by thread "2".
255 TimelineEventBlock* block_2_0 = recorder->GetNewBlock(); 261 TimelineEventBlock* block_2_0 = recorder->GetNewBlock();
256 // Blocks owned by thread "3". 262 // Blocks owned by thread "3".
257 TimelineEventBlock* block_3_0 = recorder->GetNewBlock(); 263 TimelineEventBlock* block_3_0 = recorder->GetNewBlock();
258 USE(block_3_0); 264 USE(block_3_0);
259 265
260 // Add events to each block for thread 1. 266 // Add events to each block for thread 1.
261 TimelineTestHelper::FakeThreadEvent(block_1_2, 1); 267 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B1");
262 TimelineTestHelper::FakeThreadEvent(block_1_2, 1); 268 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B2");
263 TimelineTestHelper::FakeThreadEvent(block_1_2, 1); 269 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B3");
264 // Sleep to ensure timestamps differ. 270 // Sleep to ensure timestamps differ.
265 OS::Sleep(1); 271 OS::Sleep(1);
266 TimelineTestHelper::FakeThreadEvent(block_1_0, 1); 272 TimelineTestHelper::FakeThreadEvent(block_1_0, 1, "A1");
267 OS::Sleep(1); 273 OS::Sleep(1);
268 TimelineTestHelper::FakeThreadEvent(block_1_1, 1); 274 TimelineTestHelper::FakeThreadEvent(block_1_1, 1, "C1");
269 TimelineTestHelper::FakeThreadEvent(block_1_1, 1); 275 TimelineTestHelper::FakeThreadEvent(block_1_1, 1, "C2");
270 OS::Sleep(1); 276 OS::Sleep(1);
271 277
272 // Add events to each block for thread 2. 278 // Add events to each block for thread 2.
273 TimelineTestHelper::FakeThreadEvent(block_2_0, 2); 279 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "A");
274 TimelineTestHelper::FakeThreadEvent(block_2_0, 2); 280 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "B");
275 TimelineTestHelper::FakeThreadEvent(block_2_0, 2); 281 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "C");
276 TimelineTestHelper::FakeThreadEvent(block_2_0, 2); 282 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "D");
277 TimelineTestHelper::FakeThreadEvent(block_2_0, 2); 283 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "E");
278 TimelineTestHelper::FakeThreadEvent(block_2_0, 2); 284 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "F");
279 285
280 Thread* thread = Thread::Current(); 286 Thread* thread = Thread::Current();
281 Zone* zone = thread->zone(); 287 Zone* zone = thread->zone();
282 Isolate* isolate = thread->isolate(); 288 Isolate* isolate = thread->isolate();
283 289
284 // Discover threads in recorder. 290 // Discover threads in recorder.
285 TimelineAnalysis ta(zone, isolate, recorder); 291 TimelineAnalysis ta(zone, isolate, recorder);
286 ta.BuildThreads(); 292 ta.BuildThreads();
287 // block_3_0 is never used by a thread, so we only have two threads. 293 // block_3_0 is never used by a thread, so we only have two threads.
288 EXPECT_EQ(2, ta.NumThreads()); 294 EXPECT_EQ(2, ta.NumThreads());
(...skipping 21 matching lines...) Expand all
310 EXPECT_EQ(1, block_1_0->length()); 316 EXPECT_EQ(1, block_1_0->length());
311 317
312 // Verify that block_1_1 has two events. 318 // Verify that block_1_1 has two events.
313 EXPECT_EQ(2, block_1_1->length()); 319 EXPECT_EQ(2, block_1_1->length());
314 320
315 // Thread '2" should have one block.' 321 // Thread '2" should have one block.'
316 EXPECT_EQ(1, thread_2->NumBlocks()); 322 EXPECT_EQ(1, thread_2->NumBlocks());
317 EXPECT_EQ(thread_2->At(0), block_2_0); 323 EXPECT_EQ(thread_2->At(0), block_2_0);
318 // Verify that block_2_0 has six events. 324 // Verify that block_2_0 has six events.
319 EXPECT_EQ(6, block_2_0->length()); 325 EXPECT_EQ(6, block_2_0->length());
326
327 {
328 TimelineAnalysisThreadEventIterator it(thread_1);
329 // Six events spread across three blocks.
330 EXPECT(it.HasNext());
331 EXPECT(LabelMatch(it.Next(), "B1"));
332 EXPECT(it.HasNext());
333 EXPECT(LabelMatch(it.Next(), "B2"));
334 EXPECT(it.HasNext());
335 EXPECT(LabelMatch(it.Next(), "B3"));
336 EXPECT(it.HasNext());
337 EXPECT(LabelMatch(it.Next(), "A1"));
338 EXPECT(it.HasNext());
339 EXPECT(LabelMatch(it.Next(), "C1"));
340 EXPECT(it.HasNext());
341 EXPECT(LabelMatch(it.Next(), "C2"));
342 EXPECT(!it.HasNext());
343 }
344
345 {
346 TimelineAnalysisThreadEventIterator it(thread_2);
347 // Six events spread across three blocks.
348 EXPECT(it.HasNext());
349 EXPECT(LabelMatch(it.Next(), "A"));
350 EXPECT(it.HasNext());
351 EXPECT(LabelMatch(it.Next(), "B"));
352 EXPECT(it.HasNext());
353 EXPECT(LabelMatch(it.Next(), "C"));
354 EXPECT(it.HasNext());
355 EXPECT(LabelMatch(it.Next(), "D"));
356 EXPECT(it.HasNext());
357 EXPECT(LabelMatch(it.Next(), "E"));
358 EXPECT(it.HasNext());
359 EXPECT(LabelMatch(it.Next(), "F"));
360 EXPECT(!it.HasNext());
361 }
320 } 362 }
321 363
322 364
323 TEST_CASE(TimelineRingRecorderJSONOrder) { 365 TEST_CASE(TimelineRingRecorderJSONOrder) {
324 TimelineStream stream; 366 TimelineStream stream;
325 stream.Init("testStream", true); 367 stream.Init("testStream", true);
326 368
327 TimelineEventRingRecorder* recorder = 369 TimelineEventRingRecorder* recorder =
328 new TimelineEventRingRecorder(TimelineEventBlock::kBlockSize * 2); 370 new TimelineEventRingRecorder(TimelineEventBlock::kBlockSize * 2);
329 371
(...skipping 15 matching lines...) Expand all
345 // trace-event has a requirement that events for a thread must have 387 // trace-event has a requirement that events for a thread must have
346 // monotonically increasing timestamps. 388 // monotonically increasing timestamps.
347 // Verify that "Alpha" comes before "Beta" even though "Beta" is in the first 389 // Verify that "Alpha" comes before "Beta" even though "Beta" is in the first
348 // block. 390 // block.
349 const char* alpha = strstr(js.ToCString(), "Alpha"); 391 const char* alpha = strstr(js.ToCString(), "Alpha");
350 const char* beta = strstr(js.ToCString(), "Beta"); 392 const char* beta = strstr(js.ToCString(), "Beta");
351 EXPECT(alpha < beta); 393 EXPECT(alpha < beta);
352 } 394 }
353 395
354 } // namespace dart 396 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/timeline_analysis.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698