OLD | NEW |
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/cpu.h" | 7 #include "base/cpu.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "components/tracing/process_metrics_memory_dump_provider.h" | |
16 #include "content/browser/tracing/file_tracing_provider_impl.h" | 15 #include "content/browser/tracing/file_tracing_provider_impl.h" |
17 #include "content/browser/tracing/power_tracing_agent.h" | 16 #include "content/browser/tracing/power_tracing_agent.h" |
18 #include "content/browser/tracing/trace_message_filter.h" | 17 #include "content/browser/tracing/trace_message_filter.h" |
19 #include "content/browser/tracing/tracing_ui.h" | 18 #include "content/browser/tracing/tracing_ui.h" |
20 #include "content/common/child_process_messages.h" | 19 #include "content/common/child_process_messages.h" |
21 #include "content/public/browser/browser_message_filter.h" | 20 #include "content/public/browser/browser_message_filter.h" |
22 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/browser/gpu_data_manager.h" | 22 #include "content/public/browser/gpu_data_manager.h" |
24 #include "content/public/browser/tracing_delegate.h" | 23 #include "content/public/browser/tracing_delegate.h" |
25 #include "content/public/common/child_process_host.h" | 24 #include "content/public/common/child_process_host.h" |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 void TracingControllerImpl::AddTraceMessageFilter( | 549 void TracingControllerImpl::AddTraceMessageFilter( |
551 TraceMessageFilter* trace_message_filter) { | 550 TraceMessageFilter* trace_message_filter) { |
552 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 551 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
553 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 552 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
554 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, | 553 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, |
555 base::Unretained(this), | 554 base::Unretained(this), |
556 make_scoped_refptr(trace_message_filter))); | 555 make_scoped_refptr(trace_message_filter))); |
557 return; | 556 return; |
558 } | 557 } |
559 | 558 |
560 #if defined(OS_LINUX) | |
561 // On Linux the browser process dumps process metrics for child process due to | |
562 // sandbox. | |
563 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( | |
564 trace_message_filter->peer_pid()); | |
565 #endif | |
566 | |
567 trace_message_filters_.insert(trace_message_filter); | 559 trace_message_filters_.insert(trace_message_filter); |
568 if (can_cancel_watch_event()) { | 560 if (can_cancel_watch_event()) { |
569 trace_message_filter->SendSetWatchEvent(watch_category_name_, | 561 trace_message_filter->SendSetWatchEvent(watch_category_name_, |
570 watch_event_name_); | 562 watch_event_name_); |
571 } | 563 } |
572 if (can_stop_tracing()) { | 564 if (can_stop_tracing()) { |
573 trace_message_filter->SendBeginTracing( | 565 trace_message_filter->SendBeginTracing( |
574 TraceLog::GetInstance()->GetCurrentTraceConfig()); | 566 TraceLog::GetInstance()->GetCurrentTraceConfig()); |
575 } | 567 } |
576 if (can_stop_monitoring()) { | 568 if (can_stop_monitoring()) { |
577 trace_message_filter->SendStartMonitoring( | 569 trace_message_filter->SendStartMonitoring( |
578 TraceLog::GetInstance()->GetCurrentTraceConfig()); | 570 TraceLog::GetInstance()->GetCurrentTraceConfig()); |
579 } | 571 } |
580 | 572 |
581 FOR_EACH_OBSERVER(TraceMessageFilterObserver, trace_message_filter_observers_, | 573 FOR_EACH_OBSERVER(TraceMessageFilterObserver, trace_message_filter_observers_, |
582 OnTraceMessageFilterAdded(trace_message_filter)); | 574 OnTraceMessageFilterAdded(trace_message_filter)); |
583 } | 575 } |
584 | 576 |
585 void TracingControllerImpl::RemoveTraceMessageFilter( | 577 void TracingControllerImpl::RemoveTraceMessageFilter( |
586 TraceMessageFilter* trace_message_filter) { | 578 TraceMessageFilter* trace_message_filter) { |
587 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 579 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
588 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 580 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
589 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, | 581 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, |
590 base::Unretained(this), | 582 base::Unretained(this), |
591 make_scoped_refptr(trace_message_filter))); | 583 make_scoped_refptr(trace_message_filter))); |
592 return; | 584 return; |
593 } | 585 } |
594 | 586 |
595 #if defined(OS_LINUX) | |
596 tracing::ProcessMetricsMemoryDumpProvider::UnregisterForProcess( | |
597 trace_message_filter->peer_pid()); | |
598 #endif | |
599 | |
600 // If a filter is removed while a response from that filter is pending then | 587 // If a filter is removed while a response from that filter is pending then |
601 // simulate the response. Otherwise the response count will be wrong and the | 588 // simulate the response. Otherwise the response count will be wrong and the |
602 // completion callback will never be executed. | 589 // completion callback will never be executed. |
603 if (pending_stop_tracing_ack_count_ > 0) { | 590 if (pending_stop_tracing_ack_count_ > 0) { |
604 TraceMessageFilterSet::const_iterator it = | 591 TraceMessageFilterSet::const_iterator it = |
605 pending_stop_tracing_filters_.find(trace_message_filter); | 592 pending_stop_tracing_filters_.find(trace_message_filter); |
606 if (it != pending_stop_tracing_filters_.end()) { | 593 if (it != pending_stop_tracing_filters_.end()) { |
607 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 594 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
608 base::Bind(&TracingControllerImpl::OnStopTracingAcked, | 595 base::Bind(&TracingControllerImpl::OnStopTracingAcked, |
609 base::Unretained(this), | 596 base::Unretained(this), |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 is_monitoring_ = is_monitoring; | 1123 is_monitoring_ = is_monitoring; |
1137 #if !defined(OS_ANDROID) | 1124 #if !defined(OS_ANDROID) |
1138 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 1125 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
1139 it != tracing_uis_.end(); it++) { | 1126 it != tracing_uis_.end(); it++) { |
1140 (*it)->OnMonitoringStateChanged(is_monitoring); | 1127 (*it)->OnMonitoringStateChanged(is_monitoring); |
1141 } | 1128 } |
1142 #endif | 1129 #endif |
1143 } | 1130 } |
1144 | 1131 |
1145 } // namespace content | 1132 } // namespace content |
OLD | NEW |