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" |
| 11 #include "base/debug/trace_event_impl.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
14 #include "base/location.h" | 15 #include "base/location.h" |
15 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // Hand-craft protocol notification message so we can substitute JSON | 110 // Hand-craft protocol notification message so we can substitute JSON |
110 // that we already got as string as a bare object, not a quoted string. | 111 // that we already got as string as a bare object, not a quoted string. |
111 std::string message = base::StringPrintf( | 112 std::string message = base::StringPrintf( |
112 "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }", | 113 "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }", |
113 devtools::Tracing::dataCollected::kName, | 114 devtools::Tracing::dataCollected::kName, |
114 devtools::Tracing::dataCollected::kParamValue, | 115 devtools::Tracing::dataCollected::kParamValue, |
115 trace_fragment.c_str()); | 116 trace_fragment.c_str()); |
116 SendRawMessage(message); | 117 SendRawMessage(message); |
117 } | 118 } |
118 | 119 |
119 TracingController::Options DevToolsTracingHandler::TraceOptionsFromString( | 120 base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString( |
120 const std::string& options) { | 121 const std::string& options) { |
121 std::vector<std::string> split; | 122 std::vector<std::string> split; |
122 std::vector<std::string>::iterator iter; | 123 std::vector<std::string>::iterator iter; |
123 int ret = 0; | 124 base::debug::TraceOptions::RecordMode mode = |
| 125 base::debug::TraceOptions::RECORD_UNTIL_FULL; |
| 126 bool enable_sampling = false; |
124 | 127 |
125 base::SplitString(options, ',', &split); | 128 base::SplitString(options, ',', &split); |
126 for (iter = split.begin(); iter != split.end(); ++iter) { | 129 for (iter = split.begin(); iter != split.end(); ++iter) { |
127 if (*iter == kRecordUntilFull) { | 130 if (*iter == kRecordUntilFull) { |
128 ret &= ~TracingController::RECORD_CONTINUOUSLY; | 131 mode = base::debug::TraceOptions::RECORD_UNTIL_FULL; |
129 } else if (*iter == kRecordContinuously) { | 132 } else if (*iter == kRecordContinuously) { |
130 ret |= TracingController::RECORD_CONTINUOUSLY; | 133 mode = base::debug::TraceOptions::RECORD_CONTINUOUSLY; |
131 } else if (*iter == kEnableSampling) { | 134 } else if (*iter == kEnableSampling) { |
132 ret |= TracingController::ENABLE_SAMPLING; | 135 enable_sampling = true; |
133 } | 136 } |
134 } | 137 } |
135 return static_cast<TracingController::Options>(ret); | 138 return base::debug::TraceOptions(mode, enable_sampling); |
136 } | 139 } |
137 | 140 |
138 scoped_refptr<DevToolsProtocol::Response> | 141 scoped_refptr<DevToolsProtocol::Response> |
139 DevToolsTracingHandler::OnStart( | 142 DevToolsTracingHandler::OnStart( |
140 scoped_refptr<DevToolsProtocol::Command> command) { | 143 scoped_refptr<DevToolsProtocol::Command> command) { |
141 is_recording_ = true; | 144 is_recording_ = true; |
142 std::string categories; | 145 std::string categories; |
143 base::DictionaryValue* params = command->params(); | 146 base::DictionaryValue* params = command->params(); |
144 if (params) | 147 if (params) |
145 params->GetString(devtools::Tracing::start::kParamCategories, &categories); | 148 params->GetString(devtools::Tracing::start::kParamCategories, &categories); |
146 | 149 |
147 TracingController::Options options = TracingController::DEFAULT_OPTIONS; | 150 base::debug::TraceOptions options; |
148 if (params && params->HasKey(devtools::Tracing::start::kParamOptions)) { | 151 if (params && params->HasKey(devtools::Tracing::start::kParamOptions)) { |
149 std::string options_param; | 152 std::string options_param; |
150 params->GetString(devtools::Tracing::start::kParamOptions, &options_param); | 153 params->GetString(devtools::Tracing::start::kParamOptions, &options_param); |
151 options = TraceOptionsFromString(options_param); | 154 options = TraceOptionsFromString(options_param); |
152 } | 155 } |
153 | 156 |
154 if (params && params->HasKey( | 157 if (params && params->HasKey( |
155 devtools::Tracing::start::kParamBufferUsageReportingInterval)) { | 158 devtools::Tracing::start::kParamBufferUsageReportingInterval)) { |
156 double usage_reporting_interval = 0.0; | 159 double usage_reporting_interval = 0.0; |
157 params->GetDouble( | 160 params->GetDouble( |
(...skipping 12 matching lines...) Expand all Loading... |
170 weak_factory_.GetWeakPtr())), | 173 weak_factory_.GetWeakPtr())), |
171 true)); | 174 true)); |
172 buffer_usage_poll_timer_->Reset(); | 175 buffer_usage_poll_timer_->Reset(); |
173 } | 176 } |
174 } | 177 } |
175 | 178 |
176 // If inspected target is a render process Tracing.start will be handled by | 179 // If inspected target is a render process Tracing.start will be handled by |
177 // tracing agent in the renderer. | 180 // tracing agent in the renderer. |
178 if (target_ == Renderer) { | 181 if (target_ == Renderer) { |
179 TracingController::GetInstance()->EnableRecording( | 182 TracingController::GetInstance()->EnableRecording( |
180 categories, options, TracingController::EnableRecordingDoneCallback()); | 183 categories, |
| 184 options, |
| 185 false, |
| 186 TracingController::EnableRecordingDoneCallback()); |
181 return NULL; | 187 return NULL; |
182 } | 188 } |
183 | 189 |
184 TracingController::GetInstance()->EnableRecording( | 190 TracingController::GetInstance()->EnableRecording( |
185 categories, options, | 191 categories, |
| 192 options, |
| 193 false, |
186 base::Bind(&DevToolsTracingHandler::OnTracingStarted, | 194 base::Bind(&DevToolsTracingHandler::OnTracingStarted, |
187 weak_factory_.GetWeakPtr(), | 195 weak_factory_.GetWeakPtr(), |
188 command)); | 196 command)); |
189 | 197 |
190 return command->AsyncResponsePromise(); | 198 return command->AsyncResponsePromise(); |
191 } | 199 } |
192 | 200 |
193 void DevToolsTracingHandler::OnTracingStarted( | 201 void DevToolsTracingHandler::OnTracingStarted( |
194 scoped_refptr<DevToolsProtocol::Command> command) { | 202 scoped_refptr<DevToolsProtocol::Command> command) { |
195 SendAsyncResponse(command->SuccessResponse(NULL)); | 203 SendAsyncResponse(command->SuccessResponse(NULL)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 it != category_set.end(); ++it) { | 250 it != category_set.end(); ++it) { |
243 category_list->AppendString(*it); | 251 category_list->AppendString(*it); |
244 } | 252 } |
245 | 253 |
246 response->Set(devtools::Tracing::getCategories::kResponseCategories, | 254 response->Set(devtools::Tracing::getCategories::kResponseCategories, |
247 category_list); | 255 category_list); |
248 SendAsyncResponse(command->SuccessResponse(response)); | 256 SendAsyncResponse(command->SuccessResponse(response)); |
249 } | 257 } |
250 | 258 |
251 } // namespace content | 259 } // namespace content |
OLD | NEW |