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 27 matching lines...) Expand all Loading... | |
| 38 using base::trace_event::TraceLog; | 38 using base::trace_event::TraceLog; |
| 39 using base::trace_event::TraceConfig; | 39 using base::trace_event::TraceConfig; |
| 40 | 40 |
| 41 namespace content { | 41 namespace content { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = | 45 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = |
| 46 LAZY_INSTANCE_INITIALIZER; | 46 LAZY_INSTANCE_INITIALIZER; |
| 47 | 47 |
| 48 const char kChromeTracingAgentName[] = "chrome"; | |
| 49 #if defined(OS_CHROMEOS) | |
| 50 const char kCrOSTracingAgentName[] = "cros"; | |
| 51 #endif | |
| 52 const char kETWTracingAgentName[] = "etw"; | |
| 53 const char kChromeTraceLabel[] = "traceEvents"; | |
| 48 | 54 |
| 49 std::string GetNetworkTypeString() { | 55 std::string GetNetworkTypeString() { |
| 50 switch (net::NetworkChangeNotifier::GetConnectionType()) { | 56 switch (net::NetworkChangeNotifier::GetConnectionType()) { |
| 51 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | 57 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| 52 return "Ethernet"; | 58 return "Ethernet"; |
| 53 case net::NetworkChangeNotifier::CONNECTION_WIFI: | 59 case net::NetworkChangeNotifier::CONNECTION_WIFI: |
| 54 return "WiFi"; | 60 return "WiFi"; |
| 55 case net::NetworkChangeNotifier::CONNECTION_2G: | 61 case net::NetworkChangeNotifier::CONNECTION_2G: |
| 56 return "2G"; | 62 return "2G"; |
| 57 case net::NetworkChangeNotifier::CONNECTION_3G: | 63 case net::NetworkChangeNotifier::CONNECTION_3G: |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 } | 144 } |
| 139 | 145 |
| 140 TracingControllerImpl::TracingControllerImpl() | 146 TracingControllerImpl::TracingControllerImpl() |
| 141 : pending_stop_tracing_ack_count_(0), | 147 : pending_stop_tracing_ack_count_(0), |
| 142 pending_capture_monitoring_snapshot_ack_count_(0), | 148 pending_capture_monitoring_snapshot_ack_count_(0), |
| 143 pending_trace_log_status_ack_count_(0), | 149 pending_trace_log_status_ack_count_(0), |
| 144 maximum_trace_buffer_usage_(0), | 150 maximum_trace_buffer_usage_(0), |
| 145 approximate_event_count_(0), | 151 approximate_event_count_(0), |
| 146 pending_memory_dump_ack_count_(0), | 152 pending_memory_dump_ack_count_(0), |
| 147 failed_memory_dump_count_(0), | 153 failed_memory_dump_count_(0), |
| 148 // Tracing may have been enabled by ContentMainRunner if kTraceStartup | |
| 149 // is specified in command line. | |
| 150 #if defined(OS_CHROMEOS) || defined(OS_WIN) | |
| 151 is_system_tracing_(false), | |
| 152 #endif | |
| 153 is_tracing_(false), | 154 is_tracing_(false), |
| 154 is_monitoring_(false), | 155 is_monitoring_(false) { |
| 155 is_power_tracing_(false) { | |
| 156 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( | 156 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( |
| 157 this /* delegate */, true /* is_coordinator */); | 157 this /* delegate */, true /* is_coordinator */); |
| 158 | 158 |
| 159 // Deliberately leaked, like this class. | 159 // Deliberately leaked, like this class. |
| 160 base::FileTracing::SetProvider(new FileTracingProviderImpl); | 160 base::FileTracing::SetProvider(new FileTracingProviderImpl); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TracingControllerImpl::~TracingControllerImpl() { | 163 TracingControllerImpl::~TracingControllerImpl() { |
| 164 // This is a Leaky instance. | 164 // This is a Leaky instance. |
| 165 NOTREACHED(); | 165 NOTREACHED(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 203 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 204 | 204 |
| 205 TraceLog::GetInstance()->SetDisabled(); | 205 TraceLog::GetInstance()->SetDisabled(); |
| 206 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 206 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool TracingControllerImpl::StartTracing( | 209 bool TracingControllerImpl::StartTracing( |
| 210 const TraceConfig& trace_config, | 210 const TraceConfig& trace_config, |
| 211 const StartTracingDoneCallback& callback) { | 211 const StartTracingDoneCallback& callback) { |
| 212 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 212 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 213 DCHECK(additional_tracing_agents_.empty()); | |
| 213 | 214 |
| 214 if (!can_start_tracing()) | 215 if (!can_start_tracing()) |
| 215 return false; | 216 return false; |
| 216 is_tracing_ = true; | 217 is_tracing_ = true; |
| 218 start_tracing_done_callback_ = callback; | |
| 217 | 219 |
| 218 #if defined(OS_ANDROID) | 220 #if defined(OS_ANDROID) |
| 219 if (pending_get_categories_done_callback_.is_null()) | 221 if (pending_get_categories_done_callback_.is_null()) |
| 220 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 222 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 221 #endif | 223 #endif |
| 222 | 224 |
| 223 if (trace_config.IsSystraceEnabled()) { | 225 if (trace_config.IsSystraceEnabled()) { |
| 224 DCHECK(!is_power_tracing_); | 226 if (PowerTracingAgent::GetInstance()->StartAgentTracing(trace_config)) |
| 225 is_power_tracing_ = PowerTracingAgent::GetInstance()->StartTracing(); | 227 additional_tracing_agents_.push_back(PowerTracingAgent::GetInstance()); |
| 226 #if defined(OS_CHROMEOS) | 228 #if defined(OS_CHROMEOS) |
| 227 DCHECK(!is_system_tracing_); | 229 if (chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> |
| 228 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | 230 StartAgentTracing(trace_config)) { |
| 229 StartSystemTracing(); | 231 additional_tracing_agents_.push_back( |
| 230 is_system_tracing_ = true; | 232 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()); |
| 233 } | |
|
stevenjb
2015/12/14 18:22:40
Can this be:
DebugDaemonClient debug_daemon = chro
Zhen Wang
2015/12/14 21:03:57
Done.
| |
| 231 #elif defined(OS_WIN) | 234 #elif defined(OS_WIN) |
| 232 DCHECK(!is_system_tracing_); | 235 if (EtwSystemEventConsumer::GetInstance()->StartAgentTracing( |
| 233 is_system_tracing_ = | 236 trace_config)) { |
| 234 EtwSystemEventConsumer::GetInstance()->StartSystemTracing(); | 237 additional_tracing_agents_.push_back( |
| 238 EtwSystemEventConsumer::GetInstance()); | |
| 239 } | |
| 235 #endif | 240 #endif |
| 236 } | 241 } |
| 237 | 242 |
| 238 // TraceLog may have been enabled in startup tracing before threads are ready. | 243 // TraceLog may have been enabled in startup tracing before threads are ready. |
| 239 if (TraceLog::GetInstance()->IsEnabled()) | 244 if (TraceLog::GetInstance()->IsEnabled()) |
| 240 return true; | 245 return true; |
| 241 | 246 return StartAgentTracing(trace_config); |
| 242 base::Closure on_start_tracing_done_callback = | |
| 243 base::Bind(&TracingControllerImpl::OnStartTracingDone, | |
| 244 base::Unretained(this), | |
| 245 trace_config, callback); | |
| 246 if (!BrowserThread::PostTask( | |
| 247 BrowserThread::FILE, FROM_HERE, | |
| 248 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, | |
| 249 base::Unretained(this), trace_config, | |
| 250 base::trace_event::TraceLog::RECORDING_MODE, | |
| 251 on_start_tracing_done_callback))) { | |
| 252 // BrowserThread::PostTask fails if the threads haven't been created yet, | |
| 253 // so it should be safe to just use TraceLog::SetEnabled directly. | |
| 254 base::trace_event::TraceLog::GetInstance()->SetEnabled( | |
| 255 trace_config, base::trace_event::TraceLog::RECORDING_MODE); | |
| 256 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 257 on_start_tracing_done_callback); | |
| 258 } | |
| 259 | |
| 260 return true; | |
| 261 } | 247 } |
| 262 | 248 |
| 263 void TracingControllerImpl::OnStartTracingDone( | 249 void TracingControllerImpl::OnStartAgentTracingDone( |
| 264 const TraceConfig& trace_config, | 250 const TraceConfig& trace_config, |
| 265 const StartTracingDoneCallback& callback) { | 251 const StartTracingDoneCallback& callback) { |
| 266 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 252 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 267 | 253 |
| 268 TRACE_EVENT_API_ADD_METADATA_EVENT("IsTimeTicksHighResolution", "value", | 254 TRACE_EVENT_API_ADD_METADATA_EVENT("IsTimeTicksHighResolution", "value", |
| 269 base::TimeTicks::IsHighResolution()); | 255 base::TimeTicks::IsHighResolution()); |
| 270 TRACE_EVENT_API_ADD_METADATA_EVENT("TraceConfig", "value", | 256 TRACE_EVENT_API_ADD_METADATA_EVENT("TraceConfig", "value", |
| 271 trace_config.AsConvertableToTraceFormat()); | 257 trace_config.AsConvertableToTraceFormat()); |
| 272 | 258 |
| 273 // Notify all child processes. | 259 // Notify all child processes. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 #if defined(OS_ANDROID) | 304 #if defined(OS_ANDROID) |
| 319 if (pending_get_categories_done_callback_.is_null()) | 305 if (pending_get_categories_done_callback_.is_null()) |
| 320 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 306 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 321 #endif | 307 #endif |
| 322 | 308 |
| 323 // Count myself (local trace) in pending_stop_tracing_ack_count_, | 309 // Count myself (local trace) in pending_stop_tracing_ack_count_, |
| 324 // acked below. | 310 // acked below. |
| 325 pending_stop_tracing_ack_count_ = trace_message_filters_.size() + 1; | 311 pending_stop_tracing_ack_count_ = trace_message_filters_.size() + 1; |
| 326 pending_stop_tracing_filters_ = trace_message_filters_; | 312 pending_stop_tracing_filters_ = trace_message_filters_; |
| 327 | 313 |
| 328 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 314 pending_stop_tracing_ack_count_ += additional_tracing_agents_.size(); |
| 329 if (is_system_tracing_) { | 315 for (auto it : additional_tracing_agents_) { |
| 330 // Disable system tracing. | |
| 331 is_system_tracing_ = false; | |
| 332 ++pending_stop_tracing_ack_count_; | |
| 333 | |
| 334 #if defined(OS_CHROMEOS) | 316 #if defined(OS_CHROMEOS) |
| 335 scoped_refptr<base::TaskRunner> task_runner = | 317 if (it->GetTracingAgentName() == kCrOSTracingAgentName) { |
|
stevenjb
2015/12/14 18:22:40
This is awkward. See note above.
Zhen Wang
2015/12/14 21:03:57
Done.
| |
| 336 BrowserThread::GetBlockingPool(); | 318 scoped_refptr<base::TaskRunner> task_runner = |
| 337 chromeos::DBusThreadManager::Get() | 319 BrowserThread::GetBlockingPool(); |
| 338 ->GetDebugDaemonClient() | 320 static_cast<chromeos::DebugDaemonClient*>( |
| 339 ->RequestStopSystemTracing( | 321 it)->SetStopAgentTracingTaskRunner(task_runner); |
| 340 task_runner, | 322 } |
| 341 base::Bind(&TracingControllerImpl::OnEndSystemTracingAcked, | |
| 342 base::Unretained(this))); | |
| 343 #elif defined(OS_WIN) | |
| 344 EtwSystemEventConsumer::GetInstance()->StopSystemTracing( | |
| 345 base::Bind(&TracingControllerImpl::OnEndSystemTracingAcked, | |
| 346 base::Unretained(this))); | |
| 347 #endif | 323 #endif |
| 348 } | 324 it->StopAgentTracing( |
| 349 #endif // defined(OS_CHROMEOS) || defined(OS_WIN) | 325 base::Bind(&TracingControllerImpl::OnEndAgentTracingAcked, |
| 350 | |
| 351 if (is_power_tracing_) { | |
| 352 is_power_tracing_ = false; | |
| 353 ++pending_stop_tracing_ack_count_; | |
| 354 PowerTracingAgent::GetInstance()->StopTracing( | |
| 355 base::Bind(&TracingControllerImpl::OnEndPowerTracingAcked, | |
| 356 base::Unretained(this))); | 326 base::Unretained(this))); |
| 357 } | 327 } |
| 328 additional_tracing_agents_.clear(); | |
| 358 | 329 |
| 359 // Handle special case of zero child processes by immediately flushing the | 330 StopAgentTracing(StopAgentTracingCallback()); |
| 360 // trace log. Once the flush has completed the caller will be notified that | |
| 361 // tracing has ended. | |
| 362 if (pending_stop_tracing_ack_count_ == 1) { | |
| 363 // Flush/cancel asynchronously now, because we don't have any children to | |
| 364 // wait for. | |
| 365 if (trace_data_sink_) { | |
| 366 TraceLog::GetInstance()->Flush( | |
| 367 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, | |
| 368 base::Unretained(this)), | |
| 369 true); | |
| 370 } else { | |
| 371 TraceLog::GetInstance()->CancelTracing( | |
| 372 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, | |
| 373 base::Unretained(this))); | |
| 374 } | |
| 375 } | |
| 376 | |
| 377 // Notify all child processes. | |
| 378 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | |
| 379 it != trace_message_filters_.end(); ++it) { | |
| 380 if (trace_data_sink_) | |
| 381 it->get()->SendEndTracing(); | |
| 382 else | |
| 383 it->get()->SendCancelTracing(); | |
| 384 } | |
| 385 } | 331 } |
| 386 | 332 |
| 387 bool TracingControllerImpl::StartMonitoring( | 333 bool TracingControllerImpl::StartMonitoring( |
| 388 const TraceConfig& trace_config, | 334 const TraceConfig& trace_config, |
| 389 const StartMonitoringDoneCallback& callback) { | 335 const StartMonitoringDoneCallback& callback) { |
| 390 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 391 | 337 |
| 392 if (!can_start_monitoring()) | 338 if (!can_start_monitoring()) |
| 393 return false; | 339 return false; |
| 394 OnMonitoringStateChanged(true); | 340 OnMonitoringStateChanged(true); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 // Trigger callback if one is set. | 677 // Trigger callback if one is set. |
| 732 if (!pending_get_categories_done_callback_.is_null()) { | 678 if (!pending_get_categories_done_callback_.is_null()) { |
| 733 pending_get_categories_done_callback_.Run(known_category_groups_); | 679 pending_get_categories_done_callback_.Run(known_category_groups_); |
| 734 pending_get_categories_done_callback_.Reset(); | 680 pending_get_categories_done_callback_.Reset(); |
| 735 } else if (trace_data_sink_.get()) { | 681 } else if (trace_data_sink_.get()) { |
| 736 trace_data_sink_->Close(); | 682 trace_data_sink_->Close(); |
| 737 trace_data_sink_ = NULL; | 683 trace_data_sink_ = NULL; |
| 738 } | 684 } |
| 739 } | 685 } |
| 740 | 686 |
| 741 void TracingControllerImpl::OnEndPowerTracingAcked( | 687 void TracingControllerImpl::OnEndAgentTracingAcked( |
| 688 const std::string& agent_name, | |
| 689 const std::string& events_label, | |
| 742 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 690 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 743 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 691 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 744 | 692 |
| 745 if (trace_data_sink_.get()) { | 693 if (trace_data_sink_.get()) { |
| 746 std::string json_string = base::GetQuotedJSONString(events_str_ptr->data()); | 694 std::string json_string; |
| 747 trace_data_sink_->SetPowerTrace(json_string); | 695 if (agent_name == kETWTracingAgentName) { |
| 696 // The Windows kernel events are kept into a JSON format stored as string | |
| 697 // and must not be escaped. | |
| 698 json_string = events_str_ptr->data(); | |
| 699 } else { | |
| 700 json_string = base::GetQuotedJSONString(events_str_ptr->data()); | |
| 701 } | |
| 702 trace_data_sink_->AddAgentTrace(events_label, json_string); | |
| 748 } | 703 } |
| 749 std::vector<std::string> category_groups; | 704 std::vector<std::string> category_groups; |
| 750 OnStopTracingAcked(NULL, category_groups); | 705 OnStopTracingAcked(NULL, category_groups); |
| 751 } | 706 } |
| 752 | 707 |
| 753 #if defined(OS_CHROMEOS) || defined(OS_WIN) | |
| 754 void TracingControllerImpl::OnEndSystemTracingAcked( | |
| 755 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | |
| 756 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 757 | |
| 758 if (trace_data_sink_.get()) { | |
| 759 #if defined(OS_WIN) | |
| 760 // The Windows kernel events are kept into a JSon format stored as string | |
| 761 // and must not be escaped. | |
| 762 std::string json_string = events_str_ptr->data(); | |
| 763 #else | |
| 764 std::string json_string = | |
| 765 base::GetQuotedJSONString(events_str_ptr->data()); | |
| 766 #endif | |
| 767 trace_data_sink_->SetSystemTrace(json_string); | |
| 768 } | |
| 769 DCHECK(!is_system_tracing_); | |
| 770 std::vector<std::string> category_groups; | |
| 771 OnStopTracingAcked(NULL, category_groups); | |
| 772 } | |
| 773 #endif | |
| 774 | |
| 775 void TracingControllerImpl::OnCaptureMonitoringSnapshotAcked( | 708 void TracingControllerImpl::OnCaptureMonitoringSnapshotAcked( |
| 776 TraceMessageFilter* trace_message_filter) { | 709 TraceMessageFilter* trace_message_filter) { |
| 777 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 710 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 778 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 711 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 779 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, | 712 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, |
| 780 base::Unretained(this), | 713 base::Unretained(this), |
| 781 make_scoped_refptr(trace_message_filter))); | 714 make_scoped_refptr(trace_message_filter))); |
| 782 return; | 715 return; |
| 783 } | 716 } |
| 784 | 717 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 917 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); | 850 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); |
| 918 tracing_uis_.insert(tracing_ui); | 851 tracing_uis_.insert(tracing_ui); |
| 919 } | 852 } |
| 920 | 853 |
| 921 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) { | 854 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) { |
| 922 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); | 855 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); |
| 923 DCHECK(it != tracing_uis_.end()); | 856 DCHECK(it != tracing_uis_.end()); |
| 924 tracing_uis_.erase(it); | 857 tracing_uis_.erase(it); |
| 925 } | 858 } |
| 926 | 859 |
| 860 std::string TracingControllerImpl::GetTracingAgentName() { | |
| 861 return kChromeTracingAgentName; | |
| 862 } | |
| 863 | |
| 864 std::string TracingControllerImpl::GetTraceEventLabel() { | |
| 865 return kChromeTraceLabel; | |
| 866 } | |
| 867 | |
| 868 bool TracingControllerImpl::StartAgentTracing( | |
| 869 const base::trace_event::TraceConfig& trace_config) { | |
| 870 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 871 | |
| 872 base::Closure on_start_tracing_done_callback = | |
| 873 base::Bind(&TracingControllerImpl::OnStartAgentTracingDone, | |
| 874 base::Unretained(this), | |
| 875 trace_config, start_tracing_done_callback_); | |
| 876 if (!BrowserThread::PostTask( | |
| 877 BrowserThread::FILE, FROM_HERE, | |
| 878 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, | |
| 879 base::Unretained(this), trace_config, | |
| 880 base::trace_event::TraceLog::RECORDING_MODE, | |
| 881 on_start_tracing_done_callback))) { | |
| 882 // BrowserThread::PostTask fails if the threads haven't been created yet, | |
| 883 // so it should be safe to just use TraceLog::SetEnabled directly. | |
| 884 base::trace_event::TraceLog::GetInstance()->SetEnabled( | |
| 885 trace_config, base::trace_event::TraceLog::RECORDING_MODE); | |
| 886 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 887 on_start_tracing_done_callback); | |
| 888 } | |
| 889 | |
| 890 return true; | |
| 891 } | |
| 892 | |
| 893 void TracingControllerImpl::StopAgentTracing( | |
| 894 const StopAgentTracingCallback& callback) { | |
| 895 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 896 // Handle special case of zero child processes by immediately flushing the | |
| 897 // trace log. Once the flush has completed the caller will be notified that | |
| 898 // tracing has ended. | |
| 899 if (pending_stop_tracing_ack_count_ == 1) { | |
| 900 // Flush/cancel asynchronously now, because we don't have any children to | |
| 901 // wait for. | |
| 902 if (trace_data_sink_) { | |
| 903 TraceLog::GetInstance()->Flush( | |
| 904 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, | |
| 905 base::Unretained(this)), | |
| 906 true); | |
| 907 } else { | |
| 908 TraceLog::GetInstance()->CancelTracing( | |
| 909 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, | |
| 910 base::Unretained(this))); | |
| 911 } | |
| 912 } | |
| 913 | |
| 914 // Notify all child processes. | |
| 915 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | |
| 916 it != trace_message_filters_.end(); ++it) { | |
|
stevenjb
2015/12/14 18:22:40
for (auto it : trace_message_filters_)
Zhen Wang
2015/12/14 21:03:57
Done.
| |
| 917 if (trace_data_sink_) | |
| 918 it->get()->SendEndTracing(); | |
| 919 else | |
| 920 it->get()->SendCancelTracing(); | |
| 921 } | |
| 922 } | |
| 923 | |
| 924 bool TracingControllerImpl::SupportsExplicitClockSync() { | |
| 925 // TODO(zhenw): return true after implementing explicit clock sync. | |
| 926 return false; | |
| 927 } | |
| 928 | |
| 929 void TracingControllerImpl::RecordClockSyncMarker( | |
| 930 int sync_id, | |
| 931 const RecordClockSyncMarkerCallback& callback) { | |
| 932 DCHECK(SupportsExplicitClockSync()); | |
| 933 // TODO(zhenw): implement explicit clock sync. | |
| 934 } | |
| 935 | |
| 936 void TracingControllerImpl::IssueClockSyncMarker() { | |
| 937 // TODO(zhenw): implement explicit clock sync. | |
| 938 } | |
| 939 | |
| 927 void TracingControllerImpl::RequestGlobalMemoryDump( | 940 void TracingControllerImpl::RequestGlobalMemoryDump( |
| 928 const base::trace_event::MemoryDumpRequestArgs& args, | 941 const base::trace_event::MemoryDumpRequestArgs& args, |
| 929 const base::trace_event::MemoryDumpCallback& callback) { | 942 const base::trace_event::MemoryDumpCallback& callback) { |
| 930 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 943 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 931 BrowserThread::PostTask( | 944 BrowserThread::PostTask( |
| 932 BrowserThread::UI, FROM_HERE, | 945 BrowserThread::UI, FROM_HERE, |
| 933 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump, | 946 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump, |
| 934 base::Unretained(this), args, callback)); | 947 base::Unretained(this), args, callback)); |
| 935 return; | 948 return; |
| 936 } | 949 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1053 is_monitoring_ = is_monitoring; | 1066 is_monitoring_ = is_monitoring; |
| 1054 #if !defined(OS_ANDROID) | 1067 #if !defined(OS_ANDROID) |
| 1055 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 1068 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
| 1056 it != tracing_uis_.end(); it++) { | 1069 it != tracing_uis_.end(); it++) { |
| 1057 (*it)->OnMonitoringStateChanged(is_monitoring); | 1070 (*it)->OnMonitoringStateChanged(is_monitoring); |
| 1058 } | 1071 } |
| 1059 #endif | 1072 #endif |
| 1060 } | 1073 } |
| 1061 | 1074 |
| 1062 } // namespace content | 1075 } // namespace content |
| OLD | NEW |