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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 445413003: Creating a framework for suppressing pollution of the profiler data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding 1 forgotten time parameter. Created 6 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 | Annotate | Revision Log
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // Now instigate another birth, while we are timing the run of the first 161 // Now instigate another birth, while we are timing the run of the first
162 // execution. 162 // execution.
163 ThreadData::NowForStartOfRun(first_birth); 163 ThreadData::NowForStartOfRun(first_birth);
164 // Create a child (using the same birth location). 164 // Create a child (using the same birth location).
165 // TrackingInfo will call TallyABirth() during construction. 165 // TrackingInfo will call TallyABirth() during construction.
166 base::TimeTicks kBogusBirthTime; 166 base::TimeTicks kBogusBirthTime;
167 base::TrackingInfo pending_task(location, kBogusBirthTime); 167 base::TrackingInfo pending_task(location, kBogusBirthTime);
168 TrackedTime start_time(pending_task.time_posted); 168 TrackedTime start_time(pending_task.time_posted);
169 // Finally conclude the outer run. 169 // Finally conclude the outer run.
170 TrackedTime end_time = ThreadData::NowForEndOfRun(); 170 TrackedTime end_time = ThreadData::NowForEndOfRun();
171 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, start_time, 171 TaskStopwatch stopwatch;
172 end_time); 172 stopwatch.Start(start_time);
173 stopwatch.Stop(end_time);
174
175 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
173 176
174 birth_map.clear(); 177 birth_map.clear();
175 death_map.clear(); 178 death_map.clear();
176 parent_child_set.clear(); 179 parent_child_set.clear();
177 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); 180 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
178 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 181 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
179 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. 182 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births.
180 EXPECT_EQ(1u, death_map.size()); // 1 location. 183 EXPECT_EQ(1u, death_map.size()); // 1 location.
181 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. 184 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death.
182 if (ThreadData::TrackingParentChildStatus()) { 185 if (ThreadData::TrackingParentChildStatus()) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 const base::TimeTicks kTimePosted = base::TimeTicks() + 346 const base::TimeTicks kTimePosted = base::TimeTicks() +
344 base::TimeDelta::FromMilliseconds(1); 347 base::TimeDelta::FromMilliseconds(1);
345 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 348 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
346 // TrackingInfo will call TallyABirth() during construction. 349 // TrackingInfo will call TallyABirth() during construction.
347 base::TrackingInfo pending_task(location, kDelayedStartTime); 350 base::TrackingInfo pending_task(location, kDelayedStartTime);
348 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 351 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
349 352
350 const TrackedTime kStartOfRun = TrackedTime() + 353 const TrackedTime kStartOfRun = TrackedTime() +
351 Duration::FromMilliseconds(5); 354 Duration::FromMilliseconds(5);
352 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 355 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
353 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 356 TaskStopwatch stopwatch;
354 kStartOfRun, kEndOfRun); 357 stopwatch.Start(kStartOfRun);
358 stopwatch.Stop(kEndOfRun);
359
360 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
355 361
356 ProcessDataSnapshot process_data; 362 ProcessDataSnapshot process_data;
357 ThreadData::Snapshot(false, &process_data); 363 ThreadData::Snapshot(false, &process_data);
358 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 364 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
359 kMainThreadName, 1, 2, 4); 365 kMainThreadName, 1, 2, 4);
360 } 366 }
361 367
362 // We will deactivate tracking after the birth, and before the death, and 368 // We will deactivate tracking after the birth, and before the death, and
363 // demonstrate that the lifecycle is completely tallied. This ensures that 369 // demonstrate that the lifecycle is completely tallied. This ensures that
364 // our tallied births are matched by tallied deaths (except for when the 370 // our tallied births are matched by tallied deaths (except for when the
(...skipping 14 matching lines...) Expand all
379 base::TrackingInfo pending_task(location, kDelayedStartTime); 385 base::TrackingInfo pending_task(location, kDelayedStartTime);
380 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 386 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
381 387
382 // Turn off tracking now that we have births. 388 // Turn off tracking now that we have births.
383 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( 389 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus(
384 ThreadData::DEACTIVATED)); 390 ThreadData::DEACTIVATED));
385 391
386 const TrackedTime kStartOfRun = TrackedTime() + 392 const TrackedTime kStartOfRun = TrackedTime() +
387 Duration::FromMilliseconds(5); 393 Duration::FromMilliseconds(5);
388 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 394 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
389 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 395 TaskStopwatch stopwatch;
390 kStartOfRun, kEndOfRun); 396 stopwatch.Start(kStartOfRun);
397 stopwatch.Stop(kEndOfRun);
398
399 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
391 400
392 ProcessDataSnapshot process_data; 401 ProcessDataSnapshot process_data;
393 ThreadData::Snapshot(false, &process_data); 402 ThreadData::Snapshot(false, &process_data);
394 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 403 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
395 kMainThreadName, 1, 2, 4); 404 kMainThreadName, 1, 2, 4);
396 } 405 }
397 406
398 // We will deactivate tracking before starting a life cycle, and neither 407 // We will deactivate tracking before starting a life cycle, and neither
399 // the birth nor the death will be recorded. 408 // the birth nor the death will be recorded.
400 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { 409 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) {
401 // Start in the deactivated state. 410 // Start in the deactivated state.
402 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) 411 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED))
403 return; 412 return;
404 413
405 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; 414 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread";
406 Location location(kFunction, kFile, kLineNumber, NULL); 415 Location location(kFunction, kFile, kLineNumber, NULL);
407 TallyABirth(location, kMainThreadName); 416 TallyABirth(location, kMainThreadName);
408 417
409 const base::TimeTicks kTimePosted = base::TimeTicks() + 418 const base::TimeTicks kTimePosted = base::TimeTicks() +
410 base::TimeDelta::FromMilliseconds(1); 419 base::TimeDelta::FromMilliseconds(1);
411 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 420 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
412 // TrackingInfo will call TallyABirth() during construction. 421 // TrackingInfo will call TallyABirth() during construction.
413 base::TrackingInfo pending_task(location, kDelayedStartTime); 422 base::TrackingInfo pending_task(location, kDelayedStartTime);
414 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 423 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
415 424
416 const TrackedTime kStartOfRun = TrackedTime() + 425 const TrackedTime kStartOfRun = TrackedTime() +
417 Duration::FromMilliseconds(5); 426 Duration::FromMilliseconds(5);
418 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 427 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
419 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 428 TaskStopwatch stopwatch;
420 kStartOfRun, kEndOfRun); 429 stopwatch.Start(kStartOfRun);
430 stopwatch.Stop(kEndOfRun);
431
432 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
421 433
422 ProcessDataSnapshot process_data; 434 ProcessDataSnapshot process_data;
423 ThreadData::Snapshot(false, &process_data); 435 ThreadData::Snapshot(false, &process_data);
424 EXPECT_EQ(0u, process_data.tasks.size()); 436 EXPECT_EQ(0u, process_data.tasks.size());
425 EXPECT_EQ(0u, process_data.descendants.size()); 437 EXPECT_EQ(0u, process_data.descendants.size());
426 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 438 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
427 } 439 }
428 440
429 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) { 441 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) {
430 if (!ThreadData::InitializeAndSetTrackingStatus( 442 if (!ThreadData::InitializeAndSetTrackingStatus(
431 ThreadData::PROFILING_CHILDREN_ACTIVE)) 443 ThreadData::PROFILING_CHILDREN_ACTIVE))
432 return; 444 return;
433 445
434 const char kFunction[] = "LifeCycleToSnapshotWorkerThread"; 446 const char kFunction[] = "LifeCycleToSnapshotWorkerThread";
435 Location location(kFunction, kFile, kLineNumber, NULL); 447 Location location(kFunction, kFile, kLineNumber, NULL);
436 // Do not delete |birth|. We don't own it. 448 // Do not delete |birth|. We don't own it.
437 Births* birth = ThreadData::TallyABirthIfActive(location); 449 Births* birth = ThreadData::TallyABirthIfActive(location);
438 EXPECT_NE(reinterpret_cast<Births*>(NULL), birth); 450 EXPECT_NE(reinterpret_cast<Births*>(NULL), birth);
439 451
440 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); 452 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1);
441 const TrackedTime kStartOfRun = TrackedTime() + 453 const TrackedTime kStartOfRun = TrackedTime() +
442 Duration::FromMilliseconds(5); 454 Duration::FromMilliseconds(5);
443 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 455 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
444 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, 456 TaskStopwatch stopwatch;
445 kStartOfRun, kEndOfRun); 457 stopwatch.Start(kStartOfRun);
458 stopwatch.Stop(kEndOfRun);
459
460 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, stopwatch);
446 461
447 // Call for the ToSnapshot, but tell it to not reset the maxes after scanning. 462 // Call for the ToSnapshot, but tell it to not reset the maxes after scanning.
448 ProcessDataSnapshot process_data; 463 ProcessDataSnapshot process_data;
449 ThreadData::Snapshot(false, &process_data); 464 ThreadData::Snapshot(false, &process_data);
450 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, 465 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
451 kWorkerThreadName, 1, 2, 4); 466 kWorkerThreadName, 1, 2, 4);
452 467
453 // Call for the ToSnapshot, but tell it to reset the maxes after scanning. 468 // Call for the ToSnapshot, but tell it to reset the maxes after scanning.
454 // We'll still get the same values, but the data will be reset (which we'll 469 // We'll still get the same values, but the data will be reset (which we'll
455 // see in a moment). 470 // see in a moment).
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 const base::TimeTicks kTimePosted = base::TimeTicks() + 511 const base::TimeTicks kTimePosted = base::TimeTicks() +
497 base::TimeDelta::FromMilliseconds(1); 512 base::TimeDelta::FromMilliseconds(1);
498 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 513 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
499 // TrackingInfo will call TallyABirth() during construction. 514 // TrackingInfo will call TallyABirth() during construction.
500 base::TrackingInfo pending_task(location, kDelayedStartTime); 515 base::TrackingInfo pending_task(location, kDelayedStartTime);
501 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 516 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
502 517
503 const TrackedTime kStartOfRun = TrackedTime() + 518 const TrackedTime kStartOfRun = TrackedTime() +
504 Duration::FromMilliseconds(5); 519 Duration::FromMilliseconds(5);
505 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 520 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
506 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 521 TaskStopwatch stopwatch;
507 kStartOfRun, kEndOfRun); 522 stopwatch.Start(kStartOfRun);
523 stopwatch.Stop(kEndOfRun);
524
525 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
508 526
509 // TrackingInfo will call TallyABirth() during construction. 527 // TrackingInfo will call TallyABirth() during construction.
510 base::TrackingInfo pending_task2(location, kDelayedStartTime); 528 base::TrackingInfo pending_task2(location, kDelayedStartTime);
511 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 529 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
530 stopwatch.Start(kStartOfRun);
531 stopwatch.Stop(kEndOfRun);
512 532
513 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, 533 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch);
514 kStartOfRun, kEndOfRun);
515 534
516 ProcessDataSnapshot process_data; 535 ProcessDataSnapshot process_data;
517 ThreadData::Snapshot(false, &process_data); 536 ThreadData::Snapshot(false, &process_data);
518 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 537 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
519 kMainThreadName, 2, 2, 4); 538 kMainThreadName, 2, 2, 4);
520 } 539 }
521 540
522 TEST_F(TrackedObjectsTest, DifferentLives) { 541 TEST_F(TrackedObjectsTest, DifferentLives) {
523 if (!ThreadData::InitializeAndSetTrackingStatus( 542 if (!ThreadData::InitializeAndSetTrackingStatus(
524 ThreadData::PROFILING_CHILDREN_ACTIVE)) 543 ThreadData::PROFILING_CHILDREN_ACTIVE))
525 return; 544 return;
526 545
527 // Use a well named thread. 546 // Use a well named thread.
528 ThreadData::InitializeThreadContext(kMainThreadName); 547 ThreadData::InitializeThreadContext(kMainThreadName);
529 const char kFunction[] = "DifferentLives"; 548 const char kFunction[] = "DifferentLives";
530 Location location(kFunction, kFile, kLineNumber, NULL); 549 Location location(kFunction, kFile, kLineNumber, NULL);
531 550
532 const base::TimeTicks kTimePosted = base::TimeTicks() + 551 const base::TimeTicks kTimePosted = base::TimeTicks() +
533 base::TimeDelta::FromMilliseconds(1); 552 base::TimeDelta::FromMilliseconds(1);
534 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 553 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
535 // TrackingInfo will call TallyABirth() during construction. 554 // TrackingInfo will call TallyABirth() during construction.
536 base::TrackingInfo pending_task(location, kDelayedStartTime); 555 base::TrackingInfo pending_task(location, kDelayedStartTime);
537 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 556 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
538 557
539 const TrackedTime kStartOfRun = TrackedTime() + 558 const TrackedTime kStartOfRun = TrackedTime() +
540 Duration::FromMilliseconds(5); 559 Duration::FromMilliseconds(5);
541 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 560 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
542 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 561 TaskStopwatch stopwatch;
543 kStartOfRun, kEndOfRun); 562 stopwatch.Start(kStartOfRun);
563 stopwatch.Stop(kEndOfRun);
564
565 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
544 566
545 const int kSecondFakeLineNumber = 999; 567 const int kSecondFakeLineNumber = 999;
546 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); 568 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
547 569
548 // TrackingInfo will call TallyABirth() during construction. 570 // TrackingInfo will call TallyABirth() during construction.
549 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); 571 base::TrackingInfo pending_task2(second_location, kDelayedStartTime);
550 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 572 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
551 573
552 ProcessDataSnapshot process_data; 574 ProcessDataSnapshot process_data;
553 ThreadData::Snapshot(false, &process_data); 575 ThreadData::Snapshot(false, &process_data);
(...skipping 20 matching lines...) Expand all
574 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_max); 596 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_max);
575 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sample); 597 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sample);
576 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sum); 598 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sum);
577 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_max); 599 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_max);
578 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sample); 600 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sample);
579 EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name); 601 EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name);
580 EXPECT_EQ(0u, process_data.descendants.size()); 602 EXPECT_EQ(0u, process_data.descendants.size());
581 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 603 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
582 } 604 }
583 605
606 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) {
607 if (!ThreadData::InitializeAndSetTrackingStatus(
608 ThreadData::PROFILING_CHILDREN_ACTIVE))
609 return;
jar (doing other things) 2014/08/26 04:09:10 nit: When the conditional of the if runs across mo
vadimt 2014/08/26 19:15:05 Agree, braces help when 'if' with condition takes
610
611 const char kFunction[] = "TaskWithNestedExclusion";
612 Location location(kFunction, kFile, kLineNumber, NULL);
613 TallyABirth(location, kMainThreadName);
614
615 const base::TimeTicks kTimePosted = base::TimeTicks() +
616 base::TimeDelta::FromMilliseconds(1);
617 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
618 // TrackingInfo will call TallyABirth() during construction.
619 base::TrackingInfo pending_task(location, kDelayedStartTime);
620 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
621
622 const TrackedTime kStartOfRun = TrackedTime() +
623 Duration::FromMilliseconds(5);
624 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(15);
625 TaskStopwatch task_stopwatch;
626 task_stopwatch.Start(kStartOfRun);
627 {
628 TaskStopwatch exclusion_stopwatch;
629 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(8));
630 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(12));
631 }
632 task_stopwatch.Stop(kEndOfRun);
633
634 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
635
636 ProcessDataSnapshot process_data;
637 ThreadData::Snapshot(false, &process_data);
638 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
639 kMainThreadName, 1, 6, 4);
640 }
641
642 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) {
643 if (!ThreadData::InitializeAndSetTrackingStatus(
644 ThreadData::PROFILING_CHILDREN_ACTIVE))
645 return;
646
647 const char kFunction[] = "TaskWith2NestedExclusions";
648 Location location(kFunction, kFile, kLineNumber, NULL);
649 TallyABirth(location, kMainThreadName);
650
651 const base::TimeTicks kTimePosted = base::TimeTicks() +
652 base::TimeDelta::FromMilliseconds(1);
653 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
654 // TrackingInfo will call TallyABirth() during construction.
655 base::TrackingInfo pending_task(location, kDelayedStartTime);
656 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
657
658 const TrackedTime kStartOfRun = TrackedTime() +
659 Duration::FromMilliseconds(5);
660 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(25);
661 TaskStopwatch task_stopwatch;
662 task_stopwatch.Start(kStartOfRun);
663 {
664 TaskStopwatch exclusion_stopwatch;
665 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(8));
666 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(12));
667
668 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(15));
669 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(18));
670 }
671 task_stopwatch.Stop(kEndOfRun);
672
673 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
674
675 ProcessDataSnapshot process_data;
676 ThreadData::Snapshot(false, &process_data);
677 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
678 kMainThreadName, 1, 13, 4);
679 }
680
681 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
682 if (!ThreadData::InitializeAndSetTrackingStatus(
683 ThreadData::PROFILING_CHILDREN_ACTIVE))
684 return;
685
686 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask";
687 Location location(kFunction, kFile, kLineNumber, NULL);
688
689 const int kSecondFakeLineNumber = 999;
690
691 TallyABirth(location, kMainThreadName);
692
693 const base::TimeTicks kTimePosted = base::TimeTicks() +
694 base::TimeDelta::FromMilliseconds(1);
695 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
696 // TrackingInfo will call TallyABirth() during construction.
697 base::TrackingInfo pending_task(location, kDelayedStartTime);
698 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
699
700 const TrackedTime kStartOfRun = TrackedTime() +
701 Duration::FromMilliseconds(5);
702 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(15);
703 TaskStopwatch task_stopwatch;
704 task_stopwatch.Start(kStartOfRun);
705 {
706 TaskStopwatch exclusion_stopwatch;
707 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(8));
708 {
709 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
710 base::TrackingInfo nested_task(second_location, kDelayedStartTime);
711 // Overwrite implied Now().
712 nested_task.time_posted =
713 base::TimeTicks() + base::TimeDelta::FromMilliseconds(8);
714 TaskStopwatch nested_task_stopwatch;
715 nested_task_stopwatch.Start(
716 TrackedTime() + Duration::FromMilliseconds(9));
717 nested_task_stopwatch.Stop(
718 TrackedTime() + Duration::FromMilliseconds(11));
719 ThreadData::TallyRunOnNamedThreadIfTracking(
720 nested_task, nested_task_stopwatch);
721 }
722 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(12));
723 }
724 task_stopwatch.Stop(kEndOfRun);
725
726 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
727
728 ProcessDataSnapshot process_data;
729 ThreadData::Snapshot(false, &process_data);
730 ASSERT_EQ(2u, process_data.tasks.size());
731 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name);
732 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name);
733 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number);
734 EXPECT_EQ(kMainThreadName, process_data.tasks[0].birth.thread_name);
735 EXPECT_EQ(1, process_data.tasks[0].death_data.count);
736 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_sum);
737 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_max);
738 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_sample);
739 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sum);
740 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_max);
741 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sample);
742 EXPECT_EQ(kMainThreadName, process_data.tasks[0].death_thread_name);
743 EXPECT_EQ(kFile, process_data.tasks[1].birth.location.file_name);
744 EXPECT_EQ(kFunction, process_data.tasks[1].birth.location.function_name);
745 EXPECT_EQ(kSecondFakeLineNumber,
746 process_data.tasks[1].birth.location.line_number);
747 EXPECT_EQ(kMainThreadName, process_data.tasks[1].birth.thread_name);
748 EXPECT_EQ(1, process_data.tasks[1].death_data.count);
749 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_sum);
750 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_max);
751 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_sample);
752 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_sum);
753 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_max);
754 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_sample);
755 EXPECT_EQ(kMainThreadName, process_data.tasks[1].death_thread_name);
756 EXPECT_EQ(0u, process_data.descendants.size());
757 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
758 }
759
584 } // namespace tracked_objects 760 } // namespace tracked_objects
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698