Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(937)

Side by Side Diff: content/browser/devtools/protocol/tracing_handler.cc

Issue 1408363004: [DevTools] Filter any messages from previous sessions in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 void TracingHandler::OnTraceDataCollected(const std::string& trace_fragment) { 107 void TracingHandler::OnTraceDataCollected(const std::string& trace_fragment) {
108 // Hand-craft protocol notification message so we can substitute JSON 108 // Hand-craft protocol notification message so we can substitute JSON
109 // that we already got as string as a bare object, not a quoted string. 109 // that we already got as string as a bare object, not a quoted string.
110 std::string message( 110 std::string message(
111 "{ \"method\": \"Tracing.dataCollected\", \"params\": { \"value\": ["); 111 "{ \"method\": \"Tracing.dataCollected\", \"params\": { \"value\": [");
112 const size_t messageSuffixSize = 10; 112 const size_t messageSuffixSize = 10;
113 message.reserve(message.size() + trace_fragment.size() + messageSuffixSize); 113 message.reserve(message.size() + trace_fragment.size() + messageSuffixSize);
114 message += trace_fragment; 114 message += trace_fragment;
115 message += "] } }"; 115 message += "] } }";
116 client_->SendRawMessage(message); 116 client_->SendRawMessage(0, message);
117 } 117 }
118 118
119 void TracingHandler::OnTraceComplete() { 119 void TracingHandler::OnTraceComplete() {
120 client_->TracingComplete(TracingCompleteParams::Create()); 120 client_->TracingComplete(TracingCompleteParams::Create());
121 } 121 }
122 122
123 void TracingHandler::OnTraceToStreamComplete(const std::string& stream_handle) { 123 void TracingHandler::OnTraceToStreamComplete(const std::string& stream_handle) {
124 client_->TracingComplete( 124 client_->TracingComplete(
125 TracingCompleteParams::Create()->set_stream(stream_handle)); 125 TracingCompleteParams::Create()->set_stream(stream_handle));
126 } 126 }
127 127
128 Response TracingHandler::Start(DevToolsCommandId command_id, 128 Response TracingHandler::Start(int session_id,
129 DevToolsCommandId command_id,
129 const std::string* categories, 130 const std::string* categories,
130 const std::string* options, 131 const std::string* options,
131 const double* buffer_usage_reporting_interval, 132 const double* buffer_usage_reporting_interval,
132 const std::string* transfer_mode) { 133 const std::string* transfer_mode) {
133 if (IsRecording()) 134 if (IsRecording())
134 return Response::InternalError("Tracing is already started"); 135 return Response::InternalError("Tracing is already started");
135 136
136 did_initiate_recording_ = true; 137 did_initiate_recording_ = true;
137 return_as_stream_ = 138 return_as_stream_ =
138 transfer_mode && *transfer_mode == start::kTransferModeReturnAsStream; 139 transfer_mode && *transfer_mode == start::kTransferModeReturnAsStream;
139 base::trace_event::TraceConfig trace_config( 140 base::trace_event::TraceConfig trace_config(
140 categories ? *categories : std::string(), 141 categories ? *categories : std::string(),
141 options ? *options : std::string()); 142 options ? *options : std::string());
142 if (buffer_usage_reporting_interval) 143 if (buffer_usage_reporting_interval)
143 SetupTimer(*buffer_usage_reporting_interval); 144 SetupTimer(*buffer_usage_reporting_interval);
144 145
145 // If inspected target is a render process Tracing.start will be handled by 146 // If inspected target is a render process Tracing.start will be handled by
146 // tracing agent in the renderer. 147 // tracing agent in the renderer.
147 if (target_ == Renderer) { 148 if (target_ == Renderer) {
148 TracingController::GetInstance()->EnableRecording( 149 TracingController::GetInstance()->EnableRecording(
149 trace_config, 150 trace_config,
150 TracingController::EnableRecordingDoneCallback()); 151 TracingController::EnableRecordingDoneCallback());
151 return Response::FallThrough(); 152 return Response::FallThrough();
152 } 153 }
153 154
154 TracingController::GetInstance()->EnableRecording( 155 TracingController::GetInstance()->EnableRecording(
155 trace_config, 156 trace_config,
156 base::Bind(&TracingHandler::OnRecordingEnabled, 157 base::Bind(&TracingHandler::OnRecordingEnabled,
157 weak_factory_.GetWeakPtr(), 158 weak_factory_.GetWeakPtr(), session_id, command_id));
158 command_id));
159 return Response::OK(); 159 return Response::OK();
160 } 160 }
161 161
162 Response TracingHandler::End(DevToolsCommandId command_id) { 162 Response TracingHandler::End(int session_id, DevToolsCommandId command_id) {
163 // Startup tracing triggered by --trace-config-file is a special case, where 163 // Startup tracing triggered by --trace-config-file is a special case, where
164 // tracing is started automatically upon browser startup and can be stopped 164 // tracing is started automatically upon browser startup and can be stopped
165 // via DevTools. 165 // via DevTools.
166 if (!did_initiate_recording_ && !IsStartupTracingActive()) 166 if (!did_initiate_recording_ && !IsStartupTracingActive())
167 return Response::InternalError("Tracing is not started"); 167 return Response::InternalError("Tracing is not started");
168 168
169 scoped_refptr<TracingController::TraceDataSink> proxy; 169 scoped_refptr<TracingController::TraceDataSink> proxy;
170 if (return_as_stream_) { 170 if (return_as_stream_) {
171 proxy = new DevToolsStreamTraceSink( 171 proxy = new DevToolsStreamTraceSink(
172 weak_factory_.GetWeakPtr(), io_context_->CreateTempFileBackedStream()); 172 weak_factory_.GetWeakPtr(), io_context_->CreateTempFileBackedStream());
173 } else { 173 } else {
174 proxy = new DevToolsTraceSinkProxy(weak_factory_.GetWeakPtr()); 174 proxy = new DevToolsTraceSinkProxy(weak_factory_.GetWeakPtr());
175 } 175 }
176 DisableRecording(proxy); 176 DisableRecording(proxy);
177 // If inspected target is a render process Tracing.end will be handled by 177 // If inspected target is a render process Tracing.end will be handled by
178 // tracing agent in the renderer. 178 // tracing agent in the renderer.
179 return target_ == Renderer ? Response::FallThrough() : Response::OK(); 179 return target_ == Renderer ? Response::FallThrough() : Response::OK();
180 } 180 }
181 181
182 Response TracingHandler::GetCategories(DevToolsCommandId command_id) { 182 Response TracingHandler::GetCategories(int session_id,
183 DevToolsCommandId command_id) {
183 TracingController::GetInstance()->GetCategories( 184 TracingController::GetInstance()->GetCategories(
184 base::Bind(&TracingHandler::OnCategoriesReceived, 185 base::Bind(&TracingHandler::OnCategoriesReceived,
185 weak_factory_.GetWeakPtr(), 186 weak_factory_.GetWeakPtr(), session_id, command_id));
186 command_id));
187 return Response::OK(); 187 return Response::OK();
188 } 188 }
189 189
190 void TracingHandler::OnRecordingEnabled(DevToolsCommandId command_id) { 190 void TracingHandler::OnRecordingEnabled(int session_id,
191 client_->SendStartResponse(command_id, StartResponse::Create()); 191 DevToolsCommandId command_id) {
192 client_->SendStartResponse(session_id, command_id, StartResponse::Create());
192 } 193 }
193 194
194 void TracingHandler::OnBufferUsage(float percent_full, 195 void TracingHandler::OnBufferUsage(float percent_full,
195 size_t approximate_event_count) { 196 size_t approximate_event_count) {
196 // TODO(crbug426117): remove set_value once all clients have switched to 197 // TODO(crbug426117): remove set_value once all clients have switched to
197 // the new interface of the event. 198 // the new interface of the event.
198 client_->BufferUsage(BufferUsageParams::Create() 199 client_->BufferUsage(BufferUsageParams::Create()
199 ->set_value(percent_full) 200 ->set_value(percent_full)
200 ->set_percent_full(percent_full) 201 ->set_percent_full(percent_full)
201 ->set_event_count(approximate_event_count)); 202 ->set_event_count(approximate_event_count));
202 } 203 }
203 204
204 void TracingHandler::OnCategoriesReceived( 205 void TracingHandler::OnCategoriesReceived(
206 int session_id,
205 DevToolsCommandId command_id, 207 DevToolsCommandId command_id,
206 const std::set<std::string>& category_set) { 208 const std::set<std::string>& category_set) {
207 std::vector<std::string> categories; 209 std::vector<std::string> categories;
208 for (const std::string& category : category_set) 210 for (const std::string& category : category_set)
209 categories.push_back(category); 211 categories.push_back(category);
210 client_->SendGetCategoriesResponse(command_id, 212 client_->SendGetCategoriesResponse(
213 session_id, command_id,
211 GetCategoriesResponse::Create()->set_categories(categories)); 214 GetCategoriesResponse::Create()->set_categories(categories));
212 } 215 }
213 216
214 Response TracingHandler::RequestMemoryDump(DevToolsCommandId command_id) { 217 Response TracingHandler::RequestMemoryDump(int session_id,
218 DevToolsCommandId command_id) {
215 if (!IsRecording()) 219 if (!IsRecording())
216 return Response::InternalError("Tracing is not started"); 220 return Response::InternalError("Tracing is not started");
217 221
218 base::trace_event::MemoryDumpManager::GetInstance()->RequestGlobalDump( 222 base::trace_event::MemoryDumpManager::GetInstance()->RequestGlobalDump(
219 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED, 223 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED,
220 base::trace_event::MemoryDumpLevelOfDetail::DETAILED, 224 base::trace_event::MemoryDumpLevelOfDetail::DETAILED,
221 base::Bind(&TracingHandler::OnMemoryDumpFinished, 225 base::Bind(&TracingHandler::OnMemoryDumpFinished,
222 weak_factory_.GetWeakPtr(), command_id)); 226 weak_factory_.GetWeakPtr(), session_id, command_id));
223 return Response::OK(); 227 return Response::OK();
224 } 228 }
225 229
226 void TracingHandler::OnMemoryDumpFinished(DevToolsCommandId command_id, 230 void TracingHandler::OnMemoryDumpFinished(int session_id,
231 DevToolsCommandId command_id,
227 uint64 dump_guid, 232 uint64 dump_guid,
228 bool success) { 233 bool success) {
229 client_->SendRequestMemoryDumpResponse( 234 client_->SendRequestMemoryDumpResponse(
230 command_id, 235 session_id, command_id,
231 RequestMemoryDumpResponse::Create() 236 RequestMemoryDumpResponse::Create()
232 ->set_dump_guid(base::StringPrintf("0x%" PRIx64, dump_guid)) 237 ->set_dump_guid(base::StringPrintf("0x%" PRIx64, dump_guid))
233 ->set_success(success)); 238 ->set_success(success));
234 } 239 }
235 240
236 void TracingHandler::SetupTimer(double usage_reporting_interval) { 241 void TracingHandler::SetupTimer(double usage_reporting_interval) {
237 if (usage_reporting_interval == 0) return; 242 if (usage_reporting_interval == 0) return;
238 243
239 if (usage_reporting_interval < kMinimumReportingInterval) 244 if (usage_reporting_interval < kMinimumReportingInterval)
240 usage_reporting_interval = kMinimumReportingInterval; 245 usage_reporting_interval = kMinimumReportingInterval;
(...skipping 22 matching lines...) Expand all
263 } 268 }
264 269
265 bool TracingHandler::IsStartupTracingActive() { 270 bool TracingHandler::IsStartupTracingActive() {
266 return ::tracing::TraceConfigFile::GetInstance()->IsEnabled() && 271 return ::tracing::TraceConfigFile::GetInstance()->IsEnabled() &&
267 TracingController::GetInstance()->IsRecording(); 272 TracingController::GetInstance()->IsRecording();
268 } 273 }
269 274
270 } // namespace tracing 275 } // namespace tracing
271 } // namespace devtools 276 } // namespace devtools
272 } // namespace content 277 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698