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) | |
|
dsinclair
2017/03/06 14:25:59
Why not put this with the if defined(OS_CHROMEOS)
Earl Ou
2017/03/07 10:27:03
Done.
| |
| 307 if (trace_config.IsSystraceEnabled()) { | |
| 308 chromeos::ArcTraceAgent::GetInstance()->StartAgentTracing( | |
| 309 trace_config, | |
| 310 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | |
| 311 base::Unretained(this))); | |
| 312 ++pending_start_tracing_ack_count_; | |
| 313 } | |
| 314 #endif | |
| 315 | |
| 300 // TraceLog may have been enabled in startup tracing before threads are ready. | 316 // TraceLog may have been enabled in startup tracing before threads are ready. |
| 301 if (TraceLog::GetInstance()->IsEnabled()) | 317 if (TraceLog::GetInstance()->IsEnabled()) |
| 302 return true; | 318 return true; |
| 303 | 319 |
| 304 StartAgentTracing(trace_config, | 320 StartAgentTracing(trace_config, |
| 305 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | 321 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 306 base::Unretained(this))); | 322 base::Unretained(this))); |
| 307 ++pending_start_tracing_ack_count_; | 323 ++pending_start_tracing_ack_count_; |
| 308 | 324 |
| 309 // Set a deadline to ensure all agents ack within a reasonable time frame. | 325 // 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) { | 571 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { |
| 556 #if defined(OS_CHROMEOS) | 572 #if defined(OS_CHROMEOS) |
| 557 auto* debug_daemon = | 573 auto* debug_daemon = |
| 558 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 574 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 559 if (agent_name == debug_daemon->GetTracingAgentName()) { | 575 if (agent_name == debug_daemon->GetTracingAgentName()) { |
| 560 additional_tracing_agents_.push_back(debug_daemon); | 576 additional_tracing_agents_.push_back(debug_daemon); |
| 561 debug_daemon->SetStopAgentTracingTaskRunner( | 577 debug_daemon->SetStopAgentTracingTaskRunner( |
| 562 BrowserThread::GetBlockingPool()); | 578 BrowserThread::GetBlockingPool()); |
| 563 return; | 579 return; |
| 564 } | 580 } |
| 581 | |
| 582 auto* arc_trace_agent = chromeos::ArcTraceAgent::GetInstance(); | |
| 583 if (agent_name == arc_trace_agent->GetTracingAgentName()) { | |
| 584 additional_tracing_agents_.push_back(arc_trace_agent); | |
| 585 return; | |
| 586 } | |
| 565 #elif defined(OS_WIN) | 587 #elif defined(OS_WIN) |
| 566 auto* etw_agent = EtwTracingAgent::GetInstance(); | 588 auto* etw_agent = EtwTracingAgent::GetInstance(); |
| 567 if (agent_name == etw_agent->GetTracingAgentName()) { | 589 if (agent_name == etw_agent->GetTracingAgentName()) { |
| 568 additional_tracing_agents_.push_back(etw_agent); | 590 additional_tracing_agents_.push_back(etw_agent); |
| 569 return; | 591 return; |
| 570 } | 592 } |
| 571 #endif | 593 #endif |
| 572 | 594 |
| 573 #if defined(ENABLE_POWER_TRACING) | 595 #if defined(ENABLE_POWER_TRACING) |
| 574 auto* power_agent = PowerTracingAgent::GetInstance(); | 596 auto* power_agent = PowerTracingAgent::GetInstance(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 } | 681 } |
| 660 | 682 |
| 661 void TracingControllerImpl::OnEndAgentTracingAcked( | 683 void TracingControllerImpl::OnEndAgentTracingAcked( |
| 662 const std::string& agent_name, | 684 const std::string& agent_name, |
| 663 const std::string& events_label, | 685 const std::string& events_label, |
| 664 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 686 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 665 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 687 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 666 | 688 |
| 667 if (trace_data_sink_.get() && events_str_ptr && | 689 if (trace_data_sink_.get() && events_str_ptr && |
| 668 !events_str_ptr->data().empty()) { | 690 !events_str_ptr->data().empty()) { |
| 669 std::string json_string; | |
| 670 if (agent_name == kETWTracingAgentName) { | 691 if (agent_name == kETWTracingAgentName) { |
| 671 // The Windows kernel events are kept into a JSON format stored as string | 692 // The Windows kernel events are kept into a JSON format stored as string |
| 672 // and must not be escaped. | 693 // and must not be escaped. |
| 673 json_string = events_str_ptr->data(); | 694 trace_data_sink_->AddAgentTrace(events_label, events_str_ptr->data()); |
| 674 } else { | 695 } else if (agent_name != kArcTracingAgentName) { |
| 675 json_string = base::GetQuotedJSONString(events_str_ptr->data()); | 696 // ARC trace data is obtained via systrace. Ignore the empty data. |
| 697 // For other trace data, quoted as JSON string and merge them into | |
| 698 // |trace_data_sink|. | |
| 699 trace_data_sink_->AddAgentTrace( | |
| 700 events_label, base::GetQuotedJSONString(events_str_ptr->data())); | |
| 676 } | 701 } |
| 677 trace_data_sink_->AddAgentTrace(events_label, json_string); | |
| 678 } | 702 } |
| 679 std::vector<std::string> category_groups; | 703 std::vector<std::string> category_groups; |
| 680 OnStopTracingAcked(NULL, category_groups); | 704 OnStopTracingAcked(NULL, category_groups); |
| 681 } | 705 } |
| 682 | 706 |
| 683 void TracingControllerImpl::OnTraceDataCollected( | 707 void TracingControllerImpl::OnTraceDataCollected( |
| 684 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 708 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 685 // OnTraceDataCollected may be called from any browser thread, either by the | 709 // OnTraceDataCollected may be called from any browser thread, either by the |
| 686 // local event trace system or from child processes via TraceMessageFilter. | 710 // local event trace system or from child processes via TraceMessageFilter. |
| 687 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 711 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 void TracingControllerImpl::RecordClockSyncMarker( | 846 void TracingControllerImpl::RecordClockSyncMarker( |
| 823 const std::string& sync_id, | 847 const std::string& sync_id, |
| 824 const RecordClockSyncMarkerCallback& callback) { | 848 const RecordClockSyncMarkerCallback& callback) { |
| 825 DCHECK(SupportsExplicitClockSync()); | 849 DCHECK(SupportsExplicitClockSync()); |
| 826 | 850 |
| 827 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); | 851 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); |
| 828 } | 852 } |
| 829 | 853 |
| 830 void TracingControllerImpl::IssueClockSyncMarker() { | 854 void TracingControllerImpl::IssueClockSyncMarker() { |
| 831 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 855 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 832 DCHECK(pending_clock_sync_ack_count_ == 0); | 856 DCHECK_EQ(0, pending_clock_sync_ack_count_); |
| 833 | 857 |
| 834 for (auto* it : additional_tracing_agents_) { | 858 for (auto* it : additional_tracing_agents_) { |
| 835 if (it->SupportsExplicitClockSync()) { | 859 if (it->SupportsExplicitClockSync()) { |
| 836 it->RecordClockSyncMarker( | 860 it->RecordClockSyncMarker( |
| 837 base::GenerateGUID(), | 861 base::GenerateGUID(), |
| 838 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, | 862 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, |
| 839 base::Unretained(this))); | 863 base::Unretained(this))); |
| 840 pending_clock_sync_ack_count_++; | 864 pending_clock_sync_ack_count_++; |
| 841 } | 865 } |
| 842 } | 866 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 862 // success indicator instead of having to rely on sentinel issue_ts and | 886 // success indicator instead of having to rely on sentinel issue_ts and |
| 863 // issue_end_ts values to signal failure. | 887 // issue_end_ts values to signal failure. |
| 864 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks())) | 888 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks())) |
| 865 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); | 889 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); |
| 866 | 890 |
| 867 // Timer is not running means that clock sync already timed out. | 891 // Timer is not running means that clock sync already timed out. |
| 868 if (!clock_sync_timer_.IsRunning()) | 892 if (!clock_sync_timer_.IsRunning()) |
| 869 return; | 893 return; |
| 870 | 894 |
| 871 // Stop tracing only if all agents report back. | 895 // Stop tracing only if all agents report back. |
| 872 if(--pending_clock_sync_ack_count_ == 0) { | 896 if (--pending_clock_sync_ack_count_ == 0) { |
| 873 clock_sync_timer_.Stop(); | 897 clock_sync_timer_.Stop(); |
| 874 StopTracingAfterClockSync(); | 898 StopTracingAfterClockSync(); |
| 875 } | 899 } |
| 876 } | 900 } |
| 877 | 901 |
| 878 void TracingControllerImpl::AddFilteredMetadata( | 902 void TracingControllerImpl::AddFilteredMetadata( |
| 879 TracingController::TraceDataSink* sink, | 903 TracingController::TraceDataSink* sink, |
| 880 std::unique_ptr<base::DictionaryValue> metadata, | 904 std::unique_ptr<base::DictionaryValue> metadata, |
| 881 const MetadataFilterPredicate& filter) { | 905 const MetadataFilterPredicate& filter) { |
| 882 if (filter.is_null()) { | 906 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). | 1084 // Schedule the next queued dump (if applicable). |
| 1061 if (!queued_memory_dump_requests_.empty()) { | 1085 if (!queued_memory_dump_requests_.empty()) { |
| 1062 BrowserThread::PostTask( | 1086 BrowserThread::PostTask( |
| 1063 BrowserThread::UI, FROM_HERE, | 1087 BrowserThread::UI, FROM_HERE, |
| 1064 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, | 1088 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, |
| 1065 base::Unretained(this))); | 1089 base::Unretained(this))); |
| 1066 } | 1090 } |
| 1067 } | 1091 } |
| 1068 | 1092 |
| 1069 } // namespace content | 1093 } // namespace content |
| OLD | NEW |