Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/protocol/tracing_handler.h" | 5 #include "content/browser/devtools/protocol/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/format_macros.h" | 10 #include "base/format_macros.h" |
| 11 #include "base/json/json_writer.h" | |
| 11 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 16 #include "base/trace_event/memory_dump_manager.h" | 17 #include "base/trace_event/memory_dump_manager.h" |
| 17 #include "base/trace_event/trace_event_impl.h" | 18 #include "base/trace_event/trace_event_impl.h" |
| 18 #include "base/trace_event/tracing_agent.h" | 19 #include "base/trace_event/tracing_agent.h" |
| 19 #include "components/tracing/trace_config_file.h" | 20 #include "components/tracing/trace_config_file.h" |
| 20 #include "content/browser/devtools/devtools_io_context.h" | 21 #include "content/browser/devtools/devtools_io_context.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 124 |
| 124 void TracingHandler::OnTraceComplete() { | 125 void TracingHandler::OnTraceComplete() { |
| 125 client_->TracingComplete(TracingCompleteParams::Create()); | 126 client_->TracingComplete(TracingCompleteParams::Create()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void TracingHandler::OnTraceToStreamComplete(const std::string& stream_handle) { | 129 void TracingHandler::OnTraceToStreamComplete(const std::string& stream_handle) { |
| 129 client_->TracingComplete( | 130 client_->TracingComplete( |
| 130 TracingCompleteParams::Create()->set_stream(stream_handle)); | 131 TracingCompleteParams::Create()->set_stream(stream_handle)); |
| 131 } | 132 } |
| 132 | 133 |
| 133 Response TracingHandler::Start(DevToolsCommandId command_id, | 134 Response TracingHandler::Start( |
| 134 const std::string* categories, | 135 DevToolsCommandId command_id, |
| 135 const std::string* options, | 136 const std::string* categories, |
| 136 const double* buffer_usage_reporting_interval, | 137 const std::string* options, |
| 137 const std::string* transfer_mode) { | 138 const double* buffer_usage_reporting_interval, |
| 139 const std::string* transfer_mode, | |
| 140 const scoped_ptr<base::DictionaryValue>& config) { | |
| 138 if (IsTracing()) | 141 if (IsTracing()) |
| 139 return Response::InternalError("Tracing is already started"); | 142 return Response::InternalError("Tracing is already started"); |
| 140 | 143 |
| 144 if (config && (categories || options)) { | |
| 145 return Response::InternalError( | |
| 146 "Both trace config and categories/options are specified. Only one way " | |
| 147 "should be used; and using trace config is preferred."); | |
| 148 } | |
| 149 | |
| 141 did_initiate_recording_ = true; | 150 did_initiate_recording_ = true; |
| 142 return_as_stream_ = | 151 return_as_stream_ = |
| 143 transfer_mode && *transfer_mode == start::kTransferModeReturnAsStream; | 152 transfer_mode && *transfer_mode == start::kTransferModeReturnAsStream; |
| 144 base::trace_event::TraceConfig trace_config( | |
| 145 categories ? *categories : std::string(), | |
| 146 options ? *options : std::string()); | |
| 147 if (buffer_usage_reporting_interval) | 153 if (buffer_usage_reporting_interval) |
| 148 SetupTimer(*buffer_usage_reporting_interval); | 154 SetupTimer(*buffer_usage_reporting_interval); |
| 149 | 155 |
| 156 base::trace_event::TraceConfig trace_config; | |
| 157 if (config) { | |
| 158 scoped_ptr<base::DictionaryValue> tracing_style_dict = | |
| 159 base::trace_event::TraceConfig::DevToolsToTracingStyle(config); | |
| 160 std::string trace_config_str; | |
| 161 base::JSONWriter::Write(*tracing_style_dict, &trace_config_str); | |
|
caseq
2016/03/05 02:25:24
Why do we have to do an extra roundtrip of writing
Primiano Tucci (use gerrit)
2016/03/06 01:24:37
I think a good layering would be:
- move your di
| |
| 162 trace_config = base::trace_event::TraceConfig(trace_config_str); | |
| 163 } else if (categories || options) { | |
| 164 trace_config = base::trace_event::TraceConfig( | |
| 165 categories ? *categories : std::string(), | |
| 166 options ? *options : std::string()); | |
| 167 } | |
| 168 | |
| 150 // If inspected target is a render process Tracing.start will be handled by | 169 // If inspected target is a render process Tracing.start will be handled by |
| 151 // tracing agent in the renderer. | 170 // tracing agent in the renderer. |
| 152 TracingController::GetInstance()->StartTracing( | 171 TracingController::GetInstance()->StartTracing( |
| 153 trace_config, | 172 trace_config, |
| 154 base::Bind(&TracingHandler::OnRecordingEnabled, | 173 base::Bind(&TracingHandler::OnRecordingEnabled, |
| 155 weak_factory_.GetWeakPtr(), | 174 weak_factory_.GetWeakPtr(), |
| 156 command_id)); | 175 command_id)); |
| 157 | 176 |
| 158 return target_ == Renderer ? Response::FallThrough() : Response::OK(); | 177 return target_ == Renderer ? Response::FallThrough() : Response::OK(); |
| 159 } | 178 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 } | 296 } |
| 278 | 297 |
| 279 bool TracingHandler::IsStartupTracingActive() { | 298 bool TracingHandler::IsStartupTracingActive() { |
| 280 return ::tracing::TraceConfigFile::GetInstance()->IsEnabled() && | 299 return ::tracing::TraceConfigFile::GetInstance()->IsEnabled() && |
| 281 TracingController::GetInstance()->IsTracing(); | 300 TracingController::GetInstance()->IsTracing(); |
| 282 } | 301 } |
| 283 | 302 |
| 284 } // namespace tracing | 303 } // namespace tracing |
| 285 } // namespace devtools | 304 } // namespace devtools |
| 286 } // namespace content | 305 } // namespace content |
| OLD | NEW |