diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-06-18 14:10:49 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2015-06-18 13:53:24 +0000 |
commit | 813fbf95af77a531c57a8c497345ad2c61d475b3 (patch) | |
tree | 821b2c8de8365f21b6c9ba17a236fb3006a1d506 /chromium/components/tracing | |
parent | af6588f8d723931a298c995fa97259bb7f7deb55 (diff) | |
download | qtwebengine-chromium-813fbf95af77a531c57a8c497345ad2c61d475b3.tar.gz |
BASELINE: Update chromium to 44.0.2403.47
Change-Id: Ie056fedba95cf5e5c76b30c4b2c80fca4764aa2f
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'chromium/components/tracing')
6 files changed, 269 insertions, 22 deletions
diff --git a/chromium/components/tracing/BUILD.gn b/chromium/components/tracing/BUILD.gn index c2e05190ad6..5771d93c4c6 100644 --- a/chromium/components/tracing/BUILD.gn +++ b/chromium/components/tracing/BUILD.gn @@ -4,6 +4,8 @@ source_set("tracing") { sources = [ + "child_memory_dump_manager_delegate_impl.cc", + "child_memory_dump_manager_delegate_impl.h", "child_trace_message_filter.cc", "child_trace_message_filter.h", "tracing_messages.cc", diff --git a/chromium/components/tracing/child_memory_dump_manager_delegate_impl.cc b/chromium/components/tracing/child_memory_dump_manager_delegate_impl.cc new file mode 100644 index 00000000000..f8048d96716 --- /dev/null +++ b/chromium/components/tracing/child_memory_dump_manager_delegate_impl.cc @@ -0,0 +1,75 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/tracing/child_memory_dump_manager_delegate_impl.h" + +#include "base/single_thread_task_runner.h" +#include "components/tracing/child_trace_message_filter.h" + +namespace tracing { + +// static +ChildMemoryDumpManagerDelegateImpl* +ChildMemoryDumpManagerDelegateImpl::GetInstance() { + return Singleton< + ChildMemoryDumpManagerDelegateImpl, + LeakySingletonTraits<ChildMemoryDumpManagerDelegateImpl>>::get(); +} + +ChildMemoryDumpManagerDelegateImpl::ChildMemoryDumpManagerDelegateImpl() + : ctmf_(nullptr) { + base::trace_event::MemoryDumpManager::GetInstance()->SetDelegate(this); +} + +ChildMemoryDumpManagerDelegateImpl::~ChildMemoryDumpManagerDelegateImpl() { +} + +void ChildMemoryDumpManagerDelegateImpl::SetChildTraceMessageFilter( + ChildTraceMessageFilter* ctmf) { + // Check that we are either registering the CTMF or tearing it down, but not + // replacing a valid instance with another one (should never happen). + DCHECK(ctmf_ == nullptr || (ctmf == nullptr && ctmf_task_runner_ != nullptr)); + ctmf_ = ctmf; + ctmf_task_runner_ = ctmf ? (ctmf->ipc_message_loop()) : nullptr; +} + +// Invoked in child processes by the MemoryDumpManager. +void ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( + const base::trace_event::MemoryDumpRequestArgs& args, + const base::trace_event::MemoryDumpCallback& callback) { + // Bail out if we receive a dump request from the manager before the + // ChildTraceMessageFilter has been initialized. + if (!ctmf_task_runner_) { + if (!callback.is_null()) + callback.Run(args.dump_guid, false /* success */); + return; + } + + // Make sure we access |ctmf_| only on the thread where it lives to avoid + // races on shutdown. + if (!ctmf_task_runner_->BelongsToCurrentThread()) { + ctmf_task_runner_->PostTask( + FROM_HERE, + base::Bind(&ChildMemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump, + base::Unretained(this), args, callback)); + return; + } + + // The ChildTraceMessageFilter could have been destroyed while hopping on the + // right thread. If this is the case, bail out. + if (!ctmf_) { + if (!callback.is_null()) + callback.Run(args.dump_guid, false /* success */); + return; + } + + // Send the request up to the browser process' MessageDumpmanager. + ctmf_->SendGlobalMemoryDumpRequest(args, callback); +} + +bool ChildMemoryDumpManagerDelegateImpl::IsCoordinatorProcess() const { + return false; +} + +} // namespace tracing diff --git a/chromium/components/tracing/child_memory_dump_manager_delegate_impl.h b/chromium/components/tracing/child_memory_dump_manager_delegate_impl.h new file mode 100644 index 00000000000..912815dd018 --- /dev/null +++ b/chromium/components/tracing/child_memory_dump_manager_delegate_impl.h @@ -0,0 +1,61 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ +#define COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ + +#include "base/trace_event/memory_dump_manager.h" + +#include "base/memory/ref_counted.h" +#include "base/memory/singleton.h" + +namespace base { +class SingleThreadTaskRunner; +} // namespace base + +namespace tracing { + +class ChildTraceMessageFilter; + +// This class is a simple proxy class between the MemoryDumpManager and the +// ChildTraceMessageFilter. It's only purpose is to adapt the lifetime of +// CTMF to the demands of MDM, which expects the delegate to be thread-safe +// and long lived. CTMF, instead, can be torn down during browser shutdown. +// This class is registered as MDM delegate in child processes and handles +// gracefully (and thread-safely) failures in the case of a lack of the CTMF. +class ChildMemoryDumpManagerDelegateImpl + : public base::trace_event::MemoryDumpManagerDelegate { + public: + static ChildMemoryDumpManagerDelegateImpl* GetInstance(); + + // base::trace_event::MemoryDumpManagerDelegate implementation. + void RequestGlobalMemoryDump( + const base::trace_event::MemoryDumpRequestArgs& args, + const base::trace_event::MemoryDumpCallback& callback) override; + bool IsCoordinatorProcess() const override; + + void SetChildTraceMessageFilter(ChildTraceMessageFilter* ctmf); + + protected: + // Make CreateProcessDump() visible to ChildTraceMessageFilter. + friend class ChildTraceMessageFilter; + + private: + friend struct DefaultSingletonTraits<ChildMemoryDumpManagerDelegateImpl>; + + ChildMemoryDumpManagerDelegateImpl(); + ~ChildMemoryDumpManagerDelegateImpl() override; + + ChildTraceMessageFilter* ctmf_; // Not owned. + + // The SingleThreadTaskRunner where the |ctmf_| lives. + // It is NULL iff |cmtf_| is NULL. + scoped_refptr<base::SingleThreadTaskRunner> ctmf_task_runner_; + + DISALLOW_COPY_AND_ASSIGN(ChildMemoryDumpManagerDelegateImpl); +}; + +} // namespace tracing + +#endif // COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ diff --git a/chromium/components/tracing/child_trace_message_filter.cc b/chromium/components/tracing/child_trace_message_filter.cc index fe13ff57dd0..3dd1223d643 100644 --- a/chromium/components/tracing/child_trace_message_filter.cc +++ b/chromium/components/tracing/child_trace_message_filter.cc @@ -4,26 +4,33 @@ #include "components/tracing/child_trace_message_filter.h" -#include "base/debug/trace_event.h" #include "base/message_loop/message_loop_proxy.h" +#include "base/trace_event/trace_event.h" +#include "components/tracing/child_memory_dump_manager_delegate_impl.h" #include "components/tracing/tracing_messages.h" #include "ipc/ipc_channel.h" -using base::debug::TraceLog; +using base::trace_event::TraceLog; namespace tracing { ChildTraceMessageFilter::ChildTraceMessageFilter( base::MessageLoopProxy* ipc_message_loop) : sender_(NULL), - ipc_message_loop_(ipc_message_loop) {} + ipc_message_loop_(ipc_message_loop), + pending_memory_dump_guid_(0) { +} void ChildTraceMessageFilter::OnFilterAdded(IPC::Sender* sender) { sender_ = sender; sender_->Send(new TracingHostMsg_ChildSupportsTracing()); + ChildMemoryDumpManagerDelegateImpl::GetInstance()->SetChildTraceMessageFilter( + this); } void ChildTraceMessageFilter::OnFilterRemoved() { + ChildMemoryDumpManagerDelegateImpl::GetInstance()->SetChildTraceMessageFilter( + nullptr); sender_ = NULL; } @@ -36,10 +43,13 @@ bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(TracingMsg_DisableMonitoring, OnDisableMonitoring) IPC_MESSAGE_HANDLER(TracingMsg_CaptureMonitoringSnapshot, OnCaptureMonitoringSnapshot) - IPC_MESSAGE_HANDLER(TracingMsg_GetTraceBufferPercentFull, - OnGetTraceBufferPercentFull) + IPC_MESSAGE_HANDLER(TracingMsg_GetTraceLogStatus, OnGetTraceLogStatus) IPC_MESSAGE_HANDLER(TracingMsg_SetWatchEvent, OnSetWatchEvent) IPC_MESSAGE_HANDLER(TracingMsg_CancelWatchEvent, OnCancelWatchEvent) + IPC_MESSAGE_HANDLER(TracingMsg_ProcessMemoryDumpRequest, + OnProcessMemoryDumpRequest) + IPC_MESSAGE_HANDLER(TracingMsg_GlobalMemoryDumpResponse, + OnGlobalMemoryDumpResponse) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -59,11 +69,11 @@ void ChildTraceMessageFilter::OnBeginTracing( browser_time; TraceLog::GetInstance()->SetTimeOffset(time_offset); #endif - base::debug::TraceOptions trace_options; + base::trace_event::TraceOptions trace_options; trace_options.SetFromString(options); TraceLog::GetInstance()->SetEnabled( - base::debug::CategoryFilter(category_filter_str), - base::debug::TraceLog::RECORDING_MODE, + base::trace_event::CategoryFilter(category_filter_str), + base::trace_event::TraceLog::RECORDING_MODE, trace_options); } @@ -82,11 +92,11 @@ void ChildTraceMessageFilter::OnEnableMonitoring( const std::string& category_filter_str, base::TimeTicks browser_time, const std::string& options) { - base::debug::TraceOptions trace_options; + base::trace_event::TraceOptions trace_options; trace_options.SetFromString(options); TraceLog::GetInstance()->SetEnabled( - base::debug::CategoryFilter(category_filter_str), - base::debug::TraceLog::MONITORING_MODE, + base::trace_event::CategoryFilter(category_filter_str), + base::trace_event::TraceLog::MONITORING_MODE, trace_options); } @@ -105,10 +115,9 @@ void ChildTraceMessageFilter::OnCaptureMonitoringSnapshot() { this)); } -void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() { - float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); - - sender_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf)); +void ChildTraceMessageFilter::OnGetTraceLogStatus() { + sender_->Send(new TracingHostMsg_TraceLogStatusReply( + TraceLog::GetInstance()->GetStatus())); } void ChildTraceMessageFilter::OnSetWatchEvent(const std::string& category_name, @@ -170,4 +179,50 @@ void ChildTraceMessageFilter::OnMonitoringTraceDataCollected( sender_->Send(new TracingHostMsg_CaptureMonitoringSnapshotAck()); } +// Sent by the Browser's MemoryDumpManager when coordinating a global dump. +void ChildTraceMessageFilter::OnProcessMemoryDumpRequest( + const base::trace_event::MemoryDumpRequestArgs& args) { + ChildMemoryDumpManagerDelegateImpl::GetInstance()->CreateProcessDump( + args, + base::Bind(&ChildTraceMessageFilter::OnProcessMemoryDumpDone, this)); +} + +void ChildTraceMessageFilter::OnProcessMemoryDumpDone(uint64 dump_guid, + bool success) { + sender_->Send( + new TracingHostMsg_ProcessMemoryDumpResponse(dump_guid, success)); +} + +// Initiates a dump request, asking the Browser's MemoryDumpManager to +// coordinate a global memory dump. The Browser's MDM will answer back with a +// MemoryDumpResponse when all the child processes (including this one) have +// dumped, or with a NACK (|success| == false) if the dump failed (e.g., due to +// a collision with a concurrent request from another child process). +void ChildTraceMessageFilter::SendGlobalMemoryDumpRequest( + const base::trace_event::MemoryDumpRequestArgs& args, + const base::trace_event::MemoryDumpCallback& callback) { + // If there is already another dump request pending from this child process, + // there is no point bothering the Browser's MemoryDumpManager. + if (pending_memory_dump_guid_) { + if (!callback.is_null()) + callback.Run(args.dump_guid, false); + return; + } + + pending_memory_dump_guid_ = args.dump_guid; + pending_memory_dump_callback_ = callback; + sender_->Send(new TracingHostMsg_GlobalMemoryDumpRequest(args)); +} + +// Sent by the Browser's MemoryDumpManager in response of a dump request +// initiated by this child process. +void ChildTraceMessageFilter::OnGlobalMemoryDumpResponse(uint64 dump_guid, + bool success) { + DCHECK_NE(0U, pending_memory_dump_guid_); + pending_memory_dump_guid_ = 0; + if (pending_memory_dump_callback_.is_null()) + return; + pending_memory_dump_callback_.Run(dump_guid, success); +} + } // namespace tracing diff --git a/chromium/components/tracing/child_trace_message_filter.h b/chromium/components/tracing/child_trace_message_filter.h index daa00ee3bda..a6453a3e640 100644 --- a/chromium/components/tracing/child_trace_message_filter.h +++ b/chromium/components/tracing/child_trace_message_filter.h @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/memory/ref_counted_memory.h" +#include "base/trace_event/memory_dump_request_args.h" #include "ipc/message_filter.h" namespace base { @@ -25,6 +26,12 @@ class ChildTraceMessageFilter : public IPC::MessageFilter { void OnFilterRemoved() override; bool OnMessageReceived(const IPC::Message& message) override; + void SendGlobalMemoryDumpRequest( + const base::trace_event::MemoryDumpRequestArgs& args, + const base::trace_event::MemoryDumpCallback& callback); + + base::MessageLoopProxy* ipc_message_loop() const { return ipc_message_loop_; } + protected: ~ChildTraceMessageFilter() override; @@ -39,11 +46,14 @@ class ChildTraceMessageFilter : public IPC::MessageFilter { const std::string& options); void OnDisableMonitoring(); void OnCaptureMonitoringSnapshot(); - void OnGetTraceBufferPercentFull(); + void OnGetTraceLogStatus(); void OnSetWatchEvent(const std::string& category_name, const std::string& event_name); void OnCancelWatchEvent(); void OnWatchEventMatched(); + void OnProcessMemoryDumpRequest( + const base::trace_event::MemoryDumpRequestArgs& args); + void OnGlobalMemoryDumpResponse(uint64 dump_guid, bool success); // Callback from trace subsystem. void OnTraceDataCollected( @@ -54,9 +64,18 @@ class ChildTraceMessageFilter : public IPC::MessageFilter { const scoped_refptr<base::RefCountedString>& events_str_ptr, bool has_more_events); + void OnProcessMemoryDumpDone(uint64 dump_guid, bool success); + IPC::Sender* sender_; base::MessageLoopProxy* ipc_message_loop_; + // guid of the outstanding request (to the Browser's MemoryDumpManager), if + // any. 0 if there is no request pending. + uint64 pending_memory_dump_guid_; + + // callback of the outstanding memory dump request, if any. + base::trace_event::MemoryDumpCallback pending_memory_dump_callback_; + DISALLOW_COPY_AND_ASSIGN(ChildTraceMessageFilter); }; diff --git a/chromium/components/tracing/tracing_messages.h b/chromium/components/tracing/tracing_messages.h index ff891a0edaa..d9ba630fc5c 100644 --- a/chromium/components/tracing/tracing_messages.h +++ b/chromium/components/tracing/tracing_messages.h @@ -8,6 +8,8 @@ #include "base/basictypes.h" #include "base/sync_socket.h" +#include "base/trace_event/memory_dump_request_args.h" +#include "base/trace_event/trace_event_impl.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" @@ -15,11 +17,25 @@ #define IPC_MESSAGE_START TracingMsgStart +IPC_STRUCT_TRAITS_BEGIN(base::trace_event::TraceLogStatus) +IPC_STRUCT_TRAITS_MEMBER(event_capacity) +IPC_STRUCT_TRAITS_MEMBER(event_count) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(base::trace_event::MemoryDumpRequestArgs) +IPC_STRUCT_TRAITS_MEMBER(dump_guid) +IPC_STRUCT_TRAITS_MEMBER(dump_type) +IPC_STRUCT_TRAITS_END() + +IPC_ENUM_TRAITS_MAX_VALUE( + base::trace_event::MemoryDumpType, + static_cast<int>(base::trace_event::MemoryDumpType::LAST)) + // Sent to all child processes to enable trace event recording. IPC_MESSAGE_CONTROL3(TracingMsg_BeginTracing, std::string /* category_filter_str */, base::TimeTicks /* browser_time */, - std::string /* base::debug::TraceOptions */) + std::string /* base::trace_event::TraceOptions */) // Sent to all child processes to disable trace event recording. IPC_MESSAGE_CONTROL0(TracingMsg_EndTracing) @@ -28,7 +44,7 @@ IPC_MESSAGE_CONTROL0(TracingMsg_EndTracing) IPC_MESSAGE_CONTROL3(TracingMsg_EnableMonitoring, std::string /* category_filter_str */, base::TimeTicks /* browser_time */, - std::string /* base::debug::TraceOptions */) + std::string /* base::trace_event::TraceOptions */) // Sent to all child processes to stop monitoring. IPC_MESSAGE_CONTROL0(TracingMsg_DisableMonitoring) @@ -37,7 +53,7 @@ IPC_MESSAGE_CONTROL0(TracingMsg_DisableMonitoring) IPC_MESSAGE_CONTROL0(TracingMsg_CaptureMonitoringSnapshot) // Sent to all child processes to get trace buffer fullness. -IPC_MESSAGE_CONTROL0(TracingMsg_GetTraceBufferPercentFull) +IPC_MESSAGE_CONTROL0(TracingMsg_GetTraceLogStatus) // Sent to all child processes to set watch event. IPC_MESSAGE_CONTROL2(TracingMsg_SetWatchEvent, @@ -47,6 +63,16 @@ IPC_MESSAGE_CONTROL2(TracingMsg_SetWatchEvent, // Sent to all child processes to clear watch event. IPC_MESSAGE_CONTROL0(TracingMsg_CancelWatchEvent) +// Sent to all child processes to request a local (current process) memory dump. +IPC_MESSAGE_CONTROL1(TracingMsg_ProcessMemoryDumpRequest, + base::trace_event::MemoryDumpRequestArgs) + +// Reply to TracingHostMsg_GlobalMemoryDumpRequest, sent by the browser process. +// This is to get the result of a global dump initiated by a child process. +IPC_MESSAGE_CONTROL2(TracingMsg_GlobalMemoryDumpResponse, + uint64 /* dump_guid */, + bool /* success */) + // Sent everytime when a watch event is matched. IPC_MESSAGE_CONTROL0(TracingHostMsg_WatchEventMatched) @@ -69,7 +95,16 @@ IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceDataCollected, IPC_MESSAGE_CONTROL1(TracingHostMsg_MonitoringTraceDataCollected, std::string /*json trace data*/) -// Reply to TracingMsg_GetTraceBufferPercentFull. -IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceBufferPercentFullReply, - float /*trace buffer percent full*/) +// Reply to TracingMsg_GetTraceLogStatus. +IPC_MESSAGE_CONTROL1( + TracingHostMsg_TraceLogStatusReply, + base::trace_event::TraceLogStatus /*status of the trace log*/) + +// Sent to the browser to initiate a global memory dump from a child process. +IPC_MESSAGE_CONTROL1(TracingHostMsg_GlobalMemoryDumpRequest, + base::trace_event::MemoryDumpRequestArgs) +// Reply to TracingMsg_ProcessMemoryDumpRequest. +IPC_MESSAGE_CONTROL2(TracingHostMsg_ProcessMemoryDumpResponse, + uint64 /* dump_guid */, + bool /* success */) |