| 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/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 9 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/tracing_controller.h" | 15 #include "content/public/browser/tracing_controller.h" |
| 15 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 | 21 |
| 21 class InProcessTraceController { | 22 class InProcessTraceController { |
| 22 public: | 23 public: |
| 23 static InProcessTraceController* GetInstance() { | 24 static InProcessTraceController* GetInstance() { |
| 24 return Singleton<InProcessTraceController>::get(); | 25 return Singleton<InProcessTraceController>::get(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 InProcessTraceController() | 28 InProcessTraceController() |
| 28 : is_waiting_on_watch_(false), | 29 : is_waiting_on_watch_(false), |
| 29 watch_notification_count_(0) {} | 30 watch_notification_count_(0) {} |
| 30 virtual ~InProcessTraceController() {} | 31 virtual ~InProcessTraceController() {} |
| 31 | 32 |
| 32 bool BeginTracing(const std::string& category_patterns) { | 33 bool BeginTracing(const std::string& category_patterns) { |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 34 return content::TracingController::GetInstance()->EnableRecording( | 35 return content::TracingController::GetInstance()->EnableRecording( |
| 35 category_patterns, content::TracingController::DEFAULT_OPTIONS, | 36 base::debug::CategoryFilter(category_patterns), |
| 37 base::debug::TraceOptions(), |
| 36 content::TracingController::EnableRecordingDoneCallback()); | 38 content::TracingController::EnableRecordingDoneCallback()); |
| 37 } | 39 } |
| 38 | 40 |
| 39 bool BeginTracingWithWatch(const std::string& category_patterns, | 41 bool BeginTracingWithWatch(const std::string& category_patterns, |
| 40 const std::string& category_name, | 42 const std::string& category_name, |
| 41 const std::string& event_name, | 43 const std::string& event_name, |
| 42 int num_occurrences) { | 44 int num_occurrences) { |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 44 DCHECK(num_occurrences > 0); | 46 DCHECK(num_occurrences > 0); |
| 45 watch_notification_count_ = num_occurrences; | 47 watch_notification_count_ = num_occurrences; |
| 46 if (!content::TracingController::GetInstance()->SetWatchEvent( | 48 if (!content::TracingController::GetInstance()->SetWatchEvent( |
| 47 category_name, event_name, | 49 category_name, event_name, |
| 48 base::Bind(&InProcessTraceController::OnWatchEventMatched, | 50 base::Bind(&InProcessTraceController::OnWatchEventMatched, |
| 49 base::Unretained(this)))) { | 51 base::Unretained(this)))) { |
| 50 return false; | 52 return false; |
| 51 } | 53 } |
| 52 if (!content::TracingController::GetInstance()->EnableRecording( | 54 if (!content::TracingController::GetInstance()->EnableRecording( |
| 53 category_patterns, content::TracingController::DEFAULT_OPTIONS, | 55 base::debug::CategoryFilter(category_patterns), |
| 56 base::debug::TraceOptions(), |
| 54 base::Bind(&InProcessTraceController::OnEnableTracingComplete, | 57 base::Bind(&InProcessTraceController::OnEnableTracingComplete, |
| 55 base::Unretained(this)))) { | 58 base::Unretained(this)))) { |
| 56 return false; | 59 return false; |
| 57 } | 60 } |
| 58 | 61 |
| 59 message_loop_runner_ = new content::MessageLoopRunner; | 62 message_loop_runner_ = new content::MessageLoopRunner; |
| 60 message_loop_runner_->Run(); | 63 message_loop_runner_->Run(); |
| 61 return true; | 64 return true; |
| 62 } | 65 } |
| 63 | 66 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 bool WaitForWatchEvent(base::TimeDelta timeout) { | 188 bool WaitForWatchEvent(base::TimeDelta timeout) { |
| 186 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); | 189 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); |
| 187 } | 190 } |
| 188 | 191 |
| 189 bool EndTracing(std::string* json_trace_output) { | 192 bool EndTracing(std::string* json_trace_output) { |
| 190 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); | 193 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); |
| 191 } | 194 } |
| 192 | 195 |
| 193 } // namespace tracing | 196 } // namespace tracing |
| 194 | 197 |
| OLD | NEW |