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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 callback_object); | 220 callback_object); |
221 | 221 |
222 // Post a task that would be called after waiting for wait_time. This acts | 222 // Post a task that would be called after waiting for wait_time. This acts |
223 // as a watchdog, to cancel the requests for non-responsive processes. | 223 // as a watchdog, to cancel the requests for non-responsive processes. |
224 BrowserThread::PostDelayedTask( | 224 BrowserThread::PostDelayedTask( |
225 BrowserThread::UI, FROM_HERE, | 225 BrowserThread::UI, FROM_HERE, |
226 base::Bind(&RequestContext::Unregister, sequence_number), | 226 base::Bind(&RequestContext::Unregister, sequence_number), |
227 base::TimeDelta::FromMinutes(1)); | 227 base::TimeDelta::FromMinutes(1)); |
228 } | 228 } |
229 | 229 |
230 // static | |
231 void TrackingSynchronizer::OnProfilingPhaseCompletion( | |
232 ProfilerEventProto::ProfilerEvent profiling_event) { | |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
Ilya Sherman
2015/04/07 01:15:30
Throughout, please use DCHECK_CURRENTLY_ON
vadimt
2015/04/07 21:44:14
Done.
| |
234 | |
235 if (!g_tracking_synchronizer) { | |
236 // System teardown is happening. | |
237 return; | |
238 } | |
239 | |
240 g_tracking_synchronizer->NotifyAllProcessesOfProfilingPhaseCompletion( | |
241 profiling_event); | |
242 } | |
243 | |
230 void TrackingSynchronizer::OnPendingProcesses(int sequence_number, | 244 void TrackingSynchronizer::OnPendingProcesses(int sequence_number, |
231 int pending_processes, | 245 int pending_processes, |
232 bool end) { | 246 bool end) { |
233 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 247 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
234 | 248 |
235 RequestContext* request = RequestContext::GetRequestContext(sequence_number); | 249 RequestContext* request = RequestContext::GetRequestContext(sequence_number); |
236 if (!request) | 250 if (!request) |
237 return; | 251 return; |
238 request->AddProcessesPending(pending_processes); | 252 request->AddProcessesPending(pending_processes); |
239 request->SetReceivedProcessGroupCount(end); | 253 request->SetReceivedProcessGroupCount(end); |
(...skipping 14 matching lines...) Expand all Loading... | |
254 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 268 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
255 | 269 |
256 int sequence_number = GetNextAvailableSequenceNumber(); | 270 int sequence_number = GetNextAvailableSequenceNumber(); |
257 | 271 |
258 RequestContext* request = | 272 RequestContext* request = |
259 RequestContext::Register(sequence_number, callback_object); | 273 RequestContext::Register(sequence_number, callback_object); |
260 | 274 |
261 // Increment pending process count for sending browser's profiler data. | 275 // Increment pending process count for sending browser's profiler data. |
262 request->IncrementProcessesPending(); | 276 request->IncrementProcessesPending(); |
263 | 277 |
278 int current_profiling_phase = phase_completion_events_sequence_.size(); | |
279 | |
264 #if !defined(OS_IOS) | 280 #if !defined(OS_IOS) |
265 // Get profiler data from renderer and browser child processes. | 281 // Get profiler data from renderer and browser child processes. |
266 content::ProfilerController::GetInstance()->GetProfilerData(sequence_number); | 282 content::ProfilerController::GetInstance()->GetProfilerData( |
283 sequence_number, current_profiling_phase); | |
267 #endif | 284 #endif |
268 | 285 |
269 // Send process data snapshot from browser process. | 286 // Send process data snapshot from browser process. |
270 tracked_objects::ProcessDataSnapshot process_data_snapshot; | 287 tracked_objects::ProcessDataSnapshot process_data_snapshot; |
271 tracked_objects::ThreadData::Snapshot(&process_data_snapshot); | 288 tracked_objects::ThreadData::Snapshot(current_profiling_phase, |
289 &process_data_snapshot); | |
290 | |
272 DecrementPendingProcessesAndSendData(sequence_number, process_data_snapshot, | 291 DecrementPendingProcessesAndSendData(sequence_number, process_data_snapshot, |
273 content::PROCESS_TYPE_BROWSER); | 292 content::PROCESS_TYPE_BROWSER); |
274 | 293 |
275 return sequence_number; | 294 return sequence_number; |
276 } | 295 } |
277 | 296 |
297 void TrackingSynchronizer::RegisterPhaseCompletion( | |
298 ProfilerEventProto::ProfilerEvent profiling_event, | |
299 base::TimeTicks now) { | |
300 phase_completion_events_sequence_.push_back(profiling_event); | |
301 phase_start_times_.push_back(now); | |
302 } | |
303 | |
304 void TrackingSynchronizer::NotifyAllProcessesOfProfilingPhaseCompletion( | |
305 ProfilerEventProto::ProfilerEvent profiling_event) { | |
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
307 | |
308 if (variations::GetVariationParamValue("UMALogUploadInterval", | |
309 "send_split_profiles") != "true") { | |
310 return; | |
311 } | |
312 | |
313 int profiling_phase = phase_completion_events_sequence_.size(); | |
314 | |
315 RegisterPhaseCompletion(profiling_event, base::TimeTicks::Now()); | |
316 | |
317 #if !defined(OS_IOS) | |
318 // Notify renderer and browser child processes. | |
319 content::ProfilerController::GetInstance()->OnProfilingPhaseCompletion( | |
320 profiling_phase); | |
321 #endif | |
322 | |
323 // Notify browser process. | |
324 tracked_objects::ThreadData::OnProfilingPhaseCompletion(profiling_phase); | |
325 } | |
326 | |
278 void TrackingSynchronizer::SendData( | 327 void TrackingSynchronizer::SendData( |
279 const tracked_objects::ProcessDataSnapshot& profiler_data, | 328 const tracked_objects::ProcessDataSnapshot& profiler_data, |
280 content::ProcessType process_type, | 329 content::ProcessType process_type, |
281 base::TimeTicks now, | 330 base::TimeTicks now, |
282 TrackingSynchronizerObserver* observer) const { | 331 TrackingSynchronizerObserver* observer) const { |
283 // We are going to loop though past profiling phases and notify the request | 332 // We are going to loop though past profiling phases and notify the request |
284 // about each phase that is contained in profiler_data. past_events | 333 // about each phase that is contained in profiler_data. past_events |
285 // will track the set of past profiling events as we go. | 334 // will track the set of past profiling events as we go. |
286 ProfilerEvents past_events; | 335 ProfilerEvents past_events; |
287 | 336 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 | 385 |
337 ++last_used_sequence_number_; | 386 ++last_used_sequence_number_; |
338 | 387 |
339 // Watch out for wrapping to a negative number. | 388 // Watch out for wrapping to a negative number. |
340 if (last_used_sequence_number_ < 0) | 389 if (last_used_sequence_number_ < 0) |
341 last_used_sequence_number_ = 1; | 390 last_used_sequence_number_ = 1; |
342 return last_used_sequence_number_; | 391 return last_used_sequence_number_; |
343 } | 392 } |
344 | 393 |
345 } // namespace metrics | 394 } // namespace metrics |
OLD | NEW |