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/debug/trace_event_impl.h" | 10 #include "base/debug/trace_event_impl.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } else if (*iter == kEnableSampling) { | 106 } else if (*iter == kEnableSampling) { |
107 ret.enable_sampling = true; | 107 ret.enable_sampling = true; |
108 } | 108 } |
109 } | 109 } |
110 return ret; | 110 return ret; |
111 } | 111 } |
112 | 112 |
113 scoped_refptr<DevToolsProtocol::Response> | 113 scoped_refptr<DevToolsProtocol::Response> |
114 DevToolsTracingHandler::OnStart( | 114 DevToolsTracingHandler::OnStart( |
115 scoped_refptr<DevToolsProtocol::Command> command) { | 115 scoped_refptr<DevToolsProtocol::Command> command) { |
116 // If inspected target is a render process Tracing.start will be handled by | 116 if (is_recording_) { |
117 // tracing agent in the renderer. | 117 return command->InternalErrorResponse("Tracing is already started"); |
118 if (target_ == Renderer) | 118 } |
119 return NULL; | |
120 | |
121 is_recording_ = true; | 119 is_recording_ = true; |
122 | 120 |
123 std::string categories; | 121 std::string categories; |
124 base::debug::TraceOptions options; | 122 base::debug::TraceOptions options; |
125 double usage_reporting_interval = 0.0; | 123 double usage_reporting_interval = 0.0; |
126 | 124 |
127 base::DictionaryValue* params = command->params(); | 125 base::DictionaryValue* params = command->params(); |
128 if (params) { | 126 if (params) { |
129 params->GetString(devtools::Tracing::start::kParamCategories, &categories); | 127 params->GetString(devtools::Tracing::start::kParamCategories, &categories); |
130 std::string options_param; | 128 std::string options_param; |
131 if (params->GetString(devtools::Tracing::start::kParamOptions, | 129 if (params->GetString(devtools::Tracing::start::kParamOptions, |
132 &options_param)) { | 130 &options_param)) { |
133 options = TraceOptionsFromString(options_param); | 131 options = TraceOptionsFromString(options_param); |
134 } | 132 } |
135 params->GetDouble( | 133 params->GetDouble( |
136 devtools::Tracing::start::kParamBufferUsageReportingInterval, | 134 devtools::Tracing::start::kParamBufferUsageReportingInterval, |
137 &usage_reporting_interval); | 135 &usage_reporting_interval); |
138 } | 136 } |
139 | 137 |
140 SetupTimer(usage_reporting_interval); | 138 SetupTimer(usage_reporting_interval); |
141 | 139 |
| 140 // If inspected target is a render process Tracing.start will be handled by |
| 141 // tracing agent in the renderer. |
| 142 if (target_ == Renderer) { |
| 143 TracingController::GetInstance()->EnableRecording( |
| 144 base::debug::CategoryFilter(categories), |
| 145 options, |
| 146 TracingController::EnableRecordingDoneCallback()); |
| 147 return NULL; |
| 148 } |
| 149 |
142 TracingController::GetInstance()->EnableRecording( | 150 TracingController::GetInstance()->EnableRecording( |
143 base::debug::CategoryFilter(categories), | 151 base::debug::CategoryFilter(categories), |
144 options, | 152 options, |
145 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, | 153 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, |
146 weak_factory_.GetWeakPtr(), | 154 weak_factory_.GetWeakPtr(), |
147 command)); | 155 command)); |
148 return command->AsyncResponsePromise(); | 156 return command->AsyncResponsePromise(); |
149 } | 157 } |
150 | 158 |
151 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { | 159 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { |
(...skipping 23 matching lines...) Expand all Loading... |
175 | 183 |
176 void DevToolsTracingHandler::OnBufferUsage(float usage) { | 184 void DevToolsTracingHandler::OnBufferUsage(float usage) { |
177 base::DictionaryValue* params = new base::DictionaryValue(); | 185 base::DictionaryValue* params = new base::DictionaryValue(); |
178 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage); | 186 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage); |
179 SendNotification(devtools::Tracing::bufferUsage::kName, params); | 187 SendNotification(devtools::Tracing::bufferUsage::kName, params); |
180 } | 188 } |
181 | 189 |
182 scoped_refptr<DevToolsProtocol::Response> | 190 scoped_refptr<DevToolsProtocol::Response> |
183 DevToolsTracingHandler::OnEnd( | 191 DevToolsTracingHandler::OnEnd( |
184 scoped_refptr<DevToolsProtocol::Command> command) { | 192 scoped_refptr<DevToolsProtocol::Command> command) { |
| 193 if (!is_recording_) { |
| 194 return command->InternalErrorResponse("Tracing is not started"); |
| 195 } |
| 196 DisableRecording(false); |
185 // If inspected target is a render process Tracing.end will be handled by | 197 // If inspected target is a render process Tracing.end will be handled by |
186 // tracing agent in the renderer. | 198 // tracing agent in the renderer. |
187 if (target_ == Renderer) | 199 if (target_ == Renderer) |
188 return NULL; | 200 return NULL; |
189 DisableRecording(false); | |
190 return command->SuccessResponse(NULL); | 201 return command->SuccessResponse(NULL); |
191 } | 202 } |
192 | 203 |
193 void DevToolsTracingHandler::DisableRecording(bool abort) { | 204 void DevToolsTracingHandler::DisableRecording(bool abort) { |
194 is_recording_ = false; | 205 is_recording_ = false; |
195 buffer_usage_poll_timer_.reset(); | 206 buffer_usage_poll_timer_.reset(); |
196 TracingController::GetInstance()->DisableRecording( | 207 TracingController::GetInstance()->DisableRecording( |
197 abort ? NULL : new DevToolsTraceSinkProxy(weak_factory_.GetWeakPtr())); | 208 abort ? NULL : new DevToolsTraceSinkProxy(weak_factory_.GetWeakPtr())); |
198 } | 209 } |
199 | 210 |
(...skipping 20 matching lines...) Expand all Loading... |
220 for (std::set<std::string>::const_iterator it = category_set.begin(); | 231 for (std::set<std::string>::const_iterator it = category_set.begin(); |
221 it != category_set.end(); ++it) { | 232 it != category_set.end(); ++it) { |
222 category_list->AppendString(*it); | 233 category_list->AppendString(*it); |
223 } | 234 } |
224 | 235 |
225 response->Set(devtools::Tracing::getCategories::kResponseCategories, | 236 response->Set(devtools::Tracing::getCategories::kResponseCategories, |
226 category_list); | 237 category_list); |
227 SendAsyncResponse(command->SuccessResponse(response)); | 238 SendAsyncResponse(command->SuccessResponse(response)); |
228 } | 239 } |
229 | 240 |
230 void DevToolsTracingHandler::EnableTracing(const std::string& category_filter) { | |
231 if (is_recording_) | |
232 return; | |
233 is_recording_ = true; | |
234 | |
235 SetupTimer(kDefaultReportingInterval); | |
236 | |
237 TracingController::GetInstance()->EnableRecording( | |
238 base::debug::CategoryFilter(category_filter), | |
239 base::debug::TraceOptions(), | |
240 TracingController::EnableRecordingDoneCallback()); | |
241 SendNotification(devtools::Tracing::started::kName, NULL); | |
242 } | |
243 | |
244 void DevToolsTracingHandler::DisableTracing() { | |
245 if (!is_recording_) | |
246 return; | |
247 is_recording_ = false; | |
248 DisableRecording(false); | |
249 } | |
250 | |
251 | |
252 } // namespace content | 241 } // namespace content |
OLD | NEW |