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

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

Issue 1148393003: Implement Reactive Configuration in Background Tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase files depending on reactive config Created 5 years, 6 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 "base/macros.h" 7 #include "base/macros.h"
8 #include "base/time/time.h"
8 #include "content/public/browser/background_tracing_preemptive_config.h" 9 #include "content/public/browser/background_tracing_preemptive_config.h"
9 #include "content/public/browser/background_tracing_reactive_config.h" 10 #include "content/public/browser/background_tracing_reactive_config.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 namespace { 15 namespace {
15 16
16 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = 17 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller =
17 LAZY_INSTANCE_INITIALIZER; 18 LAZY_INSTANCE_INITIALIZER;
(...skipping 13 matching lines...) Expand all
31 void BackgroundTracingManagerImpl::TraceDataEndpointWrapper:: 32 void BackgroundTracingManagerImpl::TraceDataEndpointWrapper::
32 ReceiveTraceFinalContents(const std::string& file_contents) { 33 ReceiveTraceFinalContents(const std::string& file_contents) {
33 std::string tmp = file_contents; 34 std::string tmp = file_contents;
34 scoped_refptr<base::RefCountedString> contents_ptr = 35 scoped_refptr<base::RefCountedString> contents_ptr =
35 base::RefCountedString::TakeString(&tmp); 36 base::RefCountedString::TakeString(&tmp);
36 37
37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 38 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
38 base::Bind(done_callback_, contents_ptr)); 39 base::Bind(done_callback_, contents_ptr));
39 } 40 }
40 41
42 BackgroundTracingManagerImpl::TracingTimer::TracingTimer(
43 StartedFinalizingCallback callback) : callback_(callback) {
44 }
45
46 BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() {
47 }
48
49 void BackgroundTracingManagerImpl::TracingTimer::StartTimer() {
50 const int kTimeoutSecs = 10;
51 tracing_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeoutSecs),
52 this, &BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired);
53 }
54
55 void BackgroundTracingManagerImpl::TracingTimer::CancelTimer() {
56 tracing_timer_.Stop();
57 }
58
59 void BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired() {
60 BackgroundTracingManagerImpl::GetInstance()->BeginFinalizing(callback_);
61 }
62
63 void BackgroundTracingManagerImpl::TracingTimer::FireTimerForTesting() {
64 CancelTimer();
65 TracingTimerFired();
66 }
67
41 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { 68 BackgroundTracingManager* BackgroundTracingManager::GetInstance() {
42 return BackgroundTracingManagerImpl::GetInstance(); 69 return BackgroundTracingManagerImpl::GetInstance();
43 } 70 }
44 71
45 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { 72 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() {
46 return g_controller.Pointer(); 73 return g_controller.Pointer();
47 } 74 }
48 75
49 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() 76 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl()
50 : is_gathering_(false), 77 : is_gathering_(false),
(...skipping 14 matching lines...) Expand all
65 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 92 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
66 idle_callback_ = idle_callback; 93 idle_callback_ = idle_callback;
67 } 94 }
68 95
69 bool BackgroundTracingManagerImpl::IsSupportedConfig( 96 bool BackgroundTracingManagerImpl::IsSupportedConfig(
70 BackgroundTracingConfig* config) { 97 BackgroundTracingConfig* config) {
71 // No config is just fine, we just don't do anything. 98 // No config is just fine, we just don't do anything.
72 if (!config) 99 if (!config)
73 return true; 100 return true;
74 101
75 // TODO(simonhatch): Implement reactive tracing path. 102 if (config->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
76 if (config->mode != BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) 103 BackgroundTracingPreemptiveConfig* preemptive_config =
77 return false; 104 static_cast<BackgroundTracingPreemptiveConfig*>(config);
105 const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>&
106 configs = preemptive_config->configs;
107 for (size_t i = 0; i < configs.size(); ++i) {
108 if (configs[i].type !=
109 BackgroundTracingPreemptiveConfig::
110 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED)
111 return false;
112 }
113 }
78 114
79 // TODO(fmeawad): Implement uma triggers. 115 if (config->mode == BackgroundTracingConfig::REACTIVE_TRACING_MODE) {
80 BackgroundTracingPreemptiveConfig* preemptive_config = 116 BackgroundTracingReactiveConfig* reactive_config =
81 static_cast<BackgroundTracingPreemptiveConfig*>(config); 117 static_cast<BackgroundTracingReactiveConfig*>(config);
82 const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>& 118 const std::vector<BackgroundTracingReactiveConfig::TracingRule>&
83 configs = preemptive_config->configs; 119 configs = reactive_config->configs;
84 for (size_t i = 0; i < configs.size(); ++i) { 120 for (size_t i = 0; i < configs.size(); ++i) {
85 if (configs[i].type != 121 if (configs[i].type !=
86 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) 122 BackgroundTracingReactiveConfig::TRACE_FOR_10S_OR_TRIGGER_OR_FULL)
87 return false; 123 return false;
124 }
88 } 125 }
89 126
90 return true; 127 return true;
91 } 128 }
92 129
93 bool BackgroundTracingManagerImpl::SetActiveScenario( 130 bool BackgroundTracingManagerImpl::SetActiveScenario(
94 scoped_ptr<BackgroundTracingConfig> config, 131 scoped_ptr<BackgroundTracingConfig> config,
95 const BackgroundTracingManager::ReceiveCallback& receive_callback, 132 const BackgroundTracingManager::ReceiveCallback& receive_callback,
96 bool requires_anonymized_data) { 133 bool requires_anonymized_data) {
97 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 134 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 16 matching lines...) Expand all
114 return true; 151 return true;
115 } 152 }
116 153
117 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { 154 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() {
118 if (!config_) 155 if (!config_)
119 return; 156 return;
120 157
121 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { 158 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
122 EnableRecording(GetCategoryFilterStringForCategoryPreset( 159 EnableRecording(GetCategoryFilterStringForCategoryPreset(
123 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) 160 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get())
124 ->category_preset)); 161 ->category_preset),
125 } else { 162 base::trace_event::RECORD_CONTINUOUSLY);
126 // TODO(simonhatch): Implement reactive tracing path.
127 NOTREACHED();
128 } 163 }
164 // There is nothing to do in case of reactive tracing.
129 } 165 }
130 166
131 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( 167 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing(
132 TriggerHandle handle) const { 168 TriggerHandle handle) const {
133 if (!config_) 169 if (!config_)
134 return false; 170 return false;
135 171
136 // If the last trace is still uploading, we don't allow a new one to trigger. 172 // If the last trace is still uploading, we don't allow a new one to trigger.
137 if (is_gathering_) 173 if (is_gathering_)
138 return false; 174 return false;
(...skipping 14 matching lines...) Expand all
153 for (size_t i = 0; i < configs.size(); ++i) { 189 for (size_t i = 0; i < configs.size(); ++i) {
154 if (configs[i].type != BackgroundTracingPreemptiveConfig:: 190 if (configs[i].type != BackgroundTracingPreemptiveConfig::
155 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) 191 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED)
156 continue; 192 continue;
157 193
158 if (trigger_name == configs[i].named_trigger_info.trigger_name) { 194 if (trigger_name == configs[i].named_trigger_info.trigger_name) {
159 return true; 195 return true;
160 } 196 }
161 } 197 }
162 } else { 198 } else {
163 // TODO(simonhatch): Implement reactive path. 199 BackgroundTracingReactiveConfig* reactive_config =
164 NOTREACHED(); 200 static_cast<BackgroundTracingReactiveConfig*>(config_.get());
201
202 const std::vector<BackgroundTracingReactiveConfig::TracingRule>&
203 configs = reactive_config->configs;
204
205 for (size_t i = 0; i < configs.size(); ++i) {
206 if (configs[i].type !=
207 BackgroundTracingReactiveConfig::
208 TRACE_FOR_10S_OR_TRIGGER_OR_FULL)
209 continue;
210 if (trigger_name == configs[i].trigger_name) {
211 return true;
212 }
213 }
165 } 214 }
166
167 return false; 215 return false;
168 } 216 }
169 217
170 void BackgroundTracingManagerImpl::TriggerNamedEvent( 218 void BackgroundTracingManagerImpl::TriggerNamedEvent(
171 BackgroundTracingManagerImpl::TriggerHandle handle, 219 BackgroundTracingManagerImpl::TriggerHandle handle,
172 StartedFinalizingCallback callback) { 220 StartedFinalizingCallback callback) {
173 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { 221 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
174 content::BrowserThread::PostTask( 222 content::BrowserThread::PostTask(
175 content::BrowserThread::UI, FROM_HERE, 223 content::BrowserThread::UI, FROM_HERE,
176 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent, 224 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent,
177 base::Unretained(this), handle, callback)); 225 base::Unretained(this), handle, callback));
178 return; 226 return;
179 } 227 }
180 228
181 if (!IsAbleToTriggerTracing(handle)) { 229 if (!IsAbleToTriggerTracing(handle)) {
182 if (!callback.is_null()) 230 if (!callback.is_null())
183 callback.Run(false); 231 callback.Run(false);
184 return; 232 return;
185 } 233 }
186 234
187 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { 235 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
188 BeginFinalizing(callback); 236 BeginFinalizing(callback);
189 } else { 237 } else {
190 // TODO(simonhatch): Implement reactive tracing path. 238 if (is_tracing_) {
191 NOTREACHED(); 239 tracing_timer_->CancelTimer();
240 BeginFinalizing(callback);
241 return;
242 }
243
244 // It was not already tracing, start a new trace.
245 BackgroundTracingReactiveConfig* reactive_config =
246 static_cast<BackgroundTracingReactiveConfig*>(config_.get());
247 const std::vector<BackgroundTracingReactiveConfig::TracingRule>&
248 configs = reactive_config->configs;
249 std::string trigger_name = GetTriggerNameFromHandle(handle);
250 for (size_t i = 0; i < configs.size(); ++i) {
251 if (configs[i].trigger_name == trigger_name) {
252 EnableRecording(
253 GetCategoryFilterStringForCategoryPreset(
254 configs[i].category_preset),
255 base::trace_event::RECORD_UNTIL_FULL);
256 tracing_timer_.reset(new TracingTimer(callback));
257 tracing_timer_->StartTimer();
258 break;
259 }
260 }
192 } 261 }
193 } 262 }
194 263
195 BackgroundTracingManagerImpl::TriggerHandle 264 BackgroundTracingManagerImpl::TriggerHandle
196 BackgroundTracingManagerImpl::RegisterTriggerType(const char* trigger_name) { 265 BackgroundTracingManagerImpl::RegisterTriggerType(const char* trigger_name) {
197 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 266 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
198 267
199 trigger_handle_ids_ += 1; 268 trigger_handle_ids_ += 1;
200 269
201 trigger_handles_.insert( 270 trigger_handles_.insert(
(...skipping 18 matching lines...) Expand all
220 for (std::map<TriggerHandle, std::string>::iterator it = 289 for (std::map<TriggerHandle, std::string>::iterator it =
221 trigger_handles_.begin(); 290 trigger_handles_.begin();
222 it != trigger_handles_.end(); ++it) 291 it != trigger_handles_.end(); ++it)
223 trigger_names->push_back(it->second); 292 trigger_names->push_back(it->second);
224 } 293 }
225 294
226 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() { 295 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() {
227 trigger_handles_.clear(); 296 trigger_handles_.clear();
228 } 297 }
229 298
299 void BackgroundTracingManagerImpl::FireTimerForTesting() {
300 tracing_timer_->FireTimerForTesting();
301 }
302
230 void BackgroundTracingManagerImpl::EnableRecording( 303 void BackgroundTracingManagerImpl::EnableRecording(
231 std::string category_filter_str) { 304 std::string category_filter_str,
305 base::trace_event::TraceRecordMode record_mode) {
232 is_tracing_ = TracingController::GetInstance()->EnableRecording( 306 is_tracing_ = TracingController::GetInstance()->EnableRecording(
233 base::trace_event::TraceConfig(category_filter_str, 307 base::trace_event::TraceConfig(category_filter_str, record_mode),
234 base::trace_event::RECORD_CONTINUOUSLY),
235 TracingController::EnableRecordingDoneCallback()); 308 TracingController::EnableRecordingDoneCallback());
236 } 309 }
237 310
238 void BackgroundTracingManagerImpl::OnFinalizeStarted( 311 void BackgroundTracingManagerImpl::OnFinalizeStarted(
239 scoped_refptr<base::RefCountedString> file_contents) { 312 scoped_refptr<base::RefCountedString> file_contents) {
240 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 313 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
241 314
242 if (!receive_callback_.is_null()) 315 if (!receive_callback_.is_null())
243 receive_callback_.Run( 316 receive_callback_.Run(
244 file_contents.get(), 317 file_contents.get(),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 "disabled-by-default-toplevel.flow," 361 "disabled-by-default-toplevel.flow,"
289 "disabled-by-default-ipc.flow"; 362 "disabled-by-default-ipc.flow";
290 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: 363 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP:
291 return "*,disabled-by-default-blink.debug.layout"; 364 return "*,disabled-by-default-blink.debug.layout";
292 } 365 }
293 NOTREACHED(); 366 NOTREACHED();
294 return ""; 367 return "";
295 } 368 }
296 369
297 } // namspace content 370 } // 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