diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-13 00:39:26 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-13 00:39:26 +0000 |
commit | 1cb05dbbcafd3f35999606af6c8316058ce7b93a (patch) | |
tree | dfa6794b8a9c83a91d4c1bb487ab7551e3514fe3 /content | |
parent | 543f27572597201d5fae77066c9146a6a87d41d8 (diff) | |
download | chromium_src-1cb05dbbcafd3f35999606af6c8316058ce7b93a.zip chromium_src-1cb05dbbcafd3f35999606af6c8316058ce7b93a.tar.gz chromium_src-1cb05dbbcafd3f35999606af6c8316058ce7b93a.tar.bz2 |
[UMA] Use proper C++ objects to serialize tracked_objects across process boundaries.
See https://chromiumcodereview.appspot.com/9702014/ for the original code review. Uploading to a new issue due to an AppEngine error...
BUG=103480
TEST=none (refactoring, no functional change expected)
TBR=jam@chromium.org,jar@chromium.org,eroman@chromium.org,jhawkins@chromium.org,ajwong@chromium.org
Review URL: http://codereview.chromium.org/10077001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132109 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/browser_child_process_host_impl.cc | 2 | ||||
-rw-r--r-- | content/browser/profiler_controller_impl.cc | 59 | ||||
-rw-r--r-- | content/browser/profiler_controller_impl.h | 34 | ||||
-rw-r--r-- | content/browser/profiler_message_filter.cc | 18 | ||||
-rw-r--r-- | content/browser/profiler_message_filter.h | 23 | ||||
-rw-r--r-- | content/browser/renderer_host/render_process_host_impl.cc | 3 | ||||
-rw-r--r-- | content/common/child_process_messages.h | 47 | ||||
-rw-r--r-- | content/common/child_thread.cc | 22 | ||||
-rw-r--r-- | content/common/child_thread.h | 3 | ||||
-rw-r--r-- | content/public/browser/profiler_controller.h | 8 | ||||
-rw-r--r-- | content/public/browser/profiler_subscriber.h | 16 |
11 files changed, 121 insertions, 114 deletions
diff --git a/content/browser/browser_child_process_host_impl.cc b/content/browser/browser_child_process_host_impl.cc index 21b2139..23a0079 100644 --- a/content/browser/browser_child_process_host_impl.cc +++ b/content/browser/browser_child_process_host_impl.cc @@ -90,7 +90,7 @@ BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( child_process_host_.reset(ChildProcessHost::Create(this)); child_process_host_->AddFilter(new TraceMessageFilter); - child_process_host_->AddFilter(new ProfilerMessageFilter); + child_process_host_->AddFilter(new content::ProfilerMessageFilter(type)); g_child_process_list.Get().push_back(this); content::GetContentClient()->browser()->BrowserChildProcessHostCreated(this); diff --git a/content/browser/profiler_controller_impl.cc b/content/browser/profiler_controller_impl.cc index b3e40e8..a850cfd 100644 --- a/content/browser/profiler_controller_impl.cc +++ b/content/browser/profiler_controller_impl.cc @@ -5,14 +5,13 @@ #include "content/browser/profiler_controller_impl.h" #include "base/bind.h" -#include "base/values.h" +#include "base/tracked_objects.h" #include "content/common/child_process_messages.h" #include "content/public/browser/browser_child_process_host_iterator.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_data.h" #include "content/public/browser/profiler_subscriber.h" #include "content/public/browser/render_process_host.h" -#include "content/public/common/process_type.h" using content::BrowserChildProcessHostIterator; using content::BrowserThread; @@ -43,20 +42,24 @@ void ProfilerControllerImpl::OnPendingProcesses(int sequence_number, void ProfilerControllerImpl::OnProfilerDataCollected( int sequence_number, - base::DictionaryValue* profiler_data) { + const tracked_objects::ProcessDataSnapshot& profiler_data, + content::ProcessType process_type) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&ProfilerControllerImpl::OnProfilerDataCollected, base::Unretained(this), sequence_number, - profiler_data)); + profiler_data, + process_type)); return; } DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (subscriber_) - subscriber_->OnProfilerDataCollected(sequence_number, profiler_data); + if (subscriber_) { + subscriber_->OnProfilerDataCollected(sequence_number, profiler_data, + process_type); + } } void ProfilerControllerImpl::Register(ProfilerSubscriber* subscriber) { @@ -65,9 +68,9 @@ void ProfilerControllerImpl::Register(ProfilerSubscriber* subscriber) { subscriber_ = subscriber; } -void ProfilerControllerImpl::Unregister(ProfilerSubscriber* subscriber) { - if (subscriber == subscriber_) - subscriber_ = NULL; +void ProfilerControllerImpl::Unregister(const ProfilerSubscriber* subscriber) { + DCHECK_EQ(subscriber_, subscriber); + subscriber_ = NULL; } void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( @@ -76,13 +79,9 @@ void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( int pending_processes = 0; for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { - const std::string process_type = - content::GetProcessTypeNameInEnglish(iter.GetData().type); ++pending_processes; - if (!iter.Send(new ChildProcessMsg_GetChildProfilerData( - sequence_number, process_type))) { + if (!iter.Send(new ChildProcessMsg_GetChildProfilerData(sequence_number))) --pending_processes; - } } BrowserThread::PostTask( @@ -100,14 +99,11 @@ void ProfilerControllerImpl::GetProfilerData(int sequence_number) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); int pending_processes = 0; - const std::string render_process_type = - content::GetProcessTypeNameInEnglish(content::PROCESS_TYPE_RENDERER); - for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); !it.IsAtEnd(); it.Advance()) { ++pending_processes; - if (!it.GetCurrentValue()->Send(new ChildProcessMsg_GetChildProfilerData( - sequence_number, render_process_type))) { + if (!it.GetCurrentValue()->Send( + new ChildProcessMsg_GetChildProfilerData(sequence_number))) { --pending_processes; } } @@ -121,29 +117,4 @@ void ProfilerControllerImpl::GetProfilerData(int sequence_number) { sequence_number)); } -void ProfilerControllerImpl::SetProfilerStatusInChildProcesses( - tracked_objects::ThreadData::Status status) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) - iter.Send(new ChildProcessMsg_SetProfilerStatus(status)); -} - -void ProfilerControllerImpl::SetProfilerStatus( - tracked_objects::ThreadData::Status status) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - base::Bind(&ProfilerControllerImpl::SetProfilerStatusInChildProcesses, - base::Unretained(this), - status)); - - for (content::RenderProcessHost::iterator it( - content::RenderProcessHost::AllHostsIterator()); - !it.IsAtEnd(); it.Advance()) { - it.GetCurrentValue()->Send(new ChildProcessMsg_SetProfilerStatus(status)); - } -} } // namespace content diff --git a/content/browser/profiler_controller_impl.h b/content/browser/profiler_controller_impl.h index ff361ea..13f9c33 100644 --- a/content/browser/profiler_controller_impl.h +++ b/content/browser/profiler_controller_impl.h @@ -6,14 +6,18 @@ #define CONTENT_BROWSER_PROFILER_CONTROLLER_IMPL_H_ #include "base/memory/singleton.h" -#include "base/tracked_objects.h" #include "content/common/content_export.h" #include "content/public/browser/profiler_controller.h" +#include "content/public/common/process_type.h" + +namespace tracked_objects { +struct ProcessDataSnapshot; +} namespace content { // ProfilerController's implementation. -class CONTENT_EXPORT ProfilerControllerImpl : public ProfilerController { +class ProfilerControllerImpl : public ProfilerController { public: static ProfilerControllerImpl* GetInstance(); @@ -22,21 +26,24 @@ class CONTENT_EXPORT ProfilerControllerImpl : public ProfilerController { ProfilerControllerImpl(); virtual ~ProfilerControllerImpl(); - // Send number of pending processes to subscriber_. |end| is set to true if it - // is the last time. This is called on UI thread. + // Notify the |subscriber_| that it should expect at least |pending_processes| + // additional calls to OnProfilerDataCollected(). OnPendingProcess() may be + // called repeatedly; the last call will have |end| set to true, indicating + // that there is no longer a possibility for the count of pending processes to + // increase. This is called on the UI thread. void OnPendingProcesses(int sequence_number, int pending_processes, bool end); - // Send profiler_data back to subscriber_. subscriber_ assumes the ownership - // of profiler_data. This is called on UI thread. - void OnProfilerDataCollected(int sequence_number, - base::DictionaryValue* profiler_data); + // Send the |profiler_data| back to the |subscriber_|. + // This is called on the UI thread. + void OnProfilerDataCollected( + int sequence_number, + const tracked_objects::ProcessDataSnapshot& profiler_data, + content::ProcessType process_type); // ProfilerController implementation: virtual void Register(ProfilerSubscriber* subscriber) OVERRIDE; - virtual void Unregister(ProfilerSubscriber* subscriber) OVERRIDE; + virtual void Unregister(const ProfilerSubscriber* subscriber) OVERRIDE; virtual void GetProfilerData(int sequence_number) OVERRIDE; - virtual void SetProfilerStatus( - tracked_objects::ThreadData::Status status) OVERRIDE; private: friend struct DefaultSingletonTraits<ProfilerControllerImpl>; @@ -44,10 +51,6 @@ class CONTENT_EXPORT ProfilerControllerImpl : public ProfilerController { // Contact child processes and get their profiler data. void GetProfilerDataFromChildProcesses(int sequence_number); - // Contact child processes and set profiler status to |enable|. - void SetProfilerStatusInChildProcesses( - tracked_objects::ThreadData::Status status); - ProfilerSubscriber* subscriber_; DISALLOW_COPY_AND_ASSIGN(ProfilerControllerImpl); @@ -56,4 +59,3 @@ class CONTENT_EXPORT ProfilerControllerImpl : public ProfilerController { } // namespace content #endif // CONTENT_BROWSER_PROFILER_CONTROLLER_IMPL_H_ - diff --git a/content/browser/profiler_message_filter.cc b/content/browser/profiler_message_filter.cc index e0f5979..d94c7d1 100644 --- a/content/browser/profiler_message_filter.cc +++ b/content/browser/profiler_message_filter.cc @@ -5,14 +5,13 @@ #include "content/browser/profiler_message_filter.h" #include "base/tracked_objects.h" -#include "base/values.h" #include "content/browser/profiler_controller_impl.h" #include "content/common/child_process_messages.h" -using content::BrowserMessageFilter; -using content::BrowserThread; +namespace content { -ProfilerMessageFilter::ProfilerMessageFilter() { +ProfilerMessageFilter::ProfilerMessageFilter(ProcessType process_type) + : process_type_(process_type) { } ProfilerMessageFilter::~ProfilerMessageFilter() { @@ -39,10 +38,9 @@ bool ProfilerMessageFilter::OnMessageReceived(const IPC::Message& message, void ProfilerMessageFilter::OnChildProfilerData( int sequence_number, - const base::DictionaryValue& profiler_data) { - base::DictionaryValue* dictionary_value = new base::DictionaryValue; - dictionary_value->MergeDictionary(&profiler_data); - // OnProfilerDataCollected assumes the ownership of profiler_data. - content::ProfilerControllerImpl::GetInstance()->OnProfilerDataCollected( - sequence_number, dictionary_value); + const tracked_objects::ProcessDataSnapshot& profiler_data) { + ProfilerControllerImpl::GetInstance()->OnProfilerDataCollected( + sequence_number, profiler_data, process_type_); +} + } diff --git a/content/browser/profiler_message_filter.h b/content/browser/profiler_message_filter.h index 79e6e94..d403765 100644 --- a/content/browser/profiler_message_filter.h +++ b/content/browser/profiler_message_filter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -8,15 +8,18 @@ #include <string> #include "content/public/browser/browser_message_filter.h" +#include "content/public/common/process_type.h" -namespace base { -class DictionaryValue; +namespace tracked_objects { +struct ProcessDataSnapshot; } +namespace content { + // This class sends and receives profiler messages in the browser process. -class ProfilerMessageFilter : public content::BrowserMessageFilter { +class ProfilerMessageFilter : public BrowserMessageFilter { public: - ProfilerMessageFilter(); + explicit ProfilerMessageFilter(ProcessType process_type); virtual ~ProfilerMessageFilter(); // content::BrowserMessageFilter implementation. @@ -28,11 +31,15 @@ class ProfilerMessageFilter : public content::BrowserMessageFilter { private: // Message handlers. - void OnChildProfilerData(int sequence_number, - const base::DictionaryValue& profiler_data); + void OnChildProfilerData( + int sequence_number, + const tracked_objects::ProcessDataSnapshot& profiler_data); + + ProcessType process_type_; DISALLOW_COPY_AND_ASSIGN(ProfilerMessageFilter); }; -#endif // CONTENT_BROWSER_PROFILER_MESSAGE_FILTER_H_ +} // namespace content +#endif // CONTENT_BROWSER_PROFILER_MESSAGE_FILTER_H_ diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index e38a37f..0fae676 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -544,7 +544,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { content::BrowserContext::GetQuotaManager(browser_context), content::GetContentClient()->browser()->CreateQuotaPermissionContext())); channel_->AddFilter(new content::GamepadBrowserMessageFilter(this)); - channel_->AddFilter(new ProfilerMessageFilter()); + channel_->AddFilter(new content::ProfilerMessageFilter( + content::PROCESS_TYPE_RENDERER)); } int RenderProcessHostImpl::GetNextRoutingID() { diff --git a/content/common/child_process_messages.h b/content/common/child_process_messages.h index ab56be0..363c556 100644 --- a/content/common/child_process_messages.h +++ b/content/common/child_process_messages.h @@ -14,6 +14,44 @@ IPC_ENUM_TRAITS(tracked_objects::ThreadData::Status) +IPC_STRUCT_TRAITS_BEGIN(tracked_objects::LocationSnapshot) + IPC_STRUCT_TRAITS_MEMBER(file_name) + IPC_STRUCT_TRAITS_MEMBER(function_name) + IPC_STRUCT_TRAITS_MEMBER(line_number) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(tracked_objects::BirthOnThreadSnapshot) + IPC_STRUCT_TRAITS_MEMBER(location) + IPC_STRUCT_TRAITS_MEMBER(thread_name) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(tracked_objects::DeathDataSnapshot) + IPC_STRUCT_TRAITS_MEMBER(count) + IPC_STRUCT_TRAITS_MEMBER(run_duration_sum) + IPC_STRUCT_TRAITS_MEMBER(run_duration_max) + IPC_STRUCT_TRAITS_MEMBER(run_duration_sample) + IPC_STRUCT_TRAITS_MEMBER(queue_duration_sum) + IPC_STRUCT_TRAITS_MEMBER(queue_duration_max) + IPC_STRUCT_TRAITS_MEMBER(queue_duration_sample) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(tracked_objects::TaskSnapshot) + IPC_STRUCT_TRAITS_MEMBER(birth) + IPC_STRUCT_TRAITS_MEMBER(death_data) + IPC_STRUCT_TRAITS_MEMBER(death_thread_name) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(tracked_objects::ParentChildPairSnapshot) + IPC_STRUCT_TRAITS_MEMBER(parent) + IPC_STRUCT_TRAITS_MEMBER(child) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(tracked_objects::ProcessDataSnapshot) + IPC_STRUCT_TRAITS_MEMBER(tasks) + IPC_STRUCT_TRAITS_MEMBER(descendants) + IPC_STRUCT_TRAITS_MEMBER(process_id) +IPC_STRUCT_TRAITS_END() + #undef IPC_MESSAGE_EXPORT #define IPC_MESSAGE_EXPORT CONTENT_EXPORT @@ -48,9 +86,8 @@ IPC_MESSAGE_CONTROL1(ChildProcessMsg_SetProfilerStatus, // Send to all the child processes to send back profiler data (ThreadData in // tracked_objects). -IPC_MESSAGE_CONTROL2(ChildProcessMsg_GetChildProfilerData, - int, /* sequence number. */ - std::string /* pickled Value of process type. */) +IPC_MESSAGE_CONTROL1(ChildProcessMsg_GetChildProfilerData, + int /* sequence number */) // Sent to child processes to dump their handle table. IPC_MESSAGE_CONTROL0(ChildProcessMsg_DumpHandles) @@ -80,8 +117,8 @@ IPC_MESSAGE_CONTROL1(ChildProcessHostMsg_TraceBufferPercentFullReply, // Send back profiler data (ThreadData in tracked_objects). IPC_MESSAGE_CONTROL2(ChildProcessHostMsg_ChildProfilerData, - int, /* sequence number. */ - DictionaryValue /* profiler data. */) + int, /* sequence number */ + tracked_objects::ProcessDataSnapshot /* profiler data */) // Reply to ChildProcessMsg_DumpHandles when handle table dump is complete. IPC_MESSAGE_CONTROL0(ChildProcessHostMsg_DumpHandlesDone) diff --git a/content/common/child_thread.cc b/content/common/child_thread.cc index c4061b3..9277364 100644 --- a/content/common/child_thread.cc +++ b/content/common/child_thread.cc @@ -7,7 +7,6 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "base/process.h" -#include "base/process_util.h" #include "base/string_util.h" #include "base/tracked_objects.h" #include "content/common/child_process.h" @@ -28,6 +27,8 @@ #include "content/common/handle_enumerator_win.h" #endif +using tracked_objects::ThreadData; + ChildThread::ChildThread() { channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); @@ -219,21 +220,16 @@ void ChildThread::OnSetIPCLoggingEnabled(bool enable) { } #endif // IPC_MESSAGE_LOG_ENABLED -void ChildThread::OnSetProfilerStatus( - tracked_objects::ThreadData::Status status) { - tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status); +void ChildThread::OnSetProfilerStatus(ThreadData::Status status) { + ThreadData::InitializeAndSetTrackingStatus(status); } -void ChildThread::OnGetChildProfilerData( - int sequence_number, - const std::string& process_type) { - scoped_ptr<base::DictionaryValue> value( - tracked_objects::ThreadData::ToValue(false)); - value->SetString("process_type", process_type); - value->SetInteger("process_id", base::GetCurrentProcId()); +void ChildThread::OnGetChildProfilerData(int sequence_number) { + tracked_objects::ProcessDataSnapshot process_data; + ThreadData::Snapshot(false, &process_data); - Send(new ChildProcessHostMsg_ChildProfilerData( - sequence_number, *value.get())); + Send(new ChildProcessHostMsg_ChildProfilerData(sequence_number, + process_data)); } void ChildThread::OnDumpHandles() { diff --git a/content/common/child_thread.h b/content/common/child_thread.h index a63e87c..2be2b57 100644 --- a/content/common/child_thread.h +++ b/content/common/child_thread.h @@ -100,8 +100,7 @@ class CONTENT_EXPORT ChildThread : public IPC::Channel::Listener, #endif virtual void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); - virtual void OnGetChildProfilerData(int sequence_number, - const std::string& process_type); + virtual void OnGetChildProfilerData(int sequence_number); virtual void OnDumpHandles(); diff --git a/content/public/browser/profiler_controller.h b/content/public/browser/profiler_controller.h index 9627f52..e9fbe6a 100644 --- a/content/public/browser/profiler_controller.h +++ b/content/public/browser/profiler_controller.h @@ -39,18 +39,12 @@ class CONTENT_EXPORT ProfilerController { // Unregister the subscriber so that it will not be called when for example // OnProfilerDataCollected is returning profiler data from a child process. // Safe to call even if caller is not the current subscriber. - virtual void Unregister(ProfilerSubscriber* subscriber) = 0; + virtual void Unregister(const ProfilerSubscriber* subscriber) = 0; // Contact all processes and get their profiler data. virtual void GetProfilerData(int sequence_number) = 0; - - // Contact all processes and set profiler status to |enable|. - virtual void SetProfilerStatus( - tracked_objects::ThreadData::Status status) = 0; - }; } // namespace content #endif // CONTENT_PUBLIC_BROWSER_PROFILER_CONTROLLER_H_ - diff --git a/content/public/browser/profiler_subscriber.h b/content/public/browser/profiler_subscriber.h index f37947a..f6679d9 100644 --- a/content/public/browser/profiler_subscriber.h +++ b/content/public/browser/profiler_subscriber.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -6,9 +6,10 @@ #define CONTENT_PUBLIC_BROWSER_PROFILER_SUBSCRIBER_H_ #include "content/common/content_export.h" +#include "content/public/common/process_type.h" -namespace base { -class DictionaryValue; +namespace tracked_objects { +struct ProcessDataSnapshot; } namespace content { @@ -19,16 +20,17 @@ class CONTENT_EXPORT ProfilerSubscriber { virtual ~ProfilerSubscriber() {} // Send number of pending processes to subscriber. |end| is set to true if it - // is the last time. This is called on UI thread. + // is the last time. This is called on the UI thread. virtual void OnPendingProcesses(int sequence_number, int pending_processes, bool end) = 0; - // Send profiler_data back to subscriber. - // This is called on UI thread. + // Send |profiler_data| back to subscriber. + // This is called on the UI thread. virtual void OnProfilerDataCollected( int sequence_number, - base::DictionaryValue* profiler_data) = 0; + const tracked_objects::ProcessDataSnapshot& profiler_data, + ProcessType process_type) = 0; }; } // namespace content |