| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 : weak_factory_(this), target_(target), is_recording_(false) { | 58 : weak_factory_(this), target_(target), is_recording_(false) { |
| 59 RegisterCommandHandler(devtools::Tracing::start::kName, | 59 RegisterCommandHandler(devtools::Tracing::start::kName, |
| 60 base::Bind(&DevToolsTracingHandler::OnStart, | 60 base::Bind(&DevToolsTracingHandler::OnStart, |
| 61 base::Unretained(this))); | 61 base::Unretained(this))); |
| 62 RegisterCommandHandler(devtools::Tracing::end::kName, | 62 RegisterCommandHandler(devtools::Tracing::end::kName, |
| 63 base::Bind(&DevToolsTracingHandler::OnEnd, | 63 base::Bind(&DevToolsTracingHandler::OnEnd, |
| 64 base::Unretained(this))); | 64 base::Unretained(this))); |
| 65 RegisterCommandHandler(devtools::Tracing::getCategories::kName, | 65 RegisterCommandHandler(devtools::Tracing::getCategories::kName, |
| 66 base::Bind(&DevToolsTracingHandler::OnGetCategories, | 66 base::Bind(&DevToolsTracingHandler::OnGetCategories, |
| 67 base::Unretained(this))); | 67 base::Unretained(this))); |
| 68 RegisterNotificationHandler(devtools::Tracing::started::kName, |
| 69 base::Bind(&DevToolsTracingHandler::OnTracingStarted, |
| 70 base::Unretained(this))); |
| 71 RegisterNotificationHandler(devtools::Tracing::stopped::kName, |
| 72 base::Bind(&DevToolsTracingHandler::OnTracingStopped, |
| 73 base::Unretained(this))); |
| 68 } | 74 } |
| 69 | 75 |
| 70 DevToolsTracingHandler::~DevToolsTracingHandler() { | 76 DevToolsTracingHandler::~DevToolsTracingHandler() { |
| 71 } | 77 } |
| 72 | 78 |
| 73 void DevToolsTracingHandler::BeginReadingRecordingResult( | 79 void DevToolsTracingHandler::BeginReadingRecordingResult( |
| 74 const base::FilePath& path) { | 80 const base::FilePath& path) { |
| 75 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
| 76 BrowserThread::FILE, FROM_HERE, | 82 BrowserThread::FILE, FROM_HERE, |
| 77 base::Bind(&ReadFile, path, | 83 base::Bind(&ReadFile, path, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } else if (*iter == kEnableSampling) { | 147 } else if (*iter == kEnableSampling) { |
| 142 ret.enable_sampling = true; | 148 ret.enable_sampling = true; |
| 143 } | 149 } |
| 144 } | 150 } |
| 145 return ret; | 151 return ret; |
| 146 } | 152 } |
| 147 | 153 |
| 148 scoped_refptr<DevToolsProtocol::Response> | 154 scoped_refptr<DevToolsProtocol::Response> |
| 149 DevToolsTracingHandler::OnStart( | 155 DevToolsTracingHandler::OnStart( |
| 150 scoped_refptr<DevToolsProtocol::Command> command) { | 156 scoped_refptr<DevToolsProtocol::Command> command) { |
| 151 // If inspected target is a render process Tracing.start will be handled by | |
| 152 // tracing agent in the renderer. | |
| 153 if (target_ == Renderer) | |
| 154 return NULL; | |
| 155 | |
| 156 is_recording_ = true; | 157 is_recording_ = true; |
| 157 | 158 |
| 158 std::string categories; | 159 std::string categories; |
| 159 base::debug::TraceOptions options; | 160 base::debug::TraceOptions options; |
| 160 double usage_reporting_interval = 0.0; | 161 double usage_reporting_interval = 0.0; |
| 161 | 162 |
| 162 base::DictionaryValue* params = command->params(); | 163 base::DictionaryValue* params = command->params(); |
| 163 if (params) { | 164 if (params) { |
| 164 params->GetString(devtools::Tracing::start::kParamCategories, &categories); | 165 params->GetString(devtools::Tracing::start::kParamCategories, &categories); |
| 165 std::string options_param; | 166 std::string options_param; |
| 166 if (params->GetString(devtools::Tracing::start::kParamOptions, | 167 if (params->GetString(devtools::Tracing::start::kParamOptions, |
| 167 &options_param)) { | 168 &options_param)) { |
| 168 options = TraceOptionsFromString(options_param); | 169 options = TraceOptionsFromString(options_param); |
| 169 } | 170 } |
| 170 params->GetDouble( | 171 params->GetDouble( |
| 171 devtools::Tracing::start::kParamBufferUsageReportingInterval, | 172 devtools::Tracing::start::kParamBufferUsageReportingInterval, |
| 172 &usage_reporting_interval); | 173 &usage_reporting_interval); |
| 173 } | 174 } |
| 174 | 175 |
| 175 SetupTimer(usage_reporting_interval); | 176 SetupTimer(usage_reporting_interval); |
| 176 | 177 |
| 178 // If inspected target is a render process Tracing.start will be handled by |
| 179 // tracing agent in the renderer. |
| 180 if (target_ == Renderer) { |
| 181 TracingController::GetInstance()->EnableRecording( |
| 182 base::debug::CategoryFilter(categories), |
| 183 options, |
| 184 TracingController::EnableRecordingDoneCallback()); |
| 185 return NULL; |
| 186 } |
| 187 |
| 177 TracingController::GetInstance()->EnableRecording( | 188 TracingController::GetInstance()->EnableRecording( |
| 178 base::debug::CategoryFilter(categories), | 189 base::debug::CategoryFilter(categories), |
| 179 options, | 190 options, |
| 180 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, | 191 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, |
| 181 weak_factory_.GetWeakPtr(), | 192 weak_factory_.GetWeakPtr(), |
| 182 command)); | 193 command)); |
| 183 return command->AsyncResponsePromise(); | 194 return command->AsyncResponsePromise(); |
| 184 } | 195 } |
| 185 | 196 |
| 186 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { | 197 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 210 | 221 |
| 211 void DevToolsTracingHandler::OnBufferUsage(float usage) { | 222 void DevToolsTracingHandler::OnBufferUsage(float usage) { |
| 212 base::DictionaryValue* params = new base::DictionaryValue(); | 223 base::DictionaryValue* params = new base::DictionaryValue(); |
| 213 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage); | 224 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage); |
| 214 SendNotification(devtools::Tracing::bufferUsage::kName, params); | 225 SendNotification(devtools::Tracing::bufferUsage::kName, params); |
| 215 } | 226 } |
| 216 | 227 |
| 217 scoped_refptr<DevToolsProtocol::Response> | 228 scoped_refptr<DevToolsProtocol::Response> |
| 218 DevToolsTracingHandler::OnEnd( | 229 DevToolsTracingHandler::OnEnd( |
| 219 scoped_refptr<DevToolsProtocol::Command> command) { | 230 scoped_refptr<DevToolsProtocol::Command> command) { |
| 220 // If inspected target is a render process Tracing.end will be handled by | |
| 221 // tracing agent in the renderer. | |
| 222 if (target_ == Renderer) | |
| 223 return NULL; | |
| 224 DisableRecording( | 231 DisableRecording( |
| 225 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, | 232 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, |
| 226 weak_factory_.GetWeakPtr())); | 233 weak_factory_.GetWeakPtr())); |
| 227 return command->SuccessResponse(NULL); | 234 return command->SuccessResponse(NULL); |
| 228 } | 235 } |
| 229 | 236 |
| 230 void DevToolsTracingHandler::DisableRecording( | 237 void DevToolsTracingHandler::DisableRecording( |
| 231 const TracingController::TracingFileResultCallback& callback) { | 238 const TracingController::TracingFileResultCallback& callback) { |
| 232 is_recording_ = false; | 239 is_recording_ = false; |
| 233 buffer_usage_poll_timer_.reset(); | 240 buffer_usage_poll_timer_.reset(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 258 for (std::set<std::string>::const_iterator it = category_set.begin(); | 265 for (std::set<std::string>::const_iterator it = category_set.begin(); |
| 259 it != category_set.end(); ++it) { | 266 it != category_set.end(); ++it) { |
| 260 category_list->AppendString(*it); | 267 category_list->AppendString(*it); |
| 261 } | 268 } |
| 262 | 269 |
| 263 response->Set(devtools::Tracing::getCategories::kResponseCategories, | 270 response->Set(devtools::Tracing::getCategories::kResponseCategories, |
| 264 category_list); | 271 category_list); |
| 265 SendAsyncResponse(command->SuccessResponse(response)); | 272 SendAsyncResponse(command->SuccessResponse(response)); |
| 266 } | 273 } |
| 267 | 274 |
| 268 void DevToolsTracingHandler::EnableTracing(const std::string& category_filter) { | 275 void DevToolsTracingHandler::OnTracingStarted( |
| 276 scoped_refptr<DevToolsProtocol::Notification> notification) { |
| 269 if (is_recording_) | 277 if (is_recording_) |
| 270 return; | 278 return; |
| 271 is_recording_ = true; | 279 is_recording_ = true; |
| 272 | 280 |
| 273 SetupTimer(kDefaultReportingInterval); | 281 SetupTimer(kDefaultReportingInterval); |
| 274 | 282 |
| 275 TracingController::GetInstance()->EnableRecording( | 283 TracingController::GetInstance()->EnableRecording( |
| 276 base::debug::CategoryFilter(category_filter), | 284 base::debug::CategoryFilter(kDefaultCategories), |
| 277 base::debug::TraceOptions(), | 285 base::debug::TraceOptions(), |
| 278 TracingController::EnableRecordingDoneCallback()); | 286 TracingController::EnableRecordingDoneCallback()); |
| 279 SendNotification(devtools::Tracing::started::kName, NULL); | |
| 280 } | 287 } |
| 281 | 288 |
| 282 void DevToolsTracingHandler::DisableTracing() { | 289 void DevToolsTracingHandler::OnTracingStopped( |
| 290 scoped_refptr<DevToolsProtocol::Notification> notification) { |
| 283 if (!is_recording_) | 291 if (!is_recording_) |
| 284 return; | 292 return; |
| 285 is_recording_ = false; | 293 is_recording_ = false; |
| 286 DisableRecording( | 294 DisableRecording( |
| 287 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, | 295 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, |
| 288 weak_factory_.GetWeakPtr())); | 296 weak_factory_.GetWeakPtr())); |
| 289 } | 297 } |
| 290 | 298 |
| 291 | 299 |
| 292 } // namespace content | 300 } // namespace content |
| OLD | NEW |