Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 // asynchronous library loading has completed before walking the stack. If | 437 // asynchronous library loading has completed before walking the stack. If |
| 438 // false, the unloading may still be occurring during the stack walk. | 438 // false, the unloading may still be occurring during the stack walk. |
| 439 void TestLibraryUnload(bool wait_until_unloaded) { | 439 void TestLibraryUnload(bool wait_until_unloaded) { |
| 440 // Test delegate that supports intervening between the copying of the stack | 440 // Test delegate that supports intervening between the copying of the stack |
| 441 // and the walking of the stack. | 441 // and the walking of the stack. |
| 442 class StackCopiedSignaler : public NativeStackSamplerTestDelegate { | 442 class StackCopiedSignaler : public NativeStackSamplerTestDelegate { |
| 443 public: | 443 public: |
| 444 StackCopiedSignaler(WaitableEvent* stack_copied, | 444 StackCopiedSignaler(WaitableEvent* stack_copied, |
| 445 WaitableEvent* start_stack_walk, | 445 WaitableEvent* start_stack_walk, |
| 446 bool wait_to_walk_stack) | 446 bool wait_to_walk_stack) |
| 447 : stack_copied_(stack_copied), start_stack_walk_(start_stack_walk), | 447 : stack_copied_(stack_copied), |
| 448 wait_to_walk_stack_(wait_to_walk_stack) { | 448 start_stack_walk_(start_stack_walk), |
| 449 } | 449 wait_to_walk_stack_(wait_to_walk_stack) {} |
| 450 | 450 |
| 451 void OnPreStackWalk() override { | 451 void OnPreStackWalk() override { |
| 452 stack_copied_->Signal(); | 452 stack_copied_->Signal(); |
| 453 if (wait_to_walk_stack_) | 453 if (wait_to_walk_stack_) |
| 454 start_stack_walk_->Wait(); | 454 start_stack_walk_->Wait(); |
| 455 } | 455 } |
| 456 | 456 |
| 457 private: | 457 private: |
| 458 WaitableEvent* const stack_copied_; | 458 WaitableEvent* const stack_copied_; |
| 459 WaitableEvent* const start_stack_walk_; | 459 WaitableEvent* const start_stack_walk_; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 reinterpret_cast<const void*>(&TargetThread::CallWithAlloca)) | 713 reinterpret_cast<const void*>(&TargetThread::CallWithAlloca)) |
| 714 << " was not found in stack:\n" | 714 << " was not found in stack:\n" |
| 715 << FormatSampleForDiagnosticOutput(sample, profile.modules); | 715 << FormatSampleForDiagnosticOutput(sample, profile.modules); |
| 716 | 716 |
| 717 // These frames should be adjacent on the stack. | 717 // These frames should be adjacent on the stack. |
| 718 EXPECT_EQ(1, alloca_frame - end_frame) | 718 EXPECT_EQ(1, alloca_frame - end_frame) |
| 719 << "Stack:\n" | 719 << "Stack:\n" |
| 720 << FormatSampleForDiagnosticOutput(sample, profile.modules); | 720 << FormatSampleForDiagnosticOutput(sample, profile.modules); |
| 721 } | 721 } |
| 722 | 722 |
| 723 // Checks that the fire-and-forget interface works. | |
| 724 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | |
| 725 #define MAYBE_StartAndRunAsync StartAndRunAsync | |
| 726 #else | |
| 727 #define MAYBE_StartAndRunAsync DISABLED_StartAndRunAsync | |
| 728 #endif | |
| 729 TEST(StackSamplingProfilerTest, MAYBE_StartAndRunAsync) { | |
| 730 // StartAndRunAsync requires the caller to have a message loop. | |
| 731 MessageLoop message_loop; | |
| 732 | |
| 733 SamplingParams params; | |
| 734 params.samples_per_burst = 1; | |
| 735 | |
| 736 CallStackProfiles profiles; | |
| 737 WithTargetThread([¶ms, &profiles](PlatformThreadId target_thread_id) { | |
| 738 WaitableEvent sampling_thread_completed( | |
| 739 WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 740 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 741 const StackSamplingProfiler::CompletedCallback callback = | |
| 742 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles), | |
| 743 Unretained(&sampling_thread_completed)); | |
| 744 StackSamplingProfiler::StartAndRunAsync(target_thread_id, params, callback); | |
| 745 RunLoop().RunUntilIdle(); | |
| 746 sampling_thread_completed.Wait(); | |
| 747 }); | |
| 748 | |
| 749 ASSERT_EQ(1u, profiles.size()); | |
| 750 } | |
| 751 | |
| 752 // Checks that the expected number of profiles and samples are present in the | 723 // Checks that the expected number of profiles and samples are present in the |
| 753 // call stack profiles produced. | 724 // call stack profiles produced. |
| 754 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 725 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 755 #define MAYBE_MultipleProfilesAndSamples MultipleProfilesAndSamples | 726 #define MAYBE_MultipleProfilesAndSamples MultipleProfilesAndSamples |
| 756 #else | 727 #else |
| 757 #define MAYBE_MultipleProfilesAndSamples DISABLED_MultipleProfilesAndSamples | 728 #define MAYBE_MultipleProfilesAndSamples DISABLED_MultipleProfilesAndSamples |
| 758 #endif | 729 #endif |
| 759 TEST(StackSamplingProfilerTest, MAYBE_MultipleProfilesAndSamples) { | 730 TEST(StackSamplingProfilerTest, MAYBE_MultipleProfilesAndSamples) { |
| 760 SamplingParams params; | 731 SamplingParams params; |
| 761 params.burst_interval = params.sampling_interval = | 732 params.burst_interval = params.sampling_interval = |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 }); | 824 }); |
| 854 } | 825 } |
| 855 | 826 |
| 856 // Checks that the same profiler may be run multiple times. | 827 // Checks that the same profiler may be run multiple times. |
| 857 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 828 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 858 #define MAYBE_CanRunMultipleTimes CanRunMultipleTimes | 829 #define MAYBE_CanRunMultipleTimes CanRunMultipleTimes |
| 859 #else | 830 #else |
| 860 #define MAYBE_CanRunMultipleTimes DISABLED_CanRunMultipleTimes | 831 #define MAYBE_CanRunMultipleTimes DISABLED_CanRunMultipleTimes |
| 861 #endif | 832 #endif |
| 862 TEST(StackSamplingProfilerTest, MAYBE_CanRunMultipleTimes) { | 833 TEST(StackSamplingProfilerTest, MAYBE_CanRunMultipleTimes) { |
| 834 StackSamplingProfiler::TestAPI::DisableIdleShutdown(); | |
| 835 | |
| 836 WithTargetThread([](PlatformThreadId target_thread_id) { | |
| 837 SamplingParams params; | |
| 838 params.sampling_interval = TimeDelta::FromMilliseconds(0); | |
| 839 params.samples_per_burst = 1; | |
| 840 | |
| 841 CallStackProfiles profiles; | |
| 842 WaitableEvent sampling_completed(WaitableEvent::ResetPolicy::MANUAL, | |
| 843 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 844 const StackSamplingProfiler::CompletedCallback callback = | |
| 845 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles), | |
| 846 Unretained(&sampling_completed)); | |
| 847 StackSamplingProfiler profiler(target_thread_id, params, callback); | |
| 848 | |
| 849 // Just start and stop to execute code paths. | |
| 850 profiler.Start(); | |
| 851 profiler.Stop(); | |
| 852 sampling_completed.Wait(); | |
| 853 | |
| 854 // Ensure a second request will run and not block. | |
| 855 sampling_completed.Reset(); | |
| 856 profiles.clear(); | |
| 857 profiler.Start(); | |
| 858 sampling_completed.TimedWait(AVeryLongTimeDelta()); | |
| 859 profiler.Stop(); | |
| 860 sampling_completed.Wait(); | |
| 861 ASSERT_EQ(1u, profiles.size()); | |
| 862 }); | |
| 863 } | |
| 864 | |
| 865 // Checks that the different profilers may be run. | |
| 866 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | |
| 867 #define MAYBE_CanRunMultipleProfilers CanRunMultipleProfilers | |
| 868 #else | |
| 869 #define MAYBE_CanRunMultipleProfilers DISABLED_CanRunMultipleProfilers | |
| 870 #endif | |
| 871 TEST(StackSamplingProfilerTest, MAYBE_CanRunMultipleProfilers) { | |
| 872 StackSamplingProfiler::TestAPI::DisableIdleShutdown(); | |
| 873 | |
| 863 SamplingParams params; | 874 SamplingParams params; |
| 864 params.sampling_interval = TimeDelta::FromMilliseconds(0); | 875 params.sampling_interval = TimeDelta::FromMilliseconds(0); |
| 865 params.samples_per_burst = 1; | 876 params.samples_per_burst = 1; |
| 866 | 877 |
| 867 std::vector<CallStackProfile> profiles; | 878 std::vector<CallStackProfile> profiles; |
| 868 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); | 879 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); |
| 869 ASSERT_EQ(1u, profiles.size()); | 880 ASSERT_EQ(1u, profiles.size()); |
| 870 | 881 |
| 871 profiles.clear(); | 882 profiles.clear(); |
| 872 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); | 883 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); |
| 873 ASSERT_EQ(1u, profiles.size()); | 884 ASSERT_EQ(1u, profiles.size()); |
| 874 } | 885 } |
| 875 | 886 |
| 876 // Checks that requests to start profiling while another profile is taking place | 887 // Checks that additional requests will restart a stopped profiler. |
| 877 // are ignored. | |
| 878 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 888 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 879 #define MAYBE_ConcurrentProfiling ConcurrentProfiling | 889 #define MAYBE_WillRestartSampler WillRestartSampler |
| 880 #else | 890 #else |
| 881 #define MAYBE_ConcurrentProfiling DISABLED_ConcurrentProfiling | 891 #define MAYBE_WillRestartSampler DISABLED_WillRestartSampler |
| 882 #endif | 892 #endif |
| 883 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling) { | 893 TEST(StackSamplingProfilerTest, MAYBE_WillRestartSampler) { |
| 894 StackSamplingProfiler::TestAPI::DisableIdleShutdown(); | |
| 895 | |
| 896 SamplingParams params; | |
| 897 params.sampling_interval = TimeDelta::FromMilliseconds(0); | |
| 898 params.samples_per_burst = 1; | |
| 899 | |
| 900 std::vector<CallStackProfile> profiles; | |
| 901 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); | |
| 902 ASSERT_EQ(1u, profiles.size()); | |
| 903 | |
| 904 // Capture thread should still be running at this point. | |
| 905 ASSERT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); | |
| 906 | |
| 907 // Initiate an "idle" shutdown. The task will be run immediately but on | |
| 908 // another thread so wait for it to complete. | |
| 909 StackSamplingProfiler::TestAPI::InitiateSamplingThreadIdleShutdown(); | |
| 910 while (StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()) | |
| 911 PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | |
| 912 | |
| 913 // Ensure another capture will start the sampling thread and run. | |
| 914 profiles.clear(); | |
| 915 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); | |
| 916 ASSERT_EQ(1u, profiles.size()); | |
| 917 EXPECT_TRUE(StackSamplingProfiler::TestAPI::IsSamplingThreadRunning()); | |
| 918 } | |
| 919 | |
| 920 // Checks that synchronized multiple sampling requests execute in parallel. | |
| 921 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | |
| 922 #define MAYBE_ConcurrentProfiling_InSync ConcurrentProfiling_InSync | |
| 923 #else | |
| 924 #define MAYBE_ConcurrentProfiling_InSync DISABLED_ConcurrentProfiling_InSync | |
| 925 #endif | |
| 926 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling_InSync) { | |
| 884 WithTargetThread([](PlatformThreadId target_thread_id) { | 927 WithTargetThread([](PlatformThreadId target_thread_id) { |
| 885 SamplingParams params[2]; | 928 SamplingParams params[2]; |
| 886 params[0].initial_delay = TimeDelta::FromMilliseconds(10); | 929 params[0].initial_delay = TimeDelta::FromMilliseconds(10); |
|
Mike Wittman
2017/02/27 23:27:34
Do we need an initial delay for this set of params
bcwhite
2017/03/13 18:50:18
The initial delay just provides some extra time to
Mike Wittman
2017/03/14 18:57:33
Ok. Please document this within the test.
bcwhite
2017/03/16 15:56:25
Done.
| |
| 887 params[0].sampling_interval = TimeDelta::FromMilliseconds(0); | 930 params[0].sampling_interval = TimeDelta::FromMilliseconds(1); |
| 888 params[0].samples_per_burst = 1; | 931 params[0].samples_per_burst = 10; |
|
Mike Wittman
2017/02/27 23:27:35
Can we reduce this to something like 3-5 samples (
bcwhite
2017/03/13 18:50:18
The sampling will take 10ms + timer-resolution. S
Mike Wittman
2017/03/14 18:57:33
Please document this as well.
bcwhite
2017/03/16 15:56:25
Done.
Mike Wittman
2017/03/18 01:38:41
I don't see something equivalent to this in the co
bcwhite
2017/03/20 21:50:51
Done.
| |
| 889 | 932 |
| 890 params[1].sampling_interval = TimeDelta::FromMilliseconds(0); | 933 params[1].initial_delay = TimeDelta::FromMilliseconds(10); |
| 891 params[1].samples_per_burst = 1; | 934 params[1].sampling_interval = TimeDelta::FromMilliseconds(1); |
| 935 params[1].samples_per_burst = 10; | |
|
Mike Wittman
2017/02/27 23:27:34
We should make this value different than above, an
bcwhite
2017/03/13 18:50:18
Done.
| |
| 892 | 936 |
| 893 CallStackProfiles profiles[2]; | 937 CallStackProfiles profiles[2]; |
| 894 std::vector<std::unique_ptr<WaitableEvent>> sampling_completed(2); | 938 std::vector<std::unique_ptr<WaitableEvent>> sampling_completed( |
| 895 std::vector<std::unique_ptr<StackSamplingProfiler>> profiler(2); | 939 arraysize(params)); |
| 896 for (int i = 0; i < 2; ++i) { | 940 std::vector<std::unique_ptr<StackSamplingProfiler>> profiler( |
| 941 arraysize(params)); | |
| 942 for (size_t i = 0; i < arraysize(params); ++i) { | |
| 897 sampling_completed[i] = | 943 sampling_completed[i] = |
| 898 MakeUnique<WaitableEvent>(WaitableEvent::ResetPolicy::AUTOMATIC, | 944 MakeUnique<WaitableEvent>(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 899 WaitableEvent::InitialState::NOT_SIGNALED); | 945 WaitableEvent::InitialState::NOT_SIGNALED); |
| 900 const StackSamplingProfiler::CompletedCallback callback = | 946 const StackSamplingProfiler::CompletedCallback callback = |
| 901 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), | 947 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), |
| 902 Unretained(sampling_completed[i].get())); | 948 Unretained(sampling_completed[i].get())); |
| 903 profiler[i] = MakeUnique<StackSamplingProfiler>(target_thread_id, | 949 profiler[i] = MakeUnique<StackSamplingProfiler>(target_thread_id, |
| 904 params[i], callback); | 950 params[i], callback); |
| 905 } | 951 } |
| 906 | 952 |
| 907 profiler[0]->Start(); | 953 profiler[0]->Start(); |
| 908 profiler[1]->Start(); | 954 profiler[1]->Start(); |
| 909 | 955 |
| 910 std::vector<WaitableEvent*> sampling_completed_rawptrs( | 956 std::vector<WaitableEvent*> sampling_completed_rawptrs( |
| 911 sampling_completed.size()); | 957 sampling_completed.size()); |
| 912 std::transform( | 958 std::transform( |
| 913 sampling_completed.begin(), sampling_completed.end(), | 959 sampling_completed.begin(), sampling_completed.end(), |
| 914 sampling_completed_rawptrs.begin(), | 960 sampling_completed_rawptrs.begin(), |
| 915 [](const std::unique_ptr<WaitableEvent>& elem) { return elem.get(); }); | 961 [](const std::unique_ptr<WaitableEvent>& elem) { return elem.get(); }); |
| 916 // Wait for one profiler to finish. | 962 // Wait for one profiler to finish. |
| 917 size_t completed_profiler = | 963 size_t completed_profiler = WaitableEvent::WaitMany( |
| 918 WaitableEvent::WaitMany(sampling_completed_rawptrs.data(), 2); | 964 sampling_completed_rawptrs.data(), sampling_completed_rawptrs.size()); |
|
Mike Wittman
2017/02/27 23:27:35
This block of code down to this line can be extrac
bcwhite
2017/03/13 18:50:18
Done.
| |
| 919 EXPECT_EQ(1u, profiles[completed_profiler].size()); | 965 EXPECT_EQ(1u, profiles[completed_profiler].size()); |
| 920 | 966 |
| 921 size_t other_profiler = 1 - completed_profiler; | 967 size_t other_profiler = 1 - completed_profiler; |
| 922 // Give the other profiler a chance to run and observe that it hasn't. | 968 // Give the other profiler a chance to finish and verify it does so. |
| 923 EXPECT_FALSE(sampling_completed[other_profiler]->TimedWait( | 969 EXPECT_TRUE(sampling_completed[other_profiler]->TimedWait( |
|
Mike Wittman
2017/02/27 23:27:35
This should be a regular Wait() call. The test wil
bcwhite
2017/03/13 18:50:18
Done.
| |
| 924 TimeDelta::FromMilliseconds(25))); | 970 TimeDelta::FromMilliseconds(250))); |
| 971 EXPECT_EQ(1u, profiles[other_profiler].size()); | |
| 972 }); | |
| 973 } | |
| 925 | 974 |
| 926 // Start the other profiler again and it should run. | 975 // Checks that interleaved multiple sampling requests execute in parallel. |
| 927 profiler[other_profiler]->Start(); | 976 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 928 sampling_completed[other_profiler]->Wait(); | 977 #define MAYBE_ConcurrentProfiling_Interleaved ConcurrentProfiling_Interleaved |
| 929 EXPECT_EQ(1u, profiles[other_profiler].size()); | 978 #else |
| 979 #define MAYBE_ConcurrentProfiling_Interleaved \ | |
| 980 DISABLED_ConcurrentProfiling_Interleaved | |
| 981 #endif | |
| 982 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling_Interleaved) { | |
| 983 WithTargetThread([](PlatformThreadId target_thread_id) { | |
| 984 SamplingParams params[2]; | |
| 985 params[0].initial_delay = TimeDelta::FromMilliseconds(1); | |
| 986 params[0].sampling_interval = TimeDelta::FromMilliseconds(2); | |
| 987 params[0].samples_per_burst = 10; | |
| 988 | |
| 989 params[1].initial_delay = TimeDelta::FromMilliseconds(2); | |
|
Mike Wittman
2017/02/27 23:27:34
The resolution for all waiting values is the 15.6m
bcwhite
2017/03/13 18:50:18
It doesn't actually matter because events are post
Mike Wittman
2017/03/14 18:57:33
Ok, I can see that. In that case though, it's not
| |
| 990 params[1].sampling_interval = TimeDelta::FromMilliseconds(2); | |
| 991 params[1].samples_per_burst = 10; | |
|
Mike Wittman
2017/02/27 23:27:35
If this test is intending to exercise the stopping
bcwhite
2017/03/13 18:50:18
Races between exit and stop should be safe. Keepi
Mike Wittman
2017/03/14 18:57:33
If the desire is to test both winning and losing t
bcwhite
2017/03/16 15:56:25
The desire is to make sure that different sampling
| |
| 992 | |
| 993 CallStackProfiles profiles[2]; | |
| 994 std::vector<std::unique_ptr<WaitableEvent>> sampling_completed( | |
| 995 arraysize(params)); | |
| 996 std::vector<std::unique_ptr<StackSamplingProfiler>> profiler( | |
| 997 arraysize(params)); | |
| 998 for (size_t i = 0; i < arraysize(params); ++i) { | |
| 999 sampling_completed[i] = | |
| 1000 MakeUnique<WaitableEvent>(WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 1001 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 1002 const StackSamplingProfiler::CompletedCallback callback = | |
| 1003 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), | |
| 1004 Unretained(sampling_completed[i].get())); | |
| 1005 profiler[i] = MakeUnique<StackSamplingProfiler>(target_thread_id, | |
| 1006 params[i], callback); | |
| 1007 } | |
| 1008 | |
| 1009 for (size_t i = 0; i < profiler.size(); ++i) | |
| 1010 profiler[i]->Start(); | |
| 1011 | |
| 1012 std::vector<WaitableEvent*> sampling_completed_rawptrs( | |
| 1013 sampling_completed.size()); | |
| 1014 std::transform( | |
| 1015 sampling_completed.begin(), sampling_completed.end(), | |
| 1016 sampling_completed_rawptrs.begin(), | |
| 1017 [](const std::unique_ptr<WaitableEvent>& elem) { return elem.get(); }); | |
| 1018 // Wait for one profiler to finish. | |
| 1019 size_t completed_profiler = WaitableEvent::WaitMany( | |
| 1020 sampling_completed_rawptrs.data(), sampling_completed_rawptrs.size()); | |
| 1021 EXPECT_EQ(1u, profiles[completed_profiler].size()); | |
| 1022 // Stop and destroy all the profilers. Don't crash. | |
| 1023 for (size_t i = 0; i < profiler.size(); ++i) | |
| 1024 profiler[i]->Stop(); | |
| 1025 for (size_t i = 0; i < profiler.size(); ++i) | |
| 1026 profiler[i].reset(); | |
|
Mike Wittman
2017/02/27 23:27:35
The resetting code is unnecessary; the profilers w
bcwhite
2017/03/13 18:50:18
Yes but they will be destroyed in descending order
Mike Wittman
2017/03/14 18:57:33
Why do you want this in this particular test? How
bcwhite
2017/03/16 15:56:25
It's an "interleave" test so order needs to be con
| |
| 1027 }); | |
| 1028 } | |
| 1029 | |
| 1030 // Checks that several mixed sampling requests execute in parallel. | |
| 1031 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | |
| 1032 #define MAYBE_ConcurrentProfiling_Mixed ConcurrentProfiling_Mixed | |
| 1033 #else | |
| 1034 #define MAYBE_ConcurrentProfiling_Mixed DISABLED_ConcurrentProfiling_Mixed | |
| 1035 #endif | |
| 1036 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling_Mixed) { | |
| 1037 WithTargetThread([](PlatformThreadId target_thread_id) { | |
| 1038 SamplingParams params[3]; | |
| 1039 params[0].initial_delay = TimeDelta::FromMilliseconds(8); | |
|
Mike Wittman
2017/02/27 23:27:35
Same comments here with respect to the timer tick
bcwhite
2017/03/13 18:50:18
Acknowledged.
| |
| 1040 params[0].sampling_interval = TimeDelta::FromMilliseconds(4); | |
| 1041 params[0].samples_per_burst = 10; | |
| 1042 | |
| 1043 params[1].initial_delay = TimeDelta::FromMilliseconds(9); | |
| 1044 params[1].sampling_interval = TimeDelta::FromMilliseconds(3); | |
| 1045 params[1].samples_per_burst = 10; | |
| 1046 | |
| 1047 params[2].initial_delay = TimeDelta::FromMilliseconds(10); | |
| 1048 params[2].sampling_interval = TimeDelta::FromMilliseconds(2); | |
| 1049 params[2].samples_per_burst = 10; | |
| 1050 | |
| 1051 CallStackProfiles profiles[arraysize(params)]; | |
| 1052 std::vector<std::unique_ptr<WaitableEvent>> sampling_completed( | |
| 1053 arraysize(params)); | |
| 1054 std::vector<std::unique_ptr<StackSamplingProfiler>> profiler( | |
| 1055 arraysize(params)); | |
| 1056 for (size_t i = 0; i < arraysize(params); ++i) { | |
| 1057 sampling_completed[i] = | |
| 1058 MakeUnique<WaitableEvent>(WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 1059 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 1060 const StackSamplingProfiler::CompletedCallback callback = | |
| 1061 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), | |
| 1062 Unretained(sampling_completed[i].get())); | |
| 1063 profiler[i] = MakeUnique<StackSamplingProfiler>(target_thread_id, | |
| 1064 params[i], callback); | |
| 1065 } | |
| 1066 | |
| 1067 for (size_t i = 0; i < profiler.size(); ++i) | |
| 1068 profiler[i]->Start(); | |
| 1069 | |
| 1070 std::vector<WaitableEvent*> sampling_completed_rawptrs( | |
| 1071 sampling_completed.size()); | |
| 1072 std::transform( | |
| 1073 sampling_completed.begin(), sampling_completed.end(), | |
| 1074 sampling_completed_rawptrs.begin(), | |
| 1075 [](const std::unique_ptr<WaitableEvent>& elem) { return elem.get(); }); | |
| 1076 // Wait for one profiler to finish. | |
| 1077 size_t completed_profiler = WaitableEvent::WaitMany( | |
| 1078 sampling_completed_rawptrs.data(), sampling_completed_rawptrs.size()); | |
| 1079 EXPECT_EQ(1u, profiles[completed_profiler].size()); | |
| 1080 // Destroy all the profilers. Don't crash. | |
| 1081 for (size_t i = 0; i < profiler.size(); ++i) | |
| 1082 profiler[i].reset(); | |
|
Mike Wittman
2017/02/27 23:27:34
This is unnecessary.
bcwhite
2017/03/13 18:50:18
Acknowledged.
| |
| 1083 }); | |
| 1084 } | |
| 1085 | |
| 1086 // Checks that sampling requests execute in a staggered manner. | |
| 1087 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | |
| 1088 #define MAYBE_ConcurrentProfiling_Staggered ConcurrentProfiling_Staggered | |
| 1089 #else | |
| 1090 #define MAYBE_ConcurrentProfiling_Staggered \ | |
| 1091 DISABLED_ConcurrentProfiling_Staggered | |
| 1092 #endif | |
| 1093 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling_Staggered) { | |
| 1094 WithTargetThread([](PlatformThreadId target_thread_id) { | |
| 1095 SamplingParams params[3]; | |
| 1096 params[0].initial_delay = TimeDelta::FromMilliseconds(10); | |
| 1097 params[0].sampling_interval = TimeDelta::FromMilliseconds(10); | |
| 1098 params[0].samples_per_burst = 1; | |
| 1099 | |
| 1100 params[1].initial_delay = TimeDelta::FromMilliseconds(5); | |
| 1101 params[1].sampling_interval = TimeDelta::FromMilliseconds(10); | |
| 1102 params[1].samples_per_burst = 2; | |
| 1103 | |
| 1104 params[2].initial_delay = TimeDelta::FromMilliseconds(0); | |
| 1105 params[2].sampling_interval = TimeDelta::FromMilliseconds(10); | |
| 1106 params[2].samples_per_burst = 3; | |
| 1107 | |
| 1108 CallStackProfiles profiles[arraysize(params)]; | |
| 1109 std::vector<std::unique_ptr<WaitableEvent>> sampling_completed( | |
| 1110 arraysize(params)); | |
| 1111 std::vector<std::unique_ptr<StackSamplingProfiler>> profiler( | |
| 1112 arraysize(params)); | |
| 1113 for (size_t i = 0; i < arraysize(params); ++i) { | |
| 1114 sampling_completed[i] = | |
| 1115 MakeUnique<WaitableEvent>(WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 1116 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 1117 const StackSamplingProfiler::CompletedCallback callback = | |
| 1118 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), | |
| 1119 Unretained(sampling_completed[i].get())); | |
| 1120 profiler[i] = MakeUnique<StackSamplingProfiler>(target_thread_id, | |
| 1121 params[i], callback); | |
| 1122 } | |
| 1123 | |
| 1124 profiler[0]->Start(); | |
| 1125 profiler[1]->Start(); | |
| 1126 sampling_completed[0]->Wait(); | |
| 1127 EXPECT_FALSE(sampling_completed[1]->IsSignaled()); | |
|
Mike Wittman
2017/03/14 18:57:33
The first two profilers could both complete by thi
bcwhite
2017/03/16 15:56:25
Done.
| |
| 1128 profiler[2]->Start(); | |
| 1129 profiler[0]->Stop(); | |
| 1130 profiler[1]->Stop(); | |
| 1131 sampling_completed[1]->Wait(); | |
| 1132 EXPECT_FALSE(sampling_completed[2]->IsSignaled()); | |
|
Mike Wittman
2017/03/14 18:57:33
Same here for the second and third profilers.
bcwhite
2017/03/16 15:56:25
Done.
| |
| 1133 sampling_completed[2]->Wait(); | |
| 1134 EXPECT_EQ(1u, profiles[0].size()); | |
| 1135 EXPECT_EQ(1u, profiles[1].size()); | |
| 1136 EXPECT_EQ(1u, profiles[2].size()); | |
| 930 }); | 1137 }); |
| 931 } | 1138 } |
| 932 | 1139 |
| 933 // Checks that a stack that runs through another library produces a stack with | 1140 // Checks that a stack that runs through another library produces a stack with |
| 934 // the expected functions. | 1141 // the expected functions. |
| 935 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 1142 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 936 #define MAYBE_OtherLibrary OtherLibrary | 1143 #define MAYBE_OtherLibrary OtherLibrary |
| 937 #else | 1144 #else |
| 938 #define MAYBE_OtherLibrary DISABLED_OtherLibrary | 1145 #define MAYBE_OtherLibrary DISABLED_OtherLibrary |
| 939 #endif | 1146 #endif |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1017 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 1224 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 1018 #define MAYBE_UnloadedLibrary UnloadedLibrary | 1225 #define MAYBE_UnloadedLibrary UnloadedLibrary |
| 1019 #else | 1226 #else |
| 1020 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary | 1227 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary |
| 1021 #endif | 1228 #endif |
| 1022 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { | 1229 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { |
| 1023 TestLibraryUnload(true); | 1230 TestLibraryUnload(true); |
| 1024 } | 1231 } |
| 1025 | 1232 |
| 1026 } // namespace base | 1233 } // namespace base |
| OLD | NEW |