OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/metrics/profiler/tracking_synchronizer.h" | 5 #include "components/metrics/profiler/tracking_synchronizer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "base/tracked_objects.h" | 10 #include "base/tracked_objects.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 callback_object); | 211 callback_object); |
212 | 212 |
213 // Post a task that would be called after waiting for wait_time. This acts | 213 // Post a task that would be called after waiting for wait_time. This acts |
214 // as a watchdog, to cancel the requests for non-responsive processes. | 214 // as a watchdog, to cancel the requests for non-responsive processes. |
215 BrowserThread::PostDelayedTask( | 215 BrowserThread::PostDelayedTask( |
216 BrowserThread::UI, FROM_HERE, | 216 BrowserThread::UI, FROM_HERE, |
217 base::Bind(&RequestContext::Unregister, sequence_number), | 217 base::Bind(&RequestContext::Unregister, sequence_number), |
218 base::TimeDelta::FromMinutes(1)); | 218 base::TimeDelta::FromMinutes(1)); |
219 } | 219 } |
220 | 220 |
| 221 // static |
| 222 void TrackingSynchronizer::OnProfilingPhaseCompletion( |
| 223 ProfilerEventProto::ProfilerEvent profiling_event) { |
| 224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 225 |
| 226 if (!g_tracking_synchronizer) { |
| 227 // System teardown is happening. |
| 228 return; |
| 229 } |
| 230 |
| 231 g_tracking_synchronizer->NotifyAllProcessesOfProfilingPhaseCompletion( |
| 232 profiling_event); |
| 233 } |
| 234 |
221 void TrackingSynchronizer::OnPendingProcesses(int sequence_number, | 235 void TrackingSynchronizer::OnPendingProcesses(int sequence_number, |
222 int pending_processes, | 236 int pending_processes, |
223 bool end) { | 237 bool end) { |
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
225 | 239 |
226 RequestContext* request = RequestContext::GetRequestContext(sequence_number); | 240 RequestContext* request = RequestContext::GetRequestContext(sequence_number); |
227 if (!request) | 241 if (!request) |
228 return; | 242 return; |
229 request->AddProcessesPending(pending_processes); | 243 request->AddProcessesPending(pending_processes); |
230 request->SetReceivedProcessGroupCount(end); | 244 request->SetReceivedProcessGroupCount(end); |
(...skipping 14 matching lines...) Expand all Loading... |
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
246 | 260 |
247 int sequence_number = GetNextAvailableSequenceNumber(); | 261 int sequence_number = GetNextAvailableSequenceNumber(); |
248 | 262 |
249 RequestContext* request = | 263 RequestContext* request = |
250 RequestContext::Register(sequence_number, callback_object); | 264 RequestContext::Register(sequence_number, callback_object); |
251 | 265 |
252 // Increment pending process count for sending browser's profiler data. | 266 // Increment pending process count for sending browser's profiler data. |
253 request->IncrementProcessesPending(); | 267 request->IncrementProcessesPending(); |
254 | 268 |
| 269 int current_profiling_phase = phase_completion_events_sequence_.size(); |
| 270 |
255 // Get profiler data from renderer and browser child processes. | 271 // Get profiler data from renderer and browser child processes. |
256 content::ProfilerController::GetInstance()->GetProfilerData(sequence_number); | 272 content::ProfilerController::GetInstance()->GetProfilerData( |
| 273 sequence_number, current_profiling_phase); |
257 | 274 |
258 // Send process data snapshot from browser process. | 275 // Send process data snapshot from browser process. |
259 tracked_objects::ProcessDataSnapshot process_data_snapshot; | 276 tracked_objects::ProcessDataSnapshot process_data_snapshot; |
260 tracked_objects::ThreadData::Snapshot(&process_data_snapshot); | 277 tracked_objects::ThreadData::Snapshot(current_profiling_phase, |
| 278 &process_data_snapshot); |
| 279 |
261 DecrementPendingProcessesAndSendData(sequence_number, process_data_snapshot, | 280 DecrementPendingProcessesAndSendData(sequence_number, process_data_snapshot, |
262 content::PROCESS_TYPE_BROWSER); | 281 content::PROCESS_TYPE_BROWSER); |
263 | 282 |
264 return sequence_number; | 283 return sequence_number; |
265 } | 284 } |
266 | 285 |
| 286 void TrackingSynchronizer::RegisterPhaseCompletion( |
| 287 ProfilerEventProto::ProfilerEvent profiling_event, |
| 288 const base::TimeTicks& now) { |
| 289 phase_completion_events_sequence_.push_back(profiling_event); |
| 290 phase_start_times_.push_back(now); |
| 291 } |
| 292 |
| 293 void TrackingSynchronizer::NotifyAllProcessesOfProfilingPhaseCompletion( |
| 294 ProfilerEventProto::ProfilerEvent profiling_event) { |
| 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 296 |
| 297 if (variations::GetVariationParamValue("UMALogUploadInterval", |
| 298 "send_split_profiles") != "true") { |
| 299 return; |
| 300 } |
| 301 |
| 302 int profiling_phase = phase_completion_events_sequence_.size(); |
| 303 |
| 304 RegisterPhaseCompletion(profiling_event, base::TimeTicks::Now()); |
| 305 |
| 306 // Notify renderer and browser child processes. |
| 307 content::ProfilerController::GetInstance()->OnProfilingPhaseCompletion( |
| 308 profiling_phase); |
| 309 |
| 310 // Notify browser process. |
| 311 tracked_objects::ThreadData::OnProfilingPhaseCompletion(profiling_phase); |
| 312 } |
| 313 |
267 void TrackingSynchronizer::SendData( | 314 void TrackingSynchronizer::SendData( |
268 const tracked_objects::ProcessDataSnapshot& profiler_data, | 315 const tracked_objects::ProcessDataSnapshot& profiler_data, |
269 content::ProcessType process_type, | 316 content::ProcessType process_type, |
270 const base::TimeTicks& now, | 317 const base::TimeTicks& now, |
271 TrackingSynchronizerObserver* observer) const { | 318 TrackingSynchronizerObserver* observer) const { |
272 // We are going to loop though past profiling phases and notify the request | 319 // We are going to loop though past profiling phases and notify the request |
273 // about each phase that is contained in profiler_data. past_events | 320 // about each phase that is contained in profiler_data. past_events |
274 // will track the set of past profiling events as we go. | 321 // will track the set of past profiling events as we go. |
275 ProfilerEvents past_events; | 322 ProfilerEvents past_events; |
276 | 323 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 372 |
326 ++last_used_sequence_number_; | 373 ++last_used_sequence_number_; |
327 | 374 |
328 // Watch out for wrapping to a negative number. | 375 // Watch out for wrapping to a negative number. |
329 if (last_used_sequence_number_ < 0) | 376 if (last_used_sequence_number_ < 0) |
330 last_used_sequence_number_ = 1; | 377 last_used_sequence_number_ = 1; |
331 return last_used_sequence_number_; | 378 return last_used_sequence_number_; |
332 } | 379 } |
333 | 380 |
334 } // namespace metrics | 381 } // namespace metrics |
OLD | NEW |