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