Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 2699833003: arc: enable Android tracing from chrome://tracing in dev mode (Closed)
Patch Set: Fix according to the comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 chromeos::ArcTraceAgent::GetInstance()->StartAgentTracing(
Luis Héctor Chávez 2017/03/02 18:45:50 Maybe surround this with if (trace_config.IsSystra
Earl Ou 2017/03/03 05:37:50 Done.
308 trace_config, base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked,
309 base::Unretained(this)));
310 ++pending_start_tracing_ack_count_;
311 #endif
312
300 // 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.
301 if (TraceLog::GetInstance()->IsEnabled()) 314 if (TraceLog::GetInstance()->IsEnabled())
302 return true; 315 return true;
303 316
304 StartAgentTracing(trace_config, 317 StartAgentTracing(trace_config,
305 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked, 318 base::Bind(&TracingControllerImpl::OnStartAgentTracingAcked,
306 base::Unretained(this))); 319 base::Unretained(this)));
307 ++pending_start_tracing_ack_count_; 320 ++pending_start_tracing_ack_count_;
308 321
309 // Set a deadline to ensure all agents ack within a reasonable time frame. 322 // 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
555 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { 568 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) {
556 #if defined(OS_CHROMEOS) 569 #if defined(OS_CHROMEOS)
557 auto* debug_daemon = 570 auto* debug_daemon =
558 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); 571 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
559 if (agent_name == debug_daemon->GetTracingAgentName()) { 572 if (agent_name == debug_daemon->GetTracingAgentName()) {
560 additional_tracing_agents_.push_back(debug_daemon); 573 additional_tracing_agents_.push_back(debug_daemon);
561 debug_daemon->SetStopAgentTracingTaskRunner( 574 debug_daemon->SetStopAgentTracingTaskRunner(
562 BrowserThread::GetBlockingPool()); 575 BrowserThread::GetBlockingPool());
563 return; 576 return;
564 } 577 }
578
579 auto* arc_trace_agent = chromeos::ArcTraceAgent::GetInstance();
580 if (agent_name == arc_trace_agent->GetTracingAgentName()) {
581 additional_tracing_agents_.push_back(arc_trace_agent);
582 return;
583 }
565 #elif defined(OS_WIN) 584 #elif defined(OS_WIN)
566 auto* etw_agent = EtwTracingAgent::GetInstance(); 585 auto* etw_agent = EtwTracingAgent::GetInstance();
567 if (agent_name == etw_agent->GetTracingAgentName()) { 586 if (agent_name == etw_agent->GetTracingAgentName()) {
568 additional_tracing_agents_.push_back(etw_agent); 587 additional_tracing_agents_.push_back(etw_agent);
569 return; 588 return;
570 } 589 }
571 #endif 590 #endif
572 591
573 #if defined(ENABLE_POWER_TRACING) 592 #if defined(ENABLE_POWER_TRACING)
574 auto* power_agent = PowerTracingAgent::GetInstance(); 593 auto* power_agent = PowerTracingAgent::GetInstance();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 if (trace_data_sink_.get() && events_str_ptr && 686 if (trace_data_sink_.get() && events_str_ptr &&
668 !events_str_ptr->data().empty()) { 687 !events_str_ptr->data().empty()) {
669 std::string json_string; 688 std::string json_string;
670 if (agent_name == kETWTracingAgentName) { 689 if (agent_name == kETWTracingAgentName) {
671 // The Windows kernel events are kept into a JSON format stored as string 690 // The Windows kernel events are kept into a JSON format stored as string
672 // and must not be escaped. 691 // and must not be escaped.
673 json_string = events_str_ptr->data(); 692 json_string = events_str_ptr->data();
674 } else { 693 } else {
675 json_string = base::GetQuotedJSONString(events_str_ptr->data()); 694 json_string = base::GetQuotedJSONString(events_str_ptr->data());
676 } 695 }
677 trace_data_sink_->AddAgentTrace(events_label, json_string); 696
697 // ARC tracing data is obtained via systrace. Ignore the empty data here.
698 if (agent_name != kArcTracingAgentName) {
Luis Héctor Chávez 2017/03/02 18:45:50 What happens in L694 in the ARC case? Should we sk
Earl Ou 2017/03/03 05:37:50 Done.
699 trace_data_sink_->AddAgentTrace(events_label, json_string);
700 }
678 } 701 }
679 std::vector<std::string> category_groups; 702 std::vector<std::string> category_groups;
680 OnStopTracingAcked(NULL, category_groups); 703 OnStopTracingAcked(NULL, category_groups);
681 } 704 }
682 705
683 void TracingControllerImpl::OnTraceDataCollected( 706 void TracingControllerImpl::OnTraceDataCollected(
684 const scoped_refptr<base::RefCountedString>& events_str_ptr) { 707 const scoped_refptr<base::RefCountedString>& events_str_ptr) {
685 // OnTraceDataCollected may be called from any browser thread, either by the 708 // OnTraceDataCollected may be called from any browser thread, either by the
686 // local event trace system or from child processes via TraceMessageFilter. 709 // local event trace system or from child processes via TraceMessageFilter.
687 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 710 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 void TracingControllerImpl::RecordClockSyncMarker( 845 void TracingControllerImpl::RecordClockSyncMarker(
823 const std::string& sync_id, 846 const std::string& sync_id,
824 const RecordClockSyncMarkerCallback& callback) { 847 const RecordClockSyncMarkerCallback& callback) {
825 DCHECK(SupportsExplicitClockSync()); 848 DCHECK(SupportsExplicitClockSync());
826 849
827 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); 850 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id);
828 } 851 }
829 852
830 void TracingControllerImpl::IssueClockSyncMarker() { 853 void TracingControllerImpl::IssueClockSyncMarker() {
831 DCHECK_CURRENTLY_ON(BrowserThread::UI); 854 DCHECK_CURRENTLY_ON(BrowserThread::UI);
832 DCHECK(pending_clock_sync_ack_count_ == 0); 855 DCHECK_EQ(0, pending_clock_sync_ack_count_);
833 856
834 for (auto* it : additional_tracing_agents_) { 857 for (auto* it : additional_tracing_agents_) {
835 if (it->SupportsExplicitClockSync()) { 858 if (it->SupportsExplicitClockSync()) {
836 it->RecordClockSyncMarker( 859 it->RecordClockSyncMarker(
837 base::GenerateGUID(), 860 base::GenerateGUID(),
838 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, 861 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent,
839 base::Unretained(this))); 862 base::Unretained(this)));
840 pending_clock_sync_ack_count_++; 863 pending_clock_sync_ack_count_++;
841 } 864 }
842 } 865 }
(...skipping 19 matching lines...) Expand all
862 // success indicator instead of having to rely on sentinel issue_ts and 885 // success indicator instead of having to rely on sentinel issue_ts and
863 // issue_end_ts values to signal failure. 886 // issue_end_ts values to signal failure.
864 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks())) 887 if (!(issue_ts == base::TimeTicks() || issue_end_ts == base::TimeTicks()))
865 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); 888 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts);
866 889
867 // Timer is not running means that clock sync already timed out. 890 // Timer is not running means that clock sync already timed out.
868 if (!clock_sync_timer_.IsRunning()) 891 if (!clock_sync_timer_.IsRunning())
869 return; 892 return;
870 893
871 // Stop tracing only if all agents report back. 894 // Stop tracing only if all agents report back.
872 if(--pending_clock_sync_ack_count_ == 0) { 895 if (--pending_clock_sync_ack_count_ == 0) {
873 clock_sync_timer_.Stop(); 896 clock_sync_timer_.Stop();
874 StopTracingAfterClockSync(); 897 StopTracingAfterClockSync();
875 } 898 }
876 } 899 }
877 900
878 void TracingControllerImpl::AddFilteredMetadata( 901 void TracingControllerImpl::AddFilteredMetadata(
879 TracingController::TraceDataSink* sink, 902 TracingController::TraceDataSink* sink,
880 std::unique_ptr<base::DictionaryValue> metadata, 903 std::unique_ptr<base::DictionaryValue> metadata,
881 const MetadataFilterPredicate& filter) { 904 const MetadataFilterPredicate& filter) {
882 if (filter.is_null()) { 905 if (filter.is_null()) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 // Schedule the next queued dump (if applicable). 1083 // Schedule the next queued dump (if applicable).
1061 if (!queued_memory_dump_requests_.empty()) { 1084 if (!queued_memory_dump_requests_.empty()) {
1062 BrowserThread::PostTask( 1085 BrowserThread::PostTask(
1063 BrowserThread::UI, FROM_HERE, 1086 BrowserThread::UI, FROM_HERE,
1064 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump, 1087 base::Bind(&TracingControllerImpl::PerformNextQueuedGlobalMemoryDump,
1065 base::Unretained(this))); 1088 base::Unretained(this)));
1066 } 1089 }
1067 } 1090 }
1068 1091
1069 } // namespace content 1092 } // namespace content
OLDNEW
« chromeos/trace/arc_trace_agent.cc ('K') | « components/arc/common/trace.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698