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

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

Issue 2785663002: Revert of Add EnabledStateObserver to BackgroundTracingManager (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "content/browser/tracing/background_memory_tracing_observer.h"
19 #include "content/browser/tracing/background_tracing_rule.h" 18 #include "content/browser/tracing/background_tracing_rule.h"
20 #include "content/browser/tracing/tracing_controller_impl.h" 19 #include "content/browser/tracing/tracing_controller_impl.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/content_browser_client.h" 21 #include "content/public/browser/content_browser_client.h"
23 #include "content/public/browser/tracing_delegate.h" 22 #include "content/public/browser/tracing_delegate.h"
24 #include "content/public/common/content_client.h" 23 #include "content/public/common/content_client.h"
25 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
26 25
27 namespace content { 26 namespace content {
28 27
(...skipping 15 matching lines...) Expand all
44 FINALIZATION_COMPLETE = 8, 43 FINALIZATION_COMPLETE = 8,
45 SCENARIO_ACTION_FAILED_LOWRES_CLOCK = 9, 44 SCENARIO_ACTION_FAILED_LOWRES_CLOCK = 9,
46 NUMBER_OF_BACKGROUND_TRACING_METRICS, 45 NUMBER_OF_BACKGROUND_TRACING_METRICS,
47 }; 46 };
48 47
49 void RecordBackgroundTracingMetric(BackgroundTracingMetrics metric) { 48 void RecordBackgroundTracingMetric(BackgroundTracingMetrics metric) {
50 UMA_HISTOGRAM_ENUMERATION("Tracing.Background.ScenarioState", metric, 49 UMA_HISTOGRAM_ENUMERATION("Tracing.Background.ScenarioState", metric,
51 NUMBER_OF_BACKGROUND_TRACING_METRICS); 50 NUMBER_OF_BACKGROUND_TRACING_METRICS);
52 } 51 }
53 52
53 // Tracing enabled callback for BENCHMARK_MEMORY_LIGHT category preset.
54 void BenchmarkMemoryLight_TracingEnabledCallback() {
55 auto* dump_manager = base::trace_event::MemoryDumpManager::GetInstance();
56 dump_manager->RequestGlobalDump(
57 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED,
58 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND);
59 }
60
54 } // namespace 61 } // namespace
55 62
56 BackgroundTracingManagerImpl::TracingTimer::TracingTimer( 63 BackgroundTracingManagerImpl::TracingTimer::TracingTimer(
57 StartedFinalizingCallback callback) : callback_(callback) { 64 StartedFinalizingCallback callback) : callback_(callback) {
58 } 65 }
59 66
60 BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() { 67 BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() {
61 } 68 }
62 69
63 void BackgroundTracingManagerImpl::TracingTimer::StartTimer(int seconds) { 70 void BackgroundTracingManagerImpl::TracingTimer::StartTimer(int seconds) {
(...skipping 22 matching lines...) Expand all
86 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { 93 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() {
87 return g_controller.Pointer(); 94 return g_controller.Pointer();
88 } 95 }
89 96
90 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() 97 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl()
91 : delegate_(GetContentClient()->browser()->GetTracingDelegate()), 98 : delegate_(GetContentClient()->browser()->GetTracingDelegate()),
92 is_gathering_(false), 99 is_gathering_(false),
93 is_tracing_(false), 100 is_tracing_(false),
94 requires_anonymized_data_(true), 101 requires_anonymized_data_(true),
95 trigger_handle_ids_(0), 102 trigger_handle_ids_(0),
96 triggered_named_event_handle_(-1) { 103 triggered_named_event_handle_(-1) {}
97 AddEnabledStateObserver(BackgroundMemoryTracingObserver::GetInstance());
98 }
99 104
100 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() { 105 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() {
101 NOTREACHED(); 106 NOTREACHED();
102 } 107 }
103 108
104 void BackgroundTracingManagerImpl::WhenIdle( 109 void BackgroundTracingManagerImpl::WhenIdle(
105 base::Callback<void()> idle_callback) { 110 base::Callback<void()> idle_callback) {
106 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 111 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
107 idle_callback_ = idle_callback; 112 idle_callback_ = idle_callback;
108 } 113 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, 186 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
182 config_->enable_blink_features()); 187 config_->enable_blink_features());
183 } 188 }
184 189
185 if (!config_->disable_blink_features().empty()) { 190 if (!config_->disable_blink_features().empty()) {
186 command_line->AppendSwitchASCII(switches::kDisableBlinkFeatures, 191 command_line->AppendSwitchASCII(switches::kDisableBlinkFeatures,
187 config_->disable_blink_features()); 192 config_->disable_blink_features());
188 } 193 }
189 } 194 }
190 195
191 // Notify observers before starting tracing. 196 StartTracingIfConfigNeedsIt();
192 for (auto* observer : background_tracing_observer_list_)
193 observer->OnScenarioActivated(*config_);
194 197
195 StartTracingIfConfigNeedsIt();
196 RecordBackgroundTracingMetric(SCENARIO_ACTIVATED_SUCCESSFULLY); 198 RecordBackgroundTracingMetric(SCENARIO_ACTIVATED_SUCCESSFULLY);
197 return true; 199 return true;
198 } 200 }
199 201
200 bool BackgroundTracingManagerImpl::HasActiveScenario() { 202 bool BackgroundTracingManagerImpl::HasActiveScenario() {
201 return !!config_; 203 return !!config_;
202 } 204 }
203 205
204 void BackgroundTracingManagerImpl::OnStartTracingDone(
205 BackgroundTracingConfigImpl::CategoryPreset preset) {
206 DCHECK(BrowserThread::CurrentlyOn(content::BrowserThread::UI));
207 for (auto* observer : background_tracing_observer_list_)
208 observer->OnTracingEnabled(preset);
209 }
210
211 void BackgroundTracingManagerImpl::AddEnabledStateObserver(
212 EnabledStateObserver* observer) {
213 DCHECK(BrowserThread::CurrentlyOn(content::BrowserThread::UI));
214 background_tracing_observer_list_.push_back(observer);
215 }
216
217 void BackgroundTracingManagerImpl::RemoveEnabledStateObserver(
218 EnabledStateObserver* observer) {
219 DCHECK(BrowserThread::CurrentlyOn(content::BrowserThread::UI));
220 std::vector<EnabledStateObserver*>::iterator it =
221 std::find(background_tracing_observer_list_.begin(),
222 background_tracing_observer_list_.end(), observer);
223 if (it != background_tracing_observer_list_.end())
224 background_tracing_observer_list_.erase(it);
225 }
226
227 bool BackgroundTracingManagerImpl::IsTracingForTesting() { 206 bool BackgroundTracingManagerImpl::IsTracingForTesting() {
228 return is_tracing_; 207 return is_tracing_;
229 } 208 }
230 209
231 void BackgroundTracingManagerImpl::ValidateStartupScenario() { 210 void BackgroundTracingManagerImpl::ValidateStartupScenario() {
232 if (!config_ || !delegate_) 211 if (!config_ || !delegate_)
233 return; 212 return;
234 213
235 if (!delegate_->IsAllowedToBeginBackgroundScenario( 214 if (!delegate_->IsAllowedToBeginBackgroundScenario(
236 *config_.get(), requires_anonymized_data_)) { 215 *config_.get(), requires_anonymized_data_)) {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 std::string BackgroundTracingManagerImpl::GetTriggerNameFromHandle( 383 std::string BackgroundTracingManagerImpl::GetTriggerNameFromHandle(
405 BackgroundTracingManager::TriggerHandle handle) const { 384 BackgroundTracingManager::TriggerHandle handle) const {
406 CHECK(IsTriggerHandleValid(handle)); 385 CHECK(IsTriggerHandleValid(handle));
407 return trigger_handles_.find(handle)->second; 386 return trigger_handles_.find(handle)->second;
408 } 387 }
409 388
410 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() { 389 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() {
411 trigger_handles_.clear(); 390 trigger_handles_.clear();
412 } 391 }
413 392
393 void BackgroundTracingManagerImpl::SetTracingEnabledCallbackForTesting(
394 const base::Closure& callback) {
395 tracing_enabled_callback_for_testing_ = callback;
396 };
397
414 void BackgroundTracingManagerImpl::SetRuleTriggeredCallbackForTesting( 398 void BackgroundTracingManagerImpl::SetRuleTriggeredCallbackForTesting(
415 const base::Closure& callback) { 399 const base::Closure& callback) {
416 rule_triggered_callback_for_testing_ = callback; 400 rule_triggered_callback_for_testing_ = callback;
417 }; 401 };
418 402
419 void BackgroundTracingManagerImpl::FireTimerForTesting() { 403 void BackgroundTracingManagerImpl::FireTimerForTesting() {
420 DCHECK(tracing_timer_); 404 DCHECK(tracing_timer_);
421 tracing_timer_->FireTimerForTesting(); 405 tracing_timer_->FireTimerForTesting();
422 } 406 }
423 407
424 void BackgroundTracingManagerImpl::StartTracing( 408 void BackgroundTracingManagerImpl::StartTracing(
425 BackgroundTracingConfigImpl::CategoryPreset preset, 409 BackgroundTracingConfigImpl::CategoryPreset preset,
426 base::trace_event::TraceRecordMode record_mode) { 410 base::trace_event::TraceRecordMode record_mode) {
427 base::trace_event::TraceConfig trace_config( 411 base::trace_event::TraceConfig trace_config(
428 GetCategoryFilterStringForCategoryPreset(preset), record_mode); 412 GetCategoryFilterStringForCategoryPreset(preset), record_mode);
429 if (requires_anonymized_data_) 413 if (requires_anonymized_data_)
430 trace_config.EnableArgumentFilter(); 414 trace_config.EnableArgumentFilter();
431 415
432 if (preset == 416 base::Closure tracing_enabled_callback;
433 BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_MEMORY_LIGHT) { 417 if (!tracing_enabled_callback_for_testing_.is_null()) {
434 // On memory light mode, the periodic memory dumps are disabled. 418 tracing_enabled_callback = tracing_enabled_callback_for_testing_;
435 // TODO(ssid): Remove this when memory-infra supports peak detection 419 } else if (preset == BackgroundTracingConfigImpl::CategoryPreset::
436 // crbug.com/609935. 420 BENCHMARK_MEMORY_LIGHT) {
421 // On memory light mode, the periodic memory dumps are disabled and a single
422 // memory dump is requested after tracing is enabled in all the processes.
423 // TODO(ssid): Remove this when background tracing supports trace config
424 // strings and memory-infra supports peak detection crbug.com/609935.
437 base::trace_event::TraceConfig::MemoryDumpConfig memory_config; 425 base::trace_event::TraceConfig::MemoryDumpConfig memory_config;
438 memory_config.allowed_dump_modes = 426 memory_config.allowed_dump_modes =
439 std::set<base::trace_event::MemoryDumpLevelOfDetail>( 427 std::set<base::trace_event::MemoryDumpLevelOfDetail>(
440 {base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND}); 428 {base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND});
441 trace_config.ResetMemoryDumpConfig(memory_config); 429 trace_config.ResetMemoryDumpConfig(memory_config);
430 tracing_enabled_callback =
431 base::Bind(&BenchmarkMemoryLight_TracingEnabledCallback);
442 } 432 }
443 433
444 is_tracing_ = TracingController::GetInstance()->StartTracing( 434 is_tracing_ = TracingController::GetInstance()->StartTracing(
445 trace_config, 435 trace_config, tracing_enabled_callback);
446 base::Bind(&BackgroundTracingManagerImpl::OnStartTracingDone,
447 base::Unretained(this), preset));
448 RecordBackgroundTracingMetric(RECORDING_ENABLED); 436 RecordBackgroundTracingMetric(RECORDING_ENABLED);
449 } 437 }
450 438
451 void BackgroundTracingManagerImpl::OnFinalizeStarted( 439 void BackgroundTracingManagerImpl::OnFinalizeStarted(
452 std::unique_ptr<const base::DictionaryValue> metadata, 440 std::unique_ptr<const base::DictionaryValue> metadata,
453 base::RefCountedString* file_contents) { 441 base::RefCountedString* file_contents) {
454 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 442 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
455 443
456 RecordBackgroundTracingMetric(FINALIZATION_STARTED); 444 RecordBackgroundTracingMetric(FINALIZATION_STARTED);
457 UMA_HISTOGRAM_MEMORY_KB("Tracing.Background.FinalizingTraceSizeInKB", 445 UMA_HISTOGRAM_MEMORY_KB("Tracing.Background.FinalizingTraceSizeInKB",
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE: 566 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE:
579 return "blink_style"; 567 return "blink_style";
580 case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET: 568 case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET:
581 NOTREACHED(); 569 NOTREACHED();
582 } 570 }
583 NOTREACHED(); 571 NOTREACHED();
584 return ""; 572 return "";
585 } 573 }
586 574
587 } // namspace content 575 } // namspace content
OLDNEW
« no previous file with comments | « content/browser/tracing/background_tracing_manager_impl.h ('k') | content/public/browser/background_tracing_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698