| 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/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #if (defined(OS_POSIX) && defined(USE_UDEV)) || defined(OS_WIN) || \ | 35 #if (defined(OS_POSIX) && defined(USE_UDEV)) || defined(OS_WIN) || \ |
| 36 defined(OS_MACOSX) | 36 defined(OS_MACOSX) |
| 37 #define ENABLE_POWER_TRACING | 37 #define ENABLE_POWER_TRACING |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #if defined(ENABLE_POWER_TRACING) | 40 #if defined(ENABLE_POWER_TRACING) |
| 41 #include "content/browser/tracing/power_tracing_agent.h" | 41 #include "content/browser/tracing/power_tracing_agent.h" |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
| 45 #include "chromeos/dbus/arc_trace_agent.h" |
| 45 #include "chromeos/dbus/dbus_thread_manager.h" | 46 #include "chromeos/dbus/dbus_thread_manager.h" |
| 46 #include "chromeos/dbus/debug_daemon_client.h" | 47 #include "chromeos/dbus/debug_daemon_client.h" |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 50 #include "content/browser/tracing/etw_tracing_agent_win.h" | 51 #include "content/browser/tracing/etw_tracing_agent_win.h" |
| 51 #endif | 52 #endif |
| 52 | 53 |
| 53 using base::trace_event::TraceLog; | 54 using base::trace_event::TraceLog; |
| 54 using base::trace_event::TraceConfig; | 55 using base::trace_event::TraceConfig; |
| 55 | 56 |
| 56 namespace content { | 57 namespace content { |
| 57 | 58 |
| 58 namespace { | 59 namespace { |
| 59 | 60 |
| 60 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = | 61 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = |
| 61 LAZY_INSTANCE_INITIALIZER; | 62 LAZY_INSTANCE_INITIALIZER; |
| 62 | 63 |
| 63 const char kChromeTracingAgentName[] = "chrome"; | 64 const char kChromeTracingAgentName[] = "chrome"; |
| 64 const char kETWTracingAgentName[] = "etw"; | 65 const char kETWTracingAgentName[] = "etw"; |
| 66 const char kArcTracingAgentName[] = "arc"; |
| 65 const char kChromeTraceLabel[] = "traceEvents"; | 67 const char kChromeTraceLabel[] = "traceEvents"; |
| 66 | 68 |
| 67 const int kStartTracingTimeoutSeconds = 30; | 69 const int kStartTracingTimeoutSeconds = 30; |
| 68 const int kIssueClockSyncTimeoutSeconds = 30; | 70 const int kIssueClockSyncTimeoutSeconds = 30; |
| 69 const int kStopTracingRetryTimeMilliseconds = 100; | 71 const int kStopTracingRetryTimeMilliseconds = 100; |
| 70 | 72 |
| 71 std::string GetNetworkTypeString() { | 73 std::string GetNetworkTypeString() { |
| 72 switch (net::NetworkChangeNotifier::GetConnectionType()) { | 74 switch (net::NetworkChangeNotifier::GetConnectionType()) { |
| 73 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | 75 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| 74 return "Ethernet"; | 76 return "Ethernet"; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 292 } |
| 291 #elif defined(OS_WIN) | 293 #elif defined(OS_WIN) |
| 292 EtwTracingAgent::GetInstance()->StartAgentTracing( | 294 EtwTracingAgent::GetInstance()->StartAgentTracing( |
| 293 trace_config, | 295 trace_config, |
| 294 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | 296 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 295 base::Unretained(this))); | 297 base::Unretained(this))); |
| 296 ++pending_start_tracing_ack_count_; | 298 ++pending_start_tracing_ack_count_; |
| 297 #endif | 299 #endif |
| 298 } | 300 } |
| 299 | 301 |
| 302 #if defined(OS_CHROMEOS) |
| 303 auto* arc_trace_agent = |
| 304 chromeos::DBusThreadManager::Get()->GetArcTraceAgent(); |
| 305 if (arc_trace_agent) { |
| 306 arc_trace_agent->StartAgentTracing( |
| 307 trace_config, |
| 308 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 309 base::Unretained(this))); |
| 310 ++pending_start_tracing_ack_count_; |
| 311 } |
| 312 #endif |
| 313 |
| 300 // TraceLog may have been enabled in startup tracing before threads are ready. | 314 // TraceLog may have been enabled in startup tracing before threads are ready. |
| 301 if (TraceLog::GetInstance()->IsEnabled()) | 315 if (TraceLog::GetInstance()->IsEnabled()) |
| 302 return true; | 316 return true; |
| 303 | 317 |
| 304 StartAgentTracing(trace_config, | 318 StartAgentTracing(trace_config, |
| 305 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, | 319 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, |
| 306 base::Unretained(this))); | 320 base::Unretained(this))); |
| 307 ++pending_start_tracing_ack_count_; | 321 ++pending_start_tracing_ack_count_; |
| 308 | 322 |
| 309 // Set a deadline to ensure all agents ack within a reasonable time frame. | 323 // 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) { | 569 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { |
| 556 #if defined(OS_CHROMEOS) | 570 #if defined(OS_CHROMEOS) |
| 557 auto* debug_daemon = | 571 auto* debug_daemon = |
| 558 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 572 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 559 if (agent_name == debug_daemon->GetTracingAgentName()) { | 573 if (agent_name == debug_daemon->GetTracingAgentName()) { |
| 560 additional_tracing_agents_.push_back(debug_daemon); | 574 additional_tracing_agents_.push_back(debug_daemon); |
| 561 debug_daemon->SetStopAgentTracingTaskRunner( | 575 debug_daemon->SetStopAgentTracingTaskRunner( |
| 562 BrowserThread::GetBlockingPool()); | 576 BrowserThread::GetBlockingPool()); |
| 563 return; | 577 return; |
| 564 } | 578 } |
| 579 |
| 580 auto* arc_trace_agent = |
| 581 chromeos::DBusThreadManager::Get()->GetArcTraceAgent(); |
| 582 if (arc_trace_agent && agent_name == arc_trace_agent->GetTracingAgentName()) { |
| 583 additional_tracing_agents_.push_back(arc_trace_agent); |
| 584 arc_trace_agent->SetStopAgentTracingTaskRunner( |
| 585 BrowserThread::GetBlockingPool()); |
| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 683 |
| 661 void TracingControllerImpl::OnEndAgentTracingAcked( | 684 void TracingControllerImpl::OnEndAgentTracingAcked( |
| 662 const std::string& agent_name, | 685 const std::string& agent_name, |
| 663 const std::string& events_label, | 686 const std::string& events_label, |
| 664 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 687 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 665 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 688 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 666 | 689 |
| 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 or |
| 671 // The Windows kernel events are kept into a JSON format stored as string | 694 agent_name == kArcTracingAgentName) { |
| 672 // and must not be escaped. | 695 // The Windows kernel events and ARC Android tracing event are kept |
| 696 // into a JSON format stored as string and must not be escaped. |
| 673 json_string = events_str_ptr->data(); | 697 json_string = events_str_ptr->data(); |
| 674 } else { | 698 } else { |
| 675 json_string = base::GetQuotedJSONString(events_str_ptr->data()); | 699 json_string = base::GetQuotedJSONString(events_str_ptr->data()); |
| 676 } | 700 } |
| 677 trace_data_sink_->AddAgentTrace(events_label, json_string); | 701 |
| 702 if (agent_name == kArcTracingAgentName) { |
| 703 trace_data_sink_->AddTraceChunk(json_string); |
| 704 } else { |
| 705 trace_data_sink_->AddAgentTrace(events_label, json_string); |
| 706 } |
| 678 } | 707 } |
| 679 std::vector<std::string> category_groups; | 708 std::vector<std::string> category_groups; |
| 680 OnStopTracingAcked(NULL, category_groups); | 709 OnStopTracingAcked(NULL, category_groups); |
| 681 } | 710 } |
| 682 | 711 |
| 683 void TracingControllerImpl::OnTraceDataCollected( | 712 void TracingControllerImpl::OnTraceDataCollected( |
| 684 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 713 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 685 // OnTraceDataCollected may be called from any browser thread, either by the | 714 // OnTraceDataCollected may be called from any browser thread, either by the |
| 686 // local event trace system or from child processes via TraceMessageFilter. | 715 // local event trace system or from child processes via TraceMessageFilter. |
| 687 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 716 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 // Schedule the next queued dump (if applicable). | 1089 // Schedule the next queued dump (if applicable). |
| 1061 if (!queued_memory_dump_requests_.empty()) { | 1090 if (!queued_memory_dump_requests_.empty()) { |
| 1062 BrowserThread::PostTask( | 1091 BrowserThread::PostTask( |
| 1063 BrowserThread::UI, FROM_HERE, | 1092 BrowserThread::UI, FROM_HERE, |
| 1064 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, | 1093 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, |
| 1065 base::Unretained(this))); | 1094 base::Unretained(this))); |
| 1066 } | 1095 } |
| 1067 } | 1096 } |
| 1068 | 1097 |
| 1069 } // namespace content | 1098 } // namespace content |
| OLD | NEW |