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 category_patterns, base::debug::TraceOptions(), false, |
36 content::TracingController::EnableRecordingDoneCallback()); | 37 content::TracingController::EnableRecordingDoneCallback()); |
37 } | 38 } |
38 | 39 |
39 bool BeginTracingWithWatch(const std::string& category_patterns, | 40 bool BeginTracingWithWatch(const std::string& category_patterns, |
40 const std::string& category_name, | 41 const std::string& category_name, |
41 const std::string& event_name, | 42 const std::string& event_name, |
42 int num_occurrences) { | 43 int num_occurrences) { |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
44 DCHECK(num_occurrences > 0); | 45 DCHECK(num_occurrences > 0); |
45 watch_notification_count_ = num_occurrences; | 46 watch_notification_count_ = num_occurrences; |
46 if (!content::TracingController::GetInstance()->SetWatchEvent( | 47 if (!content::TracingController::GetInstance()->SetWatchEvent( |
47 category_name, event_name, | 48 category_name, event_name, |
48 base::Bind(&InProcessTraceController::OnWatchEventMatched, | 49 base::Bind(&InProcessTraceController::OnWatchEventMatched, |
49 base::Unretained(this)))) { | 50 base::Unretained(this)))) { |
50 return false; | 51 return false; |
51 } | 52 } |
52 if (!content::TracingController::GetInstance()->EnableRecording( | 53 if (!content::TracingController::GetInstance()->EnableRecording( |
53 category_patterns, content::TracingController::DEFAULT_OPTIONS, | 54 category_patterns, base::debug::TraceOptions(), false, |
54 base::Bind(&InProcessTraceController::OnEnableTracingComplete, | 55 base::Bind(&InProcessTraceController::OnEnableTracingComplete, |
55 base::Unretained(this)))) { | 56 base::Unretained(this)))) { |
56 return false; | 57 return false; |
57 } | 58 } |
58 | 59 |
59 message_loop_runner_ = new content::MessageLoopRunner; | 60 message_loop_runner_ = new content::MessageLoopRunner; |
60 message_loop_runner_->Run(); | 61 message_loop_runner_->Run(); |
61 return true; | 62 return true; |
62 } | 63 } |
63 | 64 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 bool WaitForWatchEvent(base::TimeDelta timeout) { | 186 bool WaitForWatchEvent(base::TimeDelta timeout) { |
186 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); | 187 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); |
187 } | 188 } |
188 | 189 |
189 bool EndTracing(std::string* json_trace_output) { | 190 bool EndTracing(std::string* json_trace_output) { |
190 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); | 191 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); |
191 } | 192 } |
192 | 193 |
193 } // namespace tracing | 194 } // namespace tracing |
194 | 195 |
OLD | NEW |