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

Unified Diff: base/profiler/stack_sampling_profiler_unittest.cc

Issue 2927593002: Make stack sampling profiler sample beyond startup. (Closed)
Patch Set: Temporary LOG statements for debugging. Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/profiler/stack_sampling_profiler.cc ('k') | base/time/time.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/profiler/stack_sampling_profiler_unittest.cc
diff --git a/base/profiler/stack_sampling_profiler_unittest.cc b/base/profiler/stack_sampling_profiler_unittest.cc
index 66aacf91a7ded27003cc1b13e0f1ec475eac12e0..64c410549f332ebf7979d89aa78addb4e97e85f6 100644
--- a/base/profiler/stack_sampling_profiler_unittest.cc
+++ b/base/profiler/stack_sampling_profiler_unittest.cc
@@ -5,6 +5,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <algorithm>
#include <cstdlib>
#include <memory>
#include <utility>
@@ -323,19 +324,51 @@ void SynchronousUnloadNativeLibrary(NativeLibrary library) {
}
// Called on the profiler thread when complete, to collect profiles.
-void SaveProfiles(CallStackProfiles* profiles,
- CallStackProfiles pending_profiles) {
+Optional<StackSamplingProfiler::SamplingParams> SaveProfiles(
+ CallStackProfiles* profiles,
+ CallStackProfiles pending_profiles) {
*profiles = std::move(pending_profiles);
+ return Optional<StackSamplingProfiler::SamplingParams>();
}
// Called on the profiler thread when complete. Collects profiles produced by
// the profiler, and signals an event to allow the main thread to know that that
// the profiler is done.
-void SaveProfilesAndSignalEvent(CallStackProfiles* profiles,
- WaitableEvent* event,
- CallStackProfiles pending_profiles) {
+Optional<StackSamplingProfiler::SamplingParams> SaveProfilesAndSignalEvent(
+ CallStackProfiles* profiles,
+ WaitableEvent* event,
+ CallStackProfiles pending_profiles) {
*profiles = std::move(pending_profiles);
event->Signal();
+ return Optional<StackSamplingProfiler::SamplingParams>();
+}
+
+// Similar to SaveProfilesAndSignalEvent(), but will schedule a second
+// collection after the first call back.
+Optional<StackSamplingProfiler::SamplingParams> SaveProfilesAndReschedule(
+ std::vector<CallStackProfiles>* profiles,
+ WaitableEvent* event,
+ CallStackProfiles pending_profiles) {
+ LOG(ERROR) << "SaveProfilesAndReschedule";
+ profiles->push_back(std::move(pending_profiles));
+
+ event->Signal();
+ event->Reset();
Robert Sesek 2017/07/14 19:22:39 I've just rewritten WaitableEvent on Mac and it's
+
+ if (profiles->size() == 2) {
+ LOG(ERROR) << "Returning empty params";
+ return Optional<StackSamplingProfiler::SamplingParams>();
+ }
+
+ StackSamplingProfiler::SamplingParams sampling_params;
+ sampling_params.initial_delay = base::TimeDelta::FromMilliseconds(100);
+ sampling_params.bursts = 1;
+ sampling_params.samples_per_burst = 1;
+ // Below are unused:
+ sampling_params.burst_interval = base::TimeDelta::FromMilliseconds(0);
+ sampling_params.sampling_interval = base::TimeDelta::FromMilliseconds(0);
+ LOG(ERROR) << "Returning new params";
+ return sampling_params;
}
// Executes the function with the target thread running and executing within
@@ -1020,6 +1053,40 @@ PROFILER_TEST_F(StackSamplingProfilerTest, CanRunMultipleTimes) {
});
}
+PROFILER_TEST_F(StackSamplingProfilerTest, RescheduledByCallback) {
+ LOG(ERROR) << "RescheduledByCallback start";
+ WithTargetThread([](PlatformThreadId target_thread_id) {
+ SamplingParams params;
+ params.sampling_interval = TimeDelta::FromMilliseconds(0);
+ params.samples_per_burst = 1;
+
+ std::vector<CallStackProfiles> profiles;
+ WaitableEvent sampling_completed(WaitableEvent::ResetPolicy::MANUAL,
+ WaitableEvent::InitialState::NOT_SIGNALED);
+ const StackSamplingProfiler::CompletedCallback callback =
+ Bind(&SaveProfilesAndReschedule, Unretained(&profiles),
+ Unretained(&sampling_completed));
+ StackSamplingProfiler profiler(target_thread_id, params, callback);
+
+ // Start once and wait for it to be completed.
+ LOG(ERROR) << "RescheduledByCallback call start";
+ profiler.Start();
+ LOG(ERROR) << "RescheduledByCallback call wait1";
+ sampling_completed.Wait();
+ LOG(ERROR) << "RescheduledByCallback after wait1";
+ ASSERT_EQ(1u, profiles.size());
+ ASSERT_EQ(1u, profiles[0].size());
+
+ // Now, wait for the second callback call.
+ LOG(ERROR) << "RescheduledByCallback call wait2";
+ sampling_completed.Wait();
+ LOG(ERROR) << "RescheduledByCallback after wait2";
+ profiler.Stop();
+ ASSERT_EQ(2u, profiles.size());
+ ASSERT_EQ(1u, profiles[1].size());
+ });
+}
+
// Checks that the different profilers may be run.
PROFILER_TEST_F(StackSamplingProfilerTest, CanRunMultipleProfilers) {
SamplingParams params;
« no previous file with comments | « base/profiler/stack_sampling_profiler.cc ('k') | base/time/time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698