| 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 } |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 #if defined(OS_ANDROID) | 294 #if defined(OS_ANDROID) |
| 309 if (pending_get_categories_done_callback_.is_null()) | 295 if (pending_get_categories_done_callback_.is_null()) |
| 310 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 296 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 311 #endif | 297 #endif |
| 312 | 298 |
| 313 // Count myself (local trace) in pending_stop_tracing_ack_count_, | 299 // Count myself (local trace) in pending_stop_tracing_ack_count_, |
| 314 // acked below. | 300 // acked below. |
| 315 pending_stop_tracing_ack_count_ = trace_message_filters_.size() + 1; | 301 pending_stop_tracing_ack_count_ = trace_message_filters_.size() + 1; |
| 316 pending_stop_tracing_filters_ = trace_message_filters_; | 302 pending_stop_tracing_filters_ = trace_message_filters_; |
| 317 | 303 |
| 318 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 304 pending_stop_tracing_ack_count_ += additional_tracing_agents_.size(); |
| 319 if (is_system_tracing_) { | 305 for (auto it : additional_tracing_agents_) { |
| 320 // Disable system tracing. | |
| 321 is_system_tracing_ = false; | |
| 322 ++pending_stop_tracing_ack_count_; | |
| 323 | |
| 324 #if defined(OS_CHROMEOS) | 306 #if defined(OS_CHROMEOS) |
| 325 scoped_refptr<base::TaskRunner> task_runner = | 307 if (it->GetTracingAgentName() == kCrOSTracingAgentName) { |
| 326 BrowserThread::GetBlockingPool(); | 308 scoped_refptr<base::TaskRunner> task_runner = |
| 327 chromeos::DBusThreadManager::Get() | 309 BrowserThread::GetBlockingPool(); |
| 328 ->GetDebugDaemonClient() | 310 static_cast<chromeos::DebugDaemonClient*>( |
| 329 ->RequestStopSystemTracing( | 311 it)->SetStopAgentTracingTaskRunner(task_runner); |
| 330 task_runner, | 312 } |
| 331 base::Bind(&TracingControllerImpl::OnEndSystemTracingAcked, | |
| 332 base::Unretained(this))); | |
| 333 #elif defined(OS_WIN) | |
| 334 EtwSystemEventConsumer::GetInstance()->StopSystemTracing( | |
| 335 base::Bind(&TracingControllerImpl::OnEndSystemTracingAcked, | |
| 336 base::Unretained(this))); | |
| 337 #endif | 313 #endif |
| 338 } | 314 it->StopAgentTracing( |
| 339 #endif // defined(OS_CHROMEOS) || defined(OS_WIN) | 315 base::Bind(&TracingControllerImpl::OnEndAgentTracingAcked, |
| 340 | |
| 341 if (is_power_tracing_) { | |
| 342 is_power_tracing_ = false; | |
| 343 ++pending_stop_tracing_ack_count_; | |
| 344 PowerTracingAgent::GetInstance()->StopTracing( | |
| 345 base::Bind(&TracingControllerImpl::OnEndPowerTracingAcked, | |
| 346 base::Unretained(this))); | 316 base::Unretained(this))); |
| 347 } | 317 } |
| 318 additional_tracing_agents_.clear(); |
| 348 | 319 |
| 349 // Handle special case of zero child processes by immediately flushing the | 320 StopAgentTracing(StopAgentTracingCallback()); |
| 350 // trace log. Once the flush has completed the caller will be notified that | |
| 351 // tracing has ended. | |
| 352 if (pending_stop_tracing_ack_count_ == 1) { | |
| 353 // Flush/cancel asynchronously now, because we don't have any children to | |
| 354 // wait for. | |
| 355 if (trace_data_sink_) { | |
| 356 TraceLog::GetInstance()->Flush( | |
| 357 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, | |
| 358 base::Unretained(this)), | |
| 359 true); | |
| 360 } else { | |
| 361 TraceLog::GetInstance()->CancelTracing( | |
| 362 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, | |
| 363 base::Unretained(this))); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 // Notify all child processes. | |
| 368 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | |
| 369 it != trace_message_filters_.end(); ++it) { | |
| 370 if (trace_data_sink_) | |
| 371 it->get()->SendEndTracing(); | |
| 372 else | |
| 373 it->get()->SendCancelTracing(); | |
| 374 } | |
| 375 } | 321 } |
| 376 | 322 |
| 377 bool TracingControllerImpl::StartMonitoring( | 323 bool TracingControllerImpl::StartMonitoring( |
| 378 const TraceConfig& trace_config, | 324 const TraceConfig& trace_config, |
| 379 const StartMonitoringDoneCallback& callback) { | 325 const StartMonitoringDoneCallback& callback) { |
| 380 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 326 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 381 | 327 |
| 382 if (!can_start_monitoring()) | 328 if (!can_start_monitoring()) |
| 383 return false; | 329 return false; |
| 384 OnMonitoringStateChanged(true); | 330 OnMonitoringStateChanged(true); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // Trigger callback if one is set. | 667 // Trigger callback if one is set. |
| 722 if (!pending_get_categories_done_callback_.is_null()) { | 668 if (!pending_get_categories_done_callback_.is_null()) { |
| 723 pending_get_categories_done_callback_.Run(known_category_groups_); | 669 pending_get_categories_done_callback_.Run(known_category_groups_); |
| 724 pending_get_categories_done_callback_.Reset(); | 670 pending_get_categories_done_callback_.Reset(); |
| 725 } else if (trace_data_sink_.get()) { | 671 } else if (trace_data_sink_.get()) { |
| 726 trace_data_sink_->Close(); | 672 trace_data_sink_->Close(); |
| 727 trace_data_sink_ = NULL; | 673 trace_data_sink_ = NULL; |
| 728 } | 674 } |
| 729 } | 675 } |
| 730 | 676 |
| 731 void TracingControllerImpl::OnEndPowerTracingAcked( | 677 void TracingControllerImpl::OnEndAgentTracingAcked( |
| 678 const std::string& agent_name, |
| 679 const std::string& events_label, |
| 732 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 680 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
| 733 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 681 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 734 | 682 |
| 735 if (trace_data_sink_.get()) { | 683 if (trace_data_sink_.get()) { |
| 736 std::string json_string = base::GetQuotedJSONString(events_str_ptr->data()); | 684 std::string json_string; |
| 737 trace_data_sink_->SetPowerTrace(json_string); | 685 if (agent_name == kETWTracingAgentName) { |
| 686 // The Windows kernel events are kept into a JSON format stored as string |
| 687 // and must not be escaped. |
| 688 json_string = events_str_ptr->data(); |
| 689 } else { |
| 690 json_string = base::GetQuotedJSONString(events_str_ptr->data()); |
| 691 } |
| 692 trace_data_sink_->AddAgentTrace(events_label, json_string); |
| 738 } | 693 } |
| 739 std::vector<std::string> category_groups; | 694 std::vector<std::string> category_groups; |
| 740 OnStopTracingAcked(NULL, category_groups); | 695 OnStopTracingAcked(NULL, category_groups); |
| 741 } | 696 } |
| 742 | 697 |
| 743 #if defined(OS_CHROMEOS) || defined(OS_WIN) | |
| 744 void TracingControllerImpl::OnEndSystemTracingAcked( | |
| 745 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | |
| 746 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 747 | |
| 748 if (trace_data_sink_.get()) { | |
| 749 #if defined(OS_WIN) | |
| 750 // The Windows kernel events are kept into a JSon format stored as string | |
| 751 // and must not be escaped. | |
| 752 std::string json_string = events_str_ptr->data(); | |
| 753 #else | |
| 754 std::string json_string = | |
| 755 base::GetQuotedJSONString(events_str_ptr->data()); | |
| 756 #endif | |
| 757 trace_data_sink_->SetSystemTrace(json_string); | |
| 758 } | |
| 759 DCHECK(!is_system_tracing_); | |
| 760 std::vector<std::string> category_groups; | |
| 761 OnStopTracingAcked(NULL, category_groups); | |
| 762 } | |
| 763 #endif | |
| 764 | |
| 765 void TracingControllerImpl::OnCaptureMonitoringSnapshotAcked( | 698 void TracingControllerImpl::OnCaptureMonitoringSnapshotAcked( |
| 766 TraceMessageFilter* trace_message_filter) { | 699 TraceMessageFilter* trace_message_filter) { |
| 767 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 700 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 768 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 701 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 769 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, | 702 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, |
| 770 base::Unretained(this), | 703 base::Unretained(this), |
| 771 make_scoped_refptr(trace_message_filter))); | 704 make_scoped_refptr(trace_message_filter))); |
| 772 return; | 705 return; |
| 773 } | 706 } |
| 774 | 707 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); | 840 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); |
| 908 tracing_uis_.insert(tracing_ui); | 841 tracing_uis_.insert(tracing_ui); |
| 909 } | 842 } |
| 910 | 843 |
| 911 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) { | 844 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) { |
| 912 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); | 845 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); |
| 913 DCHECK(it != tracing_uis_.end()); | 846 DCHECK(it != tracing_uis_.end()); |
| 914 tracing_uis_.erase(it); | 847 tracing_uis_.erase(it); |
| 915 } | 848 } |
| 916 | 849 |
| 850 std::string TracingControllerImpl::GetTracingAgentName() { |
| 851 return kChromeTracingAgentName; |
| 852 } |
| 853 |
| 854 std::string TracingControllerImpl::GetTraceEventLabel() { |
| 855 return kChromeTraceLabel; |
| 856 } |
| 857 |
| 858 bool TracingControllerImpl::StartAgentTracing( |
| 859 const base::trace_event::TraceConfig& trace_config) { |
| 860 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 861 |
| 862 base::Closure on_start_tracing_done_callback = |
| 863 base::Bind(&TracingControllerImpl::OnStartAgentTracingDone, |
| 864 base::Unretained(this), |
| 865 trace_config, start_tracing_done_callback_); |
| 866 if (!BrowserThread::PostTask( |
| 867 BrowserThread::FILE, FROM_HERE, |
| 868 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, |
| 869 base::Unretained(this), trace_config, |
| 870 base::trace_event::TraceLog::RECORDING_MODE, |
| 871 on_start_tracing_done_callback))) { |
| 872 // BrowserThread::PostTask fails if the threads haven't been created yet, |
| 873 // so it should be safe to just use TraceLog::SetEnabled directly. |
| 874 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 875 trace_config, base::trace_event::TraceLog::RECORDING_MODE); |
| 876 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 877 on_start_tracing_done_callback); |
| 878 } |
| 879 |
| 880 return true; |
| 881 } |
| 882 |
| 883 void TracingControllerImpl::StopAgentTracing( |
| 884 const StopAgentTracingCallback& callback) { |
| 885 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 886 // Handle special case of zero child processes by immediately flushing the |
| 887 // trace log. Once the flush has completed the caller will be notified that |
| 888 // tracing has ended. |
| 889 if (pending_stop_tracing_ack_count_ == 1) { |
| 890 // Flush/cancel asynchronously now, because we don't have any children to |
| 891 // wait for. |
| 892 if (trace_data_sink_) { |
| 893 TraceLog::GetInstance()->Flush( |
| 894 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, |
| 895 base::Unretained(this)), |
| 896 true); |
| 897 } else { |
| 898 TraceLog::GetInstance()->CancelTracing( |
| 899 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, |
| 900 base::Unretained(this))); |
| 901 } |
| 902 } |
| 903 |
| 904 // Notify all child processes. |
| 905 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
| 906 it != trace_message_filters_.end(); ++it) { |
| 907 if (trace_data_sink_) |
| 908 it->get()->SendEndTracing(); |
| 909 else |
| 910 it->get()->SendCancelTracing(); |
| 911 } |
| 912 } |
| 913 |
| 914 bool TracingControllerImpl::SupportsExplicitClockSync() { |
| 915 // TODO(zhenw): return true after implementing explicit clock sync. |
| 916 return false; |
| 917 } |
| 918 |
| 919 void TracingControllerImpl::RecordClockSyncMarker( |
| 920 int sync_id, |
| 921 const RecordClockSyncMarkerCallback& callback) { |
| 922 DCHECK(SupportsExplicitClockSync()); |
| 923 // TODO(zhenw): implement explicit clock sync. |
| 924 } |
| 925 |
| 926 void TracingControllerImpl::IssueClockSyncMarker() { |
| 927 // TODO(zhenw): implement explicit clock sync. |
| 928 } |
| 929 |
| 917 void TracingControllerImpl::RequestGlobalMemoryDump( | 930 void TracingControllerImpl::RequestGlobalMemoryDump( |
| 918 const base::trace_event::MemoryDumpRequestArgs& args, | 931 const base::trace_event::MemoryDumpRequestArgs& args, |
| 919 const base::trace_event::MemoryDumpCallback& callback) { | 932 const base::trace_event::MemoryDumpCallback& callback) { |
| 920 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 933 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 921 BrowserThread::PostTask( | 934 BrowserThread::PostTask( |
| 922 BrowserThread::UI, FROM_HERE, | 935 BrowserThread::UI, FROM_HERE, |
| 923 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump, | 936 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump, |
| 924 base::Unretained(this), args, callback)); | 937 base::Unretained(this), args, callback)); |
| 925 return; | 938 return; |
| 926 } | 939 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 is_monitoring_ = is_monitoring; | 1056 is_monitoring_ = is_monitoring; |
| 1044 #if !defined(OS_ANDROID) | 1057 #if !defined(OS_ANDROID) |
| 1045 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 1058 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
| 1046 it != tracing_uis_.end(); it++) { | 1059 it != tracing_uis_.end(); it++) { |
| 1047 (*it)->OnMonitoringStateChanged(is_monitoring); | 1060 (*it)->OnMonitoringStateChanged(is_monitoring); |
| 1048 } | 1061 } |
| 1049 #endif | 1062 #endif |
| 1050 } | 1063 } |
| 1051 | 1064 |
| 1052 } // namespace content | 1065 } // namespace content |
| OLD | NEW |