Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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::SetEnabled(const std::string& category_filter, | |
| 154 int trace_options, | |
| 155 const base::Closure& callback) { | |
| 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
|
dsinclair
2013/12/12 15:14:04
Should we add logic in here that, if we aren't on
haraken
2013/12/13 03:27:38
Renamed the method to SetEnabledOnFileThread and S
| |
| 157 | |
| 158 TraceLog::GetInstance()->SetEnabled( | |
|
haraken
2013/12/12 04:22:14
We need to dispatch SetEnabled in the FILE thread,
| |
| 159 base::debug::CategoryFilter(category_filter), | |
| 160 static_cast<TraceLog::Options>(trace_options)); | |
| 161 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | |
| 162 } | |
| 163 | |
| 164 void TracingControllerImpl::SetDisabled(const base::Closure& callback) { | |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
| 166 | |
| 167 TraceLog::GetInstance()->SetDisabled(); | |
| 168 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | |
| 169 } | |
| 170 | |
| 153 bool TracingControllerImpl::EnableRecording( | 171 bool TracingControllerImpl::EnableRecording( |
| 154 const std::string& category_filter, | 172 const std::string& category_filter, |
| 155 TracingController::Options options, | 173 TracingController::Options options, |
| 156 const EnableRecordingDoneCallback& callback) { | 174 const EnableRecordingDoneCallback& callback) { |
| 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 158 | 176 |
| 159 if (!can_enable_recording()) | 177 if (!can_enable_recording()) |
| 160 return false; | 178 return false; |
| 179 is_recording_ = true; | |
| 161 | 180 |
| 162 #if defined(OS_ANDROID) | 181 #if defined(OS_ANDROID) |
| 163 if (pending_get_categories_done_callback_.is_null()) | 182 if (pending_get_categories_done_callback_.is_null()) |
| 164 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 183 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 165 #endif | 184 #endif |
| 166 | 185 |
| 167 TraceLog::Options trace_options = (options & RECORD_CONTINUOUSLY) ? | 186 int trace_options = (options & RECORD_CONTINUOUSLY) ? |
| 168 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; | 187 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; |
| 169 if (options & ENABLE_SAMPLING) { | 188 if (options & ENABLE_SAMPLING) { |
| 170 trace_options = static_cast<TraceLog::Options>( | 189 trace_options |= TraceLog::ENABLE_SAMPLING; |
| 171 trace_options | TraceLog::ENABLE_SAMPLING); | |
| 172 } | 190 } |
| 173 // TODO(haraken): How to handle ENABLE_SYSTRACE? | 191 // TODO(haraken): How to handle ENABLE_SYSTRACE? |
| 174 | 192 |
| 175 TraceLog::GetInstance()->SetEnabled( | 193 base::Closure on_enable_recording_done_callback = |
| 176 base::debug::CategoryFilter(category_filter), trace_options); | 194 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, |
| 177 is_recording_ = true; | 195 base::Unretained(this), |
| 196 category_filter, trace_options, callback); | |
| 197 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 198 base::Bind(&TracingControllerImpl::SetEnabled, | |
| 199 base::Unretained(this), | |
| 200 category_filter, trace_options, | |
| 201 on_enable_recording_done_callback)); | |
| 202 return true; | |
| 203 } | |
| 204 | |
| 205 void TracingControllerImpl::OnEnableRecordingDone( | |
| 206 const std::string& category_filter, | |
| 207 int trace_options, | |
| 208 const EnableRecordingDoneCallback& callback) { | |
| 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 178 | 210 |
| 179 // Notify all child processes. | 211 // Notify all child processes. |
| 180 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 212 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 181 it != trace_message_filters_.end(); ++it) { | 213 it != trace_message_filters_.end(); ++it) { |
| 182 it->get()->SendBeginTracing(category_filter, trace_options); | 214 it->get()->SendBeginTracing(category_filter, |
| 215 static_cast<TraceLog::Options>(trace_options)); | |
| 183 } | 216 } |
| 184 | 217 |
| 185 if (!callback.is_null()) | 218 if (!callback.is_null()) |
| 186 callback.Run(); | 219 callback.Run(); |
| 187 return true; | |
| 188 } | 220 } |
| 189 | 221 |
| 190 bool TracingControllerImpl::DisableRecording( | 222 bool TracingControllerImpl::DisableRecording( |
| 191 const base::FilePath& result_file_path, | 223 const base::FilePath& result_file_path, |
| 192 const TracingFileResultCallback& callback) { | 224 const TracingFileResultCallback& callback) { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 194 | 226 |
| 195 if (!can_disable_recording()) | 227 if (!can_disable_recording()) |
| 196 return false; | 228 return false; |
| 197 | 229 |
| 198 pending_disable_recording_done_callback_ = callback; | |
| 199 | |
| 200 // Disable local trace early to avoid traces during end-tracing process from | 230 // Disable local trace early to avoid traces during end-tracing process from |
| 201 // interfering with the process. | 231 // interfering with the process. |
| 202 TraceLog::GetInstance()->SetDisabled(); | 232 base::Closure on_disable_recording_done_callback = |
| 233 base::Bind(&TracingControllerImpl::OnDisableRecordingDone, | |
| 234 base::Unretained(this), | |
| 235 result_file_path, callback); | |
| 236 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 237 base::Bind(&TracingControllerImpl::SetDisabled, | |
| 238 base::Unretained(this), | |
| 239 on_disable_recording_done_callback)); | |
| 240 return true; | |
| 241 } | |
| 242 | |
| 243 void TracingControllerImpl::OnDisableRecordingDone( | |
| 244 const base::FilePath& result_file_path, | |
| 245 const TracingFileResultCallback& callback) { | |
| 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 247 | |
| 248 pending_disable_recording_done_callback_ = callback; | |
| 203 | 249 |
| 204 #if defined(OS_ANDROID) | 250 #if defined(OS_ANDROID) |
| 205 if (pending_get_categories_done_callback_.is_null()) | 251 if (pending_get_categories_done_callback_.is_null()) |
| 206 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 252 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 207 #endif | 253 #endif |
| 208 | 254 |
| 209 if (!callback.is_null() || !result_file_path.empty()) | 255 if (!callback.is_null() || !result_file_path.empty()) |
| 210 result_file_.reset(new ResultFile(result_file_path)); | 256 result_file_.reset(new ResultFile(result_file_path)); |
| 211 | 257 |
| 212 // Count myself (local trace) in pending_disable_recording_ack_count_, | 258 // Count myself (local trace) in pending_disable_recording_ack_count_, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 223 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 269 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 224 base::Bind(&TracingControllerImpl::OnDisableRecordingAcked, | 270 base::Bind(&TracingControllerImpl::OnDisableRecordingAcked, |
| 225 base::Unretained(this), category_groups)); | 271 base::Unretained(this), category_groups)); |
| 226 } | 272 } |
| 227 | 273 |
| 228 // Notify all child processes. | 274 // Notify all child processes. |
| 229 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 275 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 230 it != trace_message_filters_.end(); ++it) { | 276 it != trace_message_filters_.end(); ++it) { |
| 231 it->get()->SendEndTracing(); | 277 it->get()->SendEndTracing(); |
| 232 } | 278 } |
| 233 return true; | |
| 234 } | 279 } |
| 235 | 280 |
| 236 bool TracingControllerImpl::EnableMonitoring( | 281 bool TracingControllerImpl::EnableMonitoring( |
| 237 const std::string& category_filter, | 282 const std::string& category_filter, |
| 238 TracingController::Options options, | 283 TracingController::Options options, |
| 239 const EnableMonitoringDoneCallback& callback) { | 284 const EnableMonitoringDoneCallback& callback) { |
| 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 241 | 286 |
| 242 if (!can_enable_monitoring()) | 287 if (!can_enable_monitoring()) |
| 243 return false; | 288 return false; |
| 244 is_monitoring_ = true; | 289 is_monitoring_ = true; |
| 245 | 290 |
| 246 #if defined(OS_ANDROID) | 291 #if defined(OS_ANDROID) |
| 247 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 292 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 248 #endif | 293 #endif |
| 249 | 294 |
| 250 int monitoring_tracing_options = 0; | 295 int trace_options = 0; |
| 251 if (options & ENABLE_SAMPLING) | 296 if (options & ENABLE_SAMPLING) |
| 252 monitoring_tracing_options |= base::debug::TraceLog::MONITOR_SAMPLING; | 297 trace_options |= TraceLog::MONITOR_SAMPLING; |
| 253 | 298 |
| 254 TraceLog::GetInstance()->SetEnabled( | 299 base::Closure on_enable_monitoring_done_callback = |
| 255 base::debug::CategoryFilter(category_filter), | 300 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone, |
| 256 static_cast<TraceLog::Options>(monitoring_tracing_options)); | 301 base::Unretained(this), |
| 302 category_filter, trace_options, callback); | |
| 303 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 304 base::Bind(&TracingControllerImpl::SetEnabled, | |
| 305 base::Unretained(this), | |
| 306 category_filter, trace_options, | |
| 307 on_enable_monitoring_done_callback)); | |
| 308 return true; | |
| 309 } | |
| 310 | |
| 311 void TracingControllerImpl::OnEnableMonitoringDone( | |
| 312 const std::string& category_filter, | |
| 313 int trace_options, | |
| 314 const EnableMonitoringDoneCallback& callback) { | |
| 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 257 | 316 |
| 258 // Notify all child processes. | 317 // Notify all child processes. |
| 259 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 318 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 260 it != trace_message_filters_.end(); ++it) { | 319 it != trace_message_filters_.end(); ++it) { |
| 261 it->get()->SendEnableMonitoring(category_filter, | 320 it->get()->SendEnableMonitoring(category_filter, |
| 262 static_cast<TraceLog::Options>(monitoring_tracing_options)); | 321 static_cast<TraceLog::Options>(trace_options)); |
| 263 } | 322 } |
| 264 | 323 |
| 265 if (!callback.is_null()) | 324 if (!callback.is_null()) |
| 266 callback.Run(); | 325 callback.Run(); |
| 267 return true; | |
| 268 } | 326 } |
| 269 | 327 |
| 270 bool TracingControllerImpl::DisableMonitoring( | 328 bool TracingControllerImpl::DisableMonitoring( |
| 271 const DisableMonitoringDoneCallback& callback) { | 329 const DisableMonitoringDoneCallback& callback) { |
| 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 273 | 331 |
| 274 if (!can_disable_monitoring()) | 332 if (!can_disable_monitoring()) |
| 275 return false; | 333 return false; |
| 334 | |
| 335 base::Closure on_disable_monitoring_done_callback = | |
| 336 base::Bind(&TracingControllerImpl::OnDisableMonitoringDone, | |
| 337 base::Unretained(this), callback); | |
| 338 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 339 base::Bind(&TracingControllerImpl::SetDisabled, | |
| 340 base::Unretained(this), | |
| 341 on_disable_monitoring_done_callback)); | |
| 342 return true; | |
| 343 } | |
| 344 | |
| 345 void TracingControllerImpl::OnDisableMonitoringDone( | |
| 346 const DisableMonitoringDoneCallback& callback) { | |
| 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 348 | |
| 276 is_monitoring_ = false; | 349 is_monitoring_ = false; |
| 277 | 350 |
| 278 TraceLog::GetInstance()->SetDisabled(); | |
| 279 | |
| 280 // Notify all child processes. | 351 // Notify all child processes. |
| 281 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 352 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 282 it != trace_message_filters_.end(); ++it) { | 353 it != trace_message_filters_.end(); ++it) { |
| 283 it->get()->SendDisableMonitoring(); | 354 it->get()->SendDisableMonitoring(); |
| 284 } | 355 } |
| 285 | 356 |
| 286 if (!callback.is_null()) | 357 if (!callback.is_null()) |
| 287 callback.Run(); | 358 callback.Run(); |
| 288 return true; | |
| 289 } | 359 } |
| 290 | 360 |
| 291 void TracingControllerImpl::GetMonitoringStatus( | 361 void TracingControllerImpl::GetMonitoringStatus( |
| 292 bool* out_enabled, | 362 bool* out_enabled, |
| 293 std::string* out_category_filter, | 363 std::string* out_category_filter, |
| 294 TracingController::Options* out_options) { | 364 TracingController::Options* out_options) { |
| 295 NOTIMPLEMENTED(); | 365 NOTIMPLEMENTED(); |
| 296 } | 366 } |
| 297 | 367 |
| 298 bool TracingControllerImpl::CaptureMonitoringSnapshot( | 368 bool TracingControllerImpl::CaptureMonitoringSnapshot( |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 708 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
| 639 base::Unretained(this))); | 709 base::Unretained(this))); |
| 640 return; | 710 return; |
| 641 } | 711 } |
| 642 | 712 |
| 643 if (!watch_event_callback_.is_null()) | 713 if (!watch_event_callback_.is_null()) |
| 644 watch_event_callback_.Run(); | 714 watch_event_callback_.Run(); |
| 645 } | 715 } |
| 646 | 716 |
| 647 } // namespace content | 717 } // namespace content |
| OLD | NEW |