OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/trace_controller.h" | 5 #include "content/browser/trace_controller.h" |
6 | 6 |
| 7 #include "base/debug/trace_event.h" |
7 #include "base/task.h" | 8 #include "base/task.h" |
8 #include "content/browser/browser_message_filter.h" | 9 #include "content/browser/browser_message_filter.h" |
9 #include "content/browser/trace_message_filter.h" | 10 #include "content/browser/trace_message_filter.h" |
10 #include "content/common/child_process_messages.h" | 11 #include "content/common/child_process_messages.h" |
11 #include "gpu/common/gpu_trace_event.h" | |
12 | 12 |
13 | 13 |
14 TraceController::TraceController() : | 14 TraceController::TraceController() : |
15 subscriber_(NULL), | 15 subscriber_(NULL), |
16 pending_end_ack_count_(0), | 16 pending_end_ack_count_(0), |
17 pending_bpf_ack_count_(0), | 17 pending_bpf_ack_count_(0), |
18 maximum_bpf_(0.0f), | 18 maximum_bpf_(0.0f), |
19 is_tracing_(false) { | 19 is_tracing_(false) { |
20 gpu::TraceLog::GetInstance()->SetOutputCallback( | 20 base::debug::TraceLog::GetInstance()->SetOutputCallback( |
21 NewCallback(this, &TraceController::OnTraceDataCollected)); | 21 NewCallback(this, &TraceController::OnTraceDataCollected)); |
22 } | 22 } |
23 | 23 |
24 TraceController::~TraceController() { | 24 TraceController::~TraceController() { |
25 gpu::TraceLog::GetInstance()->SetOutputCallback(NULL); | 25 base::debug::TraceLog::GetInstance()->SetOutputCallback(NULL); |
26 } | 26 } |
27 | 27 |
28 //static | 28 //static |
29 TraceController* TraceController::GetInstance() { | 29 TraceController* TraceController::GetInstance() { |
30 return Singleton<TraceController>::get(); | 30 return Singleton<TraceController>::get(); |
31 } | 31 } |
32 | 32 |
33 bool TraceController::BeginTracing(TraceSubscriber* subscriber) { | 33 bool TraceController::BeginTracing(TraceSubscriber* subscriber) { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
35 | 35 |
36 if (!can_begin_tracing() || | 36 if (!can_begin_tracing() || |
37 (subscriber_ != NULL && subscriber != subscriber_)) | 37 (subscriber_ != NULL && subscriber != subscriber_)) |
38 return false; | 38 return false; |
39 | 39 |
40 subscriber_ = subscriber; | 40 subscriber_ = subscriber; |
41 | 41 |
42 // Enable tracing | 42 // Enable tracing |
43 is_tracing_ = true; | 43 is_tracing_ = true; |
44 gpu::TraceLog::GetInstance()->SetEnabled(true); | 44 base::debug::TraceLog::GetInstance()->SetEnabled(true); |
45 | 45 |
46 // Notify all child processes. | 46 // Notify all child processes. |
47 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 47 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
48 it->get()->SendBeginTracing(); | 48 it->get()->SendBeginTracing(); |
49 } | 49 } |
50 | 50 |
51 return true; | 51 return true; |
52 } | 52 } |
53 | 53 |
54 bool TraceController::EndTracingAsync(TraceSubscriber* subscriber) { | 54 bool TraceController::EndTracingAsync(TraceSubscriber* subscriber) { |
(...skipping 30 matching lines...) Expand all Loading... |
85 | 85 |
86 if (!can_get_buffer_percent_full() || subscriber != subscriber_) | 86 if (!can_get_buffer_percent_full() || subscriber != subscriber_) |
87 return false; | 87 return false; |
88 | 88 |
89 maximum_bpf_ = 0.0f; | 89 maximum_bpf_ = 0.0f; |
90 pending_bpf_ack_count_ = filters_.size() + 1; | 90 pending_bpf_ack_count_ = filters_.size() + 1; |
91 | 91 |
92 // Handle special case of zero child processes. | 92 // Handle special case of zero child processes. |
93 if (pending_bpf_ack_count_ == 1) { | 93 if (pending_bpf_ack_count_ == 1) { |
94 // Ack asynchronously now, because we don't have any children to wait for. | 94 // Ack asynchronously now, because we don't have any children to wait for. |
95 float bpf = gpu::TraceLog::GetInstance()->GetBufferPercentFull(); | 95 float bpf = base::debug::TraceLog::GetInstance()->GetBufferPercentFull(); |
96 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 96 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
97 NewRunnableMethod(this, | 97 NewRunnableMethod(this, |
98 &TraceController::OnTraceBufferPercentFullReply, | 98 &TraceController::OnTraceBufferPercentFullReply, |
99 bpf)); | 99 bpf)); |
100 } | 100 } |
101 | 101 |
102 // Message all child processes. | 102 // Message all child processes. |
103 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { | 103 for (FilterMap::iterator it = filters_.begin(); it != filters_.end(); ++it) { |
104 it->get()->SendGetTraceBufferPercentFull(); | 104 it->get()->SendGetTraceBufferPercentFull(); |
105 } | 105 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 return; | 154 return; |
155 | 155 |
156 if (--pending_end_ack_count_ == 0) { | 156 if (--pending_end_ack_count_ == 0) { |
157 // All acks have been received. | 157 // All acks have been received. |
158 is_tracing_ = false; | 158 is_tracing_ = false; |
159 | 159 |
160 // Disable local trace. During this call, our OnTraceDataCollected will be | 160 // Disable local trace. During this call, our OnTraceDataCollected will be |
161 // called with the last of the local trace data. Since we are on the UI | 161 // called with the last of the local trace data. Since we are on the UI |
162 // thread, the call to OnTraceDataCollected will be synchronous, so we can | 162 // thread, the call to OnTraceDataCollected will be synchronous, so we can |
163 // immediately call OnEndTracingComplete below. | 163 // immediately call OnEndTracingComplete below. |
164 gpu::TraceLog::GetInstance()->SetEnabled(false); | 164 base::debug::TraceLog::GetInstance()->SetEnabled(false); |
165 | 165 |
166 // Trigger callback if one is set. | 166 // Trigger callback if one is set. |
167 if (subscriber_) { | 167 if (subscriber_) { |
168 subscriber_->OnEndTracingComplete(); | 168 subscriber_->OnEndTracingComplete(); |
169 // Clear subscriber so that others can use TraceController. | 169 // Clear subscriber so that others can use TraceController. |
170 subscriber_ = NULL; | 170 subscriber_ = NULL; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 if (pending_end_ack_count_ == 1) { | 174 if (pending_end_ack_count_ == 1) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 222 |
223 if (--pending_bpf_ack_count_ == 0) { | 223 if (--pending_bpf_ack_count_ == 0) { |
224 // Trigger callback if one is set. | 224 // Trigger callback if one is set. |
225 if (subscriber_) | 225 if (subscriber_) |
226 subscriber_->OnTraceBufferPercentFullReply(maximum_bpf_); | 226 subscriber_->OnTraceBufferPercentFullReply(maximum_bpf_); |
227 } | 227 } |
228 | 228 |
229 if (pending_bpf_ack_count_ == 1) { | 229 if (pending_bpf_ack_count_ == 1) { |
230 // The last ack represents local trace, so we need to ack it now. Note that | 230 // The last ack represents local trace, so we need to ack it now. Note that |
231 // this code only executes if there were child processes. | 231 // this code only executes if there were child processes. |
232 float bpf = gpu::TraceLog::GetInstance()->GetBufferPercentFull(); | 232 float bpf = base::debug::TraceLog::GetInstance()->GetBufferPercentFull(); |
233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
234 NewRunnableMethod(this, | 234 NewRunnableMethod(this, |
235 &TraceController::OnTraceBufferPercentFullReply, | 235 &TraceController::OnTraceBufferPercentFullReply, |
236 bpf)); | 236 bpf)); |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
OLD | NEW |