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