Chromium Code Reviews| 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 <algorithm> | |
| 7 #include <memory> | |
| 8 #include <utility> | |
| 9 | |
| 6 #include "base/bind.h" | 10 #include "base/bind.h" |
| 7 #include "base/cpu.h" | 11 #include "base/cpu.h" |
| 8 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 9 #include "base/guid.h" | 13 #include "base/guid.h" |
| 10 #include "base/json/string_escape.h" | 14 #include "base/json/string_escape.h" |
| 11 #include "base/macros.h" | 15 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 37 #define ENABLE_POWER_TRACING | 41 #define ENABLE_POWER_TRACING |
| 38 #endif | 42 #endif |
| 39 | 43 |
| 40 #if defined(ENABLE_POWER_TRACING) | 44 #if defined(ENABLE_POWER_TRACING) |
| 41 #include "content/browser/tracing/power_tracing_agent.h" | 45 #include "content/browser/tracing/power_tracing_agent.h" |
| 42 #endif | 46 #endif |
| 43 | 47 |
| 44 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 45 #include "chromeos/dbus/dbus_thread_manager.h" | 49 #include "chromeos/dbus/dbus_thread_manager.h" |
| 46 #include "chromeos/dbus/debug_daemon_client.h" | 50 #include "chromeos/dbus/debug_daemon_client.h" |
| 51 #include "chromeos/trace/arc_trace_agent.h" | |
| 47 #endif | 52 #endif |
| 48 | 53 |
| 49 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 50 #include "content/browser/tracing/etw_tracing_agent_win.h" | 55 #include "content/browser/tracing/etw_tracing_agent_win.h" |
| 51 #endif | 56 #endif |
| 52 | 57 |
| 53 using base::trace_event::TraceLog; | 58 using base::trace_event::TraceLog; |
| 54 using base::trace_event::TraceConfig; | 59 using base::trace_event::TraceConfig; |
| 55 | 60 |
| 56 namespace content { | 61 namespace content { |
| 57 | 62 |
| 58 namespace { | 63 namespace { |
| 59 | 64 |
| 60 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = | 65 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = |
| 61 LAZY_INSTANCE_INITIALIZER; | 66 LAZY_INSTANCE_INITIALIZER; |
| 62 | 67 |
| 63 const char kChromeTracingAgentName[] = "chrome"; | 68 const char kChromeTracingAgentName[] = "chrome"; |
| 64 const char kETWTracingAgentName[] = "etw"; | 69 const char kETWTracingAgentName[] = "etw"; |
| 70 const char kArcTracingAgentName[] = "arc"; | |
| 65 const char kChromeTraceLabel[] = "traceEvents"; | 71 const char kChromeTraceLabel[] = "traceEvents"; |
| 66 | 72 |
| 67 const int kStartTracingTimeoutSeconds = 30; | 73 const int kStartTracingTimeoutSeconds = 30; |
| 68 const int kIssueClockSyncTimeoutSeconds = 30; | 74 const int kIssueClockSyncTimeoutSeconds = 30; |
| 69 const int kStopTracingRetryTimeMilliseconds = 100; | 75 const int kStopTracingRetryTimeMilliseconds = 100; |
| 70 | 76 |
| 71 std::string GetNetworkTypeString() { | 77 std::string GetNetworkTypeString() { |
| 72 switch (net::NetworkChangeNotifier::GetConnectionType()) { | 78 switch (net::NetworkChangeNotifier::GetConnectionType()) { |
| 73 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | 79 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| 74 return "Ethernet"; | 80 return "Ethernet"; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 } | 296 } |
| 291 #elif defined(OS_WIN) | 297 #elif defined(OS_WIN) |
| 292 EtwTracingAgent::GetInstance()->StartAgentTracing( | 298 EtwTracingAgent::GetInstance()->StartAgentTracing( |
| 293 trace_config, | 299 trace_config, |
| 294 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | 300 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 295 base::Unretained(this))); | 301 base::Unretained(this))); |
| 296 ++pending_start_tracing_ack_count_; | 302 ++pending_start_tracing_ack_count_; |
| 297 #endif | 303 #endif |
| 298 } | 304 } |
| 299 | 305 |
| 306 #if defined(OS_CHROMEOS) | |
| 307 auto* arc_trace_agent = chromeos::ArcTraceAgent::GetInstance(); | |
| 308 if (arc_trace_agent) { | |
|
Luis Héctor Chávez
2017/02/16 16:45:11
Why would |arc_trace_agent| be nullptr? Maybe you
Earl Ou
2017/02/17 02:12:59
Done.
| |
| 309 arc_trace_agent->StartAgentTracing( | |
| 310 trace_config, | |
| 311 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | |
| 312 base::Unretained(this))); | |
| 313 ++pending_start_tracing_ack_count_; | |
| 314 } | |
| 315 #endif | |
| 316 | |
| 300 // TraceLog may have been enabled in startup tracing before threads are ready. | 317 // TraceLog may have been enabled in startup tracing before threads are ready. |
| 301 if (TraceLog::GetInstance()->IsEnabled()) | 318 if (TraceLog::GetInstance()->IsEnabled()) |
| 302 return true; | 319 return true; |
| 303 | 320 |
| 304 StartAgentTracing(trace_config, | 321 StartAgentTracing(trace_config, |
| 305 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | 322 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 306 base::Unretained(this))); | 323 base::Unretained(this))); |
| 307 ++pending_start_tracing_ack_count_; | 324 ++pending_start_tracing_ack_count_; |
| 308 | 325 |
| 309 // Set a deadline to ensure all agents ack within a reasonable time frame. | 326 // Set a deadline to ensure all agents ack within a reasonable time frame. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { | 572 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { |
| 556 #if defined(OS_CHROMEOS) | 573 #if defined(OS_CHROMEOS) |
| 557 auto* debug_daemon = | 574 auto* debug_daemon = |
| 558 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 575 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 559 if (agent_name == debug_daemon->GetTracingAgentName()) { | 576 if (agent_name == debug_daemon->GetTracingAgentName()) { |
| 560 additional_tracing_agents_.push_back(debug_daemon); | 577 additional_tracing_agents_.push_back(debug_daemon); |
| 561 debug_daemon->SetStopAgentTracingTaskRunner( | 578 debug_daemon->SetStopAgentTracingTaskRunner( |
| 562 BrowserThread::GetBlockingPool()); | 579 BrowserThread::GetBlockingPool()); |
| 563 return; | 580 return; |
| 564 } | 581 } |
| 582 | |
| 583 auto* arc_trace_agent = chromeos::ArcTraceAgent::GetInstance(); | |
| 584 if (arc_trace_agent && agent_name == arc_trace_agent->GetTracingAgentName()) { | |
| 585 additional_tracing_agents_.push_back(arc_trace_agent); | |
| 586 return; | |
| 587 } | |
| 565 #elif defined(OS_WIN) | 588 #elif defined(OS_WIN) |
| 566 auto* etw_agent = EtwTracingAgent::GetInstance(); | 589 auto* etw_agent = EtwTracingAgent::GetInstance(); |
| 567 if (agent_name == etw_agent->GetTracingAgentName()) { | 590 if (agent_name == etw_agent->GetTracingAgentName()) { |
| 568 additional_tracing_agents_.push_back(etw_agent); | 591 additional_tracing_agents_.push_back(etw_agent); |
| 569 return; | 592 return; |
| 570 } | 593 } |
| 571 #endif | 594 #endif |
| 572 | 595 |
| 573 #if defined(ENABLE_POWER_TRACING) | 596 #if defined(ENABLE_POWER_TRACING) |
| 574 auto* power_agent = PowerTracingAgent::GetInstance(); | 597 auto* power_agent = PowerTracingAgent::GetInstance(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 if (trace_data_sink_.get() && events_str_ptr && | 690 if (trace_data_sink_.get() && events_str_ptr && |
| 668 !events_str_ptr->data().empty()) { | 691 !events_str_ptr->data().empty()) { |
| 669 std::string json_string; | 692 std::string json_string; |
| 670 if (agent_name == kETWTracingAgentName) { | 693 if (agent_name == kETWTracingAgentName) { |
| 671 // The Windows kernel events are kept into a JSON format stored as string | 694 // The Windows kernel events are kept into a JSON format stored as string |
| 672 // and must not be escaped. | 695 // and must not be escaped. |
| 673 json_string = events_str_ptr->data(); | 696 json_string = events_str_ptr->data(); |
| 674 } else { | 697 } else { |
| 675 json_string = base::GetQuotedJSONString(events_str_ptr->data()); | 698 json_string = base::GetQuotedJSONString(events_str_ptr->data()); |
| 676 } | 699 } |
| 677 trace_data_sink_->AddAgentTrace(events_label, json_string); | 700 |
| 701 // ARC tracing data is obtained via systrace. Ignore the empty data here. | |
| 702 if (agent_name != kArcTracingAgentName) { | |
| 703 trace_data_sink_->AddAgentTrace(events_label, json_string); | |
| 704 } | |
| 678 } | 705 } |
| 679 std::vector<std::string> category_groups; | 706 std::vector<std::string> category_groups; |
| 680 OnStopTracingAcked(NULL, category_groups); | 707 OnStopTracingAcked(NULL, category_groups); |
| 681 } | 708 } |
| 682 | 709 |
| 683 void TracingControllerImpl::OnTraceDataCollected( | 710 void TracingControllerImpl::OnTraceDataCollected( |
| 684 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 711 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 685 // OnTraceDataCollected may be called from any browser thread, either by the | 712 // OnTraceDataCollected may be called from any browser thread, either by the |
| 686 // local event trace system or from child processes via TraceMessageFilter. | 713 // local event trace system or from child processes via TraceMessageFilter. |
| 687 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 714 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 void TracingControllerImpl::RecordClockSyncMarker( | 849 void TracingControllerImpl::RecordClockSyncMarker( |
| 823 const std::string& sync_id, | 850 const std::string& sync_id, |
| 824 const RecordClockSyncMarkerCallback& callback) { | 851 const RecordClockSyncMarkerCallback& callback) { |
| 825 DCHECK(SupportsExplicitClockSync()); | 852 DCHECK(SupportsExplicitClockSync()); |
| 826 | 853 |
| 827 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); | 854 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); |
| 828 } | 855 } |
| 829 | 856 |
| 830 void TracingControllerImpl::IssueClockSyncMarker() { | 857 void TracingControllerImpl::IssueClockSyncMarker() { |
| 831 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 858 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 832 DCHECK(pending_clock_sync_ack_count_ == 0); | 859 DCHECK_EQ(0, pending_clock_sync_ack_count_); |
| 833 | 860 |
| 834 for (auto* it : additional_tracing_agents_) { | 861 for (auto* it : additional_tracing_agents_) { |
| 835 if (it->SupportsExplicitClockSync()) { | 862 if (it->SupportsExplicitClockSync()) { |
| 836 it->RecordClockSyncMarker( | 863 it->RecordClockSyncMarker( |
| 837 base::GenerateGUID(), | 864 base::GenerateGUID(), |
| 838 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, | 865 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, |
| 839 base::Unretained(this))); | 866 base::Unretained(this))); |
| 840 pending_clock_sync_ack_count_++; | 867 pending_clock_sync_ack_count_++; |
| 841 } | 868 } |
| 842 } | 869 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 862 // success indicator instead of having to rely on sentinel issue_ts and | 889 // success indicator instead of having to rely on sentinel issue_ts and |
| 863 // issue_end_ts values to signal failure. | 890 // issue_end_ts values to signal failure. |
| 864 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks())) | 891 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks())) |
| 865 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); | 892 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); |
| 866 | 893 |
| 867 // Timer is not running means that clock sync already timed out. | 894 // Timer is not running means that clock sync already timed out. |
| 868 if (!clock_sync_timer_.IsRunning()) | 895 if (!clock_sync_timer_.IsRunning()) |
| 869 return; | 896 return; |
| 870 | 897 |
| 871 // Stop tracing only if all agents report back. | 898 // Stop tracing only if all agents report back. |
| 872 if(--pending_clock_sync_ack_count_ == 0) { | 899 if (--pending_clock_sync_ack_count_ == 0) { |
| 873 clock_sync_timer_.Stop(); | 900 clock_sync_timer_.Stop(); |
| 874 StopTracingAfterClockSync(); | 901 StopTracingAfterClockSync(); |
| 875 } | 902 } |
| 876 } | 903 } |
| 877 | 904 |
| 878 void TracingControllerImpl::AddFilteredMetadata( | 905 void TracingControllerImpl::AddFilteredMetadata( |
| 879 TracingController::TraceDataSink* sink, | 906 TracingController::TraceDataSink* sink, |
| 880 std::unique_ptr<base::DictionaryValue> metadata, | 907 std::unique_ptr<base::DictionaryValue> metadata, |
| 881 const MetadataFilterPredicate& filter) { | 908 const MetadataFilterPredicate& filter) { |
| 882 if (filter.is_null()) { | 909 if (filter.is_null()) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 // Schedule the next queued dump (if applicable). | 1087 // Schedule the next queued dump (if applicable). |
| 1061 if (!queued_memory_dump_requests_.empty()) { | 1088 if (!queued_memory_dump_requests_.empty()) { |
| 1062 BrowserThread::PostTask( | 1089 BrowserThread::PostTask( |
| 1063 BrowserThread::UI, FROM_HERE, | 1090 BrowserThread::UI, FROM_HERE, |
| 1064 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, | 1091 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, |
| 1065 base::Unretained(this))); | 1092 base::Unretained(this))); |
| 1066 } | 1093 } |
| 1067 } | 1094 } |
| 1068 | 1095 |
| 1069 } // namespace content | 1096 } // namespace content |
| OLD | NEW |