| 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/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 38 #define ENABLE_POWER_TRACING | 42 #define ENABLE_POWER_TRACING |
| 39 #endif | 43 #endif |
| 40 | 44 |
| 41 #if defined(ENABLE_POWER_TRACING) | 45 #if defined(ENABLE_POWER_TRACING) |
| 42 #include "content/browser/tracing/power_tracing_agent.h" | 46 #include "content/browser/tracing/power_tracing_agent.h" |
| 43 #endif | 47 #endif |
| 44 | 48 |
| 45 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
| 46 #include "chromeos/dbus/dbus_thread_manager.h" | 50 #include "chromeos/dbus/dbus_thread_manager.h" |
| 47 #include "chromeos/dbus/debug_daemon_client.h" | 51 #include "chromeos/dbus/debug_daemon_client.h" |
| 52 #include "content/browser/tracing/arc_tracing_agent.h" |
| 48 #endif | 53 #endif |
| 49 | 54 |
| 50 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 51 #include "content/browser/tracing/etw_tracing_agent_win.h" | 56 #include "content/browser/tracing/etw_tracing_agent_win.h" |
| 52 #endif | 57 #endif |
| 53 | 58 |
| 54 using base::trace_event::TraceLog; | 59 using base::trace_event::TraceLog; |
| 55 using base::trace_event::TraceConfig; | 60 using base::trace_event::TraceConfig; |
| 56 | 61 |
| 57 namespace content { | 62 namespace content { |
| 58 | 63 |
| 59 namespace { | 64 namespace { |
| 60 | 65 |
| 61 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = | 66 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = |
| 62 LAZY_INSTANCE_INITIALIZER; | 67 LAZY_INSTANCE_INITIALIZER; |
| 63 | 68 |
| 64 const char kChromeTracingAgentName[] = "chrome"; | 69 const char kChromeTracingAgentName[] = "chrome"; |
| 65 const char kETWTracingAgentName[] = "etw"; | 70 const char kETWTracingAgentName[] = "etw"; |
| 71 const char kArcTracingAgentName[] = "arc"; |
| 66 const char kChromeTraceLabel[] = "traceEvents"; | 72 const char kChromeTraceLabel[] = "traceEvents"; |
| 67 | 73 |
| 68 const int kStartTracingTimeoutSeconds = 30; | 74 const int kStartTracingTimeoutSeconds = 30; |
| 69 const int kIssueClockSyncTimeoutSeconds = 30; | 75 const int kIssueClockSyncTimeoutSeconds = 30; |
| 70 const int kStopTracingRetryTimeMilliseconds = 100; | 76 const int kStopTracingRetryTimeMilliseconds = 100; |
| 71 | 77 |
| 72 std::string GetNetworkTypeString() { | 78 std::string GetNetworkTypeString() { |
| 73 switch (net::NetworkChangeNotifier::GetConnectionType()) { | 79 switch (net::NetworkChangeNotifier::GetConnectionType()) { |
| 74 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | 80 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| 75 return "Ethernet"; | 81 return "Ethernet"; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 #if defined(OS_CHROMEOS) | 288 #if defined(OS_CHROMEOS) |
| 283 chromeos::DebugDaemonClient* debug_daemon = | 289 chromeos::DebugDaemonClient* debug_daemon = |
| 284 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 290 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 285 if (debug_daemon) { | 291 if (debug_daemon) { |
| 286 debug_daemon->StartAgentTracing( | 292 debug_daemon->StartAgentTracing( |
| 287 trace_config, | 293 trace_config, |
| 288 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | 294 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 289 base::Unretained(this))); | 295 base::Unretained(this))); |
| 290 ++pending_start_tracing_ack_count_; | 296 ++pending_start_tracing_ack_count_; |
| 291 } | 297 } |
| 298 |
| 299 ArcTracingAgent::GetInstance()->StartAgentTracing( |
| 300 trace_config, |
| 301 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 302 base::Unretained(this))); |
| 303 ++pending_start_tracing_ack_count_; |
| 292 #elif defined(OS_WIN) | 304 #elif defined(OS_WIN) |
| 293 EtwTracingAgent::GetInstance()->StartAgentTracing( | 305 EtwTracingAgent::GetInstance()->StartAgentTracing( |
| 294 trace_config, | 306 trace_config, |
| 295 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | 307 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 296 base::Unretained(this))); | 308 base::Unretained(this))); |
| 297 ++pending_start_tracing_ack_count_; | 309 ++pending_start_tracing_ack_count_; |
| 298 #endif | 310 #endif |
| 299 } | 311 } |
| 300 | 312 |
| 301 // TraceLog may have been enabled in startup tracing before threads are ready. | 313 // TraceLog may have been enabled in startup tracing before threads are ready. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { | 568 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { |
| 557 #if defined(OS_CHROMEOS) | 569 #if defined(OS_CHROMEOS) |
| 558 auto* debug_daemon = | 570 auto* debug_daemon = |
| 559 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 571 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 560 if (agent_name == debug_daemon->GetTracingAgentName()) { | 572 if (agent_name == debug_daemon->GetTracingAgentName()) { |
| 561 additional_tracing_agents_.push_back(debug_daemon); | 573 additional_tracing_agents_.push_back(debug_daemon); |
| 562 debug_daemon->SetStopAgentTracingTaskRunner( | 574 debug_daemon->SetStopAgentTracingTaskRunner( |
| 563 BrowserThread::GetBlockingPool()); | 575 BrowserThread::GetBlockingPool()); |
| 564 return; | 576 return; |
| 565 } | 577 } |
| 578 |
| 579 if (agent_name == kArcTracingAgentName) { |
| 580 additional_tracing_agents_.push_back(ArcTracingAgent::GetInstance()); |
| 581 return; |
| 582 } |
| 566 #elif defined(OS_WIN) | 583 #elif defined(OS_WIN) |
| 567 auto* etw_agent = EtwTracingAgent::GetInstance(); | 584 auto* etw_agent = EtwTracingAgent::GetInstance(); |
| 568 if (agent_name == etw_agent->GetTracingAgentName()) { | 585 if (agent_name == etw_agent->GetTracingAgentName()) { |
| 569 additional_tracing_agents_.push_back(etw_agent); | 586 additional_tracing_agents_.push_back(etw_agent); |
| 570 return; | 587 return; |
| 571 } | 588 } |
| 572 #endif | 589 #endif |
| 573 | 590 |
| 574 #if defined(ENABLE_POWER_TRACING) | 591 #if defined(ENABLE_POWER_TRACING) |
| 575 auto* power_agent = PowerTracingAgent::GetInstance(); | 592 auto* power_agent = PowerTracingAgent::GetInstance(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 677 } |
| 661 | 678 |
| 662 void TracingControllerImpl::OnEndAgentTracingAcked( | 679 void TracingControllerImpl::OnEndAgentTracingAcked( |
| 663 const std::string& agent_name, | 680 const std::string& agent_name, |
| 664 const std::string& events_label, | 681 const std::string& events_label, |
| 665 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 682 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 666 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 683 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 667 | 684 |
| 668 if (trace_data_sink_.get() && events_str_ptr && | 685 if (trace_data_sink_.get() && events_str_ptr && |
| 669 !events_str_ptr->data().empty()) { | 686 !events_str_ptr->data().empty()) { |
| 670 std::string json_string; | |
| 671 if (agent_name == kETWTracingAgentName) { | 687 if (agent_name == kETWTracingAgentName) { |
| 672 // The Windows kernel events are kept into a JSON format stored as string | 688 // The Windows kernel events are kept into a JSON format stored as string |
| 673 // and must not be escaped. | 689 // and must not be escaped. |
| 674 json_string = events_str_ptr->data(); | 690 trace_data_sink_->AddAgentTrace(events_label, events_str_ptr->data()); |
| 675 } else { | 691 } else if (agent_name != kArcTracingAgentName) { |
| 676 json_string = base::GetQuotedJSONString(events_str_ptr->data()); | 692 // ARC trace data is obtained via systrace. Ignore the empty data. |
| 693 // Quote other trace data as JSON strings and merge them into |
| 694 // |trace_data_sink_|. |
| 695 trace_data_sink_->AddAgentTrace( |
| 696 events_label, base::GetQuotedJSONString(events_str_ptr->data())); |
| 677 } | 697 } |
| 678 trace_data_sink_->AddAgentTrace(events_label, json_string); | |
| 679 } | 698 } |
| 680 std::vector<std::string> category_groups; | 699 std::vector<std::string> category_groups; |
| 681 OnStopTracingAcked(NULL, category_groups); | 700 OnStopTracingAcked(NULL, category_groups); |
| 682 } | 701 } |
| 683 | 702 |
| 684 void TracingControllerImpl::OnTraceDataCollected( | 703 void TracingControllerImpl::OnTraceDataCollected( |
| 685 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 704 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 686 // OnTraceDataCollected may be called from any browser thread, either by the | 705 // OnTraceDataCollected may be called from any browser thread, either by the |
| 687 // local event trace system or from child processes via TraceMessageFilter. | 706 // local event trace system or from child processes via TraceMessageFilter. |
| 688 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 707 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 void TracingControllerImpl::RecordClockSyncMarker( | 842 void TracingControllerImpl::RecordClockSyncMarker( |
| 824 const std::string& sync_id, | 843 const std::string& sync_id, |
| 825 const RecordClockSyncMarkerCallback& callback) { | 844 const RecordClockSyncMarkerCallback& callback) { |
| 826 DCHECK(SupportsExplicitClockSync()); | 845 DCHECK(SupportsExplicitClockSync()); |
| 827 | 846 |
| 828 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); | 847 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); |
| 829 } | 848 } |
| 830 | 849 |
| 831 void TracingControllerImpl::IssueClockSyncMarker() { | 850 void TracingControllerImpl::IssueClockSyncMarker() { |
| 832 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 851 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 833 DCHECK(pending_clock_sync_ack_count_ == 0); | 852 DCHECK_EQ(0, pending_clock_sync_ack_count_); |
| 834 | 853 |
| 835 for (auto* it : additional_tracing_agents_) { | 854 for (auto* it : additional_tracing_agents_) { |
| 836 if (it->SupportsExplicitClockSync()) { | 855 if (it->SupportsExplicitClockSync()) { |
| 837 it->RecordClockSyncMarker( | 856 it->RecordClockSyncMarker( |
| 838 base::GenerateGUID(), | 857 base::GenerateGUID(), |
| 839 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, | 858 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, |
| 840 base::Unretained(this))); | 859 base::Unretained(this))); |
| 841 pending_clock_sync_ack_count_++; | 860 pending_clock_sync_ack_count_++; |
| 842 } | 861 } |
| 843 } | 862 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 863 // success indicator instead of having to rely on sentinel issue_ts and | 882 // success indicator instead of having to rely on sentinel issue_ts and |
| 864 // issue_end_ts values to signal failure. | 883 // issue_end_ts values to signal failure. |
| 865 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks())) | 884 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks())) |
| 866 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); | 885 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); |
| 867 | 886 |
| 868 // Timer is not running means that clock sync already timed out. | 887 // Timer is not running means that clock sync already timed out. |
| 869 if (!clock_sync_timer_.IsRunning()) | 888 if (!clock_sync_timer_.IsRunning()) |
| 870 return; | 889 return; |
| 871 | 890 |
| 872 // Stop tracing only if all agents report back. | 891 // Stop tracing only if all agents report back. |
| 873 if(--pending_clock_sync_ack_count_ == 0) { | 892 if (--pending_clock_sync_ack_count_ == 0) { |
| 874 clock_sync_timer_.Stop(); | 893 clock_sync_timer_.Stop(); |
| 875 StopTracingAfterClockSync(); | 894 StopTracingAfterClockSync(); |
| 876 } | 895 } |
| 877 } | 896 } |
| 878 | 897 |
| 879 void TracingControllerImpl::AddFilteredMetadata( | 898 void TracingControllerImpl::AddFilteredMetadata( |
| 880 TracingController::TraceDataSink* sink, | 899 TracingController::TraceDataSink* sink, |
| 881 std::unique_ptr<base::DictionaryValue> metadata, | 900 std::unique_ptr<base::DictionaryValue> metadata, |
| 882 const MetadataFilterPredicate& filter) { | 901 const MetadataFilterPredicate& filter) { |
| 883 if (filter.is_null()) { | 902 if (filter.is_null()) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 // Schedule the next queued dump (if applicable). | 1080 // Schedule the next queued dump (if applicable). |
| 1062 if (!queued_memory_dump_requests_.empty()) { | 1081 if (!queued_memory_dump_requests_.empty()) { |
| 1063 BrowserThread::PostTask( | 1082 BrowserThread::PostTask( |
| 1064 BrowserThread::UI, FROM_HERE, | 1083 BrowserThread::UI, FROM_HERE, |
| 1065 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, | 1084 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, |
| 1066 base::Unretained(this))); | 1085 base::Unretained(this))); |
| 1067 } | 1086 } |
| 1068 } | 1087 } |
| 1069 | 1088 |
| 1070 } // namespace content | 1089 } // namespace content |
| OLD | NEW |