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

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

Issue 425593002: Refactor trace_event_impl's SetEnabled to use TraceOptions. Propagate this through the whole stack. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "content/browser/tracing/tracing_controller_impl.h" 4 #include "content/browser/tracing/tracing_controller_impl.h"
5 5
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "content/browser/tracing/trace_message_filter.h" 11 #include "content/browser/tracing/trace_message_filter.h"
12 #include "content/browser/tracing/tracing_ui.h" 12 #include "content/browser/tracing/tracing_ui.h"
13 #include "content/common/child_process_messages.h" 13 #include "content/common/child_process_messages.h"
14 #include "content/public/browser/browser_message_filter.h" 14 #include "content/public/browser/browser_message_filter.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 16
17 #if defined(OS_CHROMEOS) 17 #if defined(OS_CHROMEOS)
18 #include "chromeos/dbus/dbus_thread_manager.h" 18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/debug_daemon_client.h" 19 #include "chromeos/dbus/debug_daemon_client.h"
20 #endif 20 #endif
21 21
22 #if defined(OS_WIN) 22 #if defined(OS_WIN)
23 #include "content/browser/tracing/etw_system_event_consumer_win.h" 23 #include "content/browser/tracing/etw_system_event_consumer_win.h"
24 #endif 24 #endif
25 25
26 using base::debug::TraceLog; 26 using base::debug::TraceLog;
27 using base::debug::TraceOptions;
27 28
28 namespace content { 29 namespace content {
29 30
30 namespace { 31 namespace {
31 32
32 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = 33 base::LazyInstance<TracingControllerImpl>::Leaky g_controller =
33 LAZY_INSTANCE_INITIALIZER; 34 LAZY_INSTANCE_INITIALIZER;
34 35
35 } // namespace 36 } // namespace
36 37
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 185 }
185 186
186 bool TracingControllerImpl::GetCategories( 187 bool TracingControllerImpl::GetCategories(
187 const GetCategoriesDoneCallback& callback) { 188 const GetCategoriesDoneCallback& callback) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
189 190
190 // Known categories come back from child processes with the EndTracingAck 191 // Known categories come back from child processes with the EndTracingAck
191 // message. So to get known categories, just begin and end tracing immediately 192 // message. So to get known categories, just begin and end tracing immediately
192 // afterwards. This will ping all the child processes for categories. 193 // afterwards. This will ping all the child processes for categories.
193 pending_get_categories_done_callback_ = callback; 194 pending_get_categories_done_callback_ = callback;
194 if (!EnableRecording("*", TracingController::Options(), 195 if (!EnableRecording("*",
196 TraceOptions(),
197 false,
195 EnableRecordingDoneCallback())) { 198 EnableRecordingDoneCallback())) {
196 pending_get_categories_done_callback_.Reset(); 199 pending_get_categories_done_callback_.Reset();
197 return false; 200 return false;
198 } 201 }
199 202
200 bool ok = DisableRecording(base::FilePath(), TracingFileResultCallback()); 203 bool ok = DisableRecording(base::FilePath(), TracingFileResultCallback());
201 DCHECK(ok); 204 DCHECK(ok);
202 return true; 205 return true;
203 } 206 }
204 207
205 void TracingControllerImpl::SetEnabledOnFileThread( 208 void TracingControllerImpl::SetEnabledOnFileThread(
206 const std::string& category_filter, 209 const std::string& category_filter,
207 int mode, 210 int mode,
208 int trace_options, 211 TraceOptions trace_options,
209 const base::Closure& callback) { 212 const base::Closure& callback) {
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
211 214
212 TraceLog::GetInstance()->SetEnabled( 215 TraceLog::GetInstance()->SetEnabled(
213 base::debug::CategoryFilter(category_filter), 216 base::debug::CategoryFilter(category_filter),
214 static_cast<TraceLog::Mode>(mode), 217 static_cast<TraceLog::Mode>(mode),
215 static_cast<TraceLog::Options>(trace_options)); 218 trace_options);
216 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); 219 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
217 } 220 }
218 221
219 void TracingControllerImpl::SetDisabledOnFileThread( 222 void TracingControllerImpl::SetDisabledOnFileThread(
220 const base::Closure& callback) { 223 const base::Closure& callback) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
222 225
223 TraceLog::GetInstance()->SetDisabled(); 226 TraceLog::GetInstance()->SetDisabled();
224 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); 227 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
225 } 228 }
226 229
227 bool TracingControllerImpl::EnableRecording( 230 bool TracingControllerImpl::EnableRecording(
228 const std::string& category_filter, 231 const std::string& category_filter,
229 TracingController::Options options, 232 TraceOptions trace_options,
233 bool enable_systrace,
230 const EnableRecordingDoneCallback& callback) { 234 const EnableRecordingDoneCallback& callback) {
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
232 236
233 if (!can_enable_recording()) 237 if (!can_enable_recording())
234 return false; 238 return false;
235 is_recording_ = true; 239 is_recording_ = true;
236 240
237 #if defined(OS_ANDROID) 241 #if defined(OS_ANDROID)
238 if (pending_get_categories_done_callback_.is_null()) 242 if (pending_get_categories_done_callback_.is_null())
239 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); 243 TraceLog::GetInstance()->AddClockSyncMetadataEvent();
240 #endif 244 #endif
241 245
242 options_ = options; 246 trace_options_ = trace_options;
243 int trace_options = (options & RECORD_CONTINUOUSLY) ? 247 enable_systrace_ = enable_systrace;
244 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL;
245 if (options & ENABLE_SAMPLING) {
246 trace_options |= TraceLog::ENABLE_SAMPLING;
247 }
248 248
249 if (options & ENABLE_SYSTRACE) { 249 if (enable_systrace) {
250 #if defined(OS_CHROMEOS) 250 #if defined(OS_CHROMEOS)
251 DCHECK(!is_system_tracing_); 251 DCHECK(!is_system_tracing_);
252 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> 252 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->
253 StartSystemTracing(); 253 StartSystemTracing();
254 is_system_tracing_ = true; 254 is_system_tracing_ = true;
255 #elif defined(OS_WIN) 255 #elif defined(OS_WIN)
256 DCHECK(!is_system_tracing_); 256 DCHECK(!is_system_tracing_);
257 is_system_tracing_ = 257 is_system_tracing_ =
258 EtwSystemEventConsumer::GetInstance()->StartSystemTracing(); 258 EtwSystemEventConsumer::GetInstance()->StartSystemTracing();
259 #endif 259 #endif
260 } 260 }
261 261
262 262
263 base::Closure on_enable_recording_done_callback = 263 base::Closure on_enable_recording_done_callback =
264 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, 264 base::Bind(&TracingControllerImpl::OnEnableRecordingDone,
265 base::Unretained(this), 265 base::Unretained(this),
266 category_filter, trace_options, callback); 266 category_filter, trace_options, callback);
267 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 267 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
268 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, 268 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
269 base::Unretained(this), 269 base::Unretained(this),
270 category_filter, 270 category_filter,
271 base::debug::TraceLog::RECORDING_MODE, 271 base::debug::TraceLog::RECORDING_MODE,
272 trace_options, 272 trace_options,
273 on_enable_recording_done_callback)); 273 on_enable_recording_done_callback));
274 return true; 274 return true;
275 } 275 }
276 276
277 void TracingControllerImpl::OnEnableRecordingDone( 277 void TracingControllerImpl::OnEnableRecordingDone(
278 const std::string& category_filter, 278 const std::string& category_filter,
279 int trace_options, 279 TraceOptions trace_options,
280 const EnableRecordingDoneCallback& callback) { 280 const EnableRecordingDoneCallback& callback) {
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
282 282
283 // Notify all child processes. 283 // Notify all child processes.
284 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 284 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
285 it != trace_message_filters_.end(); ++it) { 285 it != trace_message_filters_.end(); ++it) {
286 it->get()->SendBeginTracing(category_filter, 286 it->get()->SendBeginTracing(category_filter, trace_options);
287 static_cast<TraceLog::Options>(trace_options));
288 } 287 }
289 288
290 if (!callback.is_null()) 289 if (!callback.is_null())
291 callback.Run(); 290 callback.Run();
292 } 291 }
293 292
294 bool TracingControllerImpl::DisableRecording( 293 bool TracingControllerImpl::DisableRecording(
295 const base::FilePath& result_file_path, 294 const base::FilePath& result_file_path,
296 const TracingFileResultCallback& callback) { 295 const TracingFileResultCallback& callback) {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
298 297
299 if (!can_disable_recording()) 298 if (!can_disable_recording())
300 return false; 299 return false;
301 300
302 options_ = TracingController::Options(); 301 trace_options_ = TraceOptions();
303 // Disable local trace early to avoid traces during end-tracing process from 302 // Disable local trace early to avoid traces during end-tracing process from
304 // interfering with the process. 303 // interfering with the process.
305 base::Closure on_disable_recording_done_callback = 304 base::Closure on_disable_recording_done_callback =
306 base::Bind(&TracingControllerImpl::OnDisableRecordingDone, 305 base::Bind(&TracingControllerImpl::OnDisableRecordingDone,
307 base::Unretained(this), 306 base::Unretained(this),
308 result_file_path, callback); 307 result_file_path, callback);
309 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 308 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
310 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, 309 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread,
311 base::Unretained(this), 310 base::Unretained(this),
312 on_disable_recording_done_callback)); 311 on_disable_recording_done_callback));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 367
369 // Notify all child processes. 368 // Notify all child processes.
370 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 369 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
371 it != trace_message_filters_.end(); ++it) { 370 it != trace_message_filters_.end(); ++it) {
372 it->get()->SendEndTracing(); 371 it->get()->SendEndTracing();
373 } 372 }
374 } 373 }
375 374
376 bool TracingControllerImpl::EnableMonitoring( 375 bool TracingControllerImpl::EnableMonitoring(
377 const std::string& category_filter, 376 const std::string& category_filter,
378 TracingController::Options options, 377 TraceOptions trace_options,
379 const EnableMonitoringDoneCallback& callback) { 378 const EnableMonitoringDoneCallback& callback) {
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
381 380
382 if (!can_enable_monitoring()) 381 if (!can_enable_monitoring())
383 return false; 382 return false;
384 OnMonitoringStateChanged(true); 383 OnMonitoringStateChanged(true);
385 384
386 #if defined(OS_ANDROID) 385 #if defined(OS_ANDROID)
387 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); 386 TraceLog::GetInstance()->AddClockSyncMetadataEvent();
388 #endif 387 #endif
389 388
390 options_ = options; 389 trace_options_ = trace_options;
391 int trace_options = 0;
392 if (options & ENABLE_SAMPLING)
393 trace_options |= TraceLog::ENABLE_SAMPLING;
394 390
395 base::Closure on_enable_monitoring_done_callback = 391 base::Closure on_enable_monitoring_done_callback =
396 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone, 392 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone,
397 base::Unretained(this), 393 base::Unretained(this),
398 category_filter, trace_options, callback); 394 category_filter, trace_options, callback);
399 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 395 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
400 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, 396 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
401 base::Unretained(this), 397 base::Unretained(this),
402 category_filter, 398 category_filter,
403 base::debug::TraceLog::MONITORING_MODE, 399 base::debug::TraceLog::MONITORING_MODE,
404 trace_options, 400 trace_options,
405 on_enable_monitoring_done_callback)); 401 on_enable_monitoring_done_callback));
406 return true; 402 return true;
407 } 403 }
408 404
409 void TracingControllerImpl::OnEnableMonitoringDone( 405 void TracingControllerImpl::OnEnableMonitoringDone(
410 const std::string& category_filter, 406 const std::string& category_filter,
411 int trace_options, 407 TraceOptions trace_options,
412 const EnableMonitoringDoneCallback& callback) { 408 const EnableMonitoringDoneCallback& callback) {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 410
415 // Notify all child processes. 411 // Notify all child processes.
416 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 412 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
417 it != trace_message_filters_.end(); ++it) { 413 it != trace_message_filters_.end(); ++it) {
418 it->get()->SendEnableMonitoring(category_filter, 414 it->get()->SendEnableMonitoring(category_filter, trace_options);
419 static_cast<TraceLog::Options>(trace_options));
420 } 415 }
421 416
422 if (!callback.is_null()) 417 if (!callback.is_null())
423 callback.Run(); 418 callback.Run();
424 } 419 }
425 420
426 bool TracingControllerImpl::DisableMonitoring( 421 bool TracingControllerImpl::DisableMonitoring(
427 const DisableMonitoringDoneCallback& callback) { 422 const DisableMonitoringDoneCallback& callback) {
428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
429 424
430 if (!can_disable_monitoring()) 425 if (!can_disable_monitoring())
431 return false; 426 return false;
432 427
433 options_ = TracingController::Options(); 428 trace_options_ = TraceOptions();
429 enable_systrace_ = false;
434 base::Closure on_disable_monitoring_done_callback = 430 base::Closure on_disable_monitoring_done_callback =
435 base::Bind(&TracingControllerImpl::OnDisableMonitoringDone, 431 base::Bind(&TracingControllerImpl::OnDisableMonitoringDone,
436 base::Unretained(this), callback); 432 base::Unretained(this), callback);
437 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 433 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
438 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, 434 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread,
439 base::Unretained(this), 435 base::Unretained(this),
440 on_disable_monitoring_done_callback)); 436 on_disable_monitoring_done_callback));
441 return true; 437 return true;
442 } 438 }
443 439
444 void TracingControllerImpl::OnDisableMonitoringDone( 440 void TracingControllerImpl::OnDisableMonitoringDone(
445 const DisableMonitoringDoneCallback& callback) { 441 const DisableMonitoringDoneCallback& callback) {
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
447 443
448 OnMonitoringStateChanged(false); 444 OnMonitoringStateChanged(false);
449 445
450 // Notify all child processes. 446 // Notify all child processes.
451 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 447 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
452 it != trace_message_filters_.end(); ++it) { 448 it != trace_message_filters_.end(); ++it) {
453 it->get()->SendDisableMonitoring(); 449 it->get()->SendDisableMonitoring();
454 } 450 }
455 451
456 if (!callback.is_null()) 452 if (!callback.is_null())
457 callback.Run(); 453 callback.Run();
458 } 454 }
459 455
460 void TracingControllerImpl::GetMonitoringStatus( 456 void TracingControllerImpl::GetMonitoringStatus(
461 bool* out_enabled, 457 bool* out_enabled,
462 std::string* out_category_filter, 458 std::string* out_category_filter,
463 TracingController::Options* out_options) { 459 TraceOptions* out_trace_options,
460 bool* out_enable_systrace) {
464 *out_enabled = is_monitoring_; 461 *out_enabled = is_monitoring_;
465 *out_category_filter = 462 *out_category_filter =
466 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(); 463 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString();
467 *out_options = options_; 464 *out_trace_options = trace_options_;
465 *out_enable_systrace = enable_systrace_;
468 } 466 }
469 467
470 bool TracingControllerImpl::CaptureMonitoringSnapshot( 468 bool TracingControllerImpl::CaptureMonitoringSnapshot(
471 const base::FilePath& result_file_path, 469 const base::FilePath& result_file_path,
472 const TracingFileResultCallback& callback) { 470 const TracingFileResultCallback& callback) {
473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
474 472
475 if (!can_disable_monitoring()) 473 if (!can_disable_monitoring())
476 return false; 474 return false;
477 475
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 } 591 }
594 592
595 trace_message_filters_.insert(trace_message_filter); 593 trace_message_filters_.insert(trace_message_filter);
596 if (can_cancel_watch_event()) { 594 if (can_cancel_watch_event()) {
597 trace_message_filter->SendSetWatchEvent(watch_category_name_, 595 trace_message_filter->SendSetWatchEvent(watch_category_name_,
598 watch_event_name_); 596 watch_event_name_);
599 } 597 }
600 if (can_disable_recording()) { 598 if (can_disable_recording()) {
601 trace_message_filter->SendBeginTracing( 599 trace_message_filter->SendBeginTracing(
602 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), 600 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(),
603 TraceLog::GetInstance()->trace_options()); 601 TraceLog::GetInstance()->GetCurrentTraceOptions());
604 } 602 }
605 if (can_disable_monitoring()) { 603 if (can_disable_monitoring()) {
606 trace_message_filter->SendEnableMonitoring( 604 trace_message_filter->SendEnableMonitoring(
607 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), 605 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(),
608 TraceLog::GetInstance()->trace_options()); 606 TraceLog::GetInstance()->GetCurrentTraceOptions());
609 } 607 }
610 } 608 }
611 609
612 void TracingControllerImpl::RemoveTraceMessageFilter( 610 void TracingControllerImpl::RemoveTraceMessageFilter(
613 TraceMessageFilter* trace_message_filter) { 611 TraceMessageFilter* trace_message_filter) {
614 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 612 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
615 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 613 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
616 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, 614 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter,
617 base::Unretained(this), 615 base::Unretained(this),
618 make_scoped_refptr(trace_message_filter))); 616 make_scoped_refptr(trace_message_filter)));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 is_monitoring_ = is_monitoring; 911 is_monitoring_ = is_monitoring;
914 #if !defined(OS_ANDROID) 912 #if !defined(OS_ANDROID)
915 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); 913 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin();
916 it != tracing_uis_.end(); it++) { 914 it != tracing_uis_.end(); it++) {
917 (*it)->OnMonitoringStateChanged(is_monitoring); 915 (*it)->OnMonitoringStateChanged(is_monitoring);
918 } 916 }
919 #endif 917 #endif
920 } 918 }
921 919
922 } // namespace content 920 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698