OLD | NEW |
---|---|
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/process/process_handle.h" | 8 #include "base/process/process_handle.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "content/common/child_process_messages.h" | 10 #include "content/common/child_process_messages.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 DCHECK(!subscriber_); | 65 DCHECK(!subscriber_); |
66 subscriber_ = subscriber; | 66 subscriber_ = subscriber; |
67 } | 67 } |
68 | 68 |
69 void ProfilerControllerImpl::Unregister(const ProfilerSubscriber* subscriber) { | 69 void ProfilerControllerImpl::Unregister(const ProfilerSubscriber* subscriber) { |
70 DCHECK_EQ(subscriber_, subscriber); | 70 DCHECK_EQ(subscriber_, subscriber); |
71 subscriber_ = NULL; | 71 subscriber_ = NULL; |
72 } | 72 } |
73 | 73 |
74 void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( | 74 void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( |
75 int sequence_number) { | 75 int sequence_number, |
76 int current_profiling_phase) { | |
76 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
77 | 78 |
78 int pending_processes = 0; | 79 int pending_processes = 0; |
79 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { | 80 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
80 // In some cases, there may be no child process of the given type (for | 81 // In some cases, there may be no child process of the given type (for |
81 // example, the GPU process may not exist and there may instead just be a | 82 // example, the GPU process may not exist and there may instead just be a |
82 // GPU thread in the browser process). If that's the case, then the process | 83 // GPU thread in the browser process). If that's the case, then the process |
83 // handle will be base::kNullProcessHandle and we shouldn't ask it for data. | 84 // handle will be base::kNullProcessHandle and we shouldn't ask it for data. |
84 if (iter.GetData().handle == base::kNullProcessHandle) | 85 if (iter.GetData().handle == base::kNullProcessHandle) |
85 continue; | 86 continue; |
86 | 87 |
87 ++pending_processes; | 88 ++pending_processes; |
88 if (!iter.Send(new ChildProcessMsg_GetChildProfilerData(sequence_number))) | 89 if (!iter.Send(new ChildProcessMsg_GetChildProfilerData( |
90 sequence_number, current_profiling_phase))) { | |
Ilya Sherman
2015/04/07 01:15:30
Do you understand why |sequence_number| is used in
vadimt
2015/04/07 21:44:14
See RequestContextMap. Sequence numbers are necess
| |
89 --pending_processes; | 91 --pending_processes; |
92 } | |
90 } | 93 } |
91 | 94 |
92 BrowserThread::PostTask( | 95 BrowserThread::PostTask( |
93 BrowserThread::UI, | 96 BrowserThread::UI, |
94 FROM_HERE, | 97 FROM_HERE, |
95 base::Bind( | 98 base::Bind( |
96 &ProfilerControllerImpl::OnPendingProcesses, | 99 &ProfilerControllerImpl::OnPendingProcesses, |
97 base::Unretained(this), | 100 base::Unretained(this), |
98 sequence_number, | 101 sequence_number, |
99 pending_processes, | 102 pending_processes, |
100 true)); | 103 true)); |
101 } | 104 } |
102 | 105 |
103 void ProfilerControllerImpl::GetProfilerData(int sequence_number) { | 106 void ProfilerControllerImpl::NotifyChildProcessesOfProfilingPhaseCompletion( |
107 int profiling_phase) { | |
104 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 108 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Ilya Sherman
2015/04/07 01:15:30
Hmm, shouldn't this be the IO thread? Are you not
vadimt
2015/04/07 21:44:14
Must have sneaked in since I ran this last time wi
| |
105 | 109 |
110 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { | |
111 // In some cases, there may be no child process of the given type (for | |
112 // example, the GPU process may not exist and there may instead just be a | |
113 // GPU thread in the browser process). If that's the case, then the process | |
114 // handle will be base::kNullProcessHandle and we shouldn't send it a | |
115 // message. | |
116 if (iter.GetData().handle == base::kNullProcessHandle) | |
117 continue; | |
118 | |
119 iter.Send(new ChildProcessMsg_OnProfilingPhase(profiling_phase)); | |
120 } | |
121 } | |
122 | |
123 void ProfilerControllerImpl::GetProfilerData(int sequence_number, | |
124 int current_profiling_phase) { | |
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
Ilya Sherman
2015/04/07 01:15:30
Please use DCHECK_CURRENTLY_ON
vadimt
2015/04/07 21:44:14
Done.
| |
126 | |
127 // Iterates through renderers in UI thread, and through other child processes | |
128 // in IO thread, and send them GetChildProfilerData message. Renderers have to | |
129 // be contacted from UI thread, and other processes - from IO thread. | |
106 int pending_processes = 0; | 130 int pending_processes = 0; |
107 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 131 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
108 !it.IsAtEnd(); it.Advance()) { | 132 !it.IsAtEnd(); it.Advance()) { |
109 ++pending_processes; | 133 ++pending_processes; |
110 if (!it.GetCurrentValue()->Send( | 134 if (!it.GetCurrentValue()->Send(new ChildProcessMsg_GetChildProfilerData( |
111 new ChildProcessMsg_GetChildProfilerData(sequence_number))) { | 135 sequence_number, current_profiling_phase))) { |
112 --pending_processes; | 136 --pending_processes; |
113 } | 137 } |
114 } | 138 } |
115 OnPendingProcesses(sequence_number, pending_processes, false); | 139 OnPendingProcesses(sequence_number, pending_processes, false); |
116 | 140 |
117 BrowserThread::PostTask( | 141 BrowserThread::PostTask( |
118 BrowserThread::IO, | 142 BrowserThread::IO, FROM_HERE, |
119 FROM_HERE, | |
120 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses, | 143 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses, |
121 base::Unretained(this), | 144 base::Unretained(this), sequence_number, |
122 sequence_number)); | 145 current_profiling_phase)); |
146 } | |
147 | |
148 void ProfilerControllerImpl::OnProfilingPhaseCompletion(int profiling_phase) { | |
149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
Ilya Sherman
2015/04/07 01:15:30
Please use DCHECK_CURRENTLY_ON
vadimt
2015/04/07 21:44:14
Done.
| |
150 | |
151 // Iterates through renderers in UI thread, and through other child processes | |
152 // in IO thread, and send them OnProfilingPhase message. Renderers have to be | |
153 // contacted from UI thread, and other processes - from IO thread. | |
154 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | |
155 !it.IsAtEnd(); it.Advance()) { | |
156 it.GetCurrentValue()->Send( | |
157 new ChildProcessMsg_OnProfilingPhase(profiling_phase)); | |
158 } | |
159 | |
160 BrowserThread::PostTask( | |
161 BrowserThread::IO, FROM_HERE, | |
162 base::Bind(&ProfilerControllerImpl:: | |
163 NotifyChildProcessesOfProfilingPhaseCompletion, | |
164 base::Unretained(this), profiling_phase)); | |
123 } | 165 } |
124 | 166 |
125 } // namespace content | 167 } // namespace content |
OLD | NEW |