Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/test/base/tracing.cc

Issue 105893004: Sampling profiling thread should be joined in a FILE thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/tracing/tracing_controller_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.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 16 matching lines...) Expand all
27 InProcessTraceController() 27 InProcessTraceController()
28 : is_waiting_on_watch_(false), 28 : is_waiting_on_watch_(false),
29 watch_notification_count_(0) {} 29 watch_notification_count_(0) {}
30 virtual ~InProcessTraceController() {} 30 virtual ~InProcessTraceController() {}
31 31
32 bool BeginTracing(const std::string& category_patterns) { 32 bool BeginTracing(const std::string& category_patterns) {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 return content::TracingController::GetInstance()->EnableRecording( 34 return content::TracingController::GetInstance()->EnableRecording(
35 category_patterns, content::TracingController::DEFAULT_OPTIONS, 35 category_patterns, content::TracingController::DEFAULT_OPTIONS,
36 content::TracingController::EnableRecordingDoneCallback()); 36 content::TracingController::EnableRecordingDoneCallback());
37 return true;
38 } 37 }
39 38
40 bool BeginTracingWithWatch(const std::string& category_patterns, 39 bool BeginTracingWithWatch(const std::string& category_patterns,
41 const std::string& category_name, 40 const std::string& category_name,
42 const std::string& event_name, 41 const std::string& event_name,
43 int num_occurrences) { 42 int num_occurrences) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45 DCHECK(num_occurrences > 0); 44 DCHECK(num_occurrences > 0);
46 watch_notification_count_ = num_occurrences; 45 watch_notification_count_ = num_occurrences;
47 return content::TracingController::GetInstance()->SetWatchEvent( 46 if (!content::TracingController::GetInstance()->SetWatchEvent(
48 category_name, event_name, 47 category_name, event_name,
49 base::Bind(&InProcessTraceController::OnWatchEventMatched, 48 base::Bind(&InProcessTraceController::OnWatchEventMatched,
50 base::Unretained(this))) && 49 base::Unretained(this))))
Paweł Hajdan Jr. 2014/01/02 12:27:23 nit: This should have braces {} because condition
51 BeginTracing(category_patterns); 50 return false;
51 if (!content::TracingController::GetInstance()->EnableRecording(
52 category_patterns, content::TracingController::DEFAULT_OPTIONS,
Paweł Hajdan Jr. 2014/01/02 12:27:23 nit: Please indent this +4 and add braces {}.
53 base::Bind(&InProcessTraceController::OnEnableTracingComplete,
54 base::Unretained(this))))
55 return false;
56
57 message_loop_runner_ = new content::MessageLoopRunner;
58 message_loop_runner_->Run();
59 return true;
52 } 60 }
53 61
54 bool WaitForWatchEvent(base::TimeDelta timeout) { 62 bool WaitForWatchEvent(base::TimeDelta timeout) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 if (watch_notification_count_ == 0) 64 if (watch_notification_count_ == 0)
57 return true; 65 return true;
58 66
59 if (timeout != base::TimeDelta()) { 67 if (timeout != base::TimeDelta()) {
60 timer_.Start(FROM_HERE, timeout, this, 68 timer_.Start(FROM_HERE, timeout, this,
61 &InProcessTraceController::Timeout); 69 &InProcessTraceController::Timeout);
(...skipping 24 matching lines...) Expand all
86 94
87 // Watch notifications can occur during this method's message loop run, but 95 // Watch notifications can occur during this method's message loop run, but
88 // not after, so clear them here. 96 // not after, so clear them here.
89 watch_notification_count_ = 0; 97 watch_notification_count_ = 0;
90 return true; 98 return true;
91 } 99 }
92 100
93 private: 101 private:
94 friend struct DefaultSingletonTraits<InProcessTraceController>; 102 friend struct DefaultSingletonTraits<InProcessTraceController>;
95 103
104 void OnEnableTracingComplete() {
105 message_loop_runner_->Quit();
106 }
107
96 void OnEndTracingComplete() { 108 void OnEndTracingComplete() {
97 message_loop_runner_->Quit(); 109 message_loop_runner_->Quit();
98 } 110 }
99 111
100 void OnTraceDataCollected(std::string* json_trace_output, 112 void OnTraceDataCollected(std::string* json_trace_output,
101 const base::FilePath& path) { 113 const base::FilePath& path) {
102 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 114 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
103 base::Bind(&InProcessTraceController::ReadTraceData, 115 base::Bind(&InProcessTraceController::ReadTraceData,
104 base::Unretained(this), 116 base::Unretained(this),
105 base::Unretained(json_trace_output), 117 base::Unretained(json_trace_output),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 bool WaitForWatchEvent(base::TimeDelta timeout) { 183 bool WaitForWatchEvent(base::TimeDelta timeout) {
172 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); 184 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout);
173 } 185 }
174 186
175 bool EndTracing(std::string* json_trace_output) { 187 bool EndTracing(std::string* json_trace_output) {
176 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); 188 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output);
177 } 189 }
178 190
179 } // namespace tracing 191 } // namespace tracing
180 192
OLDNEW
« no previous file with comments | « no previous file | content/browser/tracing/tracing_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698