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/tracing/trace_controller_impl.h" | 5 #include "content/browser/tracing/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" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 BrowserThread::UI, | 102 BrowserThread::UI, |
103 FROM_HERE, | 103 FROM_HERE, |
104 base::Bind(&AutoStopTraceSubscriberStdio::EndStartupTrace, | 104 base::Bind(&AutoStopTraceSubscriberStdio::EndStartupTrace, |
105 base::Unretained(subscriber.release())), | 105 base::Unretained(subscriber.release())), |
106 base::TimeDelta::FromSeconds(delay_secs)); | 106 base::TimeDelta::FromSeconds(delay_secs)); |
107 } | 107 } |
108 | 108 |
109 bool TraceControllerImpl::GetKnownCategoriesAsync(TraceSubscriber* subscriber) { | 109 bool TraceControllerImpl::GetKnownCategoriesAsync(TraceSubscriber* subscriber) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
111 | 111 |
| 112 base::debug::TraceLog::TraceMode mode = |
| 113 TraceLog::GetInstance()->GetTraceMode(); |
| 114 |
112 // Known categories come back from child processes with the EndTracingAck | 115 // Known categories come back from child processes with the EndTracingAck |
113 // message. So to get known categories, just begin and end tracing immediately | 116 // message. So to get known categories, just begin and end tracing immediately |
114 // afterwards. This will ping all the child processes for categories. | 117 // afterwards. This will ping all the child processes for categories. |
115 is_get_categories_ = true; | 118 is_get_categories_ = true; |
116 bool success = BeginTracing(subscriber, "*") && | 119 bool success = BeginTracing(subscriber, "*", mode) && |
117 EndTracingAsync(subscriber); | 120 EndTracingAsync(subscriber); |
118 is_get_categories_ = success; | 121 is_get_categories_ = success; |
119 return success; | 122 return success; |
120 } | 123 } |
121 | 124 |
122 bool TraceControllerImpl::BeginTracing( | 125 bool TraceControllerImpl::BeginTracing( |
123 TraceSubscriber* subscriber, | 126 TraceSubscriber* subscriber, |
124 const std::vector<std::string>& included_categories, | 127 const std::vector<std::string>& included_categories, |
125 const std::vector<std::string>& excluded_categories) { | 128 const std::vector<std::string>& excluded_categories, |
| 129 base::debug::TraceLog::TraceMode mode) { |
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
127 | 131 |
128 if (!can_begin_tracing(subscriber)) | 132 if (!can_begin_tracing(subscriber)) |
129 return false; | 133 return false; |
130 | 134 |
131 // Enable tracing | 135 // Enable tracing |
132 TraceLog::GetInstance()->SetEnabled(included_categories, excluded_categories); | 136 TraceLog::GetInstance()->SetEnabled(included_categories, excluded_categories, |
| 137 mode); |
133 OnTracingBegan(subscriber); | 138 OnTracingBegan(subscriber); |
134 | 139 |
135 return true; | 140 return true; |
136 } | 141 } |
137 | 142 |
138 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, | 143 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, |
139 const std::string& categories) { | 144 const std::string& categories, |
| 145 base::debug::TraceLog::TraceMode mode) { |
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
141 | 147 |
142 if (!can_begin_tracing(subscriber)) | 148 if (!can_begin_tracing(subscriber)) |
143 return false; | 149 return false; |
144 | 150 |
145 // Enable tracing | 151 // Enable tracing |
146 TraceLog::GetInstance()->SetEnabled(categories); | 152 TraceLog::GetInstance()->SetEnabled(categories, mode); |
147 | 153 |
148 OnTracingBegan(subscriber); | 154 OnTracingBegan(subscriber); |
149 | 155 |
150 return true; | 156 return true; |
151 } | 157 } |
152 | 158 |
153 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { | 159 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { |
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
155 | 161 |
156 if (!can_end_tracing() || subscriber != subscriber_) | 162 if (!can_end_tracing() || subscriber != subscriber_) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 void TraceControllerImpl::AddFilter(TraceMessageFilter* filter) { | 260 void TraceControllerImpl::AddFilter(TraceMessageFilter* filter) { |
255 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 261 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
256 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 262 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
257 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), | 263 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), |
258 make_scoped_refptr(filter))); | 264 make_scoped_refptr(filter))); |
259 return; | 265 return; |
260 } | 266 } |
261 | 267 |
262 filters_.insert(filter); | 268 filters_.insert(filter); |
263 if (is_tracing_enabled()) { | 269 if (is_tracing_enabled()) { |
264 filter->SendBeginTracing(included_categories_, excluded_categories_); | 270 filter->SendBeginTracing(included_categories_, excluded_categories_, |
| 271 trace_mode_); |
265 if (!watch_category_.empty()) | 272 if (!watch_category_.empty()) |
266 filter->SendSetWatchEvent(watch_category_, watch_name_); | 273 filter->SendSetWatchEvent(watch_category_, watch_name_); |
267 } | 274 } |
268 } | 275 } |
269 | 276 |
270 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { | 277 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { |
271 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 278 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
272 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 279 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
273 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), | 280 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), |
274 make_scoped_refptr(filter))); | 281 make_scoped_refptr(filter))); |
275 return; | 282 return; |
276 } | 283 } |
277 | 284 |
278 filters_.erase(filter); | 285 filters_.erase(filter); |
279 } | 286 } |
280 | 287 |
281 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { | 288 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { |
282 is_tracing_ = true; | 289 is_tracing_ = true; |
283 | 290 |
284 subscriber_ = subscriber; | 291 subscriber_ = subscriber; |
285 | 292 |
286 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_categories_, | 293 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_categories_, |
287 &excluded_categories_); | 294 &excluded_categories_); |
| 295 trace_mode_ = TraceLog::GetInstance()->GetTraceMode(); |
| 296 |
288 // Notify all child processes. | 297 // Notify all child processes. |
289 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 298 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
290 it->get()->SendBeginTracing(included_categories_, excluded_categories_); | 299 it->get()->SendBeginTracing(included_categories_, excluded_categories_, |
| 300 trace_mode_); |
291 } | 301 } |
292 } | 302 } |
293 | 303 |
294 void TraceControllerImpl::OnEndTracingAck( | 304 void TraceControllerImpl::OnEndTracingAck( |
295 const std::vector<std::string>& known_categories) { | 305 const std::vector<std::string>& known_categories) { |
296 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 306 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
297 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 307 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
298 base::Bind(&TraceControllerImpl::OnEndTracingAck, | 308 base::Bind(&TraceControllerImpl::OnEndTracingAck, |
299 base::Unretained(this), known_categories)); | 309 base::Unretained(this), known_categories)); |
300 return; | 310 return; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // The last ack represents local trace, so we need to ack it now. Note that | 415 // The last ack represents local trace, so we need to ack it now. Note that |
406 // this code only executes if there were child processes. | 416 // this code only executes if there were child processes. |
407 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 417 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
408 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 418 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
409 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, | 419 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
410 base::Unretained(this), bpf)); | 420 base::Unretained(this), bpf)); |
411 } | 421 } |
412 } | 422 } |
413 | 423 |
414 } // namespace content | 424 } // namespace content |
OLD | NEW |