| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/background_tracing_manager_impl.h" | 5 #include "content/browser/tracing/background_tracing_manager_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 NOTREACHED(); | 94 NOTREACHED(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void BackgroundTracingManagerImpl::WhenIdle( | 97 void BackgroundTracingManagerImpl::WhenIdle( |
| 98 base::Callback<void()> idle_callback) { | 98 base::Callback<void()> idle_callback) { |
| 99 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 99 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 100 idle_callback_ = idle_callback; | 100 idle_callback_ = idle_callback; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool BackgroundTracingManagerImpl::SetActiveScenario( | 103 bool BackgroundTracingManagerImpl::SetActiveScenario( |
| 104 scoped_ptr<BackgroundTracingConfig> config, | 104 std::unique_ptr<BackgroundTracingConfig> config, |
| 105 const BackgroundTracingManager::ReceiveCallback& receive_callback, | 105 const BackgroundTracingManager::ReceiveCallback& receive_callback, |
| 106 DataFiltering data_filtering) { | 106 DataFiltering data_filtering) { |
| 107 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 107 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 108 RecordBackgroundTracingMetric(SCENARIO_ACTIVATION_REQUESTED); | 108 RecordBackgroundTracingMetric(SCENARIO_ACTIVATION_REQUESTED); |
| 109 | 109 |
| 110 if (is_tracing_) | 110 if (is_tracing_) |
| 111 return false; | 111 return false; |
| 112 | 112 |
| 113 // If we don't have a high resolution timer available, traces will be | 113 // If we don't have a high resolution timer available, traces will be |
| 114 // too inaccurate to be useful. | 114 // too inaccurate to be useful. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 129 *config.get(), requires_anonymized_data)) { | 129 *config.get(), requires_anonymized_data)) { |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 } else { | 132 } else { |
| 133 base::MessageLoop::current()->PostTask( | 133 base::MessageLoop::current()->PostTask( |
| 134 FROM_HERE, | 134 FROM_HERE, |
| 135 base::Bind(&BackgroundTracingManagerImpl::ValidateStartupScenario, | 135 base::Bind(&BackgroundTracingManagerImpl::ValidateStartupScenario, |
| 136 base::Unretained(this))); | 136 base::Unretained(this))); |
| 137 } | 137 } |
| 138 | 138 |
| 139 scoped_ptr<const content::BackgroundTracingConfigImpl> config_impl( | 139 std::unique_ptr<const content::BackgroundTracingConfigImpl> config_impl( |
| 140 static_cast<BackgroundTracingConfigImpl*>(config.release())); | 140 static_cast<BackgroundTracingConfigImpl*>(config.release())); |
| 141 | 141 |
| 142 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 142 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 143 | 143 |
| 144 if (config_impl) { | 144 if (config_impl) { |
| 145 // No point in tracing if there's nowhere to send it. | 145 // No point in tracing if there's nowhere to send it. |
| 146 if (receive_callback.is_null()) | 146 if (receive_callback.is_null()) |
| 147 return false; | 147 return false; |
| 148 | 148 |
| 149 // If the scenario requires us to toggle Blink features, we want | 149 // If the scenario requires us to toggle Blink features, we want |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 base::trace_event::TraceConfig trace_config(category_filter_str, record_mode); | 393 base::trace_event::TraceConfig trace_config(category_filter_str, record_mode); |
| 394 if (requires_anonymized_data_) | 394 if (requires_anonymized_data_) |
| 395 trace_config.EnableArgumentFilter(); | 395 trace_config.EnableArgumentFilter(); |
| 396 | 396 |
| 397 is_tracing_ = TracingController::GetInstance()->StartTracing( | 397 is_tracing_ = TracingController::GetInstance()->StartTracing( |
| 398 trace_config, tracing_enabled_callback_for_testing_); | 398 trace_config, tracing_enabled_callback_for_testing_); |
| 399 RecordBackgroundTracingMetric(RECORDING_ENABLED); | 399 RecordBackgroundTracingMetric(RECORDING_ENABLED); |
| 400 } | 400 } |
| 401 | 401 |
| 402 void BackgroundTracingManagerImpl::OnFinalizeStarted( | 402 void BackgroundTracingManagerImpl::OnFinalizeStarted( |
| 403 scoped_ptr<const base::DictionaryValue> metadata, | 403 std::unique_ptr<const base::DictionaryValue> metadata, |
| 404 base::RefCountedString* file_contents) { | 404 base::RefCountedString* file_contents) { |
| 405 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 405 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 406 | 406 |
| 407 RecordBackgroundTracingMetric(FINALIZATION_STARTED); | 407 RecordBackgroundTracingMetric(FINALIZATION_STARTED); |
| 408 UMA_HISTOGRAM_MEMORY_KB("Tracing.Background.FinalizingTraceSizeInKB", | 408 UMA_HISTOGRAM_MEMORY_KB("Tracing.Background.FinalizingTraceSizeInKB", |
| 409 file_contents->size() / 1024); | 409 file_contents->size() / 1024); |
| 410 | 410 |
| 411 if (!receive_callback_.is_null()) { | 411 if (!receive_callback_.is_null()) { |
| 412 receive_callback_.Run( | 412 receive_callback_.Run( |
| 413 file_contents, std::move(metadata), | 413 file_contents, std::move(metadata), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 AbortScenario(); | 445 AbortScenario(); |
| 446 } | 446 } |
| 447 | 447 |
| 448 RecordBackgroundTracingMetric(FINALIZATION_COMPLETE); | 448 RecordBackgroundTracingMetric(FINALIZATION_COMPLETE); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void BackgroundTracingManagerImpl::AddCustomMetadata( | 451 void BackgroundTracingManagerImpl::AddCustomMetadata( |
| 452 TracingControllerImpl::TraceDataSink* trace_data_sink) const { | 452 TracingControllerImpl::TraceDataSink* trace_data_sink) const { |
| 453 base::DictionaryValue metadata_dict; | 453 base::DictionaryValue metadata_dict; |
| 454 | 454 |
| 455 scoped_ptr<base::DictionaryValue> config_dict(new base::DictionaryValue()); | 455 std::unique_ptr<base::DictionaryValue> config_dict( |
| 456 new base::DictionaryValue()); |
| 456 config_->IntoDict(config_dict.get()); | 457 config_->IntoDict(config_dict.get()); |
| 457 metadata_dict.Set("config", std::move(config_dict)); | 458 metadata_dict.Set("config", std::move(config_dict)); |
| 458 | 459 |
| 459 trace_data_sink->AddMetadata(metadata_dict); | 460 trace_data_sink->AddMetadata(metadata_dict); |
| 460 } | 461 } |
| 461 | 462 |
| 462 void BackgroundTracingManagerImpl::BeginFinalizing( | 463 void BackgroundTracingManagerImpl::BeginFinalizing( |
| 463 StartedFinalizingCallback callback) { | 464 StartedFinalizingCallback callback) { |
| 464 is_gathering_ = true; | 465 is_gathering_ = true; |
| 465 is_tracing_ = false; | 466 is_tracing_ = false; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_BLINK_GC: | 519 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_BLINK_GC: |
| 519 return "blink_gc,disabled-by-default-blink_gc"; | 520 return "blink_gc,disabled-by-default-blink_gc"; |
| 520 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE: | 521 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE: |
| 521 return "blink_style"; | 522 return "blink_style"; |
| 522 } | 523 } |
| 523 NOTREACHED(); | 524 NOTREACHED(); |
| 524 return ""; | 525 return ""; |
| 525 } | 526 } |
| 526 | 527 |
| 527 } // namspace content | 528 } // namspace content |
| OLD | NEW |