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 "content/browser/devtools/devtools_tracing_handler.h" | 5 #include "content/browser/devtools/devtools_tracing_handler.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 } else if (*iter == kEnableSampling) { | 141 } else if (*iter == kEnableSampling) { |
142 ret.enable_sampling = true; | 142 ret.enable_sampling = true; |
143 } | 143 } |
144 } | 144 } |
145 return ret; | 145 return ret; |
146 } | 146 } |
147 | 147 |
148 scoped_refptr<DevToolsProtocol::Response> | 148 scoped_refptr<DevToolsProtocol::Response> |
149 DevToolsTracingHandler::OnStart( | 149 DevToolsTracingHandler::OnStart( |
150 scoped_refptr<DevToolsProtocol::Command> command) { | 150 scoped_refptr<DevToolsProtocol::Command> command) { |
151 // If inspected target is a render process Tracing.start will be handled by | 151 if (is_recording_) { |
152 // tracing agent in the renderer. | 152 return command->InternalErrorResponse("Tracing is already started."); |
caseq
2014/09/15 11:38:17
nit: we don't use terminating punctuation in proto
yurys
2014/09/15 12:02:18
Done.
| |
153 if (target_ == Renderer) | 153 } |
154 return NULL; | |
155 | |
156 is_recording_ = true; | 154 is_recording_ = true; |
157 | 155 |
158 std::string categories; | 156 std::string categories; |
159 base::debug::TraceOptions options; | 157 base::debug::TraceOptions options; |
160 double usage_reporting_interval = 0.0; | 158 double usage_reporting_interval = 0.0; |
161 | 159 |
162 base::DictionaryValue* params = command->params(); | 160 base::DictionaryValue* params = command->params(); |
163 if (params) { | 161 if (params) { |
164 params->GetString(devtools::Tracing::start::kParamCategories, &categories); | 162 params->GetString(devtools::Tracing::start::kParamCategories, &categories); |
165 std::string options_param; | 163 std::string options_param; |
166 if (params->GetString(devtools::Tracing::start::kParamOptions, | 164 if (params->GetString(devtools::Tracing::start::kParamOptions, |
167 &options_param)) { | 165 &options_param)) { |
168 options = TraceOptionsFromString(options_param); | 166 options = TraceOptionsFromString(options_param); |
169 } | 167 } |
170 params->GetDouble( | 168 params->GetDouble( |
171 devtools::Tracing::start::kParamBufferUsageReportingInterval, | 169 devtools::Tracing::start::kParamBufferUsageReportingInterval, |
172 &usage_reporting_interval); | 170 &usage_reporting_interval); |
173 } | 171 } |
174 | 172 |
175 SetupTimer(usage_reporting_interval); | 173 SetupTimer(usage_reporting_interval); |
176 | 174 |
175 // If inspected target is a render process Tracing.start will be handled by | |
176 // tracing agent in the renderer. | |
177 if (target_ == Renderer) { | |
178 TracingController::GetInstance()->EnableRecording( | |
179 base::debug::CategoryFilter(categories), | |
180 options, | |
181 TracingController::EnableRecordingDoneCallback()); | |
182 return NULL; | |
183 } | |
184 | |
177 TracingController::GetInstance()->EnableRecording( | 185 TracingController::GetInstance()->EnableRecording( |
178 base::debug::CategoryFilter(categories), | 186 base::debug::CategoryFilter(categories), |
179 options, | 187 options, |
180 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, | 188 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, |
181 weak_factory_.GetWeakPtr(), | 189 weak_factory_.GetWeakPtr(), |
182 command)); | 190 command)); |
183 return command->AsyncResponsePromise(); | 191 return command->AsyncResponsePromise(); |
184 } | 192 } |
185 | 193 |
186 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { | 194 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { |
(...skipping 23 matching lines...) Expand all Loading... | |
210 | 218 |
211 void DevToolsTracingHandler::OnBufferUsage(float usage) { | 219 void DevToolsTracingHandler::OnBufferUsage(float usage) { |
212 base::DictionaryValue* params = new base::DictionaryValue(); | 220 base::DictionaryValue* params = new base::DictionaryValue(); |
213 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage); | 221 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage); |
214 SendNotification(devtools::Tracing::bufferUsage::kName, params); | 222 SendNotification(devtools::Tracing::bufferUsage::kName, params); |
215 } | 223 } |
216 | 224 |
217 scoped_refptr<DevToolsProtocol::Response> | 225 scoped_refptr<DevToolsProtocol::Response> |
218 DevToolsTracingHandler::OnEnd( | 226 DevToolsTracingHandler::OnEnd( |
219 scoped_refptr<DevToolsProtocol::Command> command) { | 227 scoped_refptr<DevToolsProtocol::Command> command) { |
228 if (!is_recording_) { | |
229 return command->InternalErrorResponse("Tracing is not started."); | |
caseq
2014/09/15 11:38:17
ditto.
yurys
2014/09/15 12:02:18
Done.
| |
230 } | |
231 DisableRecording( | |
232 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, | |
caseq
2014/09/15 11:38:17
You'll need to rebaseline this against r294801.
yurys
2014/09/15 12:02:17
Done.
| |
233 weak_factory_.GetWeakPtr())); | |
220 // If inspected target is a render process Tracing.end will be handled by | 234 // If inspected target is a render process Tracing.end will be handled by |
221 // tracing agent in the renderer. | 235 // tracing agent in the renderer. |
222 if (target_ == Renderer) | 236 if (target_ == Renderer) |
223 return NULL; | 237 return NULL; |
224 DisableRecording( | |
225 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, | |
226 weak_factory_.GetWeakPtr())); | |
227 return command->SuccessResponse(NULL); | 238 return command->SuccessResponse(NULL); |
228 } | 239 } |
229 | 240 |
230 void DevToolsTracingHandler::DisableRecording( | 241 void DevToolsTracingHandler::DisableRecording( |
231 const TracingController::TracingFileResultCallback& callback) { | 242 const TracingController::TracingFileResultCallback& callback) { |
232 is_recording_ = false; | 243 is_recording_ = false; |
233 buffer_usage_poll_timer_.reset(); | 244 buffer_usage_poll_timer_.reset(); |
234 TracingController::GetInstance()->DisableRecording(base::FilePath(), | 245 TracingController::GetInstance()->DisableRecording(base::FilePath(), |
235 callback); | 246 callback); |
236 } | 247 } |
(...skipping 21 matching lines...) Expand all Loading... | |
258 for (std::set<std::string>::const_iterator it = category_set.begin(); | 269 for (std::set<std::string>::const_iterator it = category_set.begin(); |
259 it != category_set.end(); ++it) { | 270 it != category_set.end(); ++it) { |
260 category_list->AppendString(*it); | 271 category_list->AppendString(*it); |
261 } | 272 } |
262 | 273 |
263 response->Set(devtools::Tracing::getCategories::kResponseCategories, | 274 response->Set(devtools::Tracing::getCategories::kResponseCategories, |
264 category_list); | 275 category_list); |
265 SendAsyncResponse(command->SuccessResponse(response)); | 276 SendAsyncResponse(command->SuccessResponse(response)); |
266 } | 277 } |
267 | 278 |
268 void DevToolsTracingHandler::EnableTracing(const std::string& category_filter) { | |
269 if (is_recording_) | |
270 return; | |
271 is_recording_ = true; | |
272 | |
273 SetupTimer(kDefaultReportingInterval); | |
274 | |
275 TracingController::GetInstance()->EnableRecording( | |
276 base::debug::CategoryFilter(category_filter), | |
277 base::debug::TraceOptions(), | |
278 TracingController::EnableRecordingDoneCallback()); | |
279 SendNotification(devtools::Tracing::started::kName, NULL); | |
280 } | |
281 | |
282 void DevToolsTracingHandler::DisableTracing() { | |
283 if (!is_recording_) | |
284 return; | |
285 is_recording_ = false; | |
286 DisableRecording( | |
287 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, | |
288 weak_factory_.GetWeakPtr())); | |
289 } | |
290 | |
291 | |
292 } // namespace content | 279 } // namespace content |
OLD | NEW |