OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 | 4 |
5 #include "content/browser/tracing/tracing_controller_impl.h" | 5 #include "content/browser/tracing/tracing_controller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "content/browser/tracing/trace_message_filter.h" | 12 #include "content/browser/tracing/trace_message_filter.h" |
13 #include "content/browser/tracing/tracing_ui.h" | 13 #include "content/browser/tracing/tracing_ui.h" |
14 #include "content/common/child_process_messages.h" | 14 #include "content/common/child_process_messages.h" |
15 #include "content/public/browser/browser_message_filter.h" | 15 #include "content/public/browser/browser_message_filter.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 | 17 |
18 #if defined(OS_CHROMEOS) | |
19 #include "chromeos/dbus/dbus_thread_manager.h" | |
20 #include "chromeos/dbus/debug_daemon_client.h" | |
21 #endif | |
22 | |
18 using base::debug::TraceLog; | 23 using base::debug::TraceLog; |
19 | 24 |
20 namespace content { | 25 namespace content { |
21 | 26 |
22 namespace { | 27 namespace { |
23 | 28 |
24 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = | 29 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = |
25 LAZY_INSTANCE_INITIALIZER; | 30 LAZY_INSTANCE_INITIALIZER; |
26 | 31 |
27 } // namespace | 32 } // namespace |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 | 118 |
114 | 119 |
115 TracingControllerImpl::TracingControllerImpl() : | 120 TracingControllerImpl::TracingControllerImpl() : |
116 pending_disable_recording_ack_count_(0), | 121 pending_disable_recording_ack_count_(0), |
117 pending_capture_monitoring_snapshot_ack_count_(0), | 122 pending_capture_monitoring_snapshot_ack_count_(0), |
118 pending_trace_buffer_percent_full_ack_count_(0), | 123 pending_trace_buffer_percent_full_ack_count_(0), |
119 maximum_trace_buffer_percent_full_(0), | 124 maximum_trace_buffer_percent_full_(0), |
120 // Tracing may have been enabled by ContentMainRunner if kTraceStartup | 125 // Tracing may have been enabled by ContentMainRunner if kTraceStartup |
121 // is specified in command line. | 126 // is specified in command line. |
122 is_recording_(TraceLog::GetInstance()->IsEnabled()), | 127 is_recording_(TraceLog::GetInstance()->IsEnabled()), |
123 is_monitoring_(false) { | 128 is_monitoring_(false), |
129 is_system_tracing_(false) { | |
124 } | 130 } |
125 | 131 |
126 TracingControllerImpl::~TracingControllerImpl() { | 132 TracingControllerImpl::~TracingControllerImpl() { |
127 // This is a Leaky instance. | 133 // This is a Leaky instance. |
128 NOTREACHED(); | 134 NOTREACHED(); |
129 } | 135 } |
130 | 136 |
131 TracingControllerImpl* TracingControllerImpl::GetInstance() { | 137 TracingControllerImpl* TracingControllerImpl::GetInstance() { |
132 return g_controller.Pointer(); | 138 return g_controller.Pointer(); |
133 } | 139 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 if (pending_get_categories_done_callback_.is_null()) | 193 if (pending_get_categories_done_callback_.is_null()) |
188 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 194 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
189 #endif | 195 #endif |
190 | 196 |
191 options_ = options; | 197 options_ = options; |
192 int trace_options = (options & RECORD_CONTINUOUSLY) ? | 198 int trace_options = (options & RECORD_CONTINUOUSLY) ? |
193 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; | 199 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; |
194 if (options & ENABLE_SAMPLING) { | 200 if (options & ENABLE_SAMPLING) { |
195 trace_options |= TraceLog::ENABLE_SAMPLING; | 201 trace_options |= TraceLog::ENABLE_SAMPLING; |
196 } | 202 } |
197 // TODO(haraken): How to handle ENABLE_SYSTRACE? | 203 if (options & ENABLE_SYSTRACE) { |
dsinclair
2014/01/30 14:36:06
Is SYSTRACE only for cros, or will this if () also
haraken
2014/01/31 05:58:27
Done.
| |
204 #if defined(OS_CHROMEOS) | |
205 DCHECK(!is_system_tracing_); | |
206 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | |
207 StartSystemTracing(); | |
dsinclair
2014/01/30 14:36:06
nit: indenting.
haraken
2014/01/31 05:58:27
I'm not sure but this is in the middle of an expre
| |
208 is_system_tracing_ = true; | |
209 #endif | |
210 } | |
198 | 211 |
199 base::Closure on_enable_recording_done_callback = | 212 base::Closure on_enable_recording_done_callback = |
200 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, | 213 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, |
201 base::Unretained(this), | 214 base::Unretained(this), |
202 category_filter,trace_options, callback); | 215 category_filter,trace_options, callback); |
203 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 216 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
204 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, | 217 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, |
205 base::Unretained(this), | 218 base::Unretained(this), |
206 category_filter, | 219 category_filter, |
207 base::debug::TraceLog::RECORDING_MODE, | 220 base::debug::TraceLog::RECORDING_MODE, |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 } else if (result_file_) { | 633 } else if (result_file_) { |
621 result_file_->Close( | 634 result_file_->Close( |
622 base::Bind(&TracingControllerImpl::OnResultFileClosed, | 635 base::Bind(&TracingControllerImpl::OnResultFileClosed, |
623 base::Unretained(this))); | 636 base::Unretained(this))); |
624 } | 637 } |
625 } | 638 } |
626 | 639 |
627 void TracingControllerImpl::OnResultFileClosed() { | 640 void TracingControllerImpl::OnResultFileClosed() { |
628 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
629 | 642 |
643 if (is_system_tracing_) { | |
644 // Disable system tracing now that the local trace has shutdown. | |
645 // This must be done last because we potentially need to push event | |
646 // records into the system event log for synchronizing system event | |
647 // timestamps with chrome event timestamps--and since the system event | |
648 // log is a ring-buffer (on linux) adding them at the end is the only | |
649 // way we're confident we'll have them in the final result. | |
650 is_system_tracing_ = false; | |
dsinclair
2014/01/30 14:36:06
This can only be set true inside a #if defined(OS_
haraken
2014/01/31 05:58:27
Done.
| |
651 #if defined(OS_CHROMEOS) | |
652 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | |
653 RequestStopSystemTracing( | |
dsinclair
2014/01/30 14:36:06
nit: indenting
| |
654 base::Bind(&TracingMessageHandler::OnEndSystemTracingAcked, | |
655 base::Unretained(this))); | |
656 #endif | |
657 return; | |
658 } | |
659 | |
630 if (!result_file_) | 660 if (!result_file_) |
631 return; | 661 return; |
632 | 662 |
633 if (!pending_disable_recording_done_callback_.is_null()) { | 663 if (!pending_disable_recording_done_callback_.is_null()) { |
634 pending_disable_recording_done_callback_.Run(result_file_->path()); | 664 pending_disable_recording_done_callback_.Run(result_file_->path()); |
635 pending_disable_recording_done_callback_.Reset(); | 665 pending_disable_recording_done_callback_.Reset(); |
636 } | 666 } |
637 result_file_.reset(); | 667 result_file_.reset(); |
638 } | 668 } |
639 | 669 |
670 void TracingControllerImpl::OnEndSystemTracingAcked( | |
671 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | |
672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
673 | |
674 TracingUI* tracing_ui = 0; | |
haraken
2014/01/30 13:39:46
This is a problem. Since TracingController does no
dsinclair
2014/01/30 14:36:06
So, does tracing_ui matter in this case? I though
haraken
2014/01/30 15:25:02
I'm not familiar with how the system tracing was w
haraken
2014/01/31 05:58:27
Done. I changed the code so that the system tracin
| |
675 tracing_ui->OnSystemTraceDataCollected(events_str_ptr); | |
676 DCHECK(!is_system_tracing_); | |
677 OnResultFileClosed(); | |
678 } | |
679 | |
640 void TracingControllerImpl::OnCaptureMonitoringSnapshotAcked( | 680 void TracingControllerImpl::OnCaptureMonitoringSnapshotAcked( |
641 TraceMessageFilter* trace_message_filter) { | 681 TraceMessageFilter* trace_message_filter) { |
642 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 682 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
643 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 683 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
644 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, | 684 base::Bind(&TracingControllerImpl::OnCaptureMonitoringSnapshotAcked, |
645 base::Unretained(this), | 685 base::Unretained(this), |
646 make_scoped_refptr(trace_message_filter))); | 686 make_scoped_refptr(trace_message_filter))); |
647 return; | 687 return; |
648 } | 688 } |
649 | 689 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 is_monitoring_ = is_monitoring; | 851 is_monitoring_ = is_monitoring; |
812 #if !defined(OS_ANDROID) | 852 #if !defined(OS_ANDROID) |
813 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 853 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
814 it != tracing_uis_.end(); it++) { | 854 it != tracing_uis_.end(); it++) { |
815 (*it)->OnMonitoringStateChanged(is_monitoring); | 855 (*it)->OnMonitoringStateChanged(is_monitoring); |
816 } | 856 } |
817 #endif | 857 #endif |
818 } | 858 } |
819 | 859 |
820 } // namespace content | 860 } // namespace content |
OLD | NEW |