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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 // are ignored. | 875 // are ignored. |
876 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 876 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
877 #define MAYBE_ConcurrentProfiling ConcurrentProfiling | 877 #define MAYBE_ConcurrentProfiling ConcurrentProfiling |
878 #else | 878 #else |
879 #define MAYBE_ConcurrentProfiling DISABLED_ConcurrentProfiling | 879 #define MAYBE_ConcurrentProfiling DISABLED_ConcurrentProfiling |
880 #endif | 880 #endif |
881 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling) { | 881 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling) { |
882 WithTargetThread([](PlatformThreadId target_thread_id) { | 882 WithTargetThread([](PlatformThreadId target_thread_id) { |
883 SamplingParams params[2]; | 883 SamplingParams params[2]; |
884 params[0].initial_delay = TimeDelta::FromMilliseconds(10); | 884 params[0].initial_delay = TimeDelta::FromMilliseconds(10); |
885 params[0].sampling_interval = TimeDelta::FromMilliseconds(0); | 885 params[0].sampling_interval = TimeDelta::FromMilliseconds(1); |
886 params[0].samples_per_burst = 1; | 886 params[0].samples_per_burst = 10; |
887 | 887 |
888 params[1].sampling_interval = TimeDelta::FromMilliseconds(0); | 888 params[0].initial_delay = TimeDelta::FromMilliseconds(10); |
889 params[1].samples_per_burst = 1; | 889 params[1].sampling_interval = TimeDelta::FromMilliseconds(1); |
| 890 params[1].samples_per_burst = 10; |
890 | 891 |
891 CallStackProfiles profiles[2]; | 892 CallStackProfiles profiles[2]; |
892 ScopedVector<WaitableEvent> sampling_completed; | 893 ScopedVector<WaitableEvent> sampling_completed; |
893 ScopedVector<StackSamplingProfiler> profiler; | 894 ScopedVector<StackSamplingProfiler> profiler; |
894 for (int i = 0; i < 2; ++i) { | 895 for (int i = 0; i < 2; ++i) { |
895 sampling_completed.push_back( | 896 sampling_completed.push_back( |
896 new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC, | 897 new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC, |
897 WaitableEvent::InitialState::NOT_SIGNALED)); | 898 WaitableEvent::InitialState::NOT_SIGNALED)); |
898 const StackSamplingProfiler::CompletedCallback callback = | 899 const StackSamplingProfiler::CompletedCallback callback = |
899 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), | 900 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), |
900 Unretained(sampling_completed[i])); | 901 Unretained(sampling_completed[i])); |
901 profiler.push_back( | 902 profiler.push_back( |
902 new StackSamplingProfiler(target_thread_id, params[i], callback)); | 903 new StackSamplingProfiler(target_thread_id, params[i], callback)); |
903 } | 904 } |
904 | 905 |
905 profiler[0]->Start(); | 906 profiler[0]->Start(); |
906 profiler[1]->Start(); | 907 profiler[1]->Start(); |
907 | 908 |
908 // Wait for one profiler to finish. | 909 // Wait for one profiler to finish. |
909 size_t completed_profiler = | 910 size_t completed_profiler = |
910 WaitableEvent::WaitMany(&sampling_completed[0], 2); | 911 WaitableEvent::WaitMany(&sampling_completed[0], 2); |
911 EXPECT_EQ(1u, profiles[completed_profiler].size()); | 912 EXPECT_EQ(1u, profiles[completed_profiler].size()); |
912 | 913 |
913 size_t other_profiler = 1 - completed_profiler; | 914 size_t other_profiler = 1 - completed_profiler; |
914 // Give the other profiler a chance to run and observe that it hasn't. | 915 // Give the other profiler a chance to finish and verify it does no. |
915 EXPECT_FALSE(sampling_completed[other_profiler]->TimedWait( | 916 EXPECT_TRUE(sampling_completed[other_profiler]->TimedWait( |
916 TimeDelta::FromMilliseconds(25))); | 917 TimeDelta::FromMilliseconds(250))); |
917 | |
918 // Start the other profiler again and it should run. | |
919 profiler[other_profiler]->Start(); | |
920 sampling_completed[other_profiler]->Wait(); | |
921 EXPECT_EQ(1u, profiles[other_profiler].size()); | |
922 }); | 918 }); |
923 } | 919 } |
924 | 920 |
925 // Checks that a stack that runs through another library produces a stack with | 921 // Checks that a stack that runs through another library produces a stack with |
926 // the expected functions. | 922 // the expected functions. |
927 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 923 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
928 #define MAYBE_OtherLibrary OtherLibrary | 924 #define MAYBE_OtherLibrary OtherLibrary |
929 #else | 925 #else |
930 #define MAYBE_OtherLibrary DISABLED_OtherLibrary | 926 #define MAYBE_OtherLibrary DISABLED_OtherLibrary |
931 #endif | 927 #endif |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 1005 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
1010 #define MAYBE_UnloadedLibrary UnloadedLibrary | 1006 #define MAYBE_UnloadedLibrary UnloadedLibrary |
1011 #else | 1007 #else |
1012 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary | 1008 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary |
1013 #endif | 1009 #endif |
1014 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { | 1010 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { |
1015 TestLibraryUnload(true); | 1011 TestLibraryUnload(true); |
1016 } | 1012 } |
1017 | 1013 |
1018 } // namespace base | 1014 } // namespace base |
OLD | NEW |