OLD | NEW |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 TimelineStream* stream = NULL) { | 44 TimelineStream* stream = NULL) { |
45 TimelineEvent* event = block->StartEvent(); | 45 TimelineEvent* event = block->StartEvent(); |
46 ASSERT(event != NULL); | 46 ASSERT(event != NULL); |
47 event->DurationBegin(label); | 47 event->DurationBegin(label); |
48 event->thread_ = OSThread::ThreadIdFromIntPtr(ftid); | 48 event->thread_ = OSThread::ThreadIdFromIntPtr(ftid); |
49 if (stream != NULL) { | 49 if (stream != NULL) { |
50 event->StreamInit(stream); | 50 event->StreamInit(stream); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
| 54 static void SetBlockThread(TimelineEventBlock* block, |
| 55 intptr_t ftid) { |
| 56 block->thread_id_ = OSThread::ThreadIdFromIntPtr(ftid); |
| 57 } |
| 58 |
54 static void FakeDuration( | 59 static void FakeDuration( |
55 TimelineEventRecorder* recorder, | 60 TimelineEventRecorder* recorder, |
56 const char* label, | 61 const char* label, |
57 int64_t start, | 62 int64_t start, |
58 int64_t end) { | 63 int64_t end) { |
59 ASSERT(recorder != NULL); | 64 ASSERT(recorder != NULL); |
60 ASSERT(start < end); | 65 ASSERT(start < end); |
61 ASSERT(label != NULL); | 66 ASSERT(label != NULL); |
62 TimelineEvent* event = recorder->StartEvent(); | 67 TimelineEvent* event = recorder->StartEvent(); |
63 ASSERT(event != NULL); | 68 ASSERT(event != NULL); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 EventCounterRecorder() { | 240 EventCounterRecorder() { |
236 for (intptr_t i = 0; i < TimelineEvent::kNumEventTypes; i++) { | 241 for (intptr_t i = 0; i < TimelineEvent::kNumEventTypes; i++) { |
237 counts_[i] = 0; | 242 counts_[i] = 0; |
238 } | 243 } |
239 } | 244 } |
240 | 245 |
241 void StreamEvent(TimelineEvent* event) { | 246 void StreamEvent(TimelineEvent* event) { |
242 counts_[event->event_type()]++; | 247 counts_[event->event_type()]++; |
243 } | 248 } |
244 | 249 |
245 void StreamDartEvent(const char* event) { | |
246 // NOOP. | |
247 } | |
248 | |
249 intptr_t CountFor(TimelineEvent::EventType type) { | 250 intptr_t CountFor(TimelineEvent::EventType type) { |
250 return counts_[type]; | 251 return counts_[type]; |
251 } | 252 } |
252 | 253 |
253 private: | 254 private: |
254 intptr_t counts_[TimelineEvent::kNumEventTypes]; | 255 intptr_t counts_[TimelineEvent::kNumEventTypes]; |
255 }; | 256 }; |
256 | 257 |
257 | 258 |
258 TEST_CASE(TimelineEventStreamingRecorderBasic) { | 259 TEST_CASE(TimelineEventStreamingRecorderBasic) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ASSERT(event != NULL); | 318 ASSERT(event != NULL); |
318 return strcmp(event->label(), label) == 0; | 319 return strcmp(event->label(), label) == 0; |
319 } | 320 } |
320 | 321 |
321 | 322 |
322 TEST_CASE(TimelineAnalysis_ThreadBlockCount) { | 323 TEST_CASE(TimelineAnalysis_ThreadBlockCount) { |
323 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder(); | 324 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder(); |
324 ASSERT(recorder != NULL); | 325 ASSERT(recorder != NULL); |
325 // Blocks owned by thread "1". | 326 // Blocks owned by thread "1". |
326 TimelineEventBlock* block_1_0 = recorder->GetNewBlock(); | 327 TimelineEventBlock* block_1_0 = recorder->GetNewBlock(); |
| 328 TimelineTestHelper::SetBlockThread(block_1_0, 1); |
327 TimelineEventBlock* block_1_1 = recorder->GetNewBlock(); | 329 TimelineEventBlock* block_1_1 = recorder->GetNewBlock(); |
| 330 TimelineTestHelper::SetBlockThread(block_1_1, 1); |
328 TimelineEventBlock* block_1_2 = recorder->GetNewBlock(); | 331 TimelineEventBlock* block_1_2 = recorder->GetNewBlock(); |
| 332 TimelineTestHelper::SetBlockThread(block_1_2, 1); |
329 // Blocks owned by thread "2". | 333 // Blocks owned by thread "2". |
330 TimelineEventBlock* block_2_0 = recorder->GetNewBlock(); | 334 TimelineEventBlock* block_2_0 = recorder->GetNewBlock(); |
| 335 TimelineTestHelper::SetBlockThread(block_2_0, 2); |
331 // Blocks owned by thread "3". | 336 // Blocks owned by thread "3". |
332 TimelineEventBlock* block_3_0 = recorder->GetNewBlock(); | 337 TimelineEventBlock* block_3_0 = recorder->GetNewBlock(); |
| 338 TimelineTestHelper::SetBlockThread(block_3_0, 3); |
333 USE(block_3_0); | 339 USE(block_3_0); |
334 | 340 |
335 // Add events to each block for thread 1. | 341 // Add events to each block for thread 1. |
336 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B1"); | 342 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B1"); |
337 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B2"); | 343 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B2"); |
338 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B3"); | 344 TimelineTestHelper::FakeThreadEvent(block_1_2, 1, "B3"); |
339 // Sleep to ensure timestamps differ. | 345 // Sleep to ensure timestamps differ. |
340 OS::Sleep(1); | 346 OS::Sleep(1); |
341 TimelineTestHelper::FakeThreadEvent(block_1_0, 1, "A1"); | 347 TimelineTestHelper::FakeThreadEvent(block_1_0, 1, "A1"); |
342 OS::Sleep(1); | 348 OS::Sleep(1); |
343 TimelineTestHelper::FakeThreadEvent(block_1_1, 1, "C1"); | 349 TimelineTestHelper::FakeThreadEvent(block_1_1, 1, "C1"); |
344 TimelineTestHelper::FakeThreadEvent(block_1_1, 1, "C2"); | 350 TimelineTestHelper::FakeThreadEvent(block_1_1, 1, "C2"); |
345 OS::Sleep(1); | 351 OS::Sleep(1); |
346 | 352 |
347 // Add events to each block for thread 2. | 353 // Add events to each block for thread 2. |
348 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "A"); | 354 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "A"); |
349 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "B"); | 355 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "B"); |
350 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "C"); | 356 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "C"); |
351 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "D"); | 357 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "D"); |
352 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "E"); | 358 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "E"); |
353 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "F"); | 359 TimelineTestHelper::FakeThreadEvent(block_2_0, 2, "F"); |
354 | 360 |
355 Zone* zone = thread->zone(); | 361 Zone* zone = thread->zone(); |
356 Isolate* isolate = thread->isolate(); | 362 Isolate* isolate = thread->isolate(); |
357 | 363 |
358 // Discover threads in recorder. | 364 // Discover threads in recorder. |
359 TimelineAnalysis ta(zone, isolate, recorder); | 365 TimelineAnalysis ta(zone, isolate, recorder); |
360 ta.BuildThreads(); | 366 ta.BuildThreads(); |
| 367 EXPECT(!ta.has_error()); |
361 // block_3_0 is never used by a thread, so we only have two threads. | 368 // block_3_0 is never used by a thread, so we only have two threads. |
362 EXPECT_EQ(2, ta.NumThreads()); | 369 EXPECT_EQ(2, ta.NumThreads()); |
363 | 370 |
364 // Extract both threads. | 371 // Extract both threads. |
365 TimelineAnalysisThread* thread_1 = | 372 TimelineAnalysisThread* thread_1 = |
366 ta.GetThread(OSThread::ThreadIdFromIntPtr(1)); | 373 ta.GetThread(OSThread::ThreadIdFromIntPtr(1)); |
367 TimelineAnalysisThread* thread_2 = | 374 TimelineAnalysisThread* thread_2 = |
368 ta.GetThread(OSThread::ThreadIdFromIntPtr(2)); | 375 ta.GetThread(OSThread::ThreadIdFromIntPtr(2)); |
369 EXPECT_EQ(OSThread::ThreadIdFromIntPtr(1), thread_1->id()); | 376 EXPECT_EQ(OSThread::ThreadIdFromIntPtr(1), thread_1->id()); |
370 EXPECT_EQ(OSThread::ThreadIdFromIntPtr(2), thread_2->id()); | 377 EXPECT_EQ(OSThread::ThreadIdFromIntPtr(2), thread_2->id()); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 { | 844 { |
838 TimelinePauses pauses(zone, isolate, recorder); | 845 TimelinePauses pauses(zone, isolate, recorder); |
839 pauses.Setup(); | 846 pauses.Setup(); |
840 pauses.CalculatePauseTimesForThread(tid); | 847 pauses.CalculatePauseTimesForThread(tid); |
841 EXPECT(pauses.has_error()); | 848 EXPECT(pauses.has_error()); |
842 } | 849 } |
843 TimelineTestHelper::Clear(recorder); | 850 TimelineTestHelper::Clear(recorder); |
844 } | 851 } |
845 | 852 |
846 } // namespace dart | 853 } // namespace dart |
OLD | NEW |