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

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

Issue 1284263002: Start TimelineAnalysis utility (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') | runtime/vm/vm_sources.gypi » ('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) 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 "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/timeline.h" 10 #include "vm/timeline.h"
11 #include "vm/timeline_analysis.h"
11 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 class TimelineTestHelper : public AllStatic { 16 class TimelineTestHelper : public AllStatic {
16 public: 17 public:
17 static void SetStream(TimelineEvent* event, TimelineStream* stream) { 18 static void SetStream(TimelineEvent* event, TimelineStream* stream) {
18 event->StreamInit(stream); 19 event->StreamInit(stream);
19 } 20 }
21
22 static TimelineEvent* FakeThreadEvent(
23 TimelineEventBlock* block, intptr_t ftid) {
24 TimelineEvent* event = block->StartEvent();
25 ASSERT(event != NULL);
26 event->DurationBegin("fake");
27 event->thread_ = static_cast<ThreadId>(ftid);
28 return event;
29 }
20 }; 30 };
21 31
22 32
23 TEST_CASE(TimelineEventIsValid) { 33 TEST_CASE(TimelineEventIsValid) {
24 // Create a test stream. 34 // Create a test stream.
25 TimelineStream stream; 35 TimelineStream stream;
26 stream.Init("testStream", true); 36 stream.Init("testStream", true);
27 37
28 TimelineEvent event; 38 TimelineEvent event;
29 TimelineTestHelper::SetStream(&event, &stream); 39 TimelineTestHelper::SetStream(&event, &stream);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncInstant)); 228 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncInstant));
219 229
220 event = stream.StartEvent(); 230 event = stream.StartEvent();
221 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd)); 231 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
222 event->AsyncEnd("asyncEndCabbage", async_id); 232 event->AsyncEnd("asyncEndCabbage", async_id);
223 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd)); 233 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
224 event->Complete(); 234 event->Complete();
225 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd)); 235 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd));
226 } 236 }
227 237
238
239 TEST_CASE(TimelineAnalysis_ThreadBlockCount) {
240 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder();
241 ASSERT(recorder != NULL);
242 // Blocks owned by thread "1".
243 TimelineEventBlock* block_1_0 = recorder->GetNewBlock();
244 TimelineEventBlock* block_1_1 = recorder->GetNewBlock();
245 TimelineEventBlock* block_1_2 = recorder->GetNewBlock();
246 // Blocks owned by thread "2".
247 TimelineEventBlock* block_2_0 = recorder->GetNewBlock();
248 // Blocks owned by thread "3".
249 TimelineEventBlock* block_3_0 = recorder->GetNewBlock();
250 USE(block_3_0);
251
252 // Add events to each block for thread 1.
253 TimelineTestHelper::FakeThreadEvent(block_1_2, 1);
254 TimelineTestHelper::FakeThreadEvent(block_1_2, 1);
255 TimelineTestHelper::FakeThreadEvent(block_1_2, 1);
256 // Sleep to ensure timestamps differ.
257 OS::Sleep(1);
258 TimelineTestHelper::FakeThreadEvent(block_1_0, 1);
259 OS::Sleep(1);
260 TimelineTestHelper::FakeThreadEvent(block_1_1, 1);
261 TimelineTestHelper::FakeThreadEvent(block_1_1, 1);
262 OS::Sleep(1);
263
264 // Add events to each block for thread 2.
265 TimelineTestHelper::FakeThreadEvent(block_2_0, 2);
266 TimelineTestHelper::FakeThreadEvent(block_2_0, 2);
267 TimelineTestHelper::FakeThreadEvent(block_2_0, 2);
268 TimelineTestHelper::FakeThreadEvent(block_2_0, 2);
269 TimelineTestHelper::FakeThreadEvent(block_2_0, 2);
270 TimelineTestHelper::FakeThreadEvent(block_2_0, 2);
271
272 Thread* thread = Thread::Current();
273 Zone* zone = thread->zone();
274 Isolate* isolate = thread->isolate();
275
276 // Discover threads in recorder.
277 TimelineAnalysis ta(zone, isolate, recorder);
278 ta.BuildThreads();
279 // block_c_0 is never used by a thread, so we only have two threads.
rmacnak 2015/08/12 19:51:47 block_3_0
Cutch 2015/08/12 20:31:19 Done.
280 EXPECT_EQ(2, ta.NumThreads());
281
282 // Extract both threads.
283 TimelineAnalysisThread* thread_1 = ta.GetThread(static_cast<ThreadId>(1));
284 TimelineAnalysisThread* thread_2 = ta.GetThread(static_cast<ThreadId>(2));
285 EXPECT_EQ(static_cast<ThreadId>(1), thread_1->id());
286 EXPECT_EQ(static_cast<ThreadId>(2), thread_2->id());
287
288 // Thread "1" should have three blocks.
289 EXPECT_EQ(3, thread_1->NumBlocks());
290
291 // Verify that blocks for thread "1" are sorted based on start time.
292 EXPECT_EQ(thread_1->At(0), block_1_2);
293 EXPECT_EQ(thread_1->At(1), block_1_0);
294 EXPECT_EQ(thread_1->At(2), block_1_1);
295
296 // Verify that block_1_2 has three events.
297 EXPECT_EQ(3, block_1_2->length());
298
299 // Verify that block_1_0 has one events.
300 EXPECT_EQ(1, block_1_0->length());
301
302 // Verify that block_1_1 has two events.
303 EXPECT_EQ(2, block_1_1->length());
304
305 // Thread '2" should have one block.'
306 EXPECT_EQ(1, thread_2->NumBlocks());
307 EXPECT_EQ(thread_2->At(0), block_2_0);
308 // Verify that block_2_0 has six events.
309 EXPECT_EQ(6, block_2_0->length());
310 }
311
228 } // namespace dart 312 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/timeline_analysis.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698