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_impl.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" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( | 122 bool TraceControllerImpl::BeginTracing( |
123 TraceSubscriber* subscriber, | 123 TraceSubscriber* subscriber, |
124 const std::vector<std::string>& included_categories, | 124 const std::vector<std::string>& included_tag_patterns, |
125 const std::vector<std::string>& excluded_categories) { | 125 const std::vector<std::string>& excluded_tag_patterns) { |
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
127 | 127 |
128 if (!can_begin_tracing(subscriber)) | 128 if (!can_begin_tracing(subscriber)) |
129 return false; | 129 return false; |
130 | 130 |
131 // Enable tracing | 131 // Enable tracing |
132 TraceLog::GetInstance()->SetEnabled(included_categories, excluded_categories); | 132 TraceLog::GetInstance()->SetEnabled(included_tag_patterns, |
| 133 excluded_tag_patterns); |
133 OnTracingBegan(subscriber); | 134 OnTracingBegan(subscriber); |
134 | 135 |
135 return true; | 136 return true; |
136 } | 137 } |
137 | 138 |
138 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, | 139 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, |
139 const std::string& categories) { | 140 const std::string& tag_patterns) { |
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
141 | 142 |
142 if (!can_begin_tracing(subscriber)) | 143 if (!can_begin_tracing(subscriber)) |
143 return false; | 144 return false; |
144 | 145 |
145 // Enable tracing | 146 // Enable tracing |
146 TraceLog::GetInstance()->SetEnabled(categories); | 147 TraceLog::GetInstance()->SetEnabled(tag_patterns); |
147 | 148 |
148 OnTracingBegan(subscriber); | 149 OnTracingBegan(subscriber); |
149 | 150 |
150 return true; | 151 return true; |
151 } | 152 } |
152 | 153 |
153 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { | 154 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { |
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
155 | 156 |
156 if (!can_end_tracing() || subscriber != subscriber_) | 157 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) { | 255 void TraceControllerImpl::AddFilter(TraceMessageFilter* filter) { |
255 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 256 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
256 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 257 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
257 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), | 258 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), |
258 make_scoped_refptr(filter))); | 259 make_scoped_refptr(filter))); |
259 return; | 260 return; |
260 } | 261 } |
261 | 262 |
262 filters_.insert(filter); | 263 filters_.insert(filter); |
263 if (is_tracing_enabled()) { | 264 if (is_tracing_enabled()) { |
264 filter->SendBeginTracing(included_categories_, excluded_categories_); | 265 filter->SendBeginTracing(included_tag_patterns_, excluded_tag_patterns_); |
265 if (!watch_category_.empty()) | 266 if (!watch_category_.empty()) |
266 filter->SendSetWatchEvent(watch_category_, watch_name_); | 267 filter->SendSetWatchEvent(watch_category_, watch_name_); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { | 271 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { |
271 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 272 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
272 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 273 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
273 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), | 274 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), |
274 make_scoped_refptr(filter))); | 275 make_scoped_refptr(filter))); |
275 return; | 276 return; |
276 } | 277 } |
277 | 278 |
278 filters_.erase(filter); | 279 filters_.erase(filter); |
279 } | 280 } |
280 | 281 |
281 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { | 282 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { |
282 is_tracing_ = true; | 283 is_tracing_ = true; |
283 | 284 |
284 subscriber_ = subscriber; | 285 subscriber_ = subscriber; |
285 | 286 |
286 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_categories_, | 287 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_tag_patterns_, |
287 &excluded_categories_); | 288 &excluded_tag_patterns_); |
288 // Notify all child processes. | 289 // Notify all child processes. |
289 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 290 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
290 it->get()->SendBeginTracing(included_categories_, excluded_categories_); | 291 it->get()->SendBeginTracing(included_tag_patterns_, excluded_tag_patterns_); |
291 } | 292 } |
292 } | 293 } |
293 | 294 |
294 void TraceControllerImpl::OnEndTracingAck( | 295 void TraceControllerImpl::OnEndTracingAck( |
295 const std::vector<std::string>& known_categories) { | 296 const std::vector<std::string>& known_categories) { |
296 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 297 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
297 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 298 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
298 base::Bind(&TraceControllerImpl::OnEndTracingAck, | 299 base::Bind(&TraceControllerImpl::OnEndTracingAck, |
299 base::Unretained(this), known_categories)); | 300 base::Unretained(this), known_categories)); |
300 return; | 301 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 | 406 // 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. | 407 // this code only executes if there were child processes. |
407 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 408 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
408 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 409 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
409 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, | 410 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
410 base::Unretained(this), bpf)); | 411 base::Unretained(this), bpf)); |
411 } | 412 } |
412 } | 413 } |
413 | 414 |
414 } // namespace content | 415 } // namespace content |
OLD | NEW |