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 profiling_phase) { | |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 77 DCHECK(BrowserThread::CurrentlyOn(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(sequence_number, |
90 profiling_phase))) | |
Alexei Svitkine (slow)
2015/03/06 20:06:40
Nit: {}'s
vadimt
2015/03/06 21:34:58
Done.
| |
89 --pending_processes; | 91 --pending_processes; |
90 } | 92 } |
91 | 93 |
92 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
93 BrowserThread::UI, | 95 BrowserThread::UI, |
94 FROM_HERE, | 96 FROM_HERE, |
95 base::Bind( | 97 base::Bind( |
96 &ProfilerControllerImpl::OnPendingProcesses, | 98 &ProfilerControllerImpl::OnPendingProcesses, |
97 base::Unretained(this), | 99 base::Unretained(this), |
98 sequence_number, | 100 sequence_number, |
99 pending_processes, | 101 pending_processes, |
100 true)); | 102 true)); |
101 } | 103 } |
102 | 104 |
103 void ProfilerControllerImpl::GetProfilerData(int sequence_number) { | 105 void ProfilerControllerImpl::NotifyChildProcessesOfProfilingPhaseCompletion( |
106 int profiling_phase) { | |
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
108 | |
109 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { | |
110 // In some cases, there may be no child process of the given type (for | |
111 // example, the GPU process may not exist and there may instead just be a | |
112 // GPU thread in the browser process). If that's the case, then the process | |
113 // handle will be base::kNullProcessHandle and we shouldn't send it a | |
114 // message. | |
115 if (iter.GetData().handle == base::kNullProcessHandle) | |
116 continue; | |
117 | |
118 iter.Send(new ChildProcessMsg_OnProfilingPhase(profiling_phase)); | |
119 } | |
120 } | |
121 | |
122 void ProfilerControllerImpl::GetProfilerData(int sequence_number, | |
123 int profiling_phase) { | |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
105 | 125 |
106 int pending_processes = 0; | 126 int pending_processes = 0; |
107 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 127 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
108 !it.IsAtEnd(); it.Advance()) { | 128 !it.IsAtEnd(); it.Advance()) { |
109 ++pending_processes; | 129 ++pending_processes; |
110 if (!it.GetCurrentValue()->Send( | 130 if (!it.GetCurrentValue()->Send(new ChildProcessMsg_GetChildProfilerData( |
111 new ChildProcessMsg_GetChildProfilerData(sequence_number))) { | 131 sequence_number, profiling_phase))) { |
112 --pending_processes; | 132 --pending_processes; |
113 } | 133 } |
114 } | 134 } |
115 OnPendingProcesses(sequence_number, pending_processes, false); | 135 OnPendingProcesses(sequence_number, pending_processes, false); |
116 | 136 |
117 BrowserThread::PostTask( | 137 BrowserThread::PostTask( |
118 BrowserThread::IO, | 138 BrowserThread::IO, FROM_HERE, |
119 FROM_HERE, | |
120 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses, | 139 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses, |
121 base::Unretained(this), | 140 base::Unretained(this), sequence_number, profiling_phase)); |
122 sequence_number)); | 141 } |
142 | |
143 void ProfilerControllerImpl::OnProfilingPhaseCompletion(int profiling_phase) { | |
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
145 | |
146 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | |
147 !it.IsAtEnd(); it.Advance()) { | |
148 it.GetCurrentValue()->Send( | |
149 new ChildProcessMsg_OnProfilingPhase(profiling_phase)); | |
150 } | |
151 | |
152 BrowserThread::PostTask( | |
153 BrowserThread::IO, FROM_HERE, | |
154 base::Bind(&ProfilerControllerImpl:: | |
155 NotifyChildProcessesOfProfilingPhaseCompletion, | |
156 base::Unretained(this), profiling_phase)); | |
123 } | 157 } |
124 | 158 |
125 } // namespace content | 159 } // namespace content |
OLD | NEW |