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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 1021053003: Delivering the FIRST_NONEMPTY_PAINT phase changing event to base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@phase_splitting
Patch Set: Created 5 years, 9 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 | « base/tracked_objects.cc ('k') | chrome/browser/metrics/chrome_metrics_service_client.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Test of classes in the tracked_objects.h classes. 5 // Test of classes in the tracked_objects.h classes.
6 6
7 #include "base/tracked_objects.h" 7 #include "base/tracked_objects.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 141 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
142 ThreadData* data = ThreadData::Get(); 142 ThreadData* data = ThreadData::Get();
143 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 143 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
144 ASSERT_TRUE(data); 144 ASSERT_TRUE(data);
145 EXPECT_FALSE(data->next()); 145 EXPECT_FALSE(data->next());
146 EXPECT_EQ(data, ThreadData::Get()); 146 EXPECT_EQ(data, ThreadData::Get());
147 ThreadData::BirthMap birth_map; 147 ThreadData::BirthMap birth_map;
148 ThreadData::DeathMap death_map; 148 ThreadData::DeathMap death_map;
149 ThreadData::ParentChildSet parent_child_set; 149 ThreadData::ParentChildSet parent_child_set;
150 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); 150 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
151 EXPECT_EQ(0u, birth_map.size()); 151 EXPECT_EQ(0u, birth_map.size());
152 EXPECT_EQ(0u, death_map.size()); 152 EXPECT_EQ(0u, death_map.size());
153 EXPECT_EQ(0u, parent_child_set.size()); 153 EXPECT_EQ(0u, parent_child_set.size());
154 154
155 // Clean up with no leaking. 155 // Clean up with no leaking.
156 Reset(); 156 Reset();
157 157
158 // Do it again, just to be sure we reset state completely. 158 // Do it again, just to be sure we reset state completely.
159 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( 159 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus(
160 ThreadData::PROFILING_CHILDREN_ACTIVE)); 160 ThreadData::PROFILING_CHILDREN_ACTIVE));
161 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 161 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
162 data = ThreadData::Get(); 162 data = ThreadData::Get();
163 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 163 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
164 ASSERT_TRUE(data); 164 ASSERT_TRUE(data);
165 EXPECT_FALSE(data->next()); 165 EXPECT_FALSE(data->next());
166 EXPECT_EQ(data, ThreadData::Get()); 166 EXPECT_EQ(data, ThreadData::Get());
167 birth_map.clear(); 167 birth_map.clear();
168 death_map.clear(); 168 death_map.clear();
169 parent_child_set.clear(); 169 parent_child_set.clear();
170 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); 170 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
171 EXPECT_EQ(0u, birth_map.size()); 171 EXPECT_EQ(0u, birth_map.size());
172 EXPECT_EQ(0u, death_map.size()); 172 EXPECT_EQ(0u, death_map.size());
173 EXPECT_EQ(0u, parent_child_set.size()); 173 EXPECT_EQ(0u, parent_child_set.size());
174 } 174 }
175 175
176 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { 176 TEST_F(TrackedObjectsTest, TinyStartupShutdown) {
177 if (!ThreadData::InitializeAndSetTrackingStatus( 177 if (!ThreadData::InitializeAndSetTrackingStatus(
178 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 178 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
179 return; 179 return;
180 } 180 }
181 181
182 // Instigate tracking on a single tracked object, on our thread. 182 // Instigate tracking on a single tracked object, on our thread.
183 const char kFunction[] = "TinyStartupShutdown"; 183 const char kFunction[] = "TinyStartupShutdown";
184 Location location(kFunction, kFile, kLineNumber, NULL); 184 Location location(kFunction, kFile, kLineNumber, NULL);
185 Births* first_birth = ThreadData::TallyABirthIfActive(location); 185 Births* first_birth = ThreadData::TallyABirthIfActive(location);
186 186
187 ThreadData* data = ThreadData::first(); 187 ThreadData* data = ThreadData::first();
188 ASSERT_TRUE(data); 188 ASSERT_TRUE(data);
189 EXPECT_FALSE(data->next()); 189 EXPECT_FALSE(data->next());
190 EXPECT_EQ(data, ThreadData::Get()); 190 EXPECT_EQ(data, ThreadData::Get());
191 ThreadData::BirthMap birth_map; 191 ThreadData::BirthMap birth_map;
192 ThreadData::DeathMap death_map; 192 ThreadData::DeathMap death_map;
193 ThreadData::ParentChildSet parent_child_set; 193 ThreadData::ParentChildSet parent_child_set;
194 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); 194 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
195 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 195 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
196 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. 196 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth.
197 EXPECT_EQ(0u, death_map.size()); // No deaths. 197 EXPECT_EQ(0u, death_map.size()); // No deaths.
198 EXPECT_EQ(0u, parent_child_set.size()); // No children. 198 EXPECT_EQ(0u, parent_child_set.size()); // No children.
199 199
200 200
201 // Now instigate another birth, while we are timing the run of the first 201 // Now instigate another birth, while we are timing the run of the first
202 // execution. 202 // execution.
203 ThreadData::PrepareForStartOfRun(first_birth); 203 ThreadData::PrepareForStartOfRun(first_birth);
204 // Create a child (using the same birth location). 204 // Create a child (using the same birth location).
205 // TrackingInfo will call TallyABirth() during construction. 205 // TrackingInfo will call TallyABirth() during construction.
206 const int32 start_time = 1; 206 const int32 start_time = 1;
207 base::TimeTicks kBogusBirthTime = base::TimeTicks() + 207 base::TimeTicks kBogusBirthTime = base::TimeTicks() +
208 base::TimeDelta::FromMilliseconds(start_time); 208 base::TimeDelta::FromMilliseconds(start_time);
209 base::TrackingInfo pending_task(location, kBogusBirthTime); 209 base::TrackingInfo pending_task(location, kBogusBirthTime);
210 SetTestTime(1); 210 SetTestTime(1);
211 TaskStopwatch stopwatch; 211 TaskStopwatch stopwatch;
212 stopwatch.Start(); 212 stopwatch.Start();
213 // Finally conclude the outer run. 213 // Finally conclude the outer run.
214 const int32 time_elapsed = 1000; 214 const int32 time_elapsed = 1000;
215 SetTestTime(start_time + time_elapsed); 215 SetTestTime(start_time + time_elapsed);
216 stopwatch.Stop(); 216 stopwatch.Stop();
217 217
218 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 218 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
219 219
220 birth_map.clear(); 220 birth_map.clear();
221 death_map.clear(); 221 death_map.clear();
222 parent_child_set.clear(); 222 parent_child_set.clear();
223 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); 223 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
224 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 224 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
225 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. 225 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births.
226 EXPECT_EQ(1u, death_map.size()); // 1 location. 226 EXPECT_EQ(1u, death_map.size()); // 1 location.
227 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. 227 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death.
228 if (ThreadData::TrackingParentChildStatus()) { 228 if (ThreadData::TrackingParentChildStatus()) {
229 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. 229 EXPECT_EQ(1u, parent_child_set.size()); // 1 child.
230 EXPECT_EQ(parent_child_set.begin()->first, 230 EXPECT_EQ(parent_child_set.begin()->first,
231 parent_child_set.begin()->second); 231 parent_child_set.begin()->second);
232 } else { 232 } else {
233 EXPECT_EQ(0u, parent_child_set.size()); // no stats. 233 EXPECT_EQ(0u, parent_child_set.size()); // no stats.
234 } 234 }
235 235
236 // The births were at the same location as the one known death. 236 // The births were at the same location as the one known death.
237 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); 237 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first);
238 238
239 ProcessDataSnapshot process_data; 239 ProcessDataSnapshot process_data;
240 ThreadData::Snapshot(&process_data); 240 ThreadData::Snapshot(0, &process_data);
241 241
242 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 242 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size());
243 auto it = process_data.phased_process_data_snapshots.find(0); 243 auto it = process_data.phased_process_data_snapshots.find(0);
244 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 244 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end());
245 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 245 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
246 ASSERT_EQ(1u, process_data_phase.tasks.size()); 246 ASSERT_EQ(1u, process_data_phase.tasks.size());
247 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); 247 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name);
248 EXPECT_EQ(kFunction, 248 EXPECT_EQ(kFunction,
249 process_data_phase.tasks[0].birth.location.function_name); 249 process_data_phase.tasks[0].birth.location.function_name);
250 EXPECT_EQ(kLineNumber, 250 EXPECT_EQ(kLineNumber,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // Start in the deactivated state. 331 // Start in the deactivated state.
332 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 332 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
333 return; 333 return;
334 } 334 }
335 335
336 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; 336 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread";
337 Location location(kFunction, kFile, kLineNumber, NULL); 337 Location location(kFunction, kFile, kLineNumber, NULL);
338 TallyABirth(location, std::string()); 338 TallyABirth(location, std::string());
339 339
340 ProcessDataSnapshot process_data; 340 ProcessDataSnapshot process_data;
341 ThreadData::Snapshot(&process_data); 341 ThreadData::Snapshot(0, &process_data);
342 342
343 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 343 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size());
344 auto it = process_data.phased_process_data_snapshots.find(0); 344 auto it = process_data.phased_process_data_snapshots.find(0);
345 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 345 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end());
346 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 346 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
347 347
348 EXPECT_EQ(0u, process_data_phase.tasks.size()); 348 EXPECT_EQ(0u, process_data_phase.tasks.size());
349 EXPECT_EQ(0u, process_data_phase.descendants.size()); 349 EXPECT_EQ(0u, process_data_phase.descendants.size());
350 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 350 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
351 } 351 }
352 352
353 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { 353 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) {
354 // Start in the deactivated state. 354 // Start in the deactivated state.
355 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 355 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
356 return; 356 return;
357 } 357 }
358 358
359 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; 359 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread";
360 Location location(kFunction, kFile, kLineNumber, NULL); 360 Location location(kFunction, kFile, kLineNumber, NULL);
361 TallyABirth(location, kMainThreadName); 361 TallyABirth(location, kMainThreadName);
362 362
363 ProcessDataSnapshot process_data; 363 ProcessDataSnapshot process_data;
364 ThreadData::Snapshot(&process_data); 364 ThreadData::Snapshot(0, &process_data);
365 365
366 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 366 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size());
367 auto it = process_data.phased_process_data_snapshots.find(0); 367 auto it = process_data.phased_process_data_snapshots.find(0);
368 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 368 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end());
369 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 369 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
370 370
371 EXPECT_EQ(0u, process_data_phase.tasks.size()); 371 EXPECT_EQ(0u, process_data_phase.tasks.size());
372 EXPECT_EQ(0u, process_data_phase.descendants.size()); 372 EXPECT_EQ(0u, process_data_phase.descendants.size());
373 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 373 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
374 } 374 }
375 375
376 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { 376 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) {
377 if (!ThreadData::InitializeAndSetTrackingStatus( 377 if (!ThreadData::InitializeAndSetTrackingStatus(
378 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 378 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
379 return; 379 return;
380 } 380 }
381 381
382 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; 382 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread";
383 Location location(kFunction, kFile, kLineNumber, NULL); 383 Location location(kFunction, kFile, kLineNumber, NULL);
384 TallyABirth(location, std::string()); 384 TallyABirth(location, std::string());
385 385
386 ProcessDataSnapshot process_data; 386 ProcessDataSnapshot process_data;
387 ThreadData::Snapshot(&process_data); 387 ThreadData::Snapshot(0, &process_data);
388 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, 388 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
389 kStillAlive, 1, 0, 0); 389 kStillAlive, 1, 0, 0);
390 } 390 }
391 391
392 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { 392 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) {
393 if (!ThreadData::InitializeAndSetTrackingStatus( 393 if (!ThreadData::InitializeAndSetTrackingStatus(
394 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 394 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
395 return; 395 return;
396 } 396 }
397 397
398 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; 398 const char kFunction[] = "BirthOnlyToSnapshotMainThread";
399 Location location(kFunction, kFile, kLineNumber, NULL); 399 Location location(kFunction, kFile, kLineNumber, NULL);
400 TallyABirth(location, kMainThreadName); 400 TallyABirth(location, kMainThreadName);
401 401
402 ProcessDataSnapshot process_data; 402 ProcessDataSnapshot process_data;
403 ThreadData::Snapshot(&process_data); 403 ThreadData::Snapshot(0, &process_data);
404 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, 404 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive,
405 1, 0, 0); 405 1, 0, 0);
406 } 406 }
407 407
408 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { 408 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) {
409 if (!ThreadData::InitializeAndSetTrackingStatus( 409 if (!ThreadData::InitializeAndSetTrackingStatus(
410 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 410 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
411 return; 411 return;
412 } 412 }
413 413
(...skipping 11 matching lines...) Expand all
425 const unsigned int kEndOfRun = 7; 425 const unsigned int kEndOfRun = 7;
426 SetTestTime(kStartOfRun); 426 SetTestTime(kStartOfRun);
427 TaskStopwatch stopwatch; 427 TaskStopwatch stopwatch;
428 stopwatch.Start(); 428 stopwatch.Start();
429 SetTestTime(kEndOfRun); 429 SetTestTime(kEndOfRun);
430 stopwatch.Stop(); 430 stopwatch.Stop();
431 431
432 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 432 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
433 433
434 ProcessDataSnapshot process_data; 434 ProcessDataSnapshot process_data;
435 ThreadData::Snapshot(&process_data); 435 ThreadData::Snapshot(0, &process_data);
436 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 436 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
437 kMainThreadName, 1, 2, 4); 437 kMainThreadName, 1, 2, 4);
438 } 438 }
439 439
440 TEST_F(TrackedObjectsTest, TwoPhases) {
441 if (!ThreadData::InitializeAndSetTrackingStatus(
442 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
443 return;
444 }
445
446 const char kFunction[] = "TwoPhases";
447 Location location(kFunction, kFile, kLineNumber, NULL);
448 TallyABirth(location, kMainThreadName);
449
450 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
451 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
452 // TrackingInfo will call TallyABirth() during construction.
453 base::TrackingInfo pending_task(location, kDelayedStartTime);
454 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
455
456 const unsigned int kStartOfRun = 5;
457 const unsigned int kEndOfRun = 7;
458 SetTestTime(kStartOfRun);
459 TaskStopwatch stopwatch;
460 stopwatch.Start();
461 SetTestTime(kEndOfRun);
462 stopwatch.Stop();
463
464 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
465
466 ThreadData::OnProfilingPhaseCompletion(0);
467
468 TallyABirth(location, kMainThreadName);
469
470 const TrackedTime kTimePosted1 = TrackedTime::FromMilliseconds(9);
471 const base::TimeTicks kDelayedStartTime1 = base::TimeTicks();
472 // TrackingInfo will call TallyABirth() during construction.
473 base::TrackingInfo pending_task1(location, kDelayedStartTime1);
474 pending_task1.time_posted = kTimePosted1; // Overwrite implied Now().
475
476 const unsigned int kStartOfRun1 = 11;
477 const unsigned int kEndOfRun1 = 21;
478 SetTestTime(kStartOfRun1);
479 TaskStopwatch stopwatch1;
480 stopwatch1.Start();
481 SetTestTime(kEndOfRun1);
482 stopwatch1.Stop();
483
484 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task1, stopwatch1);
485
486 ProcessDataSnapshot process_data;
487 ThreadData::Snapshot(1, &process_data);
488
489 ASSERT_EQ(2u, process_data.phased_process_data_snapshots.size());
490
491 auto it0 = process_data.phased_process_data_snapshots.find(0);
492 ASSERT_TRUE(it0 != process_data.phased_process_data_snapshots.end());
493 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second;
494
495 ASSERT_EQ(1u, process_data_phase0.tasks.size());
496
497 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name);
498 EXPECT_EQ(kFunction,
499 process_data_phase0.tasks[0].birth.location.function_name);
500 EXPECT_EQ(kLineNumber,
501 process_data_phase0.tasks[0].birth.location.line_number);
502
503 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name);
504
505 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count);
506 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum);
507 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max);
508 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample);
509 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum);
510 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max);
511 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample);
512
513 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name);
514
515 EXPECT_EQ(0u, process_data_phase0.descendants.size());
516
517 auto it1 = process_data.phased_process_data_snapshots.find(1);
518 ASSERT_TRUE(it1 != process_data.phased_process_data_snapshots.end());
519 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second;
520
521 ASSERT_EQ(1u, process_data_phase1.tasks.size());
522
523 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name);
524 EXPECT_EQ(kFunction,
525 process_data_phase1.tasks[0].birth.location.function_name);
526 EXPECT_EQ(kLineNumber,
527 process_data_phase1.tasks[0].birth.location.line_number);
528
529 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name);
530
531 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count);
532 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sum);
533 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_max);
534 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sample);
535 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum);
536 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max);
537 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample);
538
539 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name);
540
541 EXPECT_EQ(0u, process_data_phase1.descendants.size());
542
543 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
544 }
545
546 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) {
547 if (!ThreadData::InitializeAndSetTrackingStatus(
548 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
549 return;
550 }
551
552 const char kFunction[] = "TwoPhasesSecondEmpty";
553 Location location(kFunction, kFile, kLineNumber, NULL);
554 ThreadData::InitializeThreadContext(kMainThreadName);
555
556 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
557 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
558 // TrackingInfo will call TallyABirth() during construction.
559 base::TrackingInfo pending_task(location, kDelayedStartTime);
560 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
561
562 const unsigned int kStartOfRun = 5;
563 const unsigned int kEndOfRun = 7;
564 SetTestTime(kStartOfRun);
565 TaskStopwatch stopwatch;
566 stopwatch.Start();
567 SetTestTime(kEndOfRun);
568 stopwatch.Stop();
569
570 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
571
572 ThreadData::OnProfilingPhaseCompletion(0);
573
574 ProcessDataSnapshot process_data;
575 ThreadData::Snapshot(1, &process_data);
576
577 ASSERT_EQ(2u, process_data.phased_process_data_snapshots.size());
578
579 auto it0 = process_data.phased_process_data_snapshots.find(0);
580 ASSERT_TRUE(it0 != process_data.phased_process_data_snapshots.end());
581 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second;
582
583 ASSERT_EQ(1u, process_data_phase0.tasks.size());
584
585 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name);
586 EXPECT_EQ(kFunction,
587 process_data_phase0.tasks[0].birth.location.function_name);
588 EXPECT_EQ(kLineNumber,
589 process_data_phase0.tasks[0].birth.location.line_number);
590
591 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name);
592
593 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count);
594 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum);
595 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max);
596 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample);
597 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum);
598 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max);
599 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample);
600
601 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name);
602
603 EXPECT_EQ(0u, process_data_phase0.descendants.size());
604
605 auto it1 = process_data.phased_process_data_snapshots.find(1);
606 ASSERT_TRUE(it1 != process_data.phased_process_data_snapshots.end());
607 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second;
608
609 ASSERT_EQ(0u, process_data_phase1.tasks.size());
610
611 EXPECT_EQ(0u, process_data_phase1.descendants.size());
612
613 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
614 }
615
440 // We will deactivate tracking after the birth, and before the death, and 616 // We will deactivate tracking after the birth, and before the death, and
441 // demonstrate that the lifecycle is completely tallied. This ensures that 617 // demonstrate that the lifecycle is completely tallied. This ensures that
442 // our tallied births are matched by tallied deaths (except for when the 618 // our tallied births are matched by tallied deaths (except for when the
443 // task is still running, or is queued). 619 // task is still running, or is queued).
444 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { 620 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) {
445 if (!ThreadData::InitializeAndSetTrackingStatus( 621 if (!ThreadData::InitializeAndSetTrackingStatus(
446 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 622 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
447 return; 623 return;
448 } 624 }
449 625
(...skipping 15 matching lines...) Expand all
465 const unsigned int kEndOfRun = 7; 641 const unsigned int kEndOfRun = 7;
466 SetTestTime(kStartOfRun); 642 SetTestTime(kStartOfRun);
467 TaskStopwatch stopwatch; 643 TaskStopwatch stopwatch;
468 stopwatch.Start(); 644 stopwatch.Start();
469 SetTestTime(kEndOfRun); 645 SetTestTime(kEndOfRun);
470 stopwatch.Stop(); 646 stopwatch.Stop();
471 647
472 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 648 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
473 649
474 ProcessDataSnapshot process_data; 650 ProcessDataSnapshot process_data;
475 ThreadData::Snapshot(&process_data); 651 ThreadData::Snapshot(0, &process_data);
476 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 652 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
477 kMainThreadName, 1, 2, 4); 653 kMainThreadName, 1, 2, 4);
478 } 654 }
479 655
480 // We will deactivate tracking before starting a life cycle, and neither 656 // We will deactivate tracking before starting a life cycle, and neither
481 // the birth nor the death will be recorded. 657 // the birth nor the death will be recorded.
482 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { 658 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) {
483 // Start in the deactivated state. 659 // Start in the deactivated state.
484 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 660 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
485 return; 661 return;
(...skipping 13 matching lines...) Expand all
499 const unsigned int kEndOfRun = 7; 675 const unsigned int kEndOfRun = 7;
500 SetTestTime(kStartOfRun); 676 SetTestTime(kStartOfRun);
501 TaskStopwatch stopwatch; 677 TaskStopwatch stopwatch;
502 stopwatch.Start(); 678 stopwatch.Start();
503 SetTestTime(kEndOfRun); 679 SetTestTime(kEndOfRun);
504 stopwatch.Stop(); 680 stopwatch.Stop();
505 681
506 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 682 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
507 683
508 ProcessDataSnapshot process_data; 684 ProcessDataSnapshot process_data;
509 ThreadData::Snapshot(&process_data); 685 ThreadData::Snapshot(0, &process_data);
510 686
511 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 687 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size());
512 auto it = process_data.phased_process_data_snapshots.find(0); 688 auto it = process_data.phased_process_data_snapshots.find(0);
513 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 689 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end());
514 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 690 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
515 691
516 EXPECT_EQ(0u, process_data_phase.tasks.size()); 692 EXPECT_EQ(0u, process_data_phase.tasks.size());
517 EXPECT_EQ(0u, process_data_phase.descendants.size()); 693 EXPECT_EQ(0u, process_data_phase.descendants.size());
518 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 694 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
519 } 695 }
(...skipping 29 matching lines...) Expand all
549 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 725 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
550 SetTestTime(kStartOfRun); 726 SetTestTime(kStartOfRun);
551 TaskStopwatch stopwatch2; 727 TaskStopwatch stopwatch2;
552 stopwatch2.Start(); 728 stopwatch2.Start();
553 SetTestTime(kEndOfRun); 729 SetTestTime(kEndOfRun);
554 stopwatch2.Stop(); 730 stopwatch2.Stop();
555 731
556 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); 732 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2);
557 733
558 ProcessDataSnapshot process_data; 734 ProcessDataSnapshot process_data;
559 ThreadData::Snapshot(&process_data); 735 ThreadData::Snapshot(0, &process_data);
560 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 736 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
561 kMainThreadName, 2, 2, 4); 737 kMainThreadName, 2, 2, 4);
562 } 738 }
563 739
564 TEST_F(TrackedObjectsTest, DifferentLives) { 740 TEST_F(TrackedObjectsTest, DifferentLives) {
565 if (!ThreadData::InitializeAndSetTrackingStatus( 741 if (!ThreadData::InitializeAndSetTrackingStatus(
566 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 742 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
567 return; 743 return;
568 } 744 }
569 745
(...skipping 19 matching lines...) Expand all
589 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 765 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
590 766
591 const int kSecondFakeLineNumber = 999; 767 const int kSecondFakeLineNumber = 999;
592 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); 768 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
593 769
594 // TrackingInfo will call TallyABirth() during construction. 770 // TrackingInfo will call TallyABirth() during construction.
595 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); 771 base::TrackingInfo pending_task2(second_location, kDelayedStartTime);
596 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 772 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
597 773
598 ProcessDataSnapshot process_data; 774 ProcessDataSnapshot process_data;
599 ThreadData::Snapshot(&process_data); 775 ThreadData::Snapshot(0, &process_data);
600 776
601 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 777 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size());
602 auto it = process_data.phased_process_data_snapshots.find(0); 778 auto it = process_data.phased_process_data_snapshots.find(0);
603 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 779 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end());
604 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 780 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
605 781
606 ASSERT_EQ(2u, process_data_phase.tasks.size()); 782 ASSERT_EQ(2u, process_data_phase.tasks.size());
607 783
608 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); 784 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name);
609 EXPECT_EQ(kFunction, 785 EXPECT_EQ(kFunction,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 exclusion_stopwatch.Start(); 838 exclusion_stopwatch.Start();
663 SetTestTime(12); 839 SetTestTime(12);
664 exclusion_stopwatch.Stop(); 840 exclusion_stopwatch.Stop();
665 } 841 }
666 SetTestTime(15); 842 SetTestTime(15);
667 task_stopwatch.Stop(); 843 task_stopwatch.Stop();
668 844
669 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 845 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
670 846
671 ProcessDataSnapshot process_data; 847 ProcessDataSnapshot process_data;
672 ThreadData::Snapshot(&process_data); 848 ThreadData::Snapshot(0, &process_data);
673 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 849 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
674 kMainThreadName, 1, 6, 4); 850 kMainThreadName, 1, 6, 4);
675 } 851 }
676 852
677 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { 853 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) {
678 if (!ThreadData::InitializeAndSetTrackingStatus( 854 if (!ThreadData::InitializeAndSetTrackingStatus(
679 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 855 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
680 return; 856 return;
681 } 857 }
682 858
(...skipping 22 matching lines...) Expand all
705 exclusion_stopwatch2.Start(); 881 exclusion_stopwatch2.Start();
706 SetTestTime(18); 882 SetTestTime(18);
707 exclusion_stopwatch2.Stop(); 883 exclusion_stopwatch2.Stop();
708 } 884 }
709 SetTestTime(25); 885 SetTestTime(25);
710 task_stopwatch.Stop(); 886 task_stopwatch.Stop();
711 887
712 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 888 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
713 889
714 ProcessDataSnapshot process_data; 890 ProcessDataSnapshot process_data;
715 ThreadData::Snapshot(&process_data); 891 ThreadData::Snapshot(0, &process_data);
716 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 892 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
717 kMainThreadName, 1, 13, 4); 893 kMainThreadName, 1, 13, 4);
718 } 894 }
719 895
720 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { 896 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
721 if (!ThreadData::InitializeAndSetTrackingStatus( 897 if (!ThreadData::InitializeAndSetTrackingStatus(
722 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 898 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
723 return; 899 return;
724 } 900 }
725 901
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 934 }
759 SetTestTime(12); 935 SetTestTime(12);
760 exclusion_stopwatch.Stop(); 936 exclusion_stopwatch.Stop();
761 } 937 }
762 SetTestTime(15); 938 SetTestTime(15);
763 task_stopwatch.Stop(); 939 task_stopwatch.Stop();
764 940
765 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 941 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
766 942
767 ProcessDataSnapshot process_data; 943 ProcessDataSnapshot process_data;
768 ThreadData::Snapshot(&process_data); 944 ThreadData::Snapshot(0, &process_data);
769 945
770 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 946 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size());
771 auto it = process_data.phased_process_data_snapshots.find(0); 947 auto it = process_data.phased_process_data_snapshots.find(0);
772 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 948 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end());
773 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 949 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
774 950
775 // The order in which the two task follow is platform-dependent. 951 // The order in which the two task follow is platform-dependent.
776 int t0 = 952 int t0 =
777 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber) 953 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber)
778 ? 0 954 ? 0
(...skipping 27 matching lines...) Expand all
806 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); 982 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample);
807 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); 983 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum);
808 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); 984 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max);
809 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); 985 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample);
810 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); 986 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name);
811 EXPECT_EQ(0u, process_data_phase.descendants.size()); 987 EXPECT_EQ(0u, process_data_phase.descendants.size());
812 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 988 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
813 } 989 }
814 990
815 } // namespace tracked_objects 991 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « base/tracked_objects.cc ('k') | chrome/browser/metrics/chrome_metrics_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698