Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: content/browser/tracing/trace_controller_impl.cc

Issue 12150004: Category group support/Renamings. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added destructor for CategoryFilter class per CQ failure. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 TraceController* TraceController::GetInstance() { 47 TraceController* TraceController::GetInstance() {
48 return TraceControllerImpl::GetInstance(); 48 return TraceControllerImpl::GetInstance();
49 } 49 }
50 50
51 TraceControllerImpl::TraceControllerImpl() : 51 TraceControllerImpl::TraceControllerImpl() :
52 subscriber_(NULL), 52 subscriber_(NULL),
53 pending_end_ack_count_(0), 53 pending_end_ack_count_(0),
54 pending_bpf_ack_count_(0), 54 pending_bpf_ack_count_(0),
55 maximum_bpf_(0.0f), 55 maximum_bpf_(0.0f),
56 is_tracing_(false), 56 is_tracing_(false),
57 is_get_categories_(false) { 57 is_get_category_groups_(false),
58 category_filter_(
59 base::debug::CategoryFilter::kDefaultCategoryFilterString) {
58 TraceLog::GetInstance()->SetNotificationCallback( 60 TraceLog::GetInstance()->SetNotificationCallback(
59 base::Bind(&TraceControllerImpl::OnTraceNotification, 61 base::Bind(&TraceControllerImpl::OnTraceNotification,
60 base::Unretained(this))); 62 base::Unretained(this)));
61 } 63 }
62 64
63 TraceControllerImpl::~TraceControllerImpl() { 65 TraceControllerImpl::~TraceControllerImpl() {
64 // No need to SetNotificationCallback(nil) on the TraceLog since this is a 66 // No need to SetNotificationCallback(nil) on the TraceLog since this is a
65 // Leaky instance. 67 // Leaky instance.
66 NOTREACHED(); 68 NOTREACHED();
67 } 69 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 101
100 OnTracingBegan(subscriber.get()); 102 OnTracingBegan(subscriber.get());
101 BrowserThread::PostDelayedTask( 103 BrowserThread::PostDelayedTask(
102 BrowserThread::UI, 104 BrowserThread::UI,
103 FROM_HERE, 105 FROM_HERE,
104 base::Bind(&AutoStopTraceSubscriberStdio::EndStartupTrace, 106 base::Bind(&AutoStopTraceSubscriberStdio::EndStartupTrace,
105 base::Unretained(subscriber.release())), 107 base::Unretained(subscriber.release())),
106 base::TimeDelta::FromSeconds(delay_secs)); 108 base::TimeDelta::FromSeconds(delay_secs));
107 } 109 }
108 110
109 bool TraceControllerImpl::GetKnownCategoriesAsync(TraceSubscriber* subscriber) { 111 bool TraceControllerImpl::GetKnownCategoryGroupsAsync(
112 TraceSubscriber* subscriber) {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
111 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_category_groups_ = true;
116 bool success = BeginTracing(subscriber, "*", 119 bool success = BeginTracing(subscriber, "*",
117 TraceLog::GetInstance()->trace_options()) && 120 TraceLog::GetInstance()->trace_options()) &&
118 EndTracingAsync(subscriber); 121 EndTracingAsync(subscriber);
119 is_get_categories_ = success; 122 is_get_category_groups_ = success;
120 return success; 123 return success;
121 } 124 }
122 125
123 bool TraceControllerImpl::BeginTracing(
124 TraceSubscriber* subscriber,
125 const std::vector<std::string>& included_categories,
126 const std::vector<std::string>& excluded_categories,
127 base::debug::TraceLog::Options options) {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
129
130 if (!can_begin_tracing(subscriber))
131 return false;
132
133 // Enable tracing
134 TraceLog::GetInstance()->SetEnabled(included_categories, excluded_categories,
135 options);
136 OnTracingBegan(subscriber);
137
138 return true;
139 }
140
141 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber, 126 bool TraceControllerImpl::BeginTracing(TraceSubscriber* subscriber,
142 const std::string& categories, 127 const std::string& category_patterns,
143 base::debug::TraceLog::Options options) { 128 base::debug::TraceLog::Options options) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
145 130
146 if (!can_begin_tracing(subscriber)) 131 if (!can_begin_tracing(subscriber))
147 return false; 132 return false;
148 133
149 // Enable tracing 134 // Enable tracing
150 TraceLog::GetInstance()->SetEnabled(categories, options); 135 TraceLog::GetInstance()->SetEnabled(
136 base::debug::CategoryFilter(category_patterns), options);
151 137
152 OnTracingBegan(subscriber); 138 OnTracingBegan(subscriber);
153 139
154 return true; 140 return true;
155 } 141 }
156 142
157 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) { 143 bool TraceControllerImpl::EndTracingAsync(TraceSubscriber* subscriber) {
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
159 145
160 if (!can_end_tracing() || subscriber != subscriber_) 146 if (!can_end_tracing() || subscriber != subscriber_)
161 return false; 147 return false;
162 148
163 // There could be a case where there are no child processes and filters_ 149 // There could be a case where there are no child processes and filters_
164 // is empty. In that case we can immediately tell the subscriber that tracing 150 // is empty. In that case we can immediately tell the subscriber that tracing
165 // has ended. To avoid recursive calls back to the subscriber, we will just 151 // has ended. To avoid recursive calls back to the subscriber, we will just
166 // use the existing asynchronous OnEndTracingAck code. 152 // use the existing asynchronous OnEndTracingAck code.
167 // Count myself (local trace) in pending_end_ack_count_, acked below. 153 // Count myself (local trace) in pending_end_ack_count_, acked below.
168 pending_end_ack_count_ = filters_.size() + 1; 154 pending_end_ack_count_ = filters_.size() + 1;
169 155
170 // Handle special case of zero child processes. 156 // Handle special case of zero child processes.
171 if (pending_end_ack_count_ == 1) { 157 if (pending_end_ack_count_ == 1) {
172 // Ack asynchronously now, because we don't have any children to wait for. 158 // Ack asynchronously now, because we don't have any children to wait for.
173 std::vector<std::string> categories; 159 std::vector<std::string> category_groups;
174 TraceLog::GetInstance()->GetKnownCategories(&categories); 160 TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups);
175 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 161 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
176 base::Bind(&TraceControllerImpl::OnEndTracingAck, 162 base::Bind(&TraceControllerImpl::OnEndTracingAck,
177 base::Unretained(this), categories)); 163 base::Unretained(this), category_groups));
178 } 164 }
179 165
180 // Notify all child processes. 166 // Notify all child processes.
181 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { 167 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) {
182 it->get()->SendEndTracing(); 168 it->get()->SendEndTracing();
183 } 169 }
184 170
185 return true; 171 return true;
186 } 172 }
187 173
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 void TraceControllerImpl::AddFilter(TraceMessageFilter* filter) { 244 void TraceControllerImpl::AddFilter(TraceMessageFilter* filter) {
259 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 245 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
260 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 246 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
261 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this), 247 base::Bind(&TraceControllerImpl::AddFilter, base::Unretained(this),
262 make_scoped_refptr(filter))); 248 make_scoped_refptr(filter)));
263 return; 249 return;
264 } 250 }
265 251
266 filters_.insert(filter); 252 filters_.insert(filter);
267 if (is_tracing_enabled()) { 253 if (is_tracing_enabled()) {
268 filter->SendBeginTracing(included_categories_, excluded_categories_, 254 std::string cf_str = category_filter_.ToString();
269 trace_options_); 255 filter->SendBeginTracing(cf_str, trace_options_);
270 if (!watch_category_.empty()) 256 if (!watch_category_.empty())
271 filter->SendSetWatchEvent(watch_category_, watch_name_); 257 filter->SendSetWatchEvent(watch_category_, watch_name_);
272 } 258 }
273 } 259 }
274 260
275 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) { 261 void TraceControllerImpl::RemoveFilter(TraceMessageFilter* filter) {
276 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 262 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
277 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 263 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
278 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this), 264 base::Bind(&TraceControllerImpl::RemoveFilter, base::Unretained(this),
279 make_scoped_refptr(filter))); 265 make_scoped_refptr(filter)));
280 return; 266 return;
281 } 267 }
282 268
283 filters_.erase(filter); 269 filters_.erase(filter);
284 } 270 }
285 271
286 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) { 272 void TraceControllerImpl::OnTracingBegan(TraceSubscriber* subscriber) {
287 is_tracing_ = true; 273 is_tracing_ = true;
288 274
289 subscriber_ = subscriber; 275 subscriber_ = subscriber;
290 276
291 TraceLog::GetInstance()->GetEnabledTraceCategories(&included_categories_, 277 category_filter_ = TraceLog::GetInstance()->GetCurrentCategoryFilter();
292 &excluded_categories_);
293 trace_options_ = TraceLog::GetInstance()->trace_options(); 278 trace_options_ = TraceLog::GetInstance()->trace_options();
294 279
295 // Notify all child processes. 280 // Notify all child processes.
296 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { 281 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) {
297 it->get()->SendBeginTracing(included_categories_, excluded_categories_, 282 it->get()->SendBeginTracing(category_filter_.ToString(), trace_options_);
298 trace_options_);
299 } 283 }
300 } 284 }
301 285
302 void TraceControllerImpl::OnEndTracingAck( 286 void TraceControllerImpl::OnEndTracingAck(
303 const std::vector<std::string>& known_categories) { 287 const std::vector<std::string>& known_category_groups) {
304 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 288 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
305 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 289 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
306 base::Bind(&TraceControllerImpl::OnEndTracingAck, 290 base::Bind(&TraceControllerImpl::OnEndTracingAck,
307 base::Unretained(this), known_categories)); 291 base::Unretained(this), known_category_groups));
308 return; 292 return;
309 } 293 }
310 294
311 // Merge known_categories with known_categories_ 295 // Merge known_category_groups with known_category_groups_
312 known_categories_.insert(known_categories.begin(), known_categories.end()); 296 known_category_groups_.insert(known_category_groups.begin(),
297 known_category_groups.end());
313 298
314 if (pending_end_ack_count_ == 0) 299 if (pending_end_ack_count_ == 0)
315 return; 300 return;
316 301
317 if (--pending_end_ack_count_ == 0) { 302 if (--pending_end_ack_count_ == 0) {
318 // All acks have been received. 303 // All acks have been received.
319 is_tracing_ = false; 304 is_tracing_ = false;
320 305
321 // Disable local trace. 306 // Disable local trace.
322 TraceLog::GetInstance()->SetDisabled(); 307 TraceLog::GetInstance()->SetDisabled();
323 308
324 // During this call, our OnTraceDataCollected will be 309 // During this call, our OnTraceDataCollected will be
325 // called with the last of the local trace data. Since we are on the UI 310 // called with the last of the local trace data. Since we are on the UI
326 // thread, the call to OnTraceDataCollected will be synchronous, so we can 311 // thread, the call to OnTraceDataCollected will be synchronous, so we can
327 // immediately call OnEndTracingComplete below. 312 // immediately call OnEndTracingComplete below.
328 TraceLog::GetInstance()->Flush( 313 TraceLog::GetInstance()->Flush(
329 base::Bind(&TraceControllerImpl::OnTraceDataCollected, 314 base::Bind(&TraceControllerImpl::OnTraceDataCollected,
330 base::Unretained(this))); 315 base::Unretained(this)));
331 316
332 // Trigger callback if one is set. 317 // Trigger callback if one is set.
333 if (subscriber_) { 318 if (subscriber_) {
334 if (is_get_categories_) 319 if (is_get_category_groups_)
335 subscriber_->OnKnownCategoriesCollected(known_categories_); 320 subscriber_->OnKnownCategoriesCollected(known_category_groups_);
336 else 321 else
337 subscriber_->OnEndTracingComplete(); 322 subscriber_->OnEndTracingComplete();
338 // Clear subscriber so that others can use TraceController. 323 // Clear subscriber so that others can use TraceController.
339 subscriber_ = NULL; 324 subscriber_ = NULL;
340 } 325 }
341 326
342 is_get_categories_ = false; 327 is_get_category_groups_ = false;
343 } 328 }
344 329
345 if (pending_end_ack_count_ == 1) { 330 if (pending_end_ack_count_ == 1) {
346 // The last ack represents local trace, so we need to ack it now. Note that 331 // The last ack represents local trace, so we need to ack it now. Note that
347 // this code only executes if there were child processes. 332 // this code only executes if there were child processes.
348 std::vector<std::string> categories; 333 std::vector<std::string> category_groups;
349 TraceLog::GetInstance()->GetKnownCategories(&categories); 334 TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups);
350 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 335 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
351 base::Bind(&TraceControllerImpl::OnEndTracingAck, 336 base::Bind(&TraceControllerImpl::OnEndTracingAck,
352 base::Unretained(this), categories)); 337 base::Unretained(this), category_groups));
353 } 338 }
354 } 339 }
355 340
356 void TraceControllerImpl::OnTraceDataCollected( 341 void TraceControllerImpl::OnTraceDataCollected(
357 const scoped_refptr<base::RefCountedString>& events_str_ptr) { 342 const scoped_refptr<base::RefCountedString>& events_str_ptr) {
358 // OnTraceDataCollected may be called from any browser thread, either by the 343 // OnTraceDataCollected may be called from any browser thread, either by the
359 // local event trace system or from child processes via TraceMessageFilter. 344 // local event trace system or from child processes via TraceMessageFilter.
360 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 345 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
361 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 346 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
362 base::Bind(&TraceControllerImpl::OnTraceDataCollected, 347 base::Bind(&TraceControllerImpl::OnTraceDataCollected,
363 base::Unretained(this), events_str_ptr)); 348 base::Unretained(this), events_str_ptr));
364 return; 349 return;
365 } 350 }
366 351
367 // Drop trace events if we are just getting categories. 352 // Drop trace events if we are just getting categories.
368 if (subscriber_ && !is_get_categories_) 353 if (subscriber_ && !is_get_category_groups_)
369 subscriber_->OnTraceDataCollected(events_str_ptr); 354 subscriber_->OnTraceDataCollected(events_str_ptr);
370 } 355 }
371 356
372 void TraceControllerImpl::OnTraceNotification(int notification) { 357 void TraceControllerImpl::OnTraceNotification(int notification) {
373 // OnTraceNotification may be called from any browser thread, either by the 358 // OnTraceNotification may be called from any browser thread, either by the
374 // local event trace system or from child processes via TraceMessageFilter. 359 // local event trace system or from child processes via TraceMessageFilter.
375 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 360 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
376 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 361 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
377 base::Bind(&TraceControllerImpl::OnTraceNotification, 362 base::Bind(&TraceControllerImpl::OnTraceNotification,
378 base::Unretained(this), notification)); 363 base::Unretained(this), notification));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // The last ack represents local trace, so we need to ack it now. Note that 398 // The last ack represents local trace, so we need to ack it now. Note that
414 // this code only executes if there were child processes. 399 // this code only executes if there were child processes.
415 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); 400 float bpf = TraceLog::GetInstance()->GetBufferPercentFull();
416 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 401 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
417 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, 402 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply,
418 base::Unretained(this), bpf)); 403 base::Unretained(this), bpf));
419 } 404 }
420 } 405 }
421 406
422 } // namespace content 407 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/trace_controller_impl.h ('k') | content/browser/tracing/trace_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698