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

Unified Diff: base/profiler/stack_sampling_profiler_unittest.cc

Issue 2927593002: Make stack sampling profiler sample beyond startup. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
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 7cae10455d99b64b80cd8c75962013ed43a28f43..010bb260f474ebf0d9c61e5edfe4cbfe7faa231f 100644
--- a/base/profiler/stack_sampling_profiler_unittest.cc
+++ b/base/profiler/stack_sampling_profiler_unittest.cc
@@ -316,19 +316,48 @@ void SynchronousUnloadNativeLibrary(NativeLibrary library) {
}
// Called on the profiler thread when complete, to collect profiles.
-void SaveProfiles(CallStackProfiles* profiles,
- CallStackProfiles pending_profiles) {
+bool SaveProfiles(CallStackProfiles* profiles,
+ CallStackProfiles pending_profiles,
+ StackSamplingProfiler::SamplingParams* sampling_params) {
*profiles = std::move(pending_profiles);
+ return false;
}
// 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) {
+bool SaveProfilesAndSignalEvent(
+ CallStackProfiles* profiles,
+ WaitableEvent* event,
+ CallStackProfiles pending_profiles,
+ StackSamplingProfiler::SamplingParams* sampling_params) {
*profiles = std::move(pending_profiles);
event->Signal();
+ return false;
+}
+
+// Similar to SaveProfilesAndSignalEvent(), but will schedule a second
+// collection after the first call back.
+bool SaveProfilesAndReschedule(
+ std::vector<CallStackProfiles>* profiles,
+ WaitableEvent* event,
+ CallStackProfiles pending_profiles,
+ StackSamplingProfiler::SamplingParams* sampling_params) {
+ profiles->push_back(std::move(pending_profiles));
+
+ event->Signal();
+ event->Reset();
+
+ if (profiles->size() == 2)
+ return false;
+
+ sampling_params->initial_delay = base::TimeDelta::FromSeconds(1);
+ 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);
+ return true;
}
// Executes the function with the target thread running and executing within
@@ -1062,6 +1091,34 @@ TEST_F(StackSamplingProfilerTest, MAYBE_CanRunMultipleTimes) {
});
}
+TEST_F(StackSamplingProfilerTest, RescheduledByCallback) {
Alexei Svitkine (slow) 2017/06/20 20:57:39 Note: I'll need to rebase this on my other CL.
+ 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.
+ profiler.Start();
+ sampling_completed.Wait();
+ ASSERT_EQ(1u, profiles.size());
+ ASSERT_EQ(1u, profiles[0].size());
+
+ // Now, wait for the second callback call.
+ sampling_completed.Wait();
+ profiler.Stop();
+ ASSERT_EQ(2u, profiles.size());
+ ASSERT_EQ(1u, profiles[1].size());
+ });
+}
+
// Checks that the different profilers may be run.
#if defined(STACK_SAMPLING_PROFILER_SUPPORTED)
#define MAYBE_CanRunMultipleProfilers CanRunMultipleProfilers

Powered by Google App Engine
This is Rietveld 408576698