Chromium Code Reviews| 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" |
| 11 #include "components/metrics/profiler/tracking_synchronizer_observer.h" | 11 #include "components/metrics/profiler/tracking_synchronizer_observer.h" |
| 12 #include "components/variations/variations_associated_data.h" | |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/profiler_controller.h" | 14 #include "content/public/browser/profiler_controller.h" |
| 14 #include "content/public/common/process_type.h" | 15 #include "content/public/common/process_type.h" |
| 15 | 16 |
| 16 using base::TimeTicks; | 17 using base::TimeTicks; |
| 17 using content::BrowserThread; | 18 using content::BrowserThread; |
| 18 | 19 |
| 19 namespace metrics { | 20 namespace metrics { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 174 |
| 174 // static | 175 // static |
| 175 base::LazyInstance | 176 base::LazyInstance |
| 176 <TrackingSynchronizer::RequestContext::RequestContextMap>::Leaky | 177 <TrackingSynchronizer::RequestContext::RequestContextMap>::Leaky |
| 177 TrackingSynchronizer::RequestContext::outstanding_requests_ = | 178 TrackingSynchronizer::RequestContext::outstanding_requests_ = |
| 178 LAZY_INSTANCE_INITIALIZER; | 179 LAZY_INSTANCE_INITIALIZER; |
| 179 | 180 |
| 180 // TrackingSynchronizer methods and members. | 181 // TrackingSynchronizer methods and members. |
| 181 | 182 |
| 182 TrackingSynchronizer::TrackingSynchronizer() | 183 TrackingSynchronizer::TrackingSynchronizer() |
| 183 : last_used_sequence_number_(kNeverUsableSequenceNumber) { | 184 : last_used_sequence_number_(kNeverUsableSequenceNumber), |
| 185 start_time_(base::TimeTicks::Now()) { | |
| 184 DCHECK(!g_tracking_synchronizer); | 186 DCHECK(!g_tracking_synchronizer); |
| 185 g_tracking_synchronizer = this; | 187 g_tracking_synchronizer = this; |
| 188 phase_start_times_.push_back(base::TimeTicks::Now()); | |
| 186 content::ProfilerController::GetInstance()->Register(this); | 189 content::ProfilerController::GetInstance()->Register(this); |
| 187 } | 190 } |
| 188 | 191 |
| 189 TrackingSynchronizer::~TrackingSynchronizer() { | 192 TrackingSynchronizer::~TrackingSynchronizer() { |
| 190 content::ProfilerController::GetInstance()->Unregister(this); | 193 content::ProfilerController::GetInstance()->Unregister(this); |
| 191 | 194 |
| 192 // Just in case we have any pending tasks, clear them out. | 195 // Just in case we have any pending tasks, clear them out. |
| 193 RequestContext::OnShutdown(); | 196 RequestContext::OnShutdown(); |
| 194 | 197 |
| 195 g_tracking_synchronizer = NULL; | 198 g_tracking_synchronizer = NULL; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 249 |
| 247 RequestContext* request = | 250 RequestContext* request = |
| 248 RequestContext::Register(sequence_number, callback_object); | 251 RequestContext::Register(sequence_number, callback_object); |
| 249 | 252 |
| 250 // Increment pending process count for sending browser's profiler data. | 253 // Increment pending process count for sending browser's profiler data. |
| 251 request->IncrementProcessesPending(); | 254 request->IncrementProcessesPending(); |
| 252 | 255 |
| 253 // Get profiler data from renderer and browser child processes. | 256 // Get profiler data from renderer and browser child processes. |
| 254 content::ProfilerController::GetInstance()->GetProfilerData(sequence_number); | 257 content::ProfilerController::GetInstance()->GetProfilerData(sequence_number); |
| 255 | 258 |
| 256 // Send profiler_data from browser process. | 259 // Send process_data_snapshot from browser process. |
|
Alexei Svitkine (slow)
2015/03/09 17:13:35
Nit: surround in |'s or remove _'s.
vadimt
2015/03/13 23:18:01
Done.
| |
| 257 tracked_objects::ProcessDataSnapshot process_data; | 260 tracked_objects::ProcessDataSnapshot process_data_snapshot; |
| 258 tracked_objects::ThreadData::Snapshot(&process_data); | 261 tracked_objects::ThreadData::GetProcessDataSnapshot(&process_data_snapshot); |
| 259 DecrementPendingProcessesAndSendData(sequence_number, process_data, | 262 DecrementPendingProcessesAndSendData(sequence_number, process_data_snapshot, |
| 260 content::PROCESS_TYPE_BROWSER); | 263 content::PROCESS_TYPE_BROWSER); |
| 261 | 264 |
| 262 return sequence_number; | 265 return sequence_number; |
| 263 } | 266 } |
| 264 | 267 |
| 265 void TrackingSynchronizer::DecrementPendingProcessesAndSendData( | 268 void TrackingSynchronizer::DecrementPendingProcessesAndSendData( |
| 266 int sequence_number, | 269 int sequence_number, |
| 267 const tracked_objects::ProcessDataSnapshot& profiler_data, | 270 const tracked_objects::ProcessDataSnapshot& profiler_data, |
| 268 int process_type) { | 271 int process_type) { |
| 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 270 | 273 |
| 271 RequestContext* request = RequestContext::GetRequestContext(sequence_number); | 274 RequestContext* request = RequestContext::GetRequestContext(sequence_number); |
| 272 if (!request) | 275 if (!request) |
| 273 return; | 276 return; |
| 274 | 277 |
| 275 if (request->callback_object_.get()) { | 278 if (request->callback_object_.get()) { |
| 276 request->callback_object_ | 279 // We are going to loop though past profiling phases and notify the request |
| 277 ->ReceivedProfilerData(profiler_data, process_type); | 280 // about each phase that is contained in profiler_data. past_profiler_events |
| 281 // will track the set of past profiling events as we go. | |
| 282 ProfilerEventsSet past_profiler_events; | |
| 283 | |
| 284 // Go though all completed phases, and though the current one. The current | |
|
Ilya Sherman
2015/03/10 00:48:10
nit: "though" -> "through" (twice)
vadimt
2015/03/13 23:18:01
Done.
| |
| 285 // one is not in phase_completion_events_sequence_, but note the <= | |
| 286 // comparison. | |
|
Alexei Svitkine (slow)
2015/03/09 17:13:35
This logic seems sufficiently non trivial to warra
vadimt
2015/03/13 23:18:01
Done.
| |
| 287 for (size_t phase = 0; phase <= phase_completion_events_sequence_.size(); | |
| 288 ++phase) { | |
| 289 tracked_objects::PhasedProcessDataSnapshots::const_iterator it = | |
| 290 profiler_data.phased_process_data_snapshots.find(phase); | |
| 291 | |
| 292 if (it != profiler_data.phased_process_data_snapshots.end()) { | |
| 293 // If the phase is contained in the received snapshot, notify the | |
| 294 // request. | |
| 295 const base::TimeDelta phase_start = | |
| 296 phase_start_times_[phase] - start_time_; | |
| 297 const base::TimeDelta phase_finish = | |
| 298 (phase + 1 < phase_start_times_.size() | |
| 299 ? phase_start_times_[phase + 1] | |
| 300 : base::TimeTicks::Now()) - | |
| 301 start_time_; | |
| 302 request->callback_object_->ReceivedProfilerData( | |
| 303 it->second, profiler_data.process_id, process_type, phase, | |
| 304 phase_start, phase_finish, past_profiler_events); | |
| 305 } | |
| 306 | |
| 307 if (phase != phase_completion_events_sequence_.size()) { | |
| 308 past_profiler_events.push_back( | |
| 309 phase_completion_events_sequence_[phase]); | |
| 310 } | |
| 311 } | |
| 278 } | 312 } |
| 279 | 313 |
| 280 // Delete request if we have heard back from all child processes. | 314 // Delete request if we have heard back from all child processes. |
| 281 request->DecrementProcessesPending(); | 315 request->DecrementProcessesPending(); |
| 282 request->DeleteIfAllDone(); | 316 request->DeleteIfAllDone(); |
| 283 } | 317 } |
| 284 | 318 |
| 285 int TrackingSynchronizer::GetNextAvailableSequenceNumber() { | 319 int TrackingSynchronizer::GetNextAvailableSequenceNumber() { |
| 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 287 | 321 |
| 288 ++last_used_sequence_number_; | 322 ++last_used_sequence_number_; |
| 289 | 323 |
| 290 // Watch out for wrapping to a negative number. | 324 // Watch out for wrapping to a negative number. |
| 291 if (last_used_sequence_number_ < 0) | 325 if (last_used_sequence_number_ < 0) |
| 292 last_used_sequence_number_ = 1; | 326 last_used_sequence_number_ = 1; |
| 293 return last_used_sequence_number_; | 327 return last_used_sequence_number_; |
| 294 } | 328 } |
| 295 | 329 |
| 296 } // namespace metrics | 330 } // namespace metrics |
| OLD | NEW |