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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 using SamplingParams = StackSamplingProfiler::SamplingParams; | 52 using SamplingParams = StackSamplingProfiler::SamplingParams; |
| 53 using Frame = StackSamplingProfiler::Frame; | 53 using Frame = StackSamplingProfiler::Frame; |
| 54 using Frames = std::vector<StackSamplingProfiler::Frame>; | 54 using Frames = std::vector<StackSamplingProfiler::Frame>; |
| 55 using Module = StackSamplingProfiler::Module; | 55 using Module = StackSamplingProfiler::Module; |
| 56 using Sample = StackSamplingProfiler::Sample; | 56 using Sample = StackSamplingProfiler::Sample; |
| 57 using CallStackProfile = StackSamplingProfiler::CallStackProfile; | 57 using CallStackProfile = StackSamplingProfiler::CallStackProfile; |
| 58 using CallStackProfiles = StackSamplingProfiler::CallStackProfiles; | 58 using CallStackProfiles = StackSamplingProfiler::CallStackProfiles; |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 // Test delegate that signals when the thread-under-test has exited. | |
| 63 class ThreadLifetimeSignaler : public NativeStackSamplerTestDelegate { | |
| 64 public: | |
| 65 ThreadLifetimeSignaler(WaitableEvent* thread_started, | |
| 66 WaitableEvent* thread_sampled, | |
| 67 WaitableEvent* thread_exited) | |
| 68 : thread_started_(thread_started), | |
| 69 thread_sampled_(thread_sampled), | |
| 70 thread_exited_(thread_exited) {} | |
| 71 | |
| 72 void OnPostRecordSample(NativeStackSampler::ThreadState state) override { | |
| 73 if (state == NativeStackSampler::THREAD_RUNNING) { | |
| 74 if (thread_started_) { | |
| 75 thread_started_->Signal(); | |
| 76 thread_started_ = nullptr; | |
| 77 } | |
| 78 } | |
| 79 if (thread_sampled_) | |
| 80 thread_sampled_->Signal(); | |
| 81 if (state == NativeStackSampler::THREAD_EXITED) { | |
| 82 if (thread_exited_) { | |
| 83 thread_exited_->Signal(); | |
| 84 thread_exited_ = nullptr; | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 private: | |
| 90 WaitableEvent* thread_started_; | |
| 91 WaitableEvent* thread_sampled_; | |
| 92 WaitableEvent* thread_exited_; | |
| 93 }; | |
| 94 | |
| 62 // Configuration for the frames that appear on the stack. | 95 // Configuration for the frames that appear on the stack. |
| 63 struct StackConfiguration { | 96 struct StackConfiguration { |
| 64 enum Config { NORMAL, WITH_ALLOCA, WITH_OTHER_LIBRARY }; | 97 enum Config { NORMAL, WITH_ALLOCA, WITH_OTHER_LIBRARY }; |
| 65 | 98 |
| 66 explicit StackConfiguration(Config config) | 99 explicit StackConfiguration(Config config) |
| 67 : StackConfiguration(config, nullptr) { | 100 : StackConfiguration(config, nullptr) { |
| 68 EXPECT_NE(config, WITH_OTHER_LIBRARY); | 101 EXPECT_NE(config, WITH_OTHER_LIBRARY); |
| 69 } | 102 } |
| 70 | 103 |
| 71 StackConfiguration(Config config, NativeLibrary library) | 104 StackConfiguration(Config config, NativeLibrary library) |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 // asynchronous library loading has completed before walking the stack. If | 470 // asynchronous library loading has completed before walking the stack. If |
| 438 // false, the unloading may still be occurring during the stack walk. | 471 // false, the unloading may still be occurring during the stack walk. |
| 439 void TestLibraryUnload(bool wait_until_unloaded) { | 472 void TestLibraryUnload(bool wait_until_unloaded) { |
| 440 // Test delegate that supports intervening between the copying of the stack | 473 // Test delegate that supports intervening between the copying of the stack |
| 441 // and the walking of the stack. | 474 // and the walking of the stack. |
| 442 class StackCopiedSignaler : public NativeStackSamplerTestDelegate { | 475 class StackCopiedSignaler : public NativeStackSamplerTestDelegate { |
| 443 public: | 476 public: |
| 444 StackCopiedSignaler(WaitableEvent* stack_copied, | 477 StackCopiedSignaler(WaitableEvent* stack_copied, |
| 445 WaitableEvent* start_stack_walk, | 478 WaitableEvent* start_stack_walk, |
| 446 bool wait_to_walk_stack) | 479 bool wait_to_walk_stack) |
| 447 : stack_copied_(stack_copied), start_stack_walk_(start_stack_walk), | 480 : stack_copied_(stack_copied), |
| 448 wait_to_walk_stack_(wait_to_walk_stack) { | 481 start_stack_walk_(start_stack_walk), |
| 449 } | 482 wait_to_walk_stack_(wait_to_walk_stack) {} |
| 450 | 483 |
| 451 void OnPreStackWalk() override { | 484 void OnPreStackWalk() override { |
| 452 stack_copied_->Signal(); | 485 stack_copied_->Signal(); |
| 453 if (wait_to_walk_stack_) | 486 if (wait_to_walk_stack_) |
| 454 start_stack_walk_->Wait(); | 487 start_stack_walk_->Wait(); |
| 455 } | 488 } |
| 456 | 489 |
| 457 private: | 490 private: |
| 458 WaitableEvent* const stack_copied_; | 491 WaitableEvent* const stack_copied_; |
| 459 WaitableEvent* const start_stack_walk_; | 492 WaitableEvent* const start_stack_walk_; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 sample, &TargetThread::SignalAndWaitUntilSignaled); | 649 sample, &TargetThread::SignalAndWaitUntilSignaled); |
| 617 ASSERT_TRUE(loc != sample.frames.end()) | 650 ASSERT_TRUE(loc != sample.frames.end()) |
| 618 << "Function at " | 651 << "Function at " |
| 619 << MaybeFixupFunctionAddressForILT(reinterpret_cast<const void*>( | 652 << MaybeFixupFunctionAddressForILT(reinterpret_cast<const void*>( |
| 620 &TargetThread::SignalAndWaitUntilSignaled)) | 653 &TargetThread::SignalAndWaitUntilSignaled)) |
| 621 << " was not found in stack:\n" | 654 << " was not found in stack:\n" |
| 622 << FormatSampleForDiagnosticOutput(sample, profile.modules); | 655 << FormatSampleForDiagnosticOutput(sample, profile.modules); |
| 623 FilePath executable_path; | 656 FilePath executable_path; |
| 624 EXPECT_TRUE(PathService::Get(FILE_EXE, &executable_path)); | 657 EXPECT_TRUE(PathService::Get(FILE_EXE, &executable_path)); |
| 625 EXPECT_EQ(executable_path, profile.modules[loc->module_index].filename); | 658 EXPECT_EQ(executable_path, profile.modules[loc->module_index].filename); |
| 659 | |
| 660 // Ensure the sampling thread is still running at this point. | |
| 661 ASSERT_TRUE(StackSamplingProfiler::IsSamplingThreadRunningForTesting()); | |
| 662 | |
| 663 // Shutdown the sampler as though the process were about to exit. | |
| 664 StackSamplingProfiler::Shutdown(); | |
| 665 EXPECT_FALSE(StackSamplingProfiler::IsSamplingThreadRunningForTesting()); | |
| 666 | |
| 667 // Shutdown is a permanent thing in general but this needs to be undone so | |
| 668 // other tests can run. | |
| 669 StackSamplingProfiler::UndoShutdownForTesting(); | |
| 670 EXPECT_FALSE(StackSamplingProfiler::IsSamplingThreadRunningForTesting()); | |
| 626 } | 671 } |
| 627 | 672 |
| 628 // Checks that annotations are recorded in samples. | 673 // Checks that annotations are recorded in samples. |
| 629 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 674 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 630 #define MAYBE_Annotations Annotations | 675 #define MAYBE_Annotations Annotations |
| 631 #else | 676 #else |
| 632 #define MAYBE_Annotations DISABLED_Annotations | 677 #define MAYBE_Annotations DISABLED_Annotations |
| 633 #endif | 678 #endif |
| 634 TEST(StackSamplingProfilerTest, MAYBE_Annotations) { | 679 TEST(StackSamplingProfilerTest, MAYBE_Annotations) { |
| 635 StackSamplingProfiler::ResetAnnotationsForTesting(); | 680 StackSamplingProfiler::ResetAnnotationsForTesting(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 reinterpret_cast<const void*>(&TargetThread::CallWithAlloca)) | 758 reinterpret_cast<const void*>(&TargetThread::CallWithAlloca)) |
| 714 << " was not found in stack:\n" | 759 << " was not found in stack:\n" |
| 715 << FormatSampleForDiagnosticOutput(sample, profile.modules); | 760 << FormatSampleForDiagnosticOutput(sample, profile.modules); |
| 716 | 761 |
| 717 // These frames should be adjacent on the stack. | 762 // These frames should be adjacent on the stack. |
| 718 EXPECT_EQ(1, alloca_frame - end_frame) | 763 EXPECT_EQ(1, alloca_frame - end_frame) |
| 719 << "Stack:\n" | 764 << "Stack:\n" |
| 720 << FormatSampleForDiagnosticOutput(sample, profile.modules); | 765 << FormatSampleForDiagnosticOutput(sample, profile.modules); |
| 721 } | 766 } |
| 722 | 767 |
| 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 | 768 // Checks that the expected number of profiles and samples are present in the |
| 753 // call stack profiles produced. | 769 // call stack profiles produced. |
| 754 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 770 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 755 #define MAYBE_MultipleProfilesAndSamples MultipleProfilesAndSamples | 771 #define MAYBE_MultipleProfilesAndSamples MultipleProfilesAndSamples |
| 756 #else | 772 #else |
| 757 #define MAYBE_MultipleProfilesAndSamples DISABLED_MultipleProfilesAndSamples | 773 #define MAYBE_MultipleProfilesAndSamples DISABLED_MultipleProfilesAndSamples |
| 758 #endif | 774 #endif |
| 759 TEST(StackSamplingProfilerTest, MAYBE_MultipleProfilesAndSamples) { | 775 TEST(StackSamplingProfilerTest, MAYBE_MultipleProfilesAndSamples) { |
| 760 SamplingParams params; | 776 SamplingParams params; |
| 761 params.burst_interval = params.sampling_interval = | 777 params.burst_interval = params.sampling_interval = |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 target_thread_id, params, Bind(&SaveProfiles, Unretained(&profiles)))); | 862 target_thread_id, params, Bind(&SaveProfiles, Unretained(&profiles)))); |
| 847 profiler->Start(); | 863 profiler->Start(); |
| 848 profiler.reset(); | 864 profiler.reset(); |
| 849 | 865 |
| 850 // Wait longer than a sample interval to catch any use-after-free actions by | 866 // Wait longer than a sample interval to catch any use-after-free actions by |
| 851 // the profiler thread. | 867 // the profiler thread. |
| 852 PlatformThread::Sleep(TimeDelta::FromMilliseconds(50)); | 868 PlatformThread::Sleep(TimeDelta::FromMilliseconds(50)); |
| 853 }); | 869 }); |
| 854 } | 870 } |
| 855 | 871 |
| 872 // Checks that we can destroy the thread under test while profiling. | |
| 873 // This isn't officially supported but is expected to work under Windows. | |
| 874 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) && defined(OS_WIN) | |
| 875 #define MAYBE_DestroyThreadWhileProfiling DestroyThreadWhileProfiling | |
| 876 #else | |
| 877 #define MAYBE_DestroyThreadWhileProfiling DISABLED_DestroyThreadWhileProfiling | |
| 878 #endif | |
| 879 TEST(StackSamplingProfilerTest, MAYBE_DestroyThreadWhileProfiling) { | |
|
Mike Wittman
2017/02/13 22:35:57
This test can be removed since it's no longer the
bcwhite
2017/02/14 14:33:02
Done.
| |
| 880 // Set up a thread for testing. | |
| 881 StackConfiguration stack_config(StackConfiguration::NORMAL); | |
| 882 TargetThread target_thread(stack_config); | |
| 883 PlatformThreadHandle target_thread_handle; | |
| 884 ASSERT_TRUE(PlatformThread::Create(0, &target_thread, &target_thread_handle)); | |
| 885 | |
| 886 // Set up the sampler: 5 samples, 1 second apart | |
| 887 SamplingParams params; | |
| 888 params.sampling_interval = TimeDelta::FromSeconds(1); | |
| 889 params.samples_per_burst = 5; | |
| 890 std::vector<CallStackProfile> profiles; | |
| 891 WaitableEvent sampling_thread_completed( | |
| 892 WaitableEvent::ResetPolicy::MANUAL, | |
| 893 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 894 const StackSamplingProfiler::CompletedCallback callback = | |
| 895 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles), | |
| 896 Unretained(&sampling_thread_completed)); | |
| 897 | |
| 898 // Set up events to detect thread lifetime. | |
| 899 WaitableEvent thread_started(WaitableEvent::ResetPolicy::MANUAL, | |
| 900 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 901 WaitableEvent thread_sampled(WaitableEvent::ResetPolicy::MANUAL, | |
| 902 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 903 WaitableEvent thread_exited(WaitableEvent::ResetPolicy::MANUAL, | |
| 904 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 905 ThreadLifetimeSignaler test_delegate(&thread_started, &thread_sampled, | |
| 906 &thread_exited); | |
| 907 | |
| 908 // Start the thread and the sampler and wait a short while. | |
| 909 target_thread.WaitForThreadStart(); | |
| 910 StackSamplingProfiler profiler(target_thread.id(), params, callback, | |
| 911 &test_delegate); | |
| 912 profiler.Start(); | |
| 913 | |
| 914 // Delay until the thread gets started and a sample is collected. | |
| 915 thread_started.Wait(); | |
| 916 | |
| 917 // Stop the target thread. | |
| 918 target_thread.SignalThreadToFinish(); | |
| 919 PlatformThread::Join(target_thread_handle); | |
| 920 | |
| 921 // Wait for one more sampling attempt. | |
| 922 thread_sampled.Reset(); | |
| 923 thread_sampled.Wait(); | |
| 924 | |
| 925 // Stop sampling and wait for it to finish. | |
| 926 profiler.Stop(); | |
| 927 sampling_thread_completed.Wait(); | |
| 928 | |
| 929 // There should be one profile in which the first sample has frames and | |
| 930 // the last does not. | |
| 931 ASSERT_EQ(1U, profiles.size()); | |
| 932 EXPECT_NE(0U, profiles[0].samples.front().frames.size()); | |
| 933 EXPECT_EQ(0U, profiles[0].samples.back().frames.size()); | |
| 934 } | |
| 935 | |
| 856 // Checks that the same profiler may be run multiple times. | 936 // Checks that the same profiler may be run multiple times. |
| 857 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 937 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 858 #define MAYBE_CanRunMultipleTimes CanRunMultipleTimes | 938 #define MAYBE_CanRunMultipleTimes CanRunMultipleTimes |
| 859 #else | 939 #else |
| 860 #define MAYBE_CanRunMultipleTimes DISABLED_CanRunMultipleTimes | 940 #define MAYBE_CanRunMultipleTimes DISABLED_CanRunMultipleTimes |
| 861 #endif | 941 #endif |
| 862 TEST(StackSamplingProfilerTest, MAYBE_CanRunMultipleTimes) { | 942 TEST(StackSamplingProfilerTest, MAYBE_CanRunMultipleTimes) { |
| 943 StackSamplingProfiler::SetSamplingThreadIdleShutdownTimeForTesting(0); | |
| 944 | |
| 863 SamplingParams params; | 945 SamplingParams params; |
| 864 params.sampling_interval = TimeDelta::FromMilliseconds(0); | 946 params.sampling_interval = TimeDelta::FromMilliseconds(0); |
| 865 params.samples_per_burst = 1; | 947 params.samples_per_burst = 1; |
| 866 | 948 |
| 867 std::vector<CallStackProfile> profiles; | 949 std::vector<CallStackProfile> profiles; |
| 868 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); | 950 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); |
| 869 ASSERT_EQ(1u, profiles.size()); | 951 ASSERT_EQ(1u, profiles.size()); |
| 870 | 952 |
| 871 profiles.clear(); | 953 profiles.clear(); |
| 872 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); | 954 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); |
| 873 ASSERT_EQ(1u, profiles.size()); | 955 ASSERT_EQ(1u, profiles.size()); |
| 956 | |
| 957 // Capture thread should still be running at this point. | |
| 958 ASSERT_TRUE(StackSamplingProfiler::IsSamplingThreadRunningForTesting()); | |
| 959 | |
| 960 // Initiate an "idle" shutdown. The task will be run immediately but on | |
| 961 // another thread so wait for it to complete. | |
| 962 StackSamplingProfiler::InitiateSamplingThreadIdleShutdownForTesting(); | |
| 963 while (StackSamplingProfiler::IsSamplingThreadRunningForTesting()) | |
| 964 PlatformThread::YieldCurrentThread(); | |
| 965 | |
| 966 // Ensure another capture will start the sampling thread and run. | |
| 967 profiles.clear(); | |
| 968 CaptureProfiles(params, AVeryLongTimeDelta(), &profiles); | |
| 969 ASSERT_EQ(1u, profiles.size()); | |
| 970 EXPECT_TRUE(StackSamplingProfiler::IsSamplingThreadRunningForTesting()); | |
| 874 } | 971 } |
| 875 | 972 |
| 876 // Checks that requests to start profiling while another profile is taking place | 973 // Checks that requests to start profiling while another profile is taking place |
|
Mike Wittman
2017/02/13 22:35:57
This comment needs updating.
bcwhite
2017/02/14 14:33:02
Done.
| |
| 877 // are ignored. | 974 // are ignored. |
| 878 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 975 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 879 #define MAYBE_ConcurrentProfiling ConcurrentProfiling | 976 #define MAYBE_ConcurrentProfiling ConcurrentProfiling |
| 880 #else | 977 #else |
| 881 #define MAYBE_ConcurrentProfiling DISABLED_ConcurrentProfiling | 978 #define MAYBE_ConcurrentProfiling DISABLED_ConcurrentProfiling |
| 882 #endif | 979 #endif |
| 883 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling) { | 980 TEST(StackSamplingProfilerTest, MAYBE_ConcurrentProfiling) { |
| 884 WithTargetThread([](PlatformThreadId target_thread_id) { | 981 WithTargetThread([](PlatformThreadId target_thread_id) { |
| 885 SamplingParams params[2]; | 982 SamplingParams params[2]; |
| 886 params[0].initial_delay = TimeDelta::FromMilliseconds(10); | 983 params[0].initial_delay = TimeDelta::FromMilliseconds(10); |
| 887 params[0].sampling_interval = TimeDelta::FromMilliseconds(0); | 984 params[0].sampling_interval = TimeDelta::FromMilliseconds(1); |
| 888 params[0].samples_per_burst = 1; | 985 params[0].samples_per_burst = 10; |
| 889 | 986 |
| 890 params[1].sampling_interval = TimeDelta::FromMilliseconds(0); | 987 params[0].initial_delay = TimeDelta::FromMilliseconds(10); |
| 891 params[1].samples_per_burst = 1; | 988 params[1].sampling_interval = TimeDelta::FromMilliseconds(1); |
| 989 params[1].samples_per_burst = 10; | |
| 892 | 990 |
| 893 CallStackProfiles profiles[2]; | 991 CallStackProfiles profiles[2]; |
| 894 std::vector<std::unique_ptr<WaitableEvent>> sampling_completed(2); | 992 std::vector<std::unique_ptr<WaitableEvent>> sampling_completed(2); |
| 895 std::vector<std::unique_ptr<StackSamplingProfiler>> profiler(2); | 993 std::vector<std::unique_ptr<StackSamplingProfiler>> profiler(2); |
| 896 for (int i = 0; i < 2; ++i) { | 994 for (int i = 0; i < 2; ++i) { |
| 897 sampling_completed[i] = | 995 sampling_completed[i] = |
| 898 MakeUnique<WaitableEvent>(WaitableEvent::ResetPolicy::AUTOMATIC, | 996 MakeUnique<WaitableEvent>(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 899 WaitableEvent::InitialState::NOT_SIGNALED); | 997 WaitableEvent::InitialState::NOT_SIGNALED); |
| 900 const StackSamplingProfiler::CompletedCallback callback = | 998 const StackSamplingProfiler::CompletedCallback callback = |
| 901 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), | 999 Bind(&SaveProfilesAndSignalEvent, Unretained(&profiles[i]), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 912 std::transform( | 1010 std::transform( |
| 913 sampling_completed.begin(), sampling_completed.end(), | 1011 sampling_completed.begin(), sampling_completed.end(), |
| 914 sampling_completed_rawptrs.begin(), | 1012 sampling_completed_rawptrs.begin(), |
| 915 [](const std::unique_ptr<WaitableEvent>& elem) { return elem.get(); }); | 1013 [](const std::unique_ptr<WaitableEvent>& elem) { return elem.get(); }); |
| 916 // Wait for one profiler to finish. | 1014 // Wait for one profiler to finish. |
| 917 size_t completed_profiler = | 1015 size_t completed_profiler = |
| 918 WaitableEvent::WaitMany(sampling_completed_rawptrs.data(), 2); | 1016 WaitableEvent::WaitMany(sampling_completed_rawptrs.data(), 2); |
| 919 EXPECT_EQ(1u, profiles[completed_profiler].size()); | 1017 EXPECT_EQ(1u, profiles[completed_profiler].size()); |
| 920 | 1018 |
| 921 size_t other_profiler = 1 - completed_profiler; | 1019 size_t other_profiler = 1 - completed_profiler; |
| 922 // Give the other profiler a chance to run and observe that it hasn't. | 1020 // Give the other profiler a chance to finish and verify it does no. |
|
Mike Wittman
2017/02/13 22:35:57
nit: does so
bcwhite
2017/02/14 14:33:02
Done.
| |
| 923 EXPECT_FALSE(sampling_completed[other_profiler]->TimedWait( | 1021 EXPECT_TRUE(sampling_completed[other_profiler]->TimedWait( |
| 924 TimeDelta::FromMilliseconds(25))); | 1022 TimeDelta::FromMilliseconds(250))); |
| 925 | |
| 926 // Start the other profiler again and it should run. | |
| 927 profiler[other_profiler]->Start(); | |
| 928 sampling_completed[other_profiler]->Wait(); | |
| 929 EXPECT_EQ(1u, profiles[other_profiler].size()); | |
| 930 }); | 1023 }); |
| 931 } | 1024 } |
| 932 | 1025 |
| 933 // Checks that a stack that runs through another library produces a stack with | 1026 // Checks that a stack that runs through another library produces a stack with |
| 934 // the expected functions. | 1027 // the expected functions. |
| 935 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 1028 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 936 #define MAYBE_OtherLibrary OtherLibrary | 1029 #define MAYBE_OtherLibrary OtherLibrary |
| 937 #else | 1030 #else |
| 938 #define MAYBE_OtherLibrary DISABLED_OtherLibrary | 1031 #define MAYBE_OtherLibrary DISABLED_OtherLibrary |
| 939 #endif | 1032 #endif |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1017 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 1110 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
| 1018 #define MAYBE_UnloadedLibrary UnloadedLibrary | 1111 #define MAYBE_UnloadedLibrary UnloadedLibrary |
| 1019 #else | 1112 #else |
| 1020 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary | 1113 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary |
| 1021 #endif | 1114 #endif |
| 1022 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { | 1115 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { |
| 1023 TestLibraryUnload(true); | 1116 TestLibraryUnload(true); |
| 1024 } | 1117 } |
| 1025 | 1118 |
| 1026 } // namespace base | 1119 } // namespace base |
| OLD | NEW |