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/strings/string_number_conversions.h" | 10 #include "base/strings/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 #if defined(OS_CHROMEOS) | |
18 #include "chromeos/dbus/dbus_thread_manager.h" | |
19 #include "chromeos/dbus/debug_daemon_client.h" | |
20 #endif | |
21 | |
17 using base::debug::TraceLog; | 22 using base::debug::TraceLog; |
18 | 23 |
19 namespace content { | 24 namespace content { |
20 | 25 |
21 namespace { | 26 namespace { |
27 #if defined(OS_CHROMEOS) | |
28 const bool kUseSystemTrace = true; | |
29 #else | |
30 const bool kUseSystemTrace = false; | |
31 #endif | |
32 | |
22 | 33 |
23 base::LazyInstance<TraceControllerImpl>::Leaky g_controller = | 34 base::LazyInstance<TraceControllerImpl>::Leaky g_controller = |
24 LAZY_INSTANCE_INITIALIZER; | 35 LAZY_INSTANCE_INITIALIZER; |
25 | 36 |
26 class AutoStopTraceSubscriberStdio : public TraceSubscriberStdio { | 37 class AutoStopTraceSubscriberStdio : public TraceSubscriberStdio { |
27 public: | 38 public: |
28 AutoStopTraceSubscriberStdio(const base::FilePath& file_path) | 39 AutoStopTraceSubscriberStdio(const base::FilePath& file_path) |
29 : TraceSubscriberStdio(file_path) {} | 40 : TraceSubscriberStdio(file_path, |
41 FILE_TYPE_PROPERTY_LIST, | |
42 kUseSystemTrace), | |
43 tracing_completed_(false), | |
44 system_tracing_completed_(!kUseSystemTrace) {} | |
30 | 45 |
31 static void EndStartupTrace(TraceSubscriberStdio* subscriber) { | 46 static void EndStartupTrace(AutoStopTraceSubscriberStdio* subscriber) { |
32 if (!TraceControllerImpl::GetInstance()->EndTracingAsync(subscriber)) | 47 if (!TraceControllerImpl::GetInstance()->EndTracingAsync(subscriber)) |
33 delete subscriber; | 48 delete subscriber; |
49 #if defined(OS_CHROMEOS) | |
50 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | |
51 RequestStopSystemTracing( | |
52 base::Bind(&AutoStopTraceSubscriberStdio::OnEndSystemTracing, | |
53 base::Unretained(subscriber))); | |
54 #endif | |
34 // else, the tracing will end asynchronously in OnEndTracingComplete(). | 55 // else, the tracing will end asynchronously in OnEndTracingComplete(). |
35 } | 56 } |
36 | 57 |
37 virtual void OnEndTracingComplete() OVERRIDE { | 58 virtual void OnEndTracingComplete() OVERRIDE { |
38 TraceSubscriberStdio::OnEndTracingComplete(); | 59 TraceSubscriberStdio::OnEndTracingComplete(); |
39 delete this; | 60 if (system_tracing_completed_) |
dsinclair
2013/08/19 20:12:26
Are both of these methods guaranteed to be called
DaveMoore
2013/08/19 22:07:46
I believe they will both be called on the calling
| |
61 delete this; | |
40 // TODO(joth): this would be the time to automatically open up | 62 // TODO(joth): this would be the time to automatically open up |
dsinclair
2013/08/19 20:12:26
tracing_completed_ = true;?
DaveMoore
2013/08/19 22:07:46
Done.
| |
41 // chrome://tracing/ and load up the trace data collected. | 63 // chrome://tracing/ and load up the trace data collected. |
42 } | 64 } |
65 | |
66 virtual void OnEndSystemTracing( | |
67 const scoped_refptr<base::RefCountedString>& events_str_ptr) | |
68 OVERRIDE { | |
69 TraceSubscriberStdio::OnEndSystemTracing(events_str_ptr); | |
70 if (tracing_completed_) | |
71 delete this; | |
dsinclair
2013/08/19 20:12:26
system_tracing_completed_ = true?
DaveMoore
2013/08/19 22:07:46
Done.
| |
72 } | |
73 | |
74 private: | |
75 bool tracing_completed_; | |
76 bool system_tracing_completed_; | |
43 }; | 77 }; |
44 | 78 |
45 } // namespace | 79 } // namespace |
46 | 80 |
47 TraceController* TraceController::GetInstance() { | 81 TraceController* TraceController::GetInstance() { |
48 return TraceControllerImpl::GetInstance(); | 82 return TraceControllerImpl::GetInstance(); |
49 } | 83 } |
50 | 84 |
51 TraceControllerImpl::TraceControllerImpl() : | 85 TraceControllerImpl::TraceControllerImpl() : |
52 subscriber_(NULL), | 86 subscriber_(NULL), |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 // The last ack represents local trace, so we need to ack it now. Note that | 432 // The last ack represents local trace, so we need to ack it now. Note that |
399 // this code only executes if there were child processes. | 433 // this code only executes if there were child processes. |
400 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 434 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
401 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 435 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
402 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, | 436 base::Bind(&TraceControllerImpl::OnTraceBufferPercentFullReply, |
403 base::Unretained(this), bpf)); | 437 base::Unretained(this), bpf)); |
404 } | 438 } |
405 } | 439 } |
406 | 440 |
407 } // namespace content | 441 } // namespace content |
OLD | NEW |