| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/trace_controller_impl.h" | 5 #include "content/browser/tracing/trace_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "content/browser/tracing/trace_message_filter.h" | 11 #include "content/browser/tracing/trace_message_filter.h" |
| 12 #include "content/browser/tracing/trace_subscriber_stdio.h" | 12 #include "content/browser/tracing/trace_subscriber_stdio.h" |
| 13 #include "content/common/child_process_messages.h" | 13 #include "content/common/child_process_messages.h" |
| 14 #include "content/public/browser/browser_message_filter.h" | 14 #include "content/public/browser/browser_message_filter.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 | 16 |
| 17 using base::debug::TraceLog; | 17 using base::debug::TraceLog; |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 base::LazyInstance<TraceControllerImpl>::Leaky g_controller = | 23 base::LazyInstance<TraceControllerImpl>::Leaky g_controller = |
| 24 LAZY_INSTANCE_INITIALIZER; | 24 LAZY_INSTANCE_INITIALIZER; |
| 25 | 25 |
| 26 class AutoStopTraceSubscriberStdio : public TraceSubscriberStdio { | 26 class AutoStopTraceSubscriberStdio : public TraceSubscriberStdio { |
| 27 public: | 27 public: |
| 28 AutoStopTraceSubscriberStdio(const FilePath& file_path) | 28 AutoStopTraceSubscriberStdio(const base::FilePath& file_path) |
| 29 : TraceSubscriberStdio(file_path) {} | 29 : TraceSubscriberStdio(file_path) {} |
| 30 | 30 |
| 31 static void EndStartupTrace(TraceSubscriberStdio* subscriber) { | 31 static void EndStartupTrace(TraceSubscriberStdio* subscriber) { |
| 32 if (!TraceControllerImpl::GetInstance()->EndTracingAsync(subscriber)) | 32 if (!TraceControllerImpl::GetInstance()->EndTracingAsync(subscriber)) |
| 33 delete subscriber; | 33 delete subscriber; |
| 34 // else, the tracing will end asynchronously in OnEndTracingComplete(). | 34 // else, the tracing will end asynchronously in OnEndTracingComplete(). |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual void OnEndTracingComplete() { | 37 virtual void OnEndTracingComplete() { |
| 38 TraceSubscriberStdio::OnEndTracingComplete(); | 38 TraceSubscriberStdio::OnEndTracingComplete(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 65 // Leaky instance. | 65 // Leaky instance. |
| 66 NOTREACHED(); | 66 NOTREACHED(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 TraceControllerImpl* TraceControllerImpl::GetInstance() { | 69 TraceControllerImpl* TraceControllerImpl::GetInstance() { |
| 70 return g_controller.Pointer(); | 70 return g_controller.Pointer(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void TraceControllerImpl::InitStartupTracing(const CommandLine& command_line) { | 73 void TraceControllerImpl::InitStartupTracing(const CommandLine& command_line) { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 75 FilePath trace_file = command_line.GetSwitchValuePath( | 75 base::FilePath trace_file = command_line.GetSwitchValuePath( |
| 76 switches::kTraceStartupFile); | 76 switches::kTraceStartupFile); |
| 77 // trace_file = "none" means that startup events will show up for the next | 77 // trace_file = "none" means that startup events will show up for the next |
| 78 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ | 78 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ |
| 79 // EndTracing, for example). | 79 // EndTracing, for example). |
| 80 if (trace_file == FilePath().AppendASCII("none")) | 80 if (trace_file == base::FilePath().AppendASCII("none")) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 if (trace_file.empty()) { | 83 if (trace_file.empty()) { |
| 84 // Default to saving the startup trace into the current dir. | 84 // Default to saving the startup trace into the current dir. |
| 85 trace_file = FilePath().AppendASCII("chrometrace.log"); | 85 trace_file = base::FilePath().AppendASCII("chrometrace.log"); |
| 86 } | 86 } |
| 87 scoped_ptr<AutoStopTraceSubscriberStdio> subscriber( | 87 scoped_ptr<AutoStopTraceSubscriberStdio> subscriber( |
| 88 new AutoStopTraceSubscriberStdio(trace_file)); | 88 new AutoStopTraceSubscriberStdio(trace_file)); |
| 89 DCHECK(can_begin_tracing(subscriber.get())); | 89 DCHECK(can_begin_tracing(subscriber.get())); |
| 90 | 90 |
| 91 std::string delay_str = command_line.GetSwitchValueASCII( | 91 std::string delay_str = command_line.GetSwitchValueASCII( |
| 92 switches::kTraceStartupDuration); | 92 switches::kTraceStartupDuration); |
| 93 int delay_secs = 5; | 93 int delay_secs = 5; |
| 94 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { | 94 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { |
| 95 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration | 95 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 // The last ack represents local trace, so we need to ack it now. Note that | 405 // The last ack represents local trace, so we need to ack it now. Note that |
| 406 // this code only executes if there were child processes. | 406 // this code only executes if there were child processes. |
| 407 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 407 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
| 408 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 408 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 409 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, | 409 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
| 410 base::Unretained(this), bpf)); | 410 base::Unretained(this), bpf)); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace content | 414 } // namespace content |
| OLD | NEW |