| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/trace_controller.h" | 11 #include "content/public/browser/trace_controller.h" |
| 12 #include "content/public/browser/trace_subscriber.h" | 12 #include "content/public/browser/trace_subscriber.h" |
| 13 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 | 18 |
| 19 class InProcessTraceController : public content::TraceSubscriber { | 19 class InProcessTraceController : public content::TraceSubscriber { |
| 20 public: | 20 public: |
| 21 static InProcessTraceController* GetInstance() { | 21 static InProcessTraceController* GetInstance() { |
| 22 return Singleton<InProcessTraceController>::get(); | 22 return Singleton<InProcessTraceController>::get(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 InProcessTraceController() | 25 InProcessTraceController() |
| 26 : is_waiting_on_watch_(false), | 26 : is_waiting_on_watch_(false), |
| 27 watch_notification_count_(0) {} | 27 watch_notification_count_(0) {} |
| 28 virtual ~InProcessTraceController() {} | 28 virtual ~InProcessTraceController() {} |
| 29 | 29 |
| 30 bool BeginTracing(const std::string& categories) { | 30 bool BeginTracing(const std::string& category_patterns) { |
| 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 32 return content::TraceController::GetInstance()->BeginTracing( | 32 return content::TraceController::GetInstance()->BeginTracing( |
| 33 this, categories, base::debug::TraceLog::RECORD_UNTIL_FULL); | 33 this, category_patterns, base::debug::TraceLog::RECORD_UNTIL_FULL); |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool BeginTracingWithWatch(const std::string& categories, | 36 bool BeginTracingWithWatch(const std::string& category_patterns, |
| 37 const std::string& category_name, | 37 const std::string& category_name, |
| 38 const std::string& event_name, | 38 const std::string& event_name, |
| 39 int num_occurrences) { | 39 int num_occurrences) { |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 41 DCHECK(num_occurrences > 0); | 41 DCHECK(num_occurrences > 0); |
| 42 watch_notification_count_ = num_occurrences; | 42 watch_notification_count_ = num_occurrences; |
| 43 return BeginTracing(categories) && | 43 return BeginTracing(category_patterns) && |
| 44 content::TraceController::GetInstance()->SetWatchEvent( | 44 content::TraceController::GetInstance()->SetWatchEvent( |
| 45 this, category_name, event_name); | 45 this, category_name, event_name); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool WaitForWatchEvent(base::TimeDelta timeout) { | 48 bool WaitForWatchEvent(base::TimeDelta timeout) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 50 if (watch_notification_count_ == 0) | 50 if (watch_notification_count_ == 0) |
| 51 return true; | 51 return true; |
| 52 | 52 |
| 53 if (timeout != base::TimeDelta()) { | 53 if (timeout != base::TimeDelta()) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 bool is_waiting_on_watch_; | 128 bool is_waiting_on_watch_; |
| 129 int watch_notification_count_; | 129 int watch_notification_count_; |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(InProcessTraceController); | 131 DISALLOW_COPY_AND_ASSIGN(InProcessTraceController); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 } // namespace | 134 } // namespace |
| 135 | 135 |
| 136 namespace tracing { | 136 namespace tracing { |
| 137 | 137 |
| 138 bool BeginTracing(const std::string& categories) { | 138 bool BeginTracing(const std::string& category_patterns) { |
| 139 return InProcessTraceController::GetInstance()->BeginTracing(categories); | 139 return InProcessTraceController::GetInstance()->BeginTracing( |
| 140 category_patterns); |
| 140 } | 141 } |
| 141 | 142 |
| 142 bool BeginTracingWithWatch(const std::string& categories, | 143 bool BeginTracingWithWatch(const std::string& category_patterns, |
| 143 const std::string& category_name, | 144 const std::string& category_name, |
| 144 const std::string& event_name, | 145 const std::string& event_name, |
| 145 int num_occurrences) { | 146 int num_occurrences) { |
| 146 return InProcessTraceController::GetInstance()->BeginTracingWithWatch( | 147 return InProcessTraceController::GetInstance()->BeginTracingWithWatch( |
| 147 categories, category_name, event_name, num_occurrences); | 148 category_patterns, category_name, event_name, num_occurrences); |
| 148 } | 149 } |
| 149 | 150 |
| 150 bool WaitForWatchEvent(base::TimeDelta timeout) { | 151 bool WaitForWatchEvent(base::TimeDelta timeout) { |
| 151 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); | 152 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); |
| 152 } | 153 } |
| 153 | 154 |
| 154 bool EndTracing(std::string* json_trace_output) { | 155 bool EndTracing(std::string* json_trace_output) { |
| 155 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); | 156 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); |
| 156 } | 157 } |
| 157 | 158 |
| 158 } // namespace tracing | 159 } // namespace tracing |
| 159 | 160 |
| OLD | NEW |