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 "chrome/test/base/tracing.h" | 5 #include "chrome/test/base/tracing.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 static InProcessTraceController* GetInstance() { | 48 static InProcessTraceController* GetInstance() { |
49 return Singleton<InProcessTraceController>::get(); | 49 return Singleton<InProcessTraceController>::get(); |
50 } | 50 } |
51 | 51 |
52 InProcessTraceController() | 52 InProcessTraceController() |
53 : is_waiting_on_watch_(false), | 53 : is_waiting_on_watch_(false), |
54 watch_notification_count_(0) {} | 54 watch_notification_count_(0) {} |
55 virtual ~InProcessTraceController() {} | 55 virtual ~InProcessTraceController() {} |
56 | 56 |
57 bool BeginTracing(const std::string& category_patterns) { | 57 bool BeginTracing(const std::string& category_patterns) { |
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
59 return content::TracingController::GetInstance()->EnableRecording( | 59 return content::TracingController::GetInstance()->EnableRecording( |
60 base::trace_event::CategoryFilter(category_patterns), | 60 base::trace_event::CategoryFilter(category_patterns), |
61 base::trace_event::TraceOptions(), | 61 base::trace_event::TraceOptions(), |
62 content::TracingController::EnableRecordingDoneCallback()); | 62 content::TracingController::EnableRecordingDoneCallback()); |
63 } | 63 } |
64 | 64 |
65 bool BeginTracingWithWatch(const std::string& category_patterns, | 65 bool BeginTracingWithWatch(const std::string& category_patterns, |
66 const std::string& category_name, | 66 const std::string& category_name, |
67 const std::string& event_name, | 67 const std::string& event_name, |
68 int num_occurrences) { | 68 int num_occurrences) { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 69 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
70 DCHECK(num_occurrences > 0); | 70 DCHECK(num_occurrences > 0); |
71 watch_notification_count_ = num_occurrences; | 71 watch_notification_count_ = num_occurrences; |
72 if (!content::TracingController::GetInstance()->SetWatchEvent( | 72 if (!content::TracingController::GetInstance()->SetWatchEvent( |
73 category_name, event_name, | 73 category_name, event_name, |
74 base::Bind(&InProcessTraceController::OnWatchEventMatched, | 74 base::Bind(&InProcessTraceController::OnWatchEventMatched, |
75 base::Unretained(this)))) { | 75 base::Unretained(this)))) { |
76 return false; | 76 return false; |
77 } | 77 } |
78 if (!content::TracingController::GetInstance()->EnableRecording( | 78 if (!content::TracingController::GetInstance()->EnableRecording( |
79 base::trace_event::CategoryFilter(category_patterns), | 79 base::trace_event::CategoryFilter(category_patterns), |
80 base::trace_event::TraceOptions(), | 80 base::trace_event::TraceOptions(), |
81 base::Bind(&InProcessTraceController::OnEnableTracingComplete, | 81 base::Bind(&InProcessTraceController::OnEnableTracingComplete, |
82 base::Unretained(this)))) { | 82 base::Unretained(this)))) { |
83 return false; | 83 return false; |
84 } | 84 } |
85 | 85 |
86 message_loop_runner_ = new content::MessageLoopRunner; | 86 message_loop_runner_ = new content::MessageLoopRunner; |
87 message_loop_runner_->Run(); | 87 message_loop_runner_->Run(); |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
91 bool WaitForWatchEvent(base::TimeDelta timeout) { | 91 bool WaitForWatchEvent(base::TimeDelta timeout) { |
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
93 if (watch_notification_count_ == 0) | 93 if (watch_notification_count_ == 0) |
94 return true; | 94 return true; |
95 | 95 |
96 if (timeout != base::TimeDelta()) { | 96 if (timeout != base::TimeDelta()) { |
97 timer_.Start(FROM_HERE, timeout, this, | 97 timer_.Start(FROM_HERE, timeout, this, |
98 &InProcessTraceController::Timeout); | 98 &InProcessTraceController::Timeout); |
99 } | 99 } |
100 | 100 |
101 is_waiting_on_watch_ = true; | 101 is_waiting_on_watch_ = true; |
102 message_loop_runner_ = new content::MessageLoopRunner; | 102 message_loop_runner_ = new content::MessageLoopRunner; |
103 message_loop_runner_->Run(); | 103 message_loop_runner_->Run(); |
104 is_waiting_on_watch_ = false; | 104 is_waiting_on_watch_ = false; |
105 | 105 |
106 return watch_notification_count_ == 0; | 106 return watch_notification_count_ == 0; |
107 } | 107 } |
108 | 108 |
109 bool EndTracing(std::string* json_trace_output) { | 109 bool EndTracing(std::string* json_trace_output) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
111 using namespace base::debug; | 111 using namespace base::debug; |
112 | 112 |
113 if (!content::TracingController::GetInstance()->DisableRecording( | 113 if (!content::TracingController::GetInstance()->DisableRecording( |
114 new StringTraceSink( | 114 new StringTraceSink( |
115 json_trace_output, | 115 json_trace_output, |
116 base::Bind(&InProcessTraceController::OnTracingComplete, | 116 base::Bind(&InProcessTraceController::OnTracingComplete, |
117 base::Unretained(this))))) { | 117 base::Unretained(this))))) { |
118 return false; | 118 return false; |
119 } | 119 } |
120 // Wait for OnEndTracingComplete() to quit the message loop. | 120 // Wait for OnEndTracingComplete() to quit the message loop. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 bool WaitForWatchEvent(base::TimeDelta timeout) { | 181 bool WaitForWatchEvent(base::TimeDelta timeout) { |
182 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); | 182 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); |
183 } | 183 } |
184 | 184 |
185 bool EndTracing(std::string* json_trace_output) { | 185 bool EndTracing(std::string* json_trace_output) { |
186 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); | 186 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); |
187 } | 187 } |
188 | 188 |
189 } // namespace tracing | 189 } // namespace tracing |
190 | 190 |
OLD | NEW |