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/trace_controller.h" | 5 #include "content/browser/trace_controller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "content/browser/trace_message_filter.h" | 11 #include "content/browser/trace_message_filter.h" |
12 #include "content/browser/trace_subscriber_stdio.h" | 12 #include "content/browser/trace_subscriber_stdio.h" |
13 #include "content/common/child_process_messages.h" | 13 #include "content/common/child_process_messages.h" |
14 #include "content/public/browser/browser_message_filter.h" | 14 #include "content/public/browser/browser_message_filter.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 | 16 |
17 using base::debug::TraceLog; | 17 using base::debug::TraceLog; |
18 using content::BrowserMessageFilter; | 18 |
19 using content::BrowserThread; | 19 namespace content { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class AutoStopTraceSubscriberStdio : public content::TraceSubscriberStdio { | 23 class AutoStopTraceSubscriberStdio : public content::TraceSubscriberStdio { |
24 public: | 24 public: |
25 AutoStopTraceSubscriberStdio(const FilePath& file_path) | 25 AutoStopTraceSubscriberStdio(const FilePath& file_path) |
26 : TraceSubscriberStdio(file_path) {} | 26 : TraceSubscriberStdio(file_path) {} |
27 | 27 |
28 static void EndStartupTrace(TraceSubscriberStdio* subscriber) { | 28 static void EndStartupTrace(TraceSubscriberStdio* subscriber) { |
29 if (!TraceController::GetInstance()->EndTracingAsync(subscriber)) | 29 if (!TraceControllerImpl::GetInstance()->EndTracingAsync(subscriber)) |
30 delete subscriber; | 30 delete subscriber; |
31 // else, the tracing will end asynchronously in OnEndTracingComplete(). | 31 // else, the tracing will end asynchronously in OnEndTracingComplete(). |
32 } | 32 } |
33 | 33 |
34 virtual void OnEndTracingComplete() { | 34 virtual void OnEndTracingComplete() { |
35 TraceSubscriberStdio::OnEndTracingComplete(); | 35 TraceSubscriberStdio::OnEndTracingComplete(); |
36 delete this; | 36 delete this; |
37 // TODO(joth): this would be the time to automatically open up | 37 // TODO(joth): this would be the time to automatically open up |
38 // chrome://tracing/ and load up the trace data collected. | 38 // chrome://tracing/ and load up the trace data collected. |
39 } | 39 } |
40 }; | 40 }; |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 void TraceSubscriber::OnKnownCategoriesCollected( | 44 TraceController* TraceController::GetInstance() { |
45 const std::set<std::string>& known_categories) {} | 45 return TraceControllerImpl::GetInstance(); |
| 46 } |
46 | 47 |
47 void TraceSubscriber::OnTraceBufferPercentFullReply(float percent_full) {} | 48 TraceControllerImpl::TraceControllerImpl() : |
48 | |
49 TraceSubscriber::~TraceSubscriber() {} | |
50 | |
51 TraceController::TraceController() : | |
52 subscriber_(NULL), | 49 subscriber_(NULL), |
53 pending_end_ack_count_(0), | 50 pending_end_ack_count_(0), |
54 pending_bpf_ack_count_(0), | 51 pending_bpf_ack_count_(0), |
55 maximum_bpf_(0.0f), | 52 maximum_bpf_(0.0f), |
56 is_tracing_(false), | 53 is_tracing_(false), |
57 is_get_categories_(false) { | 54 is_get_categories_(false) { |
58 TraceLog::GetInstance()->SetOutputCallback( | 55 TraceLog::GetInstance()->SetOutputCallback( |
59 base::Bind(&TraceController::OnTraceDataCollected, | 56 base::Bind(&TraceControllerImpl::OnTraceDataCollected, |
60 base::Unretained(this))); | 57 base::Unretained(this))); |
61 } | 58 } |
62 | 59 |
63 TraceController::~TraceController() { | 60 TraceControllerImpl::~TraceControllerImpl() { |
64 if (TraceLog* trace_log = TraceLog::GetInstance()) | 61 if (TraceLog* trace_log = TraceLog::GetInstance()) |
65 trace_log->SetOutputCallback(TraceLog::OutputCallback()); | 62 trace_log->SetOutputCallback(TraceLog::OutputCallback()); |
66 } | 63 } |
67 | 64 |
68 TraceController* TraceController::GetInstance() { | 65 TraceControllerImpl* TraceControllerImpl::GetInstance() { |
69 return Singleton<TraceController>::get(); | 66 return Singleton<TraceControllerImpl>::get(); |
70 } | 67 } |
71 | 68 |
72 void TraceController::InitStartupTracing(const CommandLine& command_line) { | 69 void TraceControllerImpl::InitStartupTracing(const CommandLine& command_line) { |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
74 FilePath trace_file = command_line.GetSwitchValuePath( | 71 FilePath trace_file = command_line.GetSwitchValuePath( |
75 switches::kTraceStartupFile); | 72 switches::kTraceStartupFile); |
76 // trace_file = "none" means that startup events will show up for the next | 73 // trace_file = "none" means that startup events will show up for the next |
77 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ | 74 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ |
78 // EndTracing, for example). | 75 // EndTracing, for example). |
79 if (trace_file == FilePath().AppendASCII("none")) | 76 if (trace_file == FilePath().AppendASCII("none")) |
80 return; | 77 return; |
81 | 78 |
82 if (trace_file.empty()) { | 79 if (trace_file.empty()) { |
(...skipping 15 matching lines...) Expand all Loading... |
98 | 95 |
99 OnTracingBegan(subscriber.get()); | 96 OnTracingBegan(subscriber.get()); |
100 BrowserThread::PostDelayedTask( | 97 BrowserThread::PostDelayedTask( |
101 BrowserThread::UI, | 98 BrowserThread::UI, |
102 FROM_HERE, | 99 FROM_HERE, |
103 base::Bind(&AutoStopTraceSubscriberStdio::EndStartupTrace, | 100 base::Bind(&AutoStopTraceSubscriberStdio::EndStartupTrace, |
104 base::Unretained(subscriber.release())), | 101 base::Unretained(subscriber.release())), |
105 base::TimeDelta::FromSeconds(delay_secs)); | 102 base::TimeDelta::FromSeconds(delay_secs)); |
106 } | 103 } |
107 | 104 |
108 bool TraceController::GetKnownCategoriesAsync(TraceSubscriber* subscriber) { | 105 bool TraceControllerImpl::GetKnownCategoriesAsync(TraceSubscriber* subscriber) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
110 | 107 |
111 // Known categories come back from child processes with the EndTracingAck | 108 // Known categories come back from child processes with the EndTracingAck |
112 // message. So to get known categories, just begin and end tracing immediately | 109 // message. So to get known categories, just begin and end tracing immediately |
113 // afterwards. This will ping all the child processes for categories. | 110 // afterwards. This will ping all the child processes for categories. |
114 is_get_categories_ = true; | 111 is_get_categories_ = true; |
115 bool success = BeginTracing(subscriber) && EndTracingAsync(subscriber); | 112 bool success = BeginTracing(subscriber) && EndTracingAsync(subscriber); |
116 is_get_categories_ = success; | 113 is_get_categories_ = success; |
117 return success; | 114 return success; |
118 } | 115 } |
119 | 116 |
120 bool TraceController::BeginTracing(TraceSubscriber* subscriber) { | 117 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber) { |
121 std::vector<std::string> include, exclude; | 118 std::vector<std::string> include, exclude; |
122 // By default, exclude all categories that begin with test_ | 119 // By default, exclude all categories that begin with test_ |
123 exclude.push_back("test_*"); | 120 exclude.push_back("test_*"); |
124 return BeginTracing(subscriber, include, exclude); | 121 return BeginTracing(subscriber, include, exclude); |
125 } | 122 } |
126 | 123 |
127 bool TraceController::BeginTracing( | 124 bool TraceControllerImpl::BeginTracing( |
128 TraceSubscriber* subscriber, | 125 TraceSubscriber* subscriber, |
129 const std::vector<std::string>& included_categories, | 126 const std::vector<std::string>& included_categories, |
130 const std::vector<std::string>& excluded_categories) { | 127 const std::vector<std::string>& excluded_categories) { |
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
132 | 129 |
133 if (!can_begin_tracing(subscriber)) | 130 if (!can_begin_tracing(subscriber)) |
134 return false; | 131 return false; |
135 | 132 |
136 // Enable tracing | 133 // Enable tracing |
137 TraceLog::GetInstance()->SetEnabled(included_categories, excluded_categories); | 134 TraceLog::GetInstance()->SetEnabled(included_categories, excluded_categories); |
138 OnTracingBegan(subscriber); | 135 OnTracingBegan(subscriber); |
139 | 136 |
140 return true; | 137 return true; |
141 } | 138 } |
142 | 139 |
143 bool TraceController::BeginTracing(TraceSubscriber* subscriber, | 140 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, |
144 const std::string& categories) { | 141 const std::string& categories) { |
145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
146 | 143 |
147 if (!can_begin_tracing(subscriber)) | 144 if (!can_begin_tracing(subscriber)) |
148 return false; | 145 return false; |
149 | 146 |
150 // Enable tracing | 147 // Enable tracing |
151 TraceLog::GetInstance()->SetEnabled(categories); | 148 TraceLog::GetInstance()->SetEnabled(categories); |
152 | 149 |
153 OnTracingBegan(subscriber); | 150 OnTracingBegan(subscriber); |
154 | 151 |
155 return true; | 152 return true; |
156 } | 153 } |
157 | 154 |
158 bool TraceController::EndTracingAsync(TraceSubscriber* subscriber) { | 155 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { |
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
160 | 157 |
161 if (!can_end_tracing() || subscriber != subscriber_) | 158 if (!can_end_tracing() || subscriber != subscriber_) |
162 return false; | 159 return false; |
163 | 160 |
164 // There could be a case where there are no child processes and filters_ | 161 // There could be a case where there are no child processes and filters_ |
165 // is empty. In that case we can immediately tell the subscriber that tracing | 162 // is empty. In that case we can immediately tell the subscriber that tracing |
166 // has ended. To avoid recursive calls back to the subscriber, we will just | 163 // has ended. To avoid recursive calls back to the subscriber, we will just |
167 // use the existing asynchronous OnEndTracingAck code. | 164 // use the existing asynchronous OnEndTracingAck code. |
168 // Count myself (local trace) in pending_end_ack_count_, acked below. | 165 // Count myself (local trace) in pending_end_ack_count_, acked below. |
169 pending_end_ack_count_ = filters_.size() + 1; | 166 pending_end_ack_count_ = filters_.size() + 1; |
170 | 167 |
171 // Handle special case of zero child processes. | 168 // Handle special case of zero child processes. |
172 if (pending_end_ack_count_ == 1) { | 169 if (pending_end_ack_count_ == 1) { |
173 // Ack asynchronously now, because we don't have any children to wait for. | 170 // Ack asynchronously now, because we don't have any children to wait for. |
174 std::vector<std::string> categories; | 171 std::vector<std::string> categories; |
175 TraceLog::GetInstance()->GetKnownCategories(&categories); | 172 TraceLog::GetInstance()->GetKnownCategories(&categories); |
176 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 173 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
177 base::Bind(&TraceController::OnEndTracingAck, base::Unretained(this), | 174 base::Bind(&TraceControllerImpl::OnEndTracingAck, |
178 categories)); | 175 base::Unretained(this), categories)); |
179 } | 176 } |
180 | 177 |
181 // Notify all child processes. | 178 // Notify all child processes. |
182 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 179 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
183 it->get()->SendEndTracing(); | 180 it->get()->SendEndTracing(); |
184 } | 181 } |
185 | 182 |
186 return true; | 183 return true; |
187 } | 184 } |
188 | 185 |
189 bool TraceController::GetTraceBufferPercentFullAsync( | 186 bool TraceControllerImpl::GetTraceBufferPercentFullAsync( |
190 TraceSubscriber* subscriber) { | 187 TraceSubscriber* subscriber) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
192 | 189 |
193 if (!can_get_buffer_percent_full() || subscriber != subscriber_) | 190 if (!can_get_buffer_percent_full() || subscriber != subscriber_) |
194 return false; | 191 return false; |
195 | 192 |
196 maximum_bpf_ = 0.0f; | 193 maximum_bpf_ = 0.0f; |
197 pending_bpf_ack_count_ = filters_.size() + 1; | 194 pending_bpf_ack_count_ = filters_.size() + 1; |
198 | 195 |
199 // Handle special case of zero child processes. | 196 // Handle special case of zero child processes. |
200 if (pending_bpf_ack_count_ == 1) { | 197 if (pending_bpf_ack_count_ == 1) { |
201 // Ack asynchronously now, because we don't have any children to wait for. | 198 // Ack asynchronously now, because we don't have any children to wait for. |
202 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 199 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
203 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 200 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
204 base::Bind(&TraceController::OnTraceBufferPercentFullReply, | 201 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
205 base::Unretained(this), bpf)); | 202 base::Unretained(this), bpf)); |
206 } | 203 } |
207 | 204 |
208 // Message all child processes. | 205 // Message all child processes. |
209 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 206 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
210 it->get()->SendGetTraceBufferPercentFull(); | 207 it->get()->SendGetTraceBufferPercentFull(); |
211 } | 208 } |
212 | 209 |
213 return true; | 210 return true; |
214 } | 211 } |
215 | 212 |
216 void TraceController::CancelSubscriber(TraceSubscriber* subscriber) { | 213 void TraceControllerImpl::CancelSubscriber(TraceSubscriber* subscriber) { |
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
218 | 215 |
219 if (subscriber == subscriber_) { | 216 if (subscriber == subscriber_) { |
220 subscriber_ = NULL; | 217 subscriber_ = NULL; |
221 // End tracing if necessary. | 218 // End tracing if necessary. |
222 if (is_tracing_ && pending_end_ack_count_ == 0) | 219 if (is_tracing_ && pending_end_ack_count_ == 0) |
223 EndTracingAsync(NULL); | 220 EndTracingAsync(NULL); |
224 } | 221 } |
225 } | 222 } |
226 | 223 |
227 void TraceController::AddFilter(TraceMessageFilter* filter) { | 224 void TraceControllerImpl::AddFilter(TraceMessageFilter* filter) { |
228 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 225 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
229 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 226 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
230 base::Bind(&TraceController::AddFilter, base::Unretained(this), | 227 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), |
231 make_scoped_refptr(filter))); | 228 make_scoped_refptr(filter))); |
232 return; | 229 return; |
233 } | 230 } |
234 | 231 |
235 filters_.insert(filter); | 232 filters_.insert(filter); |
236 if (is_tracing_enabled()) { | 233 if (is_tracing_enabled()) { |
237 filter->SendBeginTracing(included_categories_, excluded_categories_); | 234 filter->SendBeginTracing(included_categories_, excluded_categories_); |
238 } | 235 } |
239 } | 236 } |
240 | 237 |
241 void TraceController::RemoveFilter(TraceMessageFilter* filter) { | 238 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { |
242 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 239 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
243 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 240 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
244 base::Bind(&TraceController::RemoveFilter, base::Unretained(this), | 241 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), |
245 make_scoped_refptr(filter))); | 242 make_scoped_refptr(filter))); |
246 return; | 243 return; |
247 } | 244 } |
248 | 245 |
249 filters_.erase(filter); | 246 filters_.erase(filter); |
250 } | 247 } |
251 | 248 |
252 void TraceController::OnTracingBegan(TraceSubscriber* subscriber) { | 249 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { |
253 is_tracing_ = true; | 250 is_tracing_ = true; |
254 | 251 |
255 subscriber_ = subscriber; | 252 subscriber_ = subscriber; |
256 | 253 |
257 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_categories_, | 254 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_categories_, |
258 &excluded_categories_); | 255 &excluded_categories_); |
259 // Notify all child processes. | 256 // Notify all child processes. |
260 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 257 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
261 it->get()->SendBeginTracing(included_categories_, excluded_categories_); | 258 it->get()->SendBeginTracing(included_categories_, excluded_categories_); |
262 } | 259 } |
263 } | 260 } |
264 | 261 |
265 void TraceController::OnEndTracingAck( | 262 void TraceControllerImpl::OnEndTracingAck( |
266 const std::vector<std::string>& known_categories) { | 263 const std::vector<std::string>& known_categories) { |
267 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 264 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
268 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 265 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
269 base::Bind(&TraceController::OnEndTracingAck, base::Unretained(this), | 266 base::Bind(&TraceControllerImpl::OnEndTracingAck, |
270 known_categories)); | 267 base::Unretained(this), known_categories)); |
271 return; | 268 return; |
272 } | 269 } |
273 | 270 |
274 // Merge known_categories with known_categories_ | 271 // Merge known_categories with known_categories_ |
275 known_categories_.insert(known_categories.begin(), known_categories.end()); | 272 known_categories_.insert(known_categories.begin(), known_categories.end()); |
276 | 273 |
277 if (pending_end_ack_count_ == 0) | 274 if (pending_end_ack_count_ == 0) |
278 return; | 275 return; |
279 | 276 |
280 if (--pending_end_ack_count_ == 0) { | 277 if (--pending_end_ack_count_ == 0) { |
(...skipping 18 matching lines...) Expand all Loading... |
299 | 296 |
300 is_get_categories_ = false; | 297 is_get_categories_ = false; |
301 } | 298 } |
302 | 299 |
303 if (pending_end_ack_count_ == 1) { | 300 if (pending_end_ack_count_ == 1) { |
304 // The last ack represents local trace, so we need to ack it now. Note that | 301 // The last ack represents local trace, so we need to ack it now. Note that |
305 // this code only executes if there were child processes. | 302 // this code only executes if there were child processes. |
306 std::vector<std::string> categories; | 303 std::vector<std::string> categories; |
307 TraceLog::GetInstance()->GetKnownCategories(&categories); | 304 TraceLog::GetInstance()->GetKnownCategories(&categories); |
308 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 305 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
309 base::Bind(&TraceController::OnEndTracingAck, base::Unretained(this), | 306 base::Bind(&TraceControllerImpl::OnEndTracingAck, |
310 categories)); | 307 base::Unretained(this), categories)); |
311 } | 308 } |
312 } | 309 } |
313 | 310 |
314 void TraceController::OnTraceDataCollected( | 311 void TraceControllerImpl::OnTraceDataCollected( |
315 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 312 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
316 // OnTraceDataCollected may be called from any browser thread, either by the | 313 // OnTraceDataCollected may be called from any browser thread, either by the |
317 // local event trace system or from child processes via TraceMessageFilter. | 314 // local event trace system or from child processes via TraceMessageFilter. |
318 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 315 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
319 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 316 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
320 base::Bind(&TraceController::OnTraceDataCollected, | 317 base::Bind(&TraceControllerImpl::OnTraceDataCollected, |
321 base::Unretained(this), events_str_ptr)); | 318 base::Unretained(this), events_str_ptr)); |
322 return; | 319 return; |
323 } | 320 } |
324 | 321 |
325 // Drop trace events if we are just getting categories. | 322 // Drop trace events if we are just getting categories. |
326 if (subscriber_ && !is_get_categories_) | 323 if (subscriber_ && !is_get_categories_) |
327 subscriber_->OnTraceDataCollected(events_str_ptr); | 324 subscriber_->OnTraceDataCollected(events_str_ptr); |
328 } | 325 } |
329 | 326 |
330 void TraceController::OnTraceBufferFull() { | 327 void TraceControllerImpl::OnTraceBufferFull() { |
331 // OnTraceBufferFull may be called from any browser thread, either by the | 328 // OnTraceBufferFull may be called from any browser thread, either by the |
332 // local event trace system or from child processes via TraceMessageFilter. | 329 // local event trace system or from child processes via TraceMessageFilter. |
333 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 330 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
334 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 331 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
335 base::Bind(&TraceController::OnTraceBufferFull, | 332 base::Bind(&TraceControllerImpl::OnTraceBufferFull, |
336 base::Unretained(this))); | 333 base::Unretained(this))); |
337 return; | 334 return; |
338 } | 335 } |
339 | 336 |
340 // EndTracingAsync may return false if tracing is already in the process of | 337 // EndTracingAsync may return false if tracing is already in the process of |
341 // being ended. That is ok. | 338 // being ended. That is ok. |
342 EndTracingAsync(subscriber_); | 339 EndTracingAsync(subscriber_); |
343 } | 340 } |
344 | 341 |
345 void TraceController::OnTraceBufferPercentFullReply(float percent_full) { | 342 void TraceControllerImpl::OnTraceBufferPercentFullReply(float percent_full) { |
346 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 343 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
347 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 344 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
348 base::Bind(&TraceController::OnTraceBufferPercentFullReply, | 345 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
349 base::Unretained(this), percent_full)); | 346 base::Unretained(this), percent_full)); |
350 return; | 347 return; |
351 } | 348 } |
352 | 349 |
353 if (pending_bpf_ack_count_ == 0) | 350 if (pending_bpf_ack_count_ == 0) |
354 return; | 351 return; |
355 | 352 |
356 maximum_bpf_ = (maximum_bpf_ > percent_full)? maximum_bpf_ : percent_full; | 353 maximum_bpf_ = (maximum_bpf_ > percent_full)? maximum_bpf_ : percent_full; |
357 | 354 |
358 if (--pending_bpf_ack_count_ == 0) { | 355 if (--pending_bpf_ack_count_ == 0) { |
359 // Trigger callback if one is set. | 356 // Trigger callback if one is set. |
360 if (subscriber_) | 357 if (subscriber_) |
361 subscriber_->OnTraceBufferPercentFullReply(maximum_bpf_); | 358 subscriber_->OnTraceBufferPercentFullReply(maximum_bpf_); |
362 } | 359 } |
363 | 360 |
364 if (pending_bpf_ack_count_ == 1) { | 361 if (pending_bpf_ack_count_ == 1) { |
365 // The last ack represents local trace, so we need to ack it now. Note that | 362 // The last ack represents local trace, so we need to ack it now. Note that |
366 // this code only executes if there were child processes. | 363 // this code only executes if there were child processes. |
367 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 364 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
368 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 365 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
369 base::Bind(&TraceController::OnTraceBufferPercentFullReply, | 366 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
370 base::Unretained(this), bpf)); | 367 base::Unretained(this), bpf)); |
371 } | 368 } |
372 } | 369 } |
373 | 370 |
| 371 } // namespace content |
OLD | NEW |