OLD | NEW |
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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { | 375 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { |
376 if (!ThreadData::InitializeAndSetTrackingStatus( | 376 if (!ThreadData::InitializeAndSetTrackingStatus( |
377 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 377 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
378 return; | 378 return; |
379 } | 379 } |
380 | 380 |
381 const char kFunction[] = "LifeCycleToSnapshotMainThread"; | 381 const char kFunction[] = "LifeCycleToSnapshotMainThread"; |
382 Location location(kFunction, kFile, kLineNumber, NULL); | 382 Location location(kFunction, kFile, kLineNumber, NULL); |
383 TallyABirth(location, kMainThreadName); | 383 TallyABirth(location, kMainThreadName); |
384 | 384 |
385 const base::TimeTicks kTimePosted = base::TimeTicks() + | 385 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
386 base::TimeDelta::FromMilliseconds(1); | |
387 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 386 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
388 // TrackingInfo will call TallyABirth() during construction. | 387 // TrackingInfo will call TallyABirth() during construction. |
389 base::TrackingInfo pending_task(location, kDelayedStartTime); | 388 base::TrackingInfo pending_task(location, kDelayedStartTime); |
390 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 389 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
391 | 390 |
392 const unsigned int kStartOfRun = 5; | 391 const unsigned int kStartOfRun = 5; |
393 const unsigned int kEndOfRun = 7; | 392 const unsigned int kEndOfRun = 7; |
394 SetTestTime(kStartOfRun); | 393 SetTestTime(kStartOfRun); |
395 TaskStopwatch stopwatch; | 394 TaskStopwatch stopwatch; |
396 stopwatch.Start(); | 395 stopwatch.Start(); |
(...skipping 15 matching lines...) Expand all Loading... |
412 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { | 411 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { |
413 if (!ThreadData::InitializeAndSetTrackingStatus( | 412 if (!ThreadData::InitializeAndSetTrackingStatus( |
414 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 413 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
415 return; | 414 return; |
416 } | 415 } |
417 | 416 |
418 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; | 417 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; |
419 Location location(kFunction, kFile, kLineNumber, NULL); | 418 Location location(kFunction, kFile, kLineNumber, NULL); |
420 TallyABirth(location, kMainThreadName); | 419 TallyABirth(location, kMainThreadName); |
421 | 420 |
422 const base::TimeTicks kTimePosted = base::TimeTicks() + | 421 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
423 base::TimeDelta::FromMilliseconds(1); | |
424 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 422 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
425 // TrackingInfo will call TallyABirth() during construction. | 423 // TrackingInfo will call TallyABirth() during construction. |
426 base::TrackingInfo pending_task(location, kDelayedStartTime); | 424 base::TrackingInfo pending_task(location, kDelayedStartTime); |
427 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 425 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
428 | 426 |
429 // Turn off tracking now that we have births. | 427 // Turn off tracking now that we have births. |
430 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 428 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
431 ThreadData::DEACTIVATED)); | 429 ThreadData::DEACTIVATED)); |
432 | 430 |
433 const unsigned int kStartOfRun = 5; | 431 const unsigned int kStartOfRun = 5; |
(...skipping 17 matching lines...) Expand all Loading... |
451 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { | 449 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { |
452 // Start in the deactivated state. | 450 // Start in the deactivated state. |
453 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 451 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
454 return; | 452 return; |
455 } | 453 } |
456 | 454 |
457 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; | 455 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; |
458 Location location(kFunction, kFile, kLineNumber, NULL); | 456 Location location(kFunction, kFile, kLineNumber, NULL); |
459 TallyABirth(location, kMainThreadName); | 457 TallyABirth(location, kMainThreadName); |
460 | 458 |
461 const base::TimeTicks kTimePosted = base::TimeTicks() + | 459 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
462 base::TimeDelta::FromMilliseconds(1); | |
463 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 460 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
464 // TrackingInfo will call TallyABirth() during construction. | 461 // TrackingInfo will call TallyABirth() during construction. |
465 base::TrackingInfo pending_task(location, kDelayedStartTime); | 462 base::TrackingInfo pending_task(location, kDelayedStartTime); |
466 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 463 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
467 | 464 |
468 const unsigned int kStartOfRun = 5; | 465 const unsigned int kStartOfRun = 5; |
469 const unsigned int kEndOfRun = 7; | 466 const unsigned int kEndOfRun = 7; |
470 SetTestTime(kStartOfRun); | 467 SetTestTime(kStartOfRun); |
471 TaskStopwatch stopwatch; | 468 TaskStopwatch stopwatch; |
472 stopwatch.Start(); | 469 stopwatch.Start(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 TEST_F(TrackedObjectsTest, TwoLives) { | 546 TEST_F(TrackedObjectsTest, TwoLives) { |
550 if (!ThreadData::InitializeAndSetTrackingStatus( | 547 if (!ThreadData::InitializeAndSetTrackingStatus( |
551 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 548 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
552 return; | 549 return; |
553 } | 550 } |
554 | 551 |
555 const char kFunction[] = "TwoLives"; | 552 const char kFunction[] = "TwoLives"; |
556 Location location(kFunction, kFile, kLineNumber, NULL); | 553 Location location(kFunction, kFile, kLineNumber, NULL); |
557 TallyABirth(location, kMainThreadName); | 554 TallyABirth(location, kMainThreadName); |
558 | 555 |
559 const base::TimeTicks kTimePosted = base::TimeTicks() + | 556 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
560 base::TimeDelta::FromMilliseconds(1); | |
561 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 557 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
562 // TrackingInfo will call TallyABirth() during construction. | 558 // TrackingInfo will call TallyABirth() during construction. |
563 base::TrackingInfo pending_task(location, kDelayedStartTime); | 559 base::TrackingInfo pending_task(location, kDelayedStartTime); |
564 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 560 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
565 | 561 |
566 const unsigned int kStartOfRun = 5; | 562 const unsigned int kStartOfRun = 5; |
567 const unsigned int kEndOfRun = 7; | 563 const unsigned int kEndOfRun = 7; |
568 SetTestTime(kStartOfRun); | 564 SetTestTime(kStartOfRun); |
569 TaskStopwatch stopwatch; | 565 TaskStopwatch stopwatch; |
570 stopwatch.Start(); | 566 stopwatch.Start(); |
(...skipping 23 matching lines...) Expand all Loading... |
594 if (!ThreadData::InitializeAndSetTrackingStatus( | 590 if (!ThreadData::InitializeAndSetTrackingStatus( |
595 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 591 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
596 return; | 592 return; |
597 } | 593 } |
598 | 594 |
599 // Use a well named thread. | 595 // Use a well named thread. |
600 ThreadData::InitializeThreadContext(kMainThreadName); | 596 ThreadData::InitializeThreadContext(kMainThreadName); |
601 const char kFunction[] = "DifferentLives"; | 597 const char kFunction[] = "DifferentLives"; |
602 Location location(kFunction, kFile, kLineNumber, NULL); | 598 Location location(kFunction, kFile, kLineNumber, NULL); |
603 | 599 |
604 const base::TimeTicks kTimePosted = base::TimeTicks() + | 600 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
605 base::TimeDelta::FromMilliseconds(1); | |
606 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 601 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
607 // TrackingInfo will call TallyABirth() during construction. | 602 // TrackingInfo will call TallyABirth() during construction. |
608 base::TrackingInfo pending_task(location, kDelayedStartTime); | 603 base::TrackingInfo pending_task(location, kDelayedStartTime); |
609 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 604 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
610 | 605 |
611 const unsigned int kStartOfRun = 5; | 606 const unsigned int kStartOfRun = 5; |
612 const unsigned int kEndOfRun = 7; | 607 const unsigned int kEndOfRun = 7; |
613 SetTestTime(kStartOfRun); | 608 SetTestTime(kStartOfRun); |
614 TaskStopwatch stopwatch; | 609 TaskStopwatch stopwatch; |
615 stopwatch.Start(); | 610 stopwatch.Start(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { | 656 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { |
662 if (!ThreadData::InitializeAndSetTrackingStatus( | 657 if (!ThreadData::InitializeAndSetTrackingStatus( |
663 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 658 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
664 return; | 659 return; |
665 } | 660 } |
666 | 661 |
667 const char kFunction[] = "TaskWithNestedExclusion"; | 662 const char kFunction[] = "TaskWithNestedExclusion"; |
668 Location location(kFunction, kFile, kLineNumber, NULL); | 663 Location location(kFunction, kFile, kLineNumber, NULL); |
669 TallyABirth(location, kMainThreadName); | 664 TallyABirth(location, kMainThreadName); |
670 | 665 |
671 const base::TimeTicks kTimePosted = base::TimeTicks() + | 666 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
672 base::TimeDelta::FromMilliseconds(1); | |
673 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 667 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
674 // TrackingInfo will call TallyABirth() during construction. | 668 // TrackingInfo will call TallyABirth() during construction. |
675 base::TrackingInfo pending_task(location, kDelayedStartTime); | 669 base::TrackingInfo pending_task(location, kDelayedStartTime); |
676 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 670 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
677 | 671 |
678 SetTestTime(5); | 672 SetTestTime(5); |
679 TaskStopwatch task_stopwatch; | 673 TaskStopwatch task_stopwatch; |
680 task_stopwatch.Start(); | 674 task_stopwatch.Start(); |
681 { | 675 { |
682 SetTestTime(8); | 676 SetTestTime(8); |
(...skipping 16 matching lines...) Expand all Loading... |
699 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { | 693 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { |
700 if (!ThreadData::InitializeAndSetTrackingStatus( | 694 if (!ThreadData::InitializeAndSetTrackingStatus( |
701 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 695 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
702 return; | 696 return; |
703 } | 697 } |
704 | 698 |
705 const char kFunction[] = "TaskWith2NestedExclusions"; | 699 const char kFunction[] = "TaskWith2NestedExclusions"; |
706 Location location(kFunction, kFile, kLineNumber, NULL); | 700 Location location(kFunction, kFile, kLineNumber, NULL); |
707 TallyABirth(location, kMainThreadName); | 701 TallyABirth(location, kMainThreadName); |
708 | 702 |
709 const base::TimeTicks kTimePosted = base::TimeTicks() + | 703 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
710 base::TimeDelta::FromMilliseconds(1); | |
711 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 704 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
712 // TrackingInfo will call TallyABirth() during construction. | 705 // TrackingInfo will call TallyABirth() during construction. |
713 base::TrackingInfo pending_task(location, kDelayedStartTime); | 706 base::TrackingInfo pending_task(location, kDelayedStartTime); |
714 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 707 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
715 | 708 |
716 SetTestTime(5); | 709 SetTestTime(5); |
717 TaskStopwatch task_stopwatch; | 710 TaskStopwatch task_stopwatch; |
718 task_stopwatch.Start(); | 711 task_stopwatch.Start(); |
719 { | 712 { |
720 SetTestTime(8); | 713 SetTestTime(8); |
(...skipping 25 matching lines...) Expand all Loading... |
746 return; | 739 return; |
747 } | 740 } |
748 | 741 |
749 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; | 742 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; |
750 Location location(kFunction, kFile, kLineNumber, NULL); | 743 Location location(kFunction, kFile, kLineNumber, NULL); |
751 | 744 |
752 const int kSecondFakeLineNumber = 999; | 745 const int kSecondFakeLineNumber = 999; |
753 | 746 |
754 TallyABirth(location, kMainThreadName); | 747 TallyABirth(location, kMainThreadName); |
755 | 748 |
756 const base::TimeTicks kTimePosted = base::TimeTicks() + | 749 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
757 base::TimeDelta::FromMilliseconds(1); | |
758 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 750 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
759 // TrackingInfo will call TallyABirth() during construction. | 751 // TrackingInfo will call TallyABirth() during construction. |
760 base::TrackingInfo pending_task(location, kDelayedStartTime); | 752 base::TrackingInfo pending_task(location, kDelayedStartTime); |
761 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 753 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
762 | 754 |
763 SetTestTime(5); | 755 SetTestTime(5); |
764 TaskStopwatch task_stopwatch; | 756 TaskStopwatch task_stopwatch; |
765 task_stopwatch.Start(); | 757 task_stopwatch.Start(); |
766 { | 758 { |
767 SetTestTime(8); | 759 SetTestTime(8); |
768 TaskStopwatch exclusion_stopwatch; | 760 TaskStopwatch exclusion_stopwatch; |
769 exclusion_stopwatch.Start(); | 761 exclusion_stopwatch.Start(); |
770 { | 762 { |
771 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 763 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
772 base::TrackingInfo nested_task(second_location, kDelayedStartTime); | 764 base::TrackingInfo nested_task(second_location, kDelayedStartTime); |
773 // Overwrite implied Now(). | 765 // Overwrite implied Now(). |
774 nested_task.time_posted = | 766 nested_task.time_posted = TrackedTime::FromMilliseconds(8); |
775 base::TimeTicks() + base::TimeDelta::FromMilliseconds(8); | |
776 SetTestTime(9); | 767 SetTestTime(9); |
777 TaskStopwatch nested_task_stopwatch; | 768 TaskStopwatch nested_task_stopwatch; |
778 nested_task_stopwatch.Start(); | 769 nested_task_stopwatch.Start(); |
779 SetTestTime(11); | 770 SetTestTime(11); |
780 nested_task_stopwatch.Stop(); | 771 nested_task_stopwatch.Stop(); |
781 ThreadData::TallyRunOnNamedThreadIfTracking( | 772 ThreadData::TallyRunOnNamedThreadIfTracking( |
782 nested_task, nested_task_stopwatch); | 773 nested_task, nested_task_stopwatch); |
783 } | 774 } |
784 SetTestTime(12); | 775 SetTestTime(12); |
785 exclusion_stopwatch.Stop(); | 776 exclusion_stopwatch.Stop(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 EXPECT_EQ(2, process_data.tasks[t1].death_data.run_duration_sample); | 812 EXPECT_EQ(2, process_data.tasks[t1].death_data.run_duration_sample); |
822 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sum); | 813 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sum); |
823 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_max); | 814 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_max); |
824 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sample); | 815 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sample); |
825 EXPECT_EQ(kMainThreadName, process_data.tasks[t1].death_thread_name); | 816 EXPECT_EQ(kMainThreadName, process_data.tasks[t1].death_thread_name); |
826 EXPECT_EQ(0u, process_data.descendants.size()); | 817 EXPECT_EQ(0u, process_data.descendants.size()); |
827 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 818 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
828 } | 819 } |
829 | 820 |
830 } // namespace tracked_objects | 821 } // namespace tracked_objects |
OLD | NEW |