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 "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/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 } | 141 } |
| 142 | 142 |
| 143 TracingControllerImpl::TracingControllerImpl() | 143 TracingControllerImpl::TracingControllerImpl() |
| 144 : pending_stop_tracing_ack_count_(0), | 144 : pending_stop_tracing_ack_count_(0), |
| 145 pending_capture_monitoring_snapshot_ack_count_(0), | 145 pending_capture_monitoring_snapshot_ack_count_(0), |
| 146 pending_trace_log_status_ack_count_(0), | 146 pending_trace_log_status_ack_count_(0), |
| 147 maximum_trace_buffer_usage_(0), | 147 maximum_trace_buffer_usage_(0), |
| 148 approximate_event_count_(0), | 148 approximate_event_count_(0), |
| 149 pending_memory_dump_ack_count_(0), | 149 pending_memory_dump_ack_count_(0), |
| 150 failed_memory_dump_count_(0), | 150 failed_memory_dump_count_(0), |
| 151 clock_sync_id_(0), | |
| 152 pending_clock_sync_ack_count_(0), | |
| 151 is_tracing_(false), | 153 is_tracing_(false), |
| 152 is_monitoring_(false) { | 154 is_monitoring_(false) { |
| 153 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( | 155 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( |
| 154 this /* delegate */, true /* is_coordinator */); | 156 this /* delegate */, true /* is_coordinator */); |
| 155 | 157 |
| 156 // Deliberately leaked, like this class. | 158 // Deliberately leaked, like this class. |
| 157 base::FileTracing::SetProvider(new FileTracingProviderImpl); | 159 base::FileTracing::SetProvider(new FileTracingProviderImpl); |
| 158 } | 160 } |
| 159 | 161 |
| 160 TracingControllerImpl::~TracingControllerImpl() { | 162 TracingControllerImpl::~TracingControllerImpl() { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 delegate->GetMetadataFilterPredicate()); | 282 delegate->GetMetadataFilterPredicate()); |
| 281 } | 283 } |
| 282 } | 284 } |
| 283 trace_data_sink->AddMetadata(*GenerateTracingMetadataDict().get()); | 285 trace_data_sink->AddMetadata(*GenerateTracingMetadataDict().get()); |
| 284 } | 286 } |
| 285 | 287 |
| 286 if (!can_stop_tracing()) | 288 if (!can_stop_tracing()) |
| 287 return false; | 289 return false; |
| 288 | 290 |
| 289 trace_data_sink_ = trace_data_sink; | 291 trace_data_sink_ = trace_data_sink; |
| 292 | |
| 293 // Issue clock sync marker before actually stopping tracing. | |
| 294 // StopTracingAfterClockSync() will be called after clock sync is done. | |
| 295 IssueClockSyncMarker(); | |
| 296 | |
| 297 return true; | |
| 298 } | |
| 299 | |
| 300 void TracingControllerImpl::StopTracingAfterClockSync() { | |
| 301 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 290 // Disable local trace early to avoid traces during end-tracing process from | 302 // Disable local trace early to avoid traces during end-tracing process from |
| 291 // interfering with the process. | 303 // interfering with the process. |
| 292 base::Closure on_stop_tracing_done_callback = base::Bind( | 304 base::Closure on_stop_tracing_done_callback = base::Bind( |
| 293 &TracingControllerImpl::OnStopTracingDone, base::Unretained(this)); | 305 &TracingControllerImpl::OnStopTracingDone, base::Unretained(this)); |
| 294 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 306 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 295 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, | 307 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, |
| 296 base::Unretained(this), | 308 base::Unretained(this), |
| 297 on_stop_tracing_done_callback)); | 309 on_stop_tracing_done_callback)); |
| 298 return true; | |
| 299 } | 310 } |
| 300 | 311 |
| 301 void TracingControllerImpl::OnStopTracingDone() { | 312 void TracingControllerImpl::OnStopTracingDone() { |
| 302 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 313 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 303 | 314 |
| 304 #if defined(OS_ANDROID) | 315 #if defined(OS_ANDROID) |
| 305 if (pending_get_categories_done_callback_.is_null()) | 316 if (pending_get_categories_done_callback_.is_null()) |
| 306 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 317 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 307 #endif | 318 #endif |
| 308 | 319 |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 // Notify all child processes. | 917 // Notify all child processes. |
| 907 for (auto it : trace_message_filters_) { | 918 for (auto it : trace_message_filters_) { |
| 908 if (trace_data_sink_) | 919 if (trace_data_sink_) |
| 909 it->SendEndTracing(); | 920 it->SendEndTracing(); |
| 910 else | 921 else |
| 911 it->SendCancelTracing(); | 922 it->SendCancelTracing(); |
| 912 } | 923 } |
| 913 } | 924 } |
| 914 | 925 |
| 915 bool TracingControllerImpl::SupportsExplicitClockSync() { | 926 bool TracingControllerImpl::SupportsExplicitClockSync() { |
| 916 // TODO(zhenw): return true after implementing explicit clock sync. | 927 return true; |
| 917 return false; | |
| 918 } | 928 } |
| 919 | 929 |
| 920 void TracingControllerImpl::RecordClockSyncMarker( | 930 void TracingControllerImpl::RecordClockSyncMarker( |
| 921 int sync_id, | 931 int sync_id, |
| 922 const RecordClockSyncMarkerCallback& callback) { | 932 const RecordClockSyncMarkerCallback& callback) { |
| 923 DCHECK(SupportsExplicitClockSync()); | 933 DCHECK(SupportsExplicitClockSync()); |
| 924 // TODO(zhenw): implement explicit clock sync. | 934 |
| 935 TRACE_EVENT_CLOCK_SYNC_RECEIVER(sync_id); | |
| 936 } | |
| 937 | |
| 938 int TracingControllerImpl::GetUniqueClockSyncID() { | |
| 939 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 940 // There is no need to lock because this function only runs on UI thread. | |
| 941 clock_sync_id_ += 1; | |
| 942 return clock_sync_id_; | |
|
oystein (OOO til 10th of July)
2015/12/16 02:10:05
nit: return ++clock_sync_id_;
Zhen Wang
2015/12/16 23:49:12
Done. Is there any reason to prefer combining thos
| |
| 925 } | 943 } |
| 926 | 944 |
| 927 void TracingControllerImpl::IssueClockSyncMarker() { | 945 void TracingControllerImpl::IssueClockSyncMarker() { |
| 928 // TODO(zhenw): implement explicit clock sync. | 946 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 947 | |
| 948 pending_clock_sync_ack_count_ = 0; | |
|
oystein (OOO til 10th of July)
2015/12/16 02:10:05
Can this be != 0 at this point? Would we ever have
Zhen Wang
2015/12/16 23:49:12
Updated to CHECK. But how about the following scen
| |
| 949 for (auto it : additional_tracing_agents_) { | |
|
oystein (OOO til 10th of July)
2015/12/16 02:10:05
nit: const auto& it
Zhen Wang
2015/12/16 23:49:12
Done.
| |
| 950 if (it->SupportsExplicitClockSync()) { | |
| 951 it->RecordClockSyncMarker( | |
| 952 GetUniqueClockSyncID(), | |
| 953 base::Bind(&TracingControllerImpl::OnClockSyncMarkerRecordedByAgent, | |
| 954 base::Unretained(this))); | |
| 955 pending_clock_sync_ack_count_++; | |
| 956 } | |
| 957 } | |
| 958 | |
| 959 // No clock sync is needed, stop tracing right away. | |
| 960 if (pending_clock_sync_ack_count_ == 0) | |
| 961 StopTracingAfterClockSync(); | |
| 962 } | |
| 963 | |
| 964 void TracingControllerImpl::OnClockSyncMarkerRecordedByAgent( | |
| 965 int sync_id, | |
| 966 const base::TimeTicks& issue_ts, | |
| 967 const base::TimeTicks& issue_end_ts) { | |
| 968 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 969 | |
| 970 TRACE_EVENT_CLOCK_SYNC_ISSUER(sync_id, issue_ts, issue_end_ts); | |
| 971 | |
| 972 pending_clock_sync_ack_count_--; | |
|
oystein (OOO til 10th of July)
2015/12/16 02:10:07
nit: if(--pending_clock_sync_ack_count_ == 0).
Zhen Wang
2015/12/16 23:49:12
Done.
| |
| 973 if (pending_clock_sync_ack_count_ == 0) | |
|
oystein (OOO til 10th of July)
2015/12/16 02:10:05
I feel like this makes the API a little bit fragil
Zhen Wang
2015/12/16 23:49:12
Done.
| |
| 974 StopTracingAfterClockSync(); | |
| 929 } | 975 } |
| 930 | 976 |
| 931 void TracingControllerImpl::RequestGlobalMemoryDump( | 977 void TracingControllerImpl::RequestGlobalMemoryDump( |
| 932 const base::trace_event::MemoryDumpRequestArgs& args, | 978 const base::trace_event::MemoryDumpRequestArgs& args, |
| 933 const base::trace_event::MemoryDumpCallback& callback) { | 979 const base::trace_event::MemoryDumpCallback& callback) { |
| 934 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 980 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 935 BrowserThread::PostTask( | 981 BrowserThread::PostTask( |
| 936 BrowserThread::UI, FROM_HERE, | 982 BrowserThread::UI, FROM_HERE, |
| 937 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump, | 983 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump, |
| 938 base::Unretained(this), args, callback)); | 984 base::Unretained(this), args, callback)); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1057 is_monitoring_ = is_monitoring; | 1103 is_monitoring_ = is_monitoring; |
| 1058 #if !defined(OS_ANDROID) | 1104 #if !defined(OS_ANDROID) |
| 1059 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 1105 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
| 1060 it != tracing_uis_.end(); it++) { | 1106 it != tracing_uis_.end(); it++) { |
| 1061 (*it)->OnMonitoringStateChanged(is_monitoring); | 1107 (*it)->OnMonitoringStateChanged(is_monitoring); |
| 1062 } | 1108 } |
| 1063 #endif | 1109 #endif |
| 1064 } | 1110 } |
| 1065 | 1111 |
| 1066 } // namespace content | 1112 } // namespace content |
| OLD | NEW |