diff options
author | primiano <primiano@chromium.org> | 2015-11-02 09:29:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-02 17:30:27 +0000 |
commit | f0dfbf833838e2e0209b998dac2f4333d729ceef (patch) | |
tree | 72b8a1899a779947b0f5e5d8a5fe4fdb56698c9d /components | |
parent | 4d792fca0847afa0b5b406154ad2da91a83f50e4 (diff) | |
download | chromium_src-f0dfbf833838e2e0209b998dac2f4333d729ceef.zip chromium_src-f0dfbf833838e2e0209b998dac2f4333d729ceef.tar.gz chromium_src-f0dfbf833838e2e0209b998dac2f4333d729ceef.tar.bz2 |
[tracing] Move memory-infra dumps to dedicated thread
After the CL the memory dump providers which don't specify a
task_runner affinity are invoked on a dedicate thread.
This is to avoid janking the main thread when tracing using
memory-infra.
Also, this CL ensures that the unbound dumpers are always
executed last (when the preemption of the other dumpers
with thread-affinity is over)
BUG=547765
Review URL: https://codereview.chromium.org/1427963002
Cr-Commit-Position: refs/heads/master@{#357377}
Diffstat (limited to 'components')
-rw-r--r-- | components/tracing/child_trace_message_filter_browsertest.cc | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/components/tracing/child_trace_message_filter_browsertest.cc b/components/tracing/child_trace_message_filter_browsertest.cc index a87e976..72eb8a1 100644 --- a/components/tracing/child_trace_message_filter_browsertest.cc +++ b/components/tracing/child_trace_message_filter_browsertest.cc @@ -33,7 +33,7 @@ class MockDumpProvider : public base::trace_event::MemoryDumpProvider { base::trace_event::ProcessMemoryDump* pmd)); }; -class ChildTracingTest : public content::RenderViewTest { +class ChildTracingTest : public content::RenderViewTest, public IPC::Listener { public: // Used as callback argument for MemoryDumpManager::RequestGlobalDump(): void OnMemoryDumpCallback(uint64 dump_guid, bool status) { @@ -59,18 +59,24 @@ class ChildTracingTest : public content::RenderViewTest { callback_call_count_ = 0; last_callback_dump_guid_ = 0; last_callback_status_ = false; + wait_for_ipc_message_type_ = 0; callback_ = base::Bind(&ChildTracingTest::OnMemoryDumpCallback, base::Unretained(this)); task_runner_ = base::ThreadTaskRunnerHandle::Get(); ctmf_ = make_scoped_refptr(new ChildTraceMessageFilter(task_runner_.get())); render_thread_->AddFilter(ctmf_.get()); + // Add a filter to the TestSink which allows to WaitForIPCMessage() by + // posting a nested RunLoop closure when a given IPC Message is seen. + render_thread_->sink().AddFilter(this); + // Getting an instance of |ChildMemoryDumpManagerDelegateImpl| calls // |MemoryDumpManager::Initialize| with the correct delegate. ChildMemoryDumpManagerDelegateImpl::GetInstance(); } void TearDown() override { + render_thread_->sink().RemoveFilter(this); RenderViewTest::TearDown(); MemoryDumpManager::GetInstance()->UnregisterDumpProvider( mock_dump_provider_.get()); @@ -79,6 +85,26 @@ class ChildTracingTest : public content::RenderViewTest { task_runner_ = nullptr; } + // IPC::Filter implementation. + bool OnMessageReceived(const IPC::Message& message) override { + if (message.type() == wait_for_ipc_message_type_) { + DCHECK(!wait_for_ipc_closure_.is_null()); + task_runner_->PostTask(FROM_HERE, wait_for_ipc_closure_); + } + // Always propagate messages to the sink, never consume them here. + return false; + } + + const IPC::Message* WaitForIPCMessage(uint32_t message_type) { + base::RunLoop run_loop; + wait_for_ipc_message_type_ = message_type; + wait_for_ipc_closure_ = run_loop.QuitClosure(); + run_loop.Run(); + wait_for_ipc_message_type_ = 0; + wait_for_ipc_closure_.Reset(); + return render_thread_->sink().GetUniqueMessageMatching(message_type); + } + // Simulates a synthetic browser -> child (this process) IPC message. void SimulateSyntheticMessageFromBrowser(const IPC::Message& msg) { task_runner_->PostTask( @@ -107,8 +133,8 @@ class ChildTracingTest : public content::RenderViewTest { {dump_guid, MemoryDumpType::EXPLICITLY_TRIGGERED})); // Check that a child -> browser response to the local dump request is sent. - const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( - TracingHostMsg_ProcessMemoryDumpResponse::ID); + const IPC::Message* msg = + WaitForIPCMessage(TracingHostMsg_ProcessMemoryDumpResponse::ID); EXPECT_NE(nullptr, msg); // Check that the |dump_guid| and the |sucess| fields are properly set. @@ -138,6 +164,8 @@ class ChildTracingTest : public content::RenderViewTest { scoped_ptr<MockDumpProvider> mock_dump_provider_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_; base::trace_event::MemoryDumpCallback callback_; + uint32_t wait_for_ipc_message_type_; + base::Closure wait_for_ipc_closure_; uint32 callback_call_count_; uint64 last_callback_dump_guid_; bool last_callback_status_; |