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

Side by Side Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 105893004: Sampling profiling thread should be joined in a FILE thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/tracing/tracing_controller_impl.h" 5 #include "content/browser/tracing/tracing_controller_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 EnableRecordingDoneCallback())) { 143 EnableRecordingDoneCallback())) {
144 pending_get_categories_done_callback_.Reset(); 144 pending_get_categories_done_callback_.Reset();
145 return false; 145 return false;
146 } 146 }
147 147
148 bool ok = DisableRecording(base::FilePath(), TracingFileResultCallback()); 148 bool ok = DisableRecording(base::FilePath(), TracingFileResultCallback());
149 DCHECK(ok); 149 DCHECK(ok);
150 return true; 150 return true;
151 } 151 }
152 152
153 void TracingControllerImpl::SetEnabledOnFileThread(
154 const std::string& category_filter,
155 int trace_options,
156 const base::Closure& callback) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
158
159 TraceLog::GetInstance()->SetEnabled(
160 base::debug::CategoryFilter(category_filter),
161 static_cast<TraceLog::Options>(trace_options));
162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
163 }
164
165 void TracingControllerImpl::SetDisabledOnFileThread(
166 const base::Closure& callback) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
168
169 TraceLog::GetInstance()->SetDisabled();
170 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
171 }
172
153 bool TracingControllerImpl::EnableRecording( 173 bool TracingControllerImpl::EnableRecording(
154 const std::string& category_filter, 174 const std::string& category_filter,
155 TracingController::Options options, 175 TracingController::Options options,
156 const EnableRecordingDoneCallback& callback) { 176 const EnableRecordingDoneCallback& callback) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
158 178
159 if (!can_enable_recording()) 179 if (!can_enable_recording())
160 return false; 180 return false;
181 is_recording_ = true;
161 182
162 #if defined(OS_ANDROID) 183 #if defined(OS_ANDROID)
163 if (pending_get_categories_done_callback_.is_null()) 184 if (pending_get_categories_done_callback_.is_null())
164 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); 185 TraceLog::GetInstance()->AddClockSyncMetadataEvent();
165 #endif 186 #endif
166 187
167 TraceLog::Options trace_options = (options & RECORD_CONTINUOUSLY) ? 188 int trace_options = (options & RECORD_CONTINUOUSLY) ?
168 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; 189 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL;
169 if (options & ENABLE_SAMPLING) { 190 if (options & ENABLE_SAMPLING) {
170 trace_options = static_cast<TraceLog::Options>( 191 trace_options |= TraceLog::ENABLE_SAMPLING;
171 trace_options | TraceLog::ENABLE_SAMPLING);
172 } 192 }
173 // TODO(haraken): How to handle ENABLE_SYSTRACE? 193 // TODO(haraken): How to handle ENABLE_SYSTRACE?
174 194
175 TraceLog::GetInstance()->SetEnabled( 195 base::Closure on_enable_recording_done_callback =
176 base::debug::CategoryFilter(category_filter), trace_options); 196 base::Bind(&TracingControllerImpl::OnEnableRecordingDone,
177 is_recording_ = true; 197 base::Unretained(this),
198 category_filter, trace_options, callback);
199 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
200 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
201 base::Unretained(this),
202 category_filter, trace_options,
203 on_enable_recording_done_callback));
204 return true;
205 }
206
207 void TracingControllerImpl::OnEnableRecordingDone(
208 const std::string& category_filter,
209 int trace_options,
210 const EnableRecordingDoneCallback& callback) {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
178 212
179 // Notify all child processes. 213 // Notify all child processes.
180 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 214 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
181 it != trace_message_filters_.end(); ++it) { 215 it != trace_message_filters_.end(); ++it) {
182 it->get()->SendBeginTracing(category_filter, trace_options); 216 it->get()->SendBeginTracing(category_filter,
217 static_cast<TraceLog::Options>(trace_options));
183 } 218 }
184 219
185 if (!callback.is_null()) 220 if (!callback.is_null())
186 callback.Run(); 221 callback.Run();
187 return true;
188 } 222 }
189 223
190 bool TracingControllerImpl::DisableRecording( 224 bool TracingControllerImpl::DisableRecording(
191 const base::FilePath& result_file_path, 225 const base::FilePath& result_file_path,
192 const TracingFileResultCallback& callback) { 226 const TracingFileResultCallback& callback) {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 228
195 if (!can_disable_recording()) 229 if (!can_disable_recording())
196 return false; 230 return false;
197 231
198 pending_disable_recording_done_callback_ = callback;
199
200 // Disable local trace early to avoid traces during end-tracing process from 232 // Disable local trace early to avoid traces during end-tracing process from
201 // interfering with the process. 233 // interfering with the process.
202 TraceLog::GetInstance()->SetDisabled(); 234 base::Closure on_disable_recording_done_callback =
235 base::Bind(&TracingControllerImpl::OnDisableRecordingDone,
236 base::Unretained(this),
237 result_file_path, callback);
238 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
239 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread,
240 base::Unretained(this),
241 on_disable_recording_done_callback));
242 return true;
243 }
244
245 void TracingControllerImpl::OnDisableRecordingDone(
246 const base::FilePath& result_file_path,
247 const TracingFileResultCallback& callback) {
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
249
250 pending_disable_recording_done_callback_ = callback;
203 251
204 #if defined(OS_ANDROID) 252 #if defined(OS_ANDROID)
205 if (pending_get_categories_done_callback_.is_null()) 253 if (pending_get_categories_done_callback_.is_null())
206 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); 254 TraceLog::GetInstance()->AddClockSyncMetadataEvent();
207 #endif 255 #endif
208 256
209 if (!callback.is_null() || !result_file_path.empty()) 257 if (!callback.is_null() || !result_file_path.empty())
210 result_file_.reset(new ResultFile(result_file_path)); 258 result_file_.reset(new ResultFile(result_file_path));
211 259
212 // Count myself (local trace) in pending_disable_recording_ack_count_, 260 // Count myself (local trace) in pending_disable_recording_ack_count_,
213 // acked below. 261 // acked below.
214 pending_disable_recording_ack_count_ = trace_message_filters_.size() + 1; 262 pending_disable_recording_ack_count_ = trace_message_filters_.size() + 1;
215 pending_disable_recording_filters_ = trace_message_filters_; 263 pending_disable_recording_filters_ = trace_message_filters_;
216 264
217 // Handle special case of zero child processes by immediately flushing the 265 // Handle special case of zero child processes by immediately flushing the
218 // trace log. Once the flush has completed the caller will be notified that 266 // trace log. Once the flush has completed the caller will be notified that
219 // tracing has ended. 267 // tracing has ended.
220 if (pending_disable_recording_ack_count_ == 1) { 268 if (pending_disable_recording_ack_count_ == 1) {
221 // Flush asynchronously now, because we don't have any children to wait for. 269 // Flush asynchronously now, because we don't have any children to wait for.
222 TraceLog::GetInstance()->Flush( 270 TraceLog::GetInstance()->Flush(
223 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected, 271 base::Bind(&TracingControllerImpl::OnLocalTraceDataCollected,
224 base::Unretained(this))); 272 base::Unretained(this)));
225 } 273 }
226 274
227 // Notify all child processes. 275 // Notify all child processes.
228 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 276 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
229 it != trace_message_filters_.end(); ++it) { 277 it != trace_message_filters_.end(); ++it) {
230 it->get()->SendEndTracing(); 278 it->get()->SendEndTracing();
231 } 279 }
232 return true;
233 } 280 }
234 281
235 bool TracingControllerImpl::EnableMonitoring( 282 bool TracingControllerImpl::EnableMonitoring(
236 const std::string& category_filter, 283 const std::string& category_filter,
237 TracingController::Options options, 284 TracingController::Options options,
238 const EnableMonitoringDoneCallback& callback) { 285 const EnableMonitoringDoneCallback& callback) {
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
240 287
241 if (!can_enable_monitoring()) 288 if (!can_enable_monitoring())
242 return false; 289 return false;
243 is_monitoring_ = true; 290 is_monitoring_ = true;
244 291
245 #if defined(OS_ANDROID) 292 #if defined(OS_ANDROID)
246 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); 293 TraceLog::GetInstance()->AddClockSyncMetadataEvent();
247 #endif 294 #endif
248 295
249 int monitoring_tracing_options = 0; 296 int trace_options = 0;
250 if (options & ENABLE_SAMPLING) 297 if (options & ENABLE_SAMPLING)
251 monitoring_tracing_options |= base::debug::TraceLog::MONITOR_SAMPLING; 298 trace_options |= TraceLog::MONITOR_SAMPLING;
252 299
253 TraceLog::GetInstance()->SetEnabled( 300 base::Closure on_enable_monitoring_done_callback =
254 base::debug::CategoryFilter(category_filter), 301 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone,
255 static_cast<TraceLog::Options>(monitoring_tracing_options)); 302 base::Unretained(this),
303 category_filter, trace_options, callback);
304 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
305 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
306 base::Unretained(this),
307 category_filter, trace_options,
308 on_enable_monitoring_done_callback));
309 return true;
310 }
311
312 void TracingControllerImpl::OnEnableMonitoringDone(
313 const std::string& category_filter,
314 int trace_options,
315 const EnableMonitoringDoneCallback& callback) {
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
256 317
257 // Notify all child processes. 318 // Notify all child processes.
258 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 319 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
259 it != trace_message_filters_.end(); ++it) { 320 it != trace_message_filters_.end(); ++it) {
260 it->get()->SendEnableMonitoring(category_filter, 321 it->get()->SendEnableMonitoring(category_filter,
261 static_cast<TraceLog::Options>(monitoring_tracing_options)); 322 static_cast<TraceLog::Options>(trace_options));
262 } 323 }
263 324
264 if (!callback.is_null()) 325 if (!callback.is_null())
265 callback.Run(); 326 callback.Run();
266 return true;
267 } 327 }
268 328
269 bool TracingControllerImpl::DisableMonitoring( 329 bool TracingControllerImpl::DisableMonitoring(
270 const DisableMonitoringDoneCallback& callback) { 330 const DisableMonitoringDoneCallback& callback) {
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
272 332
273 if (!can_disable_monitoring()) 333 if (!can_disable_monitoring())
274 return false; 334 return false;
335
336 base::Closure on_disable_monitoring_done_callback =
337 base::Bind(&TracingControllerImpl::OnDisableMonitoringDone,
338 base::Unretained(this), callback);
339 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
340 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread,
341 base::Unretained(this),
342 on_disable_monitoring_done_callback));
343 return true;
344 }
345
346 void TracingControllerImpl::OnDisableMonitoringDone(
347 const DisableMonitoringDoneCallback& callback) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
349
275 is_monitoring_ = false; 350 is_monitoring_ = false;
276 351
277 TraceLog::GetInstance()->SetDisabled();
278
279 // Notify all child processes. 352 // Notify all child processes.
280 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); 353 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
281 it != trace_message_filters_.end(); ++it) { 354 it != trace_message_filters_.end(); ++it) {
282 it->get()->SendDisableMonitoring(); 355 it->get()->SendDisableMonitoring();
283 } 356 }
284 357
285 if (!callback.is_null()) 358 if (!callback.is_null())
286 callback.Run(); 359 callback.Run();
287 return true;
288 } 360 }
289 361
290 void TracingControllerImpl::GetMonitoringStatus( 362 void TracingControllerImpl::GetMonitoringStatus(
291 bool* out_enabled, 363 bool* out_enabled,
292 std::string* out_category_filter, 364 std::string* out_category_filter,
293 TracingController::Options* out_options) { 365 TracingController::Options* out_options) {
294 NOTIMPLEMENTED(); 366 NOTIMPLEMENTED();
295 } 367 }
296 368
297 bool TracingControllerImpl::CaptureMonitoringSnapshot( 369 bool TracingControllerImpl::CaptureMonitoringSnapshot(
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 base::Bind(&TracingControllerImpl::OnWatchEventMatched, 775 base::Bind(&TracingControllerImpl::OnWatchEventMatched,
704 base::Unretained(this))); 776 base::Unretained(this)));
705 return; 777 return;
706 } 778 }
707 779
708 if (!watch_event_callback_.is_null()) 780 if (!watch_event_callback_.is_null())
709 watch_event_callback_.Run(); 781 watch_event_callback_.Run();
710 } 782 }
711 783
712 } // namespace content 784 } // namespace content
OLDNEW
« chrome/test/base/tracing.cc ('K') | « content/browser/tracing/tracing_controller_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698