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

Side by Side Diff: content/browser/profiler_controller_impl.cc

Issue 9702014: [UMA] Use proper C++ objects to serialize tracked_objects across process boundaries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/profiler_controller_impl.h" 5 #include "content/browser/profiler_controller_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/tracked_objects.h"
9 #include "content/common/child_process_messages.h" 9 #include "content/common/child_process_messages.h"
10 #include "content/public/browser/browser_child_process_host_iterator.h" 10 #include "content/public/browser/browser_child_process_host_iterator.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/child_process_data.h" 12 #include "content/public/browser/child_process_data.h"
13 #include "content/public/browser/profiler_subscriber.h" 13 #include "content/public/browser/profiler_subscriber.h"
14 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/common/process_type.h" 15 #include "content/public/common/serialized_profiler_data.h"
16 16
17 using content::BrowserChildProcessHostIterator; 17 using content::BrowserChildProcessHostIterator;
18 using content::BrowserThread; 18 using content::BrowserThread;
19 19
20 namespace content { 20 namespace content {
21 21
22 content::ProfilerController* content::ProfilerController::GetInstance() { 22 content::ProfilerController* content::ProfilerController::GetInstance() {
23 return ProfilerControllerImpl::GetInstance(); 23 return ProfilerControllerImpl::GetInstance();
24 } 24 }
25 25
(...skipping 10 matching lines...) Expand all
36 void ProfilerControllerImpl::OnPendingProcesses(int sequence_number, 36 void ProfilerControllerImpl::OnPendingProcesses(int sequence_number,
37 int pending_processes, 37 int pending_processes,
38 bool end) { 38 bool end) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 if (subscriber_) 40 if (subscriber_)
41 subscriber_->OnPendingProcesses(sequence_number, pending_processes, end); 41 subscriber_->OnPendingProcesses(sequence_number, pending_processes, end);
42 } 42 }
43 43
44 void ProfilerControllerImpl::OnProfilerDataCollected( 44 void ProfilerControllerImpl::OnProfilerDataCollected(
45 int sequence_number, 45 int sequence_number,
46 base::DictionaryValue* profiler_data) { 46 const SerializedProfilerData& profiler_data) {
47 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 47 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
48 BrowserThread::PostTask( 48 BrowserThread::PostTask(
49 BrowserThread::UI, FROM_HERE, 49 BrowserThread::UI, FROM_HERE,
50 base::Bind(&ProfilerControllerImpl::OnProfilerDataCollected, 50 base::Bind(&ProfilerControllerImpl::OnProfilerDataCollected,
51 base::Unretained(this), 51 base::Unretained(this),
52 sequence_number, 52 sequence_number,
53 profiler_data)); 53 profiler_data));
54 return; 54 return;
55 } 55 }
56 56
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58 if (subscriber_) 58 if (subscriber_)
59 subscriber_->OnProfilerDataCollected(sequence_number, profiler_data); 59 subscriber_->OnProfilerDataCollected(sequence_number, profiler_data);
60 } 60 }
61 61
62 void ProfilerControllerImpl::Register(ProfilerSubscriber* subscriber) { 62 void ProfilerControllerImpl::Register(ProfilerSubscriber* subscriber) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 DCHECK(!subscriber_); 64 DCHECK(!subscriber_);
65 subscriber_ = subscriber; 65 subscriber_ = subscriber;
66 } 66 }
67 67
68 void ProfilerControllerImpl::Unregister(ProfilerSubscriber* subscriber) { 68 void ProfilerControllerImpl::Unregister(const ProfilerSubscriber* subscriber) {
69 if (subscriber == subscriber_) 69 DCHECK_EQ(subscriber_, subscriber);
70 subscriber_ = NULL; 70 subscriber_ = NULL;
71 } 71 }
72 72
73 void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( 73 void ProfilerControllerImpl::GetProfilerDataFromChildProcesses(
74 int sequence_number) { 74 int sequence_number) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
76 76
77 int pending_processes = 0; 77 int pending_processes = 0;
78 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { 78 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) {
79 const std::string process_type =
80 content::GetProcessTypeNameInEnglish(iter.GetData().type);
81 ++pending_processes; 79 ++pending_processes;
82 if (!iter.Send(new ChildProcessMsg_GetChildProfilerData( 80 if (!iter.Send(new ChildProcessMsg_GetChildProfilerData(
83 sequence_number, process_type))) { 81 sequence_number, iter.GetData().type))) {
84 --pending_processes; 82 --pending_processes;
85 } 83 }
86 } 84 }
87 85
88 BrowserThread::PostTask( 86 BrowserThread::PostTask(
89 BrowserThread::UI, 87 BrowserThread::UI,
90 FROM_HERE, 88 FROM_HERE,
91 base::Bind( 89 base::Bind(
92 &ProfilerControllerImpl::OnPendingProcesses, 90 &ProfilerControllerImpl::OnPendingProcesses,
93 base::Unretained(this), 91 base::Unretained(this),
94 sequence_number, 92 sequence_number,
95 pending_processes, 93 pending_processes,
96 true)); 94 true));
97 } 95 }
98 96
99 void ProfilerControllerImpl::GetProfilerData(int sequence_number) { 97 void ProfilerControllerImpl::GetProfilerData(int sequence_number) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
101 99
102 int pending_processes = 0; 100 int pending_processes = 0;
103 const std::string render_process_type =
104 content::GetProcessTypeNameInEnglish(content::PROCESS_TYPE_RENDERER);
105
106 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); 101 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
107 !it.IsAtEnd(); it.Advance()) { 102 !it.IsAtEnd(); it.Advance()) {
108 ++pending_processes; 103 ++pending_processes;
109 if (!it.GetCurrentValue()->Send(new ChildProcessMsg_GetChildProfilerData( 104 if (!it.GetCurrentValue()->Send(new ChildProcessMsg_GetChildProfilerData(
110 sequence_number, render_process_type))) { 105 sequence_number, content::PROCESS_TYPE_RENDERER))) {
111 --pending_processes; 106 --pending_processes;
112 } 107 }
113 } 108 }
114 OnPendingProcesses(sequence_number, pending_processes, false); 109 OnPendingProcesses(sequence_number, pending_processes, false);
115 110
116 BrowserThread::PostTask( 111 BrowserThread::PostTask(
117 BrowserThread::IO, 112 BrowserThread::IO,
118 FROM_HERE, 113 FROM_HERE,
119 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses, 114 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses,
120 base::Unretained(this), 115 base::Unretained(this),
121 sequence_number)); 116 sequence_number));
122 } 117 }
123 118
124 void ProfilerControllerImpl::SetProfilerStatusInChildProcesses(
125 tracked_objects::ThreadData::Status status) {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
127
128 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter)
129 iter.Send(new ChildProcessMsg_SetProfilerStatus(status));
130 }
131
132 void ProfilerControllerImpl::SetProfilerStatus(
133 tracked_objects::ThreadData::Status status) {
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
135
136 BrowserThread::PostTask(
137 BrowserThread::IO,
138 FROM_HERE,
139 base::Bind(&ProfilerControllerImpl::SetProfilerStatusInChildProcesses,
140 base::Unretained(this),
141 status));
142
143 for (content::RenderProcessHost::iterator it(
144 content::RenderProcessHost::AllHostsIterator());
145 !it.IsAtEnd(); it.Advance()) {
146 it.GetCurrentValue()->Send(new ChildProcessMsg_SetProfilerStatus(status));
147 }
148 }
149 } // namespace content 119 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698