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

Side by Side Diff: base/profiler/stack_sampling_profiler_unittest.cc

Issue 2947023002: Clean up ifdefs in base stack sampling profiler unit test. (Closed)
Patch Set: missed some TEST_F's Created 3 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <cstdlib> 8 #include <cstdlib>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #if defined(_WIN64) || (defined(OS_MACOSX) && !defined(OS_IOS)) 44 #if defined(_WIN64) || (defined(OS_MACOSX) && !defined(OS_IOS))
45 #define STACK_SAMPLING_PROFILER_SUPPORTED 1 45 #define STACK_SAMPLING_PROFILER_SUPPORTED 1
46 #endif 46 #endif
47 47
48 #if defined(OS_WIN) 48 #if defined(OS_WIN)
49 #pragma intrinsic(_ReturnAddress) 49 #pragma intrinsic(_ReturnAddress)
50 #endif 50 #endif
51 51
52 namespace base { 52 namespace base {
53 53
54 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED)
55 #define PROFILER_TEST_F(TestClass, TestName) TEST_F(TestClass, TestName)
56 #else
57 #define PROFILER_TEST_F(TestClass, TestName) \
58 TEST_F(TestClass, DISABLED_##TestName)
59 #endif
60
54 using SamplingParams = StackSamplingProfiler::SamplingParams; 61 using SamplingParams = StackSamplingProfiler::SamplingParams;
55 using Frame = StackSamplingProfiler::Frame; 62 using Frame = StackSamplingProfiler::Frame;
56 using Frames = std::vector<StackSamplingProfiler::Frame>; 63 using Frames = std::vector<StackSamplingProfiler::Frame>;
57 using Module = StackSamplingProfiler::Module; 64 using Module = StackSamplingProfiler::Module;
58 using Sample = StackSamplingProfiler::Sample; 65 using Sample = StackSamplingProfiler::Sample;
59 using CallStackProfile = StackSamplingProfiler::CallStackProfile; 66 using CallStackProfile = StackSamplingProfiler::CallStackProfile;
60 using CallStackProfiles = StackSamplingProfiler::CallStackProfiles; 67 using CallStackProfiles = StackSamplingProfiler::CallStackProfiles;
61 68
62 namespace { 69 namespace {
63 70
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 // idle-shutdown behavior. 651 // idle-shutdown behavior.
645 StackSamplingProfiler::TestAPI::Reset(); 652 StackSamplingProfiler::TestAPI::Reset();
646 } 653 }
647 }; 654 };
648 655
649 } // namespace 656 } // namespace
650 657
651 // Checks that the basic expected information is present in a sampled call stack 658 // Checks that the basic expected information is present in a sampled call stack
652 // profile. 659 // profile.
653 // macOS ASAN is not yet supported - crbug.com/718628. 660 // macOS ASAN is not yet supported - crbug.com/718628.
654 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) && \ 661 #if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
655 !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
656 #define MAYBE_Basic Basic 662 #define MAYBE_Basic Basic
657 #else 663 #else
658 #define MAYBE_Basic DISABLED_Basic 664 #define MAYBE_Basic DISABLED_Basic
659 #endif 665 #endif
660 TEST_F(StackSamplingProfilerTest, MAYBE_Basic) { 666 PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_Basic) {
661 SamplingParams params; 667 SamplingParams params;
662 params.sampling_interval = TimeDelta::FromMilliseconds(0); 668 params.sampling_interval = TimeDelta::FromMilliseconds(0);
663 params.samples_per_burst = 1; 669 params.samples_per_burst = 1;
664 670
665 std::vector<CallStackProfile> profiles; 671 std::vector<CallStackProfile> profiles;
666 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); 672 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles);
667 673
668 // Check that the profile and samples sizes are correct, and the module 674 // Check that the profile and samples sizes are correct, and the module
669 // indices are in range. 675 // indices are in range.
670 ASSERT_EQ(1u, profiles.size()); 676 ASSERT_EQ(1u, profiles.size());
(...skipping 18 matching lines...) Expand all
689 &TargetThread::SignalAndWaitUntilSignaled)) 695 &TargetThread::SignalAndWaitUntilSignaled))
690 << " was not found in stack:\n" 696 << " was not found in stack:\n"
691 << FormatSampleForDiagnosticOutput(sample, profile.modules); 697 << FormatSampleForDiagnosticOutput(sample, profile.modules);
692 FilePath executable_path; 698 FilePath executable_path;
693 EXPECT_TRUE(PathService::Get(FILE_EXE, &executable_path)); 699 EXPECT_TRUE(PathService::Get(FILE_EXE, &executable_path));
694 EXPECT_EQ(executable_path, 700 EXPECT_EQ(executable_path,
695 MakeAbsoluteFilePath(profile.modules[loc->module_index].filename)); 701 MakeAbsoluteFilePath(profile.modules[loc->module_index].filename));
696 } 702 }
697 703
698 // Checks that annotations are recorded in samples. 704 // Checks that annotations are recorded in samples.
699 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 705 PROFILER_TEST_F(StackSamplingProfilerTest, Annotations) {
700 #define MAYBE_Annotations Annotations
701 #else
702 #define MAYBE_Annotations DISABLED_Annotations
703 #endif
704 TEST_F(StackSamplingProfilerTest, MAYBE_Annotations) {
705 SamplingParams params; 706 SamplingParams params;
706 params.sampling_interval = TimeDelta::FromMilliseconds(0); 707 params.sampling_interval = TimeDelta::FromMilliseconds(0);
707 params.samples_per_burst = 1; 708 params.samples_per_burst = 1;
708 709
709 // Check that a run picks up annotations. 710 // Check that a run picks up annotations.
710 StackSamplingProfiler::SetProcessMilestone(1); 711 StackSamplingProfiler::SetProcessMilestone(1);
711 std::vector<CallStackProfile> profiles1; 712 std::vector<CallStackProfile> profiles1;
712 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles1); 713 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles1);
713 ASSERT_EQ(1u, profiles1.size()); 714 ASSERT_EQ(1u, profiles1.size());
714 const CallStackProfile& profile1 = profiles1[0]; 715 const CallStackProfile& profile1 = profiles1[0];
715 ASSERT_EQ(1u, profile1.samples.size()); 716 ASSERT_EQ(1u, profile1.samples.size());
716 const Sample& sample1 = profile1.samples[0]; 717 const Sample& sample1 = profile1.samples[0];
717 EXPECT_EQ(1u << 1, sample1.process_milestones); 718 EXPECT_EQ(1u << 1, sample1.process_milestones);
718 719
719 // Run it a second time but with changed annotations. These annotations 720 // Run it a second time but with changed annotations. These annotations
720 // should appear in the first acquired sample. 721 // should appear in the first acquired sample.
721 StackSamplingProfiler::SetProcessMilestone(2); 722 StackSamplingProfiler::SetProcessMilestone(2);
722 std::vector<CallStackProfile> profiles2; 723 std::vector<CallStackProfile> profiles2;
723 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles2); 724 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles2);
724 ASSERT_EQ(1u, profiles2.size()); 725 ASSERT_EQ(1u, profiles2.size());
725 const CallStackProfile& profile2 = profiles2[0]; 726 const CallStackProfile& profile2 = profiles2[0];
726 ASSERT_EQ(1u, profile2.samples.size()); 727 ASSERT_EQ(1u, profile2.samples.size());
727 const Sample& sample2 = profile2.samples[0]; 728 const Sample& sample2 = profile2.samples[0];
728 EXPECT_EQ(sample1.process_milestones | (1u << 2), sample2.process_milestones); 729 EXPECT_EQ(sample1.process_milestones | (1u << 2), sample2.process_milestones);
729 } 730 }
730 731
731 // Checks that the profiler handles stacks containing dynamically-allocated 732 // Checks that the profiler handles stacks containing dynamically-allocated
732 // stack memory. 733 // stack memory.
733 // macOS ASAN is not yet supported - crbug.com/718628. 734 // macOS ASAN is not yet supported - crbug.com/718628.
734 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) && \ 735 #if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
735 !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
736 #define MAYBE_Alloca Alloca 736 #define MAYBE_Alloca Alloca
737 #else 737 #else
738 #define MAYBE_Alloca DISABLED_Alloca 738 #define MAYBE_Alloca DISABLED_Alloca
739 #endif 739 #endif
740 TEST_F(StackSamplingProfilerTest, MAYBE_Alloca) { 740 PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_Alloca) {
741 SamplingParams params; 741 SamplingParams params;
742 params.sampling_interval = TimeDelta::FromMilliseconds(0); 742 params.sampling_interval = TimeDelta::FromMilliseconds(0);
743 params.samples_per_burst = 1; 743 params.samples_per_burst = 1;
744 744
745 std::vector<CallStackProfile> profiles; 745 std::vector<CallStackProfile> profiles;
746 WithTargetThread( 746 WithTargetThread(
747 [&params, &profiles](PlatformThreadId target_thread_id) { 747 [&params, &profiles](PlatformThreadId target_thread_id) {
748 WaitableEvent sampling_thread_completed( 748 WaitableEvent sampling_thread_completed(
749 WaitableEvent::ResetPolicy::MANUAL, 749 WaitableEvent::ResetPolicy::MANUAL,
750 WaitableEvent::InitialState::NOT_SIGNALED); 750 WaitableEvent::InitialState::NOT_SIGNALED);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 << FormatSampleForDiagnosticOutput(sample, profile.modules); 785 << FormatSampleForDiagnosticOutput(sample, profile.modules);
786 786
787 // These frames should be adjacent on the stack. 787 // These frames should be adjacent on the stack.
788 EXPECT_EQ(1, alloca_frame - end_frame) 788 EXPECT_EQ(1, alloca_frame - end_frame)
789 << "Stack:\n" 789 << "Stack:\n"
790 << FormatSampleForDiagnosticOutput(sample, profile.modules); 790 << FormatSampleForDiagnosticOutput(sample, profile.modules);
791 } 791 }
792 792
793 // Checks that the expected number of profiles and samples are present in the 793 // Checks that the expected number of profiles and samples are present in the
794 // call stack profiles produced. 794 // call stack profiles produced.
795 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 795 PROFILER_TEST_F(StackSamplingProfilerTest, MultipleProfilesAndSamples) {
796 #define MAYBE_MultipleProfilesAndSamples MultipleProfilesAndSamples
797 #else
798 #define MAYBE_MultipleProfilesAndSamples DISABLED_MultipleProfilesAndSamples
799 #endif
800 TEST_F(StackSamplingProfilerTest, MAYBE_MultipleProfilesAndSamples) {
801 SamplingParams params; 796 SamplingParams params;
802 params.burst_interval = params.sampling_interval = 797 params.burst_interval = params.sampling_interval =
803 TimeDelta::FromMilliseconds(0); 798 TimeDelta::FromMilliseconds(0);
804 params.bursts = 2; 799 params.bursts = 2;
805 params.samples_per_burst = 3; 800 params.samples_per_burst = 3;
806 801
807 std::vector<CallStackProfile> profiles; 802 std::vector<CallStackProfile> profiles;
808 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); 803 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles);
809 804
810 ASSERT_EQ(2u, profiles.size()); 805 ASSERT_EQ(2u, profiles.size());
811 EXPECT_EQ(3u, profiles[0].samples.size()); 806 EXPECT_EQ(3u, profiles[0].samples.size());
812 EXPECT_EQ(3u, profiles[1].samples.size()); 807 EXPECT_EQ(3u, profiles[1].samples.size());
813 } 808 }
814 809
815 // Checks that a profiler can stop/destruct without ever having started. 810 // Checks that a profiler can stop/destruct without ever having started.
816 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 811 PROFILER_TEST_F(StackSamplingProfilerTest, StopWithoutStarting) {
817 #define MAYBE_StopWithoutStarting StopWithoutStarting
818 #else
819 #define MAYBE_StopWithoutStarting DISABLED_StopWithoutStarting
820 #endif
821 TEST_F(StackSamplingProfilerTest, MAYBE_StopWithoutStarting) {
822 WithTargetThread([](PlatformThreadId target_thread_id) { 812 WithTargetThread([](PlatformThreadId target_thread_id) {
823 SamplingParams params; 813 SamplingParams params;
824 params.sampling_interval = TimeDelta::FromMilliseconds(0); 814 params.sampling_interval = TimeDelta::FromMilliseconds(0);
825 params.samples_per_burst = 1; 815 params.samples_per_burst = 1;
826 816
827 CallStackProfiles profiles; 817 CallStackProfiles profiles;
828 WaitableEvent sampling_completed(WaitableEvent::ResetPolicy::MANUAL, 818 WaitableEvent sampling_completed(WaitableEvent::ResetPolicy::MANUAL,
829 WaitableEvent::InitialState::NOT_SIGNALED); 819 WaitableEvent::InitialState::NOT_SIGNALED);
830 const StackSamplingProfiler::CompletedCallback callback = 820 const StackSamplingProfiler::CompletedCallback callback =
831 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles), 821 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles),
832 Unretained(&sampling_completed)); 822 Unretained(&sampling_completed));
833 StackSamplingProfiler profiler(target_thread_id, params, callback); 823 StackSamplingProfiler profiler(target_thread_id, params, callback);
834 824
835 profiler.Stop(); // Constructed but never started. 825 profiler.Stop(); // Constructed but never started.
836 EXPECT_FALSE(sampling_completed.IsSignaled()); 826 EXPECT_FALSE(sampling_completed.IsSignaled());
837 }); 827 });
838 } 828 }
839 829
840 // Checks that its okay to stop a profiler before it finishes even when the 830 // Checks that its okay to stop a profiler before it finishes even when the
841 // sampling thread continues to run. 831 // sampling thread continues to run.
842 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 832 PROFILER_TEST_F(StackSamplingProfilerTest, StopSafely) {
843 #define MAYBE_StopSafely StopSafely
844 #else
845 #define MAYBE_StopSafely DISABLED_StopSafely
846 #endif
847 TEST_F(StackSamplingProfilerTest, MAYBE_StopSafely) {
848 // Test delegate that counts samples. 833 // Test delegate that counts samples.
849 class SampleRecordedCounter : public NativeStackSamplerTestDelegate { 834 class SampleRecordedCounter : public NativeStackSamplerTestDelegate {
850 public: 835 public:
851 SampleRecordedCounter() {} 836 SampleRecordedCounter() {}
852 837
853 void OnPreStackWalk() override { 838 void OnPreStackWalk() override {
854 AutoLock lock(lock_); 839 AutoLock lock(lock_);
855 ++count_; 840 ++count_;
856 } 841 }
857 842
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 while (samples_recorded[1].Get() < count1 + 2) 897 while (samples_recorded[1].Get() < count1 + 2)
913 PlatformThread::Sleep(TimeDelta::FromMilliseconds(1)); 898 PlatformThread::Sleep(TimeDelta::FromMilliseconds(1));
914 899
915 // Ensure that the first profiler didn't do anything since it was stopped. 900 // Ensure that the first profiler didn't do anything since it was stopped.
916 EXPECT_EQ(count0, samples_recorded[0].Get()); 901 EXPECT_EQ(count0, samples_recorded[0].Get());
917 }); 902 });
918 } 903 }
919 904
920 // Checks that no call stack profiles are captured if the profiling is stopped 905 // Checks that no call stack profiles are captured if the profiling is stopped
921 // during the initial delay. 906 // during the initial delay.
922 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 907 PROFILER_TEST_F(StackSamplingProfilerTest, StopDuringInitialDelay) {
923 #define MAYBE_StopDuringInitialDelay StopDuringInitialDelay
924 #else
925 #define MAYBE_StopDuringInitialDelay DISABLED_StopDuringInitialDelay
926 #endif
927 TEST_F(StackSamplingProfilerTest, MAYBE_StopDuringInitialDelay) {
928 SamplingParams params; 908 SamplingParams params;
929 params.initial_delay = TimeDelta::FromSeconds(60); 909 params.initial_delay = TimeDelta::FromSeconds(60);
930 910
931 std::vector<CallStackProfile> profiles; 911 std::vector<CallStackProfile> profiles;
932 CaptureProfiles(params, TimeDelta::FromMilliseconds(0), &profiles); 912 CaptureProfiles(params, TimeDelta::FromMilliseconds(0), &profiles);
933 913
934 EXPECT_TRUE(profiles.empty()); 914 EXPECT_TRUE(profiles.empty());
935 } 915 }
936 916
937 // Checks that the single completed call stack profile is captured if the 917 // Checks that the single completed call stack profile is captured if the
938 // profiling is stopped between bursts. 918 // profiling is stopped between bursts.
939 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 919 PROFILER_TEST_F(StackSamplingProfilerTest, StopDuringInterBurstInterval) {
940 #define MAYBE_StopDuringInterBurstInterval StopDuringInterBurstInterval
941 #else
942 #define MAYBE_StopDuringInterBurstInterval DISABLED_StopDuringInterBurstInterval
943 #endif
944 TEST_F(StackSamplingProfilerTest, MAYBE_StopDuringInterBurstInterval) {
945 SamplingParams params; 920 SamplingParams params;
946 params.sampling_interval = TimeDelta::FromMilliseconds(0); 921 params.sampling_interval = TimeDelta::FromMilliseconds(0);
947 params.burst_interval = TimeDelta::FromSeconds(60); 922 params.burst_interval = TimeDelta::FromSeconds(60);
948 params.bursts = 2; 923 params.bursts = 2;
949 params.samples_per_burst = 1; 924 params.samples_per_burst = 1;
950 925
951 std::vector<CallStackProfile> profiles; 926 std::vector<CallStackProfile> profiles;
952 CaptureProfiles(params, TimeDelta::FromMilliseconds(50), &profiles); 927 CaptureProfiles(params, TimeDelta::FromMilliseconds(50), &profiles);
953 928
954 ASSERT_EQ(1u, profiles.size()); 929 ASSERT_EQ(1u, profiles.size());
955 EXPECT_EQ(1u, profiles[0].samples.size()); 930 EXPECT_EQ(1u, profiles[0].samples.size());
956 } 931 }
957 932
958 // Checks that tasks can be stopped before completion and incomplete call stack 933 // Checks that tasks can be stopped before completion and incomplete call stack
959 // profiles are captured. 934 // profiles are captured.
960 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 935 PROFILER_TEST_F(StackSamplingProfilerTest, StopDuringInterSampleInterval) {
961 #define MAYBE_StopDuringInterSampleInterval StopDuringInterSampleInterval
962 #else
963 #define MAYBE_StopDuringInterSampleInterval \
964 DISABLED_StopDuringInterSampleInterval
965 #endif
966 TEST_F(StackSamplingProfilerTest, MAYBE_StopDuringInterSampleInterval) {
967 // Test delegate that counts samples. 936 // Test delegate that counts samples.
968 class SampleRecordedEvent : public NativeStackSamplerTestDelegate { 937 class SampleRecordedEvent : public NativeStackSamplerTestDelegate {
969 public: 938 public:
970 SampleRecordedEvent() 939 SampleRecordedEvent()
971 : sample_recorded_(WaitableEvent::ResetPolicy::MANUAL, 940 : sample_recorded_(WaitableEvent::ResetPolicy::MANUAL,
972 WaitableEvent::InitialState::NOT_SIGNALED) {} 941 WaitableEvent::InitialState::NOT_SIGNALED) {}
973 942
974 void OnPreStackWalk() override { sample_recorded_.Signal(); } 943 void OnPreStackWalk() override { sample_recorded_.Signal(); }
975 944
976 void WaitForSample() { sample_recorded_.Wait(); } 945 void WaitForSample() { sample_recorded_.Wait(); }
(...skipping 19 matching lines...) Expand all
996 // Ensure that it can stop safely. 965 // Ensure that it can stop safely.
997 profiler_info.profiler.Stop(); 966 profiler_info.profiler.Stop();
998 profiler_info.completed.Wait(); 967 profiler_info.completed.Wait();
999 968
1000 ASSERT_EQ(1u, profiler_info.profiles.size()); 969 ASSERT_EQ(1u, profiler_info.profiles.size());
1001 EXPECT_EQ(1u, profiler_info.profiles[0].samples.size()); 970 EXPECT_EQ(1u, profiler_info.profiles[0].samples.size());
1002 }); 971 });
1003 } 972 }
1004 973
1005 // Checks that we can destroy the profiler while profiling. 974 // Checks that we can destroy the profiler while profiling.
1006 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 975 PROFILER_TEST_F(StackSamplingProfilerTest, DestroyProfilerWhileProfiling) {
1007 #define MAYBE_DestroyProfilerWhileProfiling DestroyProfilerWhileProfiling
1008 #else
1009 #define MAYBE_DestroyProfilerWhileProfiling \
1010 DISABLED_DestroyProfilerWhileProfiling
1011 #endif
1012 TEST_F(StackSamplingProfilerTest, MAYBE_DestroyProfilerWhileProfiling) {
1013 SamplingParams params; 976 SamplingParams params;
1014 params.sampling_interval = TimeDelta::FromMilliseconds(10); 977 params.sampling_interval = TimeDelta::FromMilliseconds(10);
1015 978
1016 CallStackProfiles profiles; 979 CallStackProfiles profiles;
1017 WithTargetThread([&params, &profiles](PlatformThreadId target_thread_id) { 980 WithTargetThread([&params, &profiles](PlatformThreadId target_thread_id) {
1018 std::unique_ptr<StackSamplingProfiler> profiler; 981 std::unique_ptr<StackSamplingProfiler> profiler;
1019 profiler.reset(new StackSamplingProfiler( 982 profiler.reset(new StackSamplingProfiler(
1020 target_thread_id, params, Bind(&SaveProfiles, Unretained(&profiles)))); 983 target_thread_id, params, Bind(&SaveProfiles, Unretained(&profiles))));
1021 profiler->Start(); 984 profiler->Start();
1022 profiler.reset(); 985 profiler.reset();
1023 986
1024 // Wait longer than a sample interval to catch any use-after-free actions by 987 // Wait longer than a sample interval to catch any use-after-free actions by
1025 // the profiler thread. 988 // the profiler thread.
1026 PlatformThread::Sleep(TimeDelta::FromMilliseconds(50)); 989 PlatformThread::Sleep(TimeDelta::FromMilliseconds(50));
1027 }); 990 });
1028 } 991 }
1029 992
1030 // Checks that the same profiler may be run multiple times. 993 // Checks that the same profiler may be run multiple times.
1031 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 994 PROFILER_TEST_F(StackSamplingProfilerTest, CanRunMultipleTimes) {
1032 #define MAYBE_CanRunMultipleTimes CanRunMultipleTimes
1033 #else
1034 #define MAYBE_CanRunMultipleTimes DISABLED_CanRunMultipleTimes
1035 #endif
1036 TEST_F(StackSamplingProfilerTest, MAYBE_CanRunMultipleTimes) {
1037 WithTargetThread([](PlatformThreadId target_thread_id) { 995 WithTargetThread([](PlatformThreadId target_thread_id) {
1038 SamplingParams params; 996 SamplingParams params;
1039 params.sampling_interval = TimeDelta::FromMilliseconds(0); 997 params.sampling_interval = TimeDelta::FromMilliseconds(0);
1040 params.samples_per_burst = 1; 998 params.samples_per_burst = 1;
1041 999
1042 CallStackProfiles profiles; 1000 CallStackProfiles profiles;
1043 WaitableEvent sampling_completed(WaitableEvent::ResetPolicy::MANUAL, 1001 WaitableEvent sampling_completed(WaitableEvent::ResetPolicy::MANUAL,
1044 WaitableEvent::InitialState::NOT_SIGNALED); 1002 WaitableEvent::InitialState::NOT_SIGNALED);
1045 const StackSamplingProfiler::CompletedCallback callback = 1003 const StackSamplingProfiler::CompletedCallback callback =
1046 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles), 1004 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles),
1047 Unretained(&sampling_completed)); 1005 Unretained(&sampling_completed));
1048 StackSamplingProfiler profiler(target_thread_id, params, callback); 1006 StackSamplingProfiler profiler(target_thread_id, params, callback);
1049 1007
1050 // Just start and stop to execute code paths. 1008 // Just start and stop to execute code paths.
1051 profiler.Start(); 1009 profiler.Start();
1052 profiler.Stop(); 1010 profiler.Stop();
1053 sampling_completed.Wait(); 1011 sampling_completed.Wait();
1054 1012
1055 // Ensure a second request will run and not block. 1013 // Ensure a second request will run and not block.
1056 sampling_completed.Reset(); 1014 sampling_completed.Reset();
1057 profiles.clear(); 1015 profiles.clear();
1058 profiler.Start(); 1016 profiler.Start();
1059 sampling_completed.Wait(); 1017 sampling_completed.Wait();
1060 profiler.Stop(); 1018 profiler.Stop();
1061 ASSERT_EQ(1u, profiles.size()); 1019 ASSERT_EQ(1u, profiles.size());
1062 }); 1020 });
1063 } 1021 }
1064 1022
1065 // Checks that the different profilers may be run. 1023 // Checks that the different profilers may be run.
1066 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1024 PROFILER_TEST_F(StackSamplingProfilerTest, CanRunMultipleProfilers) {
1067 #define MAYBE_CanRunMultipleProfilers CanRunMultipleProfilers
1068 #else
1069 #define MAYBE_CanRunMultipleProfilers DISABLED_CanRunMultipleProfilers
1070 #endif
1071 TEST_F(StackSamplingProfilerTest, MAYBE_CanRunMultipleProfilers) {
1072 SamplingParams params; 1025 SamplingParams params;
1073 params.sampling_interval = TimeDelta::FromMilliseconds(0); 1026 params.sampling_interval = TimeDelta::FromMilliseconds(0);
1074 params.samples_per_burst = 1; 1027 params.samples_per_burst = 1;
1075 1028
1076 std::vector<CallStackProfile> profiles; 1029 std::vector<CallStackProfile> profiles;
1077 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); 1030 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles);
1078 ASSERT_EQ(1u, profiles.size()); 1031 ASSERT_EQ(1u, profiles.size());
1079 1032
1080 profiles.clear(); 1033 profiles.clear();
1081 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); 1034 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles);
1082 ASSERT_EQ(1u, profiles.size()); 1035 ASSERT_EQ(1u, profiles.size());
1083 } 1036 }
1084 1037
1085 // Checks that a sampler can be started while another is running. 1038 // Checks that a sampler can be started while another is running.
1086 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1039 PROFILER_TEST_F(StackSamplingProfilerTest, MultipleStart) {
1087 #define MAYBE_MultipleStart MultipleStart
1088 #else
1089 #define MAYBE_MultipleStart DISABLED_MultipleStart
1090 #endif
1091 TEST_F(StackSamplingProfilerTest, MAYBE_MultipleStart) {
1092 WithTargetThread([](PlatformThreadId target_thread_id) { 1040 WithTargetThread([](PlatformThreadId target_thread_id) {
1093 std::vector<SamplingParams> params(2); 1041 std::vector<SamplingParams> params(2);
1094 1042
1095 params[0].initial_delay = AVeryLongTimeDelta(); 1043 params[0].initial_delay = AVeryLongTimeDelta();
1096 params[0].samples_per_burst = 1; 1044 params[0].samples_per_burst = 1;
1097 1045
1098 params[1].sampling_interval = TimeDelta::FromMilliseconds(1); 1046 params[1].sampling_interval = TimeDelta::FromMilliseconds(1);
1099 params[1].samples_per_burst = 1; 1047 params[1].samples_per_burst = 1;
1100 1048
1101 std::vector<std::unique_ptr<TestProfilerInfo>> profiler_infos = 1049 std::vector<std::unique_ptr<TestProfilerInfo>> profiler_infos =
1102 CreateProfilers(target_thread_id, params); 1050 CreateProfilers(target_thread_id, params);
1103 1051
1104 profiler_infos[0]->profiler.Start(); 1052 profiler_infos[0]->profiler.Start();
1105 profiler_infos[1]->profiler.Start(); 1053 profiler_infos[1]->profiler.Start();
1106 profiler_infos[1]->completed.Wait(); 1054 profiler_infos[1]->completed.Wait();
1107 EXPECT_EQ(1u, profiler_infos[1]->profiles.size()); 1055 EXPECT_EQ(1u, profiler_infos[1]->profiles.size());
1108 }); 1056 });
1109 } 1057 }
1110 1058
1111 // Checks that the sampling thread can shut down. 1059 // Checks that the sampling thread can shut down.
1112 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1060 PROFILER_TEST_F(StackSamplingProfilerTest, SamplerIdleShutdown) {
1113 #define MAYBE_SamplerIdleShutdown SamplerIdleShutdown
1114 #else
1115 #define MAYBE_SamplerIdleShutdown DISABLED_SamplerIdleShutdown
1116 #endif
1117 TEST_F(StackSamplingProfilerTest, MAYBE_SamplerIdleShutdown) {
1118 SamplingParams params; 1061 SamplingParams params;
1119 params.sampling_interval = TimeDelta::FromMilliseconds(0); 1062 params.sampling_interval = TimeDelta::FromMilliseconds(0);
1120 params.samples_per_burst = 1; 1063 params.samples_per_burst = 1;
1121 1064
1122 std::vector<CallStackProfile> profiles; 1065 std::vector<CallStackProfile> profiles;
1123 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); 1066 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles);
1124 ASSERT_EQ(1u, profiles.size()); 1067 ASSERT_EQ(1u, profiles.size());
1125 1068
1126 // Capture thread should still be running at this point. 1069 // Capture thread should still be running at this point.
1127 ASSERT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); 1070 ASSERT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning());
1128 1071
1129 // Initiate an "idle" shutdown and ensure it happens. Idle-shutdown was 1072 // Initiate an "idle" shutdown and ensure it happens. Idle-shutdown was
1130 // disabled by the test fixture so the test will fail due to a timeout if 1073 // disabled by the test fixture so the test will fail due to a timeout if
1131 // it does not exit. 1074 // it does not exit.
1132 StackSamplingProfiler::TestAPI::PerformSamplingThreadIdleShutdown(false); 1075 StackSamplingProfiler::TestAPI::PerformSamplingThreadIdleShutdown(false);
1133 1076
1134 // While the shutdown has been initiated, the actual exit of the thread still 1077 // While the shutdown has been initiated, the actual exit of the thread still
1135 // happens asynchronously. Watch until the thread actually exits. This test 1078 // happens asynchronously. Watch until the thread actually exits. This test
1136 // will time-out in the case of failure. 1079 // will time-out in the case of failure.
1137 while (StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()) 1080 while (StackSamplingProfiler::TestAPI::IsSamplingThreadRunning())
1138 PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 1081 PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
1139 } 1082 }
1140 1083
1141 // Checks that additional requests will restart a stopped profiler. 1084 // Checks that additional requests will restart a stopped profiler.
1142 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1085 PROFILER_TEST_F(StackSamplingProfilerTest,
1143 #define MAYBE_WillRestartSamplerAfterIdleShutdown \ 1086 WillRestartSamplerAfterIdleShutdown) {
1144 WillRestartSamplerAfterIdleShutdown
1145 #else
1146 #define MAYBE_WillRestartSamplerAfterIdleShutdown \
1147 DISABLED_WillRestartSamplerAfterIdleShutdown
1148 #endif
1149 TEST_F(StackSamplingProfilerTest, MAYBE_WillRestartSamplerAfterIdleShutdown) {
1150 SamplingParams params; 1087 SamplingParams params;
1151 params.sampling_interval = TimeDelta::FromMilliseconds(0); 1088 params.sampling_interval = TimeDelta::FromMilliseconds(0);
1152 params.samples_per_burst = 1; 1089 params.samples_per_burst = 1;
1153 1090
1154 std::vector<CallStackProfile> profiles; 1091 std::vector<CallStackProfile> profiles;
1155 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); 1092 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles);
1156 ASSERT_EQ(1u, profiles.size()); 1093 ASSERT_EQ(1u, profiles.size());
1157 1094
1158 // Capture thread should still be running at this point. 1095 // Capture thread should still be running at this point.
1159 ASSERT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); 1096 ASSERT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning());
1160 1097
1161 // Post a ShutdownTask on the sampling thread which, when executed, will 1098 // Post a ShutdownTask on the sampling thread which, when executed, will
1162 // mark the thread as EXITING and begin shut down of the thread. 1099 // mark the thread as EXITING and begin shut down of the thread.
1163 StackSamplingProfiler::TestAPI::PerformSamplingThreadIdleShutdown(false); 1100 StackSamplingProfiler::TestAPI::PerformSamplingThreadIdleShutdown(false);
1164 1101
1165 // Ensure another capture will start the sampling thread and run. 1102 // Ensure another capture will start the sampling thread and run.
1166 profiles.clear(); 1103 profiles.clear();
1167 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); 1104 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles);
1168 ASSERT_EQ(1u, profiles.size()); 1105 ASSERT_EQ(1u, profiles.size());
1169 EXPECT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); 1106 EXPECT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning());
1170 } 1107 }
1171 1108
1172 // Checks that it's safe to stop a task after it's completed and the sampling 1109 // Checks that it's safe to stop a task after it's completed and the sampling
1173 // thread has shut-down for being idle. 1110 // thread has shut-down for being idle.
1174 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1111 PROFILER_TEST_F(StackSamplingProfilerTest, StopAfterIdleShutdown) {
1175 #define MAYBE_StopAfterIdleShutdown StopAfterIdleShutdown
1176 #else
1177 #define MAYBE_StopAfterIdleShutdown DISABLED_StopAfterIdleShutdown
1178 #endif
1179 TEST_F(StackSamplingProfilerTest, MAYBE_StopAfterIdleShutdown) {
1180 WithTargetThread([](PlatformThreadId target_thread_id) { 1112 WithTargetThread([](PlatformThreadId target_thread_id) {
1181 SamplingParams params; 1113 SamplingParams params;
1182 1114
1183 params.sampling_interval = TimeDelta::FromMilliseconds(1); 1115 params.sampling_interval = TimeDelta::FromMilliseconds(1);
1184 params.samples_per_burst = 1; 1116 params.samples_per_burst = 1;
1185 1117
1186 TestProfilerInfo profiler_info(target_thread_id, params); 1118 TestProfilerInfo profiler_info(target_thread_id, params);
1187 1119
1188 profiler_info.profiler.Start(); 1120 profiler_info.profiler.Start();
1189 profiler_info.completed.Wait(); 1121 profiler_info.completed.Wait();
1190 1122
1191 // Capture thread should still be running at this point. 1123 // Capture thread should still be running at this point.
1192 ASSERT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); 1124 ASSERT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning());
1193 1125
1194 // Perform an idle shutdown. 1126 // Perform an idle shutdown.
1195 StackSamplingProfiler::TestAPI::PerformSamplingThreadIdleShutdown(false); 1127 StackSamplingProfiler::TestAPI::PerformSamplingThreadIdleShutdown(false);
1196 1128
1197 // Stop should be safe though its impossible to know at this moment if the 1129 // Stop should be safe though its impossible to know at this moment if the
1198 // sampling thread has completely exited or will just "stop soon". 1130 // sampling thread has completely exited or will just "stop soon".
1199 profiler_info.profiler.Stop(); 1131 profiler_info.profiler.Stop();
1200 }); 1132 });
1201 } 1133 }
1202 1134
1203 // Checks that profilers can run both before and after the sampling thread has 1135 // Checks that profilers can run both before and after the sampling thread has
1204 // started. 1136 // started.
1205 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1137 PROFILER_TEST_F(StackSamplingProfilerTest,
1206 #define MAYBE_ProfileBeforeAndAfterSamplingThreadRunning \ 1138 ProfileBeforeAndAfterSamplingThreadRunning) {
1207 ProfileBeforeAndAfterSamplingThreadRunning
1208 #else
1209 #define MAYBE_ProfileBeforeAndAfterSamplingThreadRunning \
1210 DISABLED_ProfileBeforeAndAfterSamplingThreadRunning
1211 #endif
1212 TEST_F(StackSamplingProfilerTest,
1213 MAYBE_ProfileBeforeAndAfterSamplingThreadRunning) {
1214 WithTargetThread([](PlatformThreadId target_thread_id) { 1139 WithTargetThread([](PlatformThreadId target_thread_id) {
1215 std::vector<SamplingParams> params(2); 1140 std::vector<SamplingParams> params(2);
1216 1141
1217 params[0].initial_delay = AVeryLongTimeDelta(); 1142 params[0].initial_delay = AVeryLongTimeDelta();
1218 params[0].sampling_interval = TimeDelta::FromMilliseconds(1); 1143 params[0].sampling_interval = TimeDelta::FromMilliseconds(1);
1219 params[0].samples_per_burst = 1; 1144 params[0].samples_per_burst = 1;
1220 1145
1221 params[1].initial_delay = TimeDelta::FromMilliseconds(0); 1146 params[1].initial_delay = TimeDelta::FromMilliseconds(0);
1222 params[1].sampling_interval = TimeDelta::FromMilliseconds(1); 1147 params[1].sampling_interval = TimeDelta::FromMilliseconds(1);
1223 params[1].samples_per_burst = 1; 1148 params[1].samples_per_burst = 1;
1224 1149
1225 std::vector<std::unique_ptr<TestProfilerInfo>> profiler_infos = 1150 std::vector<std::unique_ptr<TestProfilerInfo>> profiler_infos =
1226 CreateProfilers(target_thread_id, params); 1151 CreateProfilers(target_thread_id, params);
1227 1152
1228 // First profiler is started when there has never been a sampling thread. 1153 // First profiler is started when there has never been a sampling thread.
1229 EXPECT_FALSE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); 1154 EXPECT_FALSE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning());
1230 profiler_infos[0]->profiler.Start(); 1155 profiler_infos[0]->profiler.Start();
1231 // Second profiler is started when sampling thread is already running. 1156 // Second profiler is started when sampling thread is already running.
1232 EXPECT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); 1157 EXPECT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning());
1233 profiler_infos[1]->profiler.Start(); 1158 profiler_infos[1]->profiler.Start();
1234 1159
1235 // Only the second profiler should finish before test times out. 1160 // Only the second profiler should finish before test times out.
1236 size_t completed_profiler = WaitForSamplingComplete(profiler_infos); 1161 size_t completed_profiler = WaitForSamplingComplete(profiler_infos);
1237 EXPECT_EQ(1U, completed_profiler); 1162 EXPECT_EQ(1U, completed_profiler);
1238 }); 1163 });
1239 } 1164 }
1240 1165
1241 // Checks that an idle-shutdown task will abort if a new profiler starts 1166 // Checks that an idle-shutdown task will abort if a new profiler starts
1242 // between when it was posted and when it runs. 1167 // between when it was posted and when it runs.
1243 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1168 PROFILER_TEST_F(StackSamplingProfilerTest, IdleShutdownAbort) {
1244 #define MAYBE_IdleShutdownAbort IdleShutdownAbort
1245 #else
1246 #define MAYBE_IdleShutdownAbort DISABLED_IdleShutdownAbort
1247 #endif
1248 TEST_F(StackSamplingProfilerTest, MAYBE_IdleShutdownAbort) {
1249 WithTargetThread([](PlatformThreadId target_thread_id) { 1169 WithTargetThread([](PlatformThreadId target_thread_id) {
1250 SamplingParams params; 1170 SamplingParams params;
1251 1171
1252 params.sampling_interval = TimeDelta::FromMilliseconds(1); 1172 params.sampling_interval = TimeDelta::FromMilliseconds(1);
1253 params.samples_per_burst = 1; 1173 params.samples_per_burst = 1;
1254 1174
1255 TestProfilerInfo profiler_info(target_thread_id, params); 1175 TestProfilerInfo profiler_info(target_thread_id, params);
1256 1176
1257 profiler_info.profiler.Start(); 1177 profiler_info.profiler.Start();
1258 profiler_info.completed.Wait(); 1178 profiler_info.completed.Wait();
(...skipping 13 matching lines...) Expand all
1272 1192
1273 // Ensure that it's still possible to run another sampler. 1193 // Ensure that it's still possible to run another sampler.
1274 TestProfilerInfo another_info(target_thread_id, params); 1194 TestProfilerInfo another_info(target_thread_id, params);
1275 another_info.profiler.Start(); 1195 another_info.profiler.Start();
1276 another_info.completed.Wait(); 1196 another_info.completed.Wait();
1277 EXPECT_EQ(1u, another_info.profiles.size()); 1197 EXPECT_EQ(1u, another_info.profiles.size());
1278 }); 1198 });
1279 } 1199 }
1280 1200
1281 // Checks that synchronized multiple sampling requests execute in parallel. 1201 // Checks that synchronized multiple sampling requests execute in parallel.
1282 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1202 PROFILER_TEST_F(StackSamplingProfilerTest, ConcurrentProfiling_InSync) {
1283 #define MAYBE_ConcurrentProfiling_InSync ConcurrentProfiling_InSync
1284 #else
1285 #define MAYBE_ConcurrentProfiling_InSync DISABLED_ConcurrentProfiling_InSync
1286 #endif
1287 TEST_F(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling_InSync) {
1288 WithTargetThread([](PlatformThreadId target_thread_id) { 1203 WithTargetThread([](PlatformThreadId target_thread_id) {
1289 std::vector<SamplingParams> params(2); 1204 std::vector<SamplingParams> params(2);
1290 1205
1291 // Providing an initial delay makes it more likely that both will be 1206 // Providing an initial delay makes it more likely that both will be
1292 // scheduled before either starts to run. Once started, samples will 1207 // scheduled before either starts to run. Once started, samples will
1293 // run ordered by their scheduled, interleaved times regardless of 1208 // run ordered by their scheduled, interleaved times regardless of
1294 // whatever interval the thread wakes up. Thus, total execution time 1209 // whatever interval the thread wakes up. Thus, total execution time
1295 // will be 10ms (delay) + 10x1ms (sampling) + 1/2 timer minimum interval. 1210 // will be 10ms (delay) + 10x1ms (sampling) + 1/2 timer minimum interval.
1296 params[0].initial_delay = TimeDelta::FromMilliseconds(10); 1211 params[0].initial_delay = TimeDelta::FromMilliseconds(10);
1297 params[0].sampling_interval = TimeDelta::FromMilliseconds(1); 1212 params[0].sampling_interval = TimeDelta::FromMilliseconds(1);
(...skipping 18 matching lines...) Expand all
1316 profiler_infos[other_profiler]->completed.Wait(); 1231 profiler_infos[other_profiler]->completed.Wait();
1317 ASSERT_EQ(1u, profiler_infos[other_profiler]->profiles.size()); 1232 ASSERT_EQ(1u, profiler_infos[other_profiler]->profiles.size());
1318 1233
1319 // Ensure each got the correct number of samples. 1234 // Ensure each got the correct number of samples.
1320 EXPECT_EQ(9u, profiler_infos[0]->profiles[0].samples.size()); 1235 EXPECT_EQ(9u, profiler_infos[0]->profiles[0].samples.size());
1321 EXPECT_EQ(8u, profiler_infos[1]->profiles[0].samples.size()); 1236 EXPECT_EQ(8u, profiler_infos[1]->profiles[0].samples.size());
1322 }); 1237 });
1323 } 1238 }
1324 1239
1325 // Checks that several mixed sampling requests execute in parallel. 1240 // Checks that several mixed sampling requests execute in parallel.
1326 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1241 PROFILER_TEST_F(StackSamplingProfilerTest, ConcurrentProfiling_Mixed) {
1327 #define MAYBE_ConcurrentProfiling_Mixed ConcurrentProfiling_Mixed
1328 #else
1329 #define MAYBE_ConcurrentProfiling_Mixed DISABLED_ConcurrentProfiling_Mixed
1330 #endif
1331 TEST_F(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling_Mixed) {
1332 WithTargetThread([](PlatformThreadId target_thread_id) { 1242 WithTargetThread([](PlatformThreadId target_thread_id) {
1333 std::vector<SamplingParams> params(3); 1243 std::vector<SamplingParams> params(3);
1334 1244
1335 params[0].initial_delay = TimeDelta::FromMilliseconds(8); 1245 params[0].initial_delay = TimeDelta::FromMilliseconds(8);
1336 params[0].sampling_interval = TimeDelta::FromMilliseconds(4); 1246 params[0].sampling_interval = TimeDelta::FromMilliseconds(4);
1337 params[0].samples_per_burst = 10; 1247 params[0].samples_per_burst = 10;
1338 1248
1339 params[1].initial_delay = TimeDelta::FromMilliseconds(9); 1249 params[1].initial_delay = TimeDelta::FromMilliseconds(9);
1340 params[1].sampling_interval = TimeDelta::FromMilliseconds(3); 1250 params[1].sampling_interval = TimeDelta::FromMilliseconds(3);
1341 params[1].samples_per_burst = 10; 1251 params[1].samples_per_burst = 10;
(...skipping 15 matching lines...) Expand all
1357 for (size_t i = 0; i < profiler_infos.size(); ++i) 1267 for (size_t i = 0; i < profiler_infos.size(); ++i)
1358 profiler_infos[i]->profiler.Stop(); 1268 profiler_infos[i]->profiler.Stop();
1359 for (size_t i = 0; i < profiler_infos.size(); ++i) 1269 for (size_t i = 0; i < profiler_infos.size(); ++i)
1360 profiler_infos[i].reset(); 1270 profiler_infos[i].reset();
1361 }); 1271 });
1362 } 1272 }
1363 1273
1364 // Checks that a stack that runs through another library produces a stack with 1274 // Checks that a stack that runs through another library produces a stack with
1365 // the expected functions. 1275 // the expected functions.
1366 // macOS ASAN is not yet supported - crbug.com/718628. 1276 // macOS ASAN is not yet supported - crbug.com/718628.
1367 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) && \ 1277 #if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
1368 !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
1369 #define MAYBE_OtherLibrary OtherLibrary 1278 #define MAYBE_OtherLibrary OtherLibrary
1370 #else 1279 #else
1371 #define MAYBE_OtherLibrary DISABLED_OtherLibrary 1280 #define MAYBE_OtherLibrary DISABLED_OtherLibrary
1372 #endif 1281 #endif
1373 TEST_F(StackSamplingProfilerTest, MAYBE_OtherLibrary) { 1282 PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_OtherLibrary) {
1374 SamplingParams params; 1283 SamplingParams params;
1375 params.sampling_interval = TimeDelta::FromMilliseconds(0); 1284 params.sampling_interval = TimeDelta::FromMilliseconds(0);
1376 params.samples_per_burst = 1; 1285 params.samples_per_burst = 1;
1377 1286
1378 std::vector<CallStackProfile> profiles; 1287 std::vector<CallStackProfile> profiles;
1379 { 1288 {
1380 ScopedNativeLibrary other_library(LoadOtherLibrary()); 1289 ScopedNativeLibrary other_library(LoadOtherLibrary());
1381 WithTargetThread( 1290 WithTargetThread(
1382 [&params, &profiles](PlatformThreadId target_thread_id) { 1291 [&params, &profiles](PlatformThreadId target_thread_id) {
1383 WaitableEvent sampling_thread_completed( 1292 WaitableEvent sampling_thread_completed(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 // TargetThread::OtherLibraryCallback 1339 // TargetThread::OtherLibraryCallback
1431 // InvokeCallbackFunction (in other library) 1340 // InvokeCallbackFunction (in other library)
1432 // TargetThread::CallThroughOtherLibrary 1341 // TargetThread::CallThroughOtherLibrary
1433 EXPECT_EQ(3, other_library_frame - end_frame) 1342 EXPECT_EQ(3, other_library_frame - end_frame)
1434 << "Stack:\n" << FormatSampleForDiagnosticOutput(sample, profile.modules); 1343 << "Stack:\n" << FormatSampleForDiagnosticOutput(sample, profile.modules);
1435 } 1344 }
1436 1345
1437 // Checks that a stack that runs through a library that is unloading produces a 1346 // Checks that a stack that runs through a library that is unloading produces a
1438 // stack, and doesn't crash. 1347 // stack, and doesn't crash.
1439 // Unloading is synchronous on the Mac, so this test is inapplicable. 1348 // Unloading is synchronous on the Mac, so this test is inapplicable.
1440 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) && !defined(OS_MACOSX) 1349 #if !defined(OS_MACOSX)
1441 #define MAYBE_UnloadingLibrary UnloadingLibrary 1350 #define MAYBE_UnloadingLibrary UnloadingLibrary
1442 #else 1351 #else
1443 #define MAYBE_UnloadingLibrary DISABLED_UnloadingLibrary 1352 #define MAYBE_UnloadingLibrary DISABLED_UnloadingLibrary
1444 #endif 1353 #endif
1445 TEST_F(StackSamplingProfilerTest, MAYBE_UnloadingLibrary) { 1354 PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_UnloadingLibrary) {
1446 TestLibraryUnload(false); 1355 TestLibraryUnload(false);
1447 } 1356 }
1448 1357
1449 // Checks that a stack that runs through a library that has been unloaded 1358 // Checks that a stack that runs through a library that has been unloaded
1450 // produces a stack, and doesn't crash. 1359 // produces a stack, and doesn't crash.
1451 // macOS ASAN is not yet supported - crbug.com/718628. 1360 // macOS ASAN is not yet supported - crbug.com/718628.
1452 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) && \ 1361 #if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
1453 !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
1454 #define MAYBE_UnloadedLibrary UnloadedLibrary 1362 #define MAYBE_UnloadedLibrary UnloadedLibrary
1455 #else 1363 #else
1456 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary 1364 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary
1457 #endif 1365 #endif
1458 TEST_F(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { 1366 PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) {
1459 TestLibraryUnload(true); 1367 TestLibraryUnload(true);
1460 } 1368 }
1461 1369
1462 // Checks that different threads can be sampled in parallel. 1370 // Checks that different threads can be sampled in parallel.
1463 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1371 PROFILER_TEST_F(StackSamplingProfilerTest, MultipleSampledThreads) {
1464 #define MAYBE_MultipleSampledThreads MultipleSampledThreads
1465 #else
1466 #define MAYBE_MultipleSampledThreads DISABLED_MultipleSampledThreads
1467 #endif
1468 TEST_F(StackSamplingProfilerTest, MAYBE_MultipleSampledThreads) {
1469 // Create target threads. The extra parethesis around the StackConfiguration 1372 // Create target threads. The extra parethesis around the StackConfiguration
1470 // call are to avoid the most-vexing-parse problem. 1373 // call are to avoid the most-vexing-parse problem.
1471 TargetThread target_thread1((StackConfiguration(StackConfiguration::NORMAL))); 1374 TargetThread target_thread1((StackConfiguration(StackConfiguration::NORMAL)));
1472 TargetThread target_thread2((StackConfiguration(StackConfiguration::NORMAL))); 1375 TargetThread target_thread2((StackConfiguration(StackConfiguration::NORMAL)));
1473 PlatformThreadHandle target_thread_handle1, target_thread_handle2; 1376 PlatformThreadHandle target_thread_handle1, target_thread_handle2;
1474 EXPECT_TRUE( 1377 EXPECT_TRUE(
1475 PlatformThread::Create(0, &target_thread1, &target_thread_handle1)); 1378 PlatformThread::Create(0, &target_thread1, &target_thread_handle1));
1476 EXPECT_TRUE( 1379 EXPECT_TRUE(
1477 PlatformThread::Create(0, &target_thread2, &target_thread_handle2)); 1380 PlatformThread::Create(0, &target_thread2, &target_thread_handle2));
1478 target_thread1.WaitForThreadStart(); 1381 target_thread1.WaitForThreadStart();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 1457
1555 private: 1458 private:
1556 WaitableEvent run_; 1459 WaitableEvent run_;
1557 1460
1558 CallStackProfiles profiles_; 1461 CallStackProfiles profiles_;
1559 WaitableEvent completed_; 1462 WaitableEvent completed_;
1560 StackSamplingProfiler profiler_; 1463 StackSamplingProfiler profiler_;
1561 }; 1464 };
1562 1465
1563 // Checks that different threads can run samplers in parallel. 1466 // Checks that different threads can run samplers in parallel.
1564 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) 1467 PROFILER_TEST_F(StackSamplingProfilerTest, MultipleProfilerThreads) {
1565 #define MAYBE_MultipleProfilerThreads MultipleProfilerThreads
1566 #else
1567 #define MAYBE_MultipleProfilerThreads DISABLED_MultipleProfilerThreads
1568 #endif
1569 TEST_F(StackSamplingProfilerTest, MAYBE_MultipleProfilerThreads) {
1570 WithTargetThread([](PlatformThreadId target_thread_id) { 1468 WithTargetThread([](PlatformThreadId target_thread_id) {
1571 // Providing an initial delay makes it more likely that both will be 1469 // Providing an initial delay makes it more likely that both will be
1572 // scheduled before either starts to run. Once started, samples will 1470 // scheduled before either starts to run. Once started, samples will
1573 // run ordered by their scheduled, interleaved times regardless of 1471 // run ordered by their scheduled, interleaved times regardless of
1574 // whatever interval the thread wakes up. 1472 // whatever interval the thread wakes up.
1575 SamplingParams params1, params2; 1473 SamplingParams params1, params2;
1576 params1.initial_delay = TimeDelta::FromMilliseconds(10); 1474 params1.initial_delay = TimeDelta::FromMilliseconds(10);
1577 params1.sampling_interval = TimeDelta::FromMilliseconds(1); 1475 params1.sampling_interval = TimeDelta::FromMilliseconds(1);
1578 params1.samples_per_burst = 9; 1476 params1.samples_per_burst = 9;
1579 params2.initial_delay = TimeDelta::FromMilliseconds(10); 1477 params2.initial_delay = TimeDelta::FromMilliseconds(10);
(...skipping 18 matching lines...) Expand all
1598 EXPECT_EQ(9u, profiler_thread1.profiles()[0].samples.size()); 1496 EXPECT_EQ(9u, profiler_thread1.profiles()[0].samples.size());
1599 ASSERT_EQ(1u, profiler_thread2.profiles().size()); 1497 ASSERT_EQ(1u, profiler_thread2.profiles().size());
1600 EXPECT_EQ(8u, profiler_thread2.profiles()[0].samples.size()); 1498 EXPECT_EQ(8u, profiler_thread2.profiles()[0].samples.size());
1601 1499
1602 profiler_thread1.Join(); 1500 profiler_thread1.Join();
1603 profiler_thread2.Join(); 1501 profiler_thread2.Join();
1604 }); 1502 });
1605 } 1503 }
1606 1504
1607 } // namespace base 1505 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698