| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 EndTracingAsync(subscriber); | 117 EndTracingAsync(subscriber); |
| 118 is_get_categories_ = success; | 118 is_get_categories_ = success; |
| 119 return success; | 119 return success; |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool TraceControllerImpl::BeginTracing( | |
| 123 TraceSubscriber* subscriber, | |
| 124 const std::vector<std::string>& included_categories, | |
| 125 const std::vector<std::string>& excluded_categories) { | |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 127 | |
| 128 if (!can_begin_tracing(subscriber)) | |
| 129 return false; | |
| 130 | |
| 131 // Enable tracing | |
| 132 TraceLog::GetInstance()->SetEnabled(included_categories, excluded_categories); | |
| 133 OnTracingBegan(subscriber); | |
| 134 | |
| 135 return true; | |
| 136 } | |
| 137 | |
| 138 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, | 122 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, |
| 139 const std::string& categories) { | 123 const std::string& categories) { |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 141 | 125 |
| 142 if (!can_begin_tracing(subscriber)) | 126 if (!can_begin_tracing(subscriber)) |
| 143 return false; | 127 return false; |
| 144 | 128 |
| 145 // Enable tracing | 129 // Enable tracing |
| 146 TraceLog::GetInstance()->SetEnabled(categories); | 130 base::debug::CategoryFilter category_filter(categories); |
| 131 TraceLog::GetInstance()->SetEnabled(category_filter); |
| 147 | 132 |
| 148 OnTracingBegan(subscriber); | 133 OnTracingBegan(subscriber); |
| 149 | 134 |
| 150 return true; | 135 return true; |
| 151 } | 136 } |
| 152 | 137 |
| 153 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { | 138 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { |
| 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 155 | 140 |
| 156 if (!can_end_tracing() || subscriber != subscriber_) | 141 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) { | 239 void TraceControllerImpl::AddFilter(TraceMessageFilter* filter) { |
| 255 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 240 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 256 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 241 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 257 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), | 242 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), |
| 258 make_scoped_refptr(filter))); | 243 make_scoped_refptr(filter))); |
| 259 return; | 244 return; |
| 260 } | 245 } |
| 261 | 246 |
| 262 filters_.insert(filter); | 247 filters_.insert(filter); |
| 263 if (is_tracing_enabled()) { | 248 if (is_tracing_enabled()) { |
| 264 filter->SendBeginTracing(included_categories_, excluded_categories_); | 249 scoped_refptr<base::RefCountedString> category_filter_str_ptr = |
| 250 new base::RefCountedString(); |
| 251 category_filter_.ToString(&(category_filter_str_ptr->data())); |
| 252 filter->SendBeginTracing(category_filter_str_ptr->data()); |
| 265 if (!watch_category_.empty()) | 253 if (!watch_category_.empty()) |
| 266 filter->SendSetWatchEvent(watch_category_, watch_name_); | 254 filter->SendSetWatchEvent(watch_category_, watch_name_); |
| 267 } | 255 } |
| 268 } | 256 } |
| 269 | 257 |
| 270 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { | 258 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { |
| 271 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 259 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 272 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 260 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 273 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), | 261 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), |
| 274 make_scoped_refptr(filter))); | 262 make_scoped_refptr(filter))); |
| 275 return; | 263 return; |
| 276 } | 264 } |
| 277 | 265 |
| 278 filters_.erase(filter); | 266 filters_.erase(filter); |
| 279 } | 267 } |
| 280 | 268 |
| 281 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { | 269 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { |
| 282 is_tracing_ = true; | 270 is_tracing_ = true; |
| 283 | 271 |
| 284 subscriber_ = subscriber; | 272 subscriber_ = subscriber; |
| 285 | 273 |
| 286 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_categories_, | 274 category_filter_ = TraceLog::GetInstance()->GetCurrentCategoryFilter(); |
| 287 &excluded_categories_); | 275 scoped_refptr<base::RefCountedString> category_filter_str_ptr = |
| 276 new base::RefCountedString(); |
| 277 category_filter_.ToString(&(category_filter_str_ptr->data())); |
| 288 // Notify all child processes. | 278 // Notify all child processes. |
| 289 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 279 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
| 290 it->get()->SendBeginTracing(included_categories_, excluded_categories_); | 280 it->get()->SendBeginTracing(category_filter_str_ptr->data()); |
| 291 } | 281 } |
| 292 } | 282 } |
| 293 | 283 |
| 294 void TraceControllerImpl::OnEndTracingAck( | 284 void TraceControllerImpl::OnEndTracingAck( |
| 295 const std::vector<std::string>& known_categories) { | 285 const std::vector<std::string>& known_categories) { |
| 296 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 286 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 297 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 287 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 298 base::Bind(&TraceControllerImpl::OnEndTracingAck, | 288 base::Bind(&TraceControllerImpl::OnEndTracingAck, |
| 299 base::Unretained(this), known_categories)); | 289 base::Unretained(this), known_categories)); |
| 300 return; | 290 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 | 395 // 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. | 396 // this code only executes if there were child processes. |
| 407 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 397 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
| 408 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 398 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 409 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, | 399 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
| 410 base::Unretained(this), bpf)); | 400 base::Unretained(this), bpf)); |
| 411 } | 401 } |
| 412 } | 402 } |
| 413 | 403 |
| 414 } // namespace content | 404 } // namespace content |
| OLD | NEW |