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

Side by Side Diff: components/metrics/profiler/tracking_synchronizer.cc

Issue 985773002: Introducing phased profiling framework (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@write_to_file
Patch Set: Fial isherman@ comments Created 5 years, 9 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 (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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 }; 173 };
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(const base::TimeTicks& now)
183 : last_used_sequence_number_(kNeverUsableSequenceNumber) { 184 : last_used_sequence_number_(kNeverUsableSequenceNumber), start_time_(now) {
184 DCHECK(!g_tracking_synchronizer); 185 DCHECK(!g_tracking_synchronizer);
185 g_tracking_synchronizer = this; 186 g_tracking_synchronizer = this;
187 phase_start_times_.push_back(now);
186 content::ProfilerController::GetInstance()->Register(this); 188 content::ProfilerController::GetInstance()->Register(this);
187 } 189 }
188 190
189 TrackingSynchronizer::~TrackingSynchronizer() { 191 TrackingSynchronizer::~TrackingSynchronizer() {
190 content::ProfilerController::GetInstance()->Unregister(this); 192 content::ProfilerController::GetInstance()->Unregister(this);
191 193
192 // Just in case we have any pending tasks, clear them out. 194 // Just in case we have any pending tasks, clear them out.
193 RequestContext::OnShutdown(); 195 RequestContext::OnShutdown();
194 196
195 g_tracking_synchronizer = NULL; 197 g_tracking_synchronizer = NULL;
(...skipping 29 matching lines...) Expand all
225 if (!request) 227 if (!request)
226 return; 228 return;
227 request->AddProcessesPending(pending_processes); 229 request->AddProcessesPending(pending_processes);
228 request->SetReceivedProcessGroupCount(end); 230 request->SetReceivedProcessGroupCount(end);
229 request->DeleteIfAllDone(); 231 request->DeleteIfAllDone();
230 } 232 }
231 233
232 void TrackingSynchronizer::OnProfilerDataCollected( 234 void TrackingSynchronizer::OnProfilerDataCollected(
233 int sequence_number, 235 int sequence_number,
234 const tracked_objects::ProcessDataSnapshot& profiler_data, 236 const tracked_objects::ProcessDataSnapshot& profiler_data,
235 int process_type) { 237 content::ProcessType process_type) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
237 DecrementPendingProcessesAndSendData(sequence_number, profiler_data, 239 DecrementPendingProcessesAndSendData(sequence_number, profiler_data,
238 process_type); 240 process_type);
239 } 241 }
240 242
241 int TrackingSynchronizer::RegisterAndNotifyAllProcesses( 243 int TrackingSynchronizer::RegisterAndNotifyAllProcesses(
242 const base::WeakPtr<TrackingSynchronizerObserver>& callback_object) { 244 const base::WeakPtr<TrackingSynchronizerObserver>& callback_object) {
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
244 246
245 int sequence_number = GetNextAvailableSequenceNumber(); 247 int sequence_number = GetNextAvailableSequenceNumber();
246 248
247 RequestContext* request = 249 RequestContext* request =
248 RequestContext::Register(sequence_number, callback_object); 250 RequestContext::Register(sequence_number, callback_object);
249 251
250 // Increment pending process count for sending browser's profiler data. 252 // Increment pending process count for sending browser's profiler data.
251 request->IncrementProcessesPending(); 253 request->IncrementProcessesPending();
252 254
253 // Get profiler data from renderer and browser child processes. 255 // Get profiler data from renderer and browser child processes.
254 content::ProfilerController::GetInstance()->GetProfilerData(sequence_number); 256 content::ProfilerController::GetInstance()->GetProfilerData(sequence_number);
255 257
256 // Send profiler_data from browser process. 258 // Send process data snapshot from browser process.
257 tracked_objects::ProcessDataSnapshot process_data; 259 tracked_objects::ProcessDataSnapshot process_data_snapshot;
258 tracked_objects::ThreadData::Snapshot(&process_data); 260 tracked_objects::ThreadData::Snapshot(&process_data_snapshot);
259 DecrementPendingProcessesAndSendData(sequence_number, process_data, 261 DecrementPendingProcessesAndSendData(sequence_number, process_data_snapshot,
260 content::PROCESS_TYPE_BROWSER); 262 content::PROCESS_TYPE_BROWSER);
261 263
262 return sequence_number; 264 return sequence_number;
263 } 265 }
264 266
267 void TrackingSynchronizer::SendData(
268 const tracked_objects::ProcessDataSnapshot& profiler_data,
269 content::ProcessType process_type,
270 const base::TimeTicks& now,
271 TrackingSynchronizerObserver* observer) const {
272 // 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
274 // will track the set of past profiling events as we go.
275 ProfilerEvents past_events;
276
277 // Go through all completed phases, and through the current one. The current
278 // one is not in phase_completion_events_sequence_, but note the <=
279 // comparison.
280 for (size_t phase = 0; phase <= phase_completion_events_sequence_.size();
281 ++phase) {
282 auto it = profiler_data.phased_process_data_snapshots.find(phase);
283
284 if (it != profiler_data.phased_process_data_snapshots.end()) {
285 // If the phase is contained in the received snapshot, notify the
286 // request.
287 const base::TimeDelta phase_start =
288 phase_start_times_[phase] - start_time_;
289 const base::TimeDelta phase_finish =
290 (phase + 1 < phase_start_times_.size() ? phase_start_times_[phase + 1]
291 : now) -
292 start_time_;
293 observer->ReceivedProfilerData(it->second, profiler_data.process_id,
294 process_type, phase, phase_start,
295 phase_finish, past_events);
296 }
297
298 if (phase != phase_completion_events_sequence_.size()) {
dcheng 2015/03/27 09:32:53 I think this would read a little more clearly as <
vadimt 2015/03/27 20:12:34 Done, but IMHO != is clearer. For example, for stl
dcheng 2015/03/30 06:56:06 Perhaps if it's near the loop variable, but this i
299 past_events.push_back(phase_completion_events_sequence_[phase]);
300 }
301 }
302 }
303
265 void TrackingSynchronizer::DecrementPendingProcessesAndSendData( 304 void TrackingSynchronizer::DecrementPendingProcessesAndSendData(
266 int sequence_number, 305 int sequence_number,
267 const tracked_objects::ProcessDataSnapshot& profiler_data, 306 const tracked_objects::ProcessDataSnapshot& profiler_data,
268 int process_type) { 307 content::ProcessType process_type) {
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
270 309
271 RequestContext* request = RequestContext::GetRequestContext(sequence_number); 310 RequestContext* request = RequestContext::GetRequestContext(sequence_number);
272 if (!request) 311 if (!request)
273 return; 312 return;
274 313
275 if (request->callback_object_.get()) { 314 TrackingSynchronizerObserver* observer = request->callback_object_.get();
276 request->callback_object_ 315 if (observer)
277 ->ReceivedProfilerData(profiler_data, process_type); 316 SendData(profiler_data, process_type, base::TimeTicks::Now(), observer);
278 }
279 317
280 // Delete request if we have heard back from all child processes. 318 // Delete request if we have heard back from all child processes.
281 request->DecrementProcessesPending(); 319 request->DecrementProcessesPending();
282 request->DeleteIfAllDone(); 320 request->DeleteIfAllDone();
283 } 321 }
284 322
285 int TrackingSynchronizer::GetNextAvailableSequenceNumber() { 323 int TrackingSynchronizer::GetNextAvailableSequenceNumber() {
286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
287 325
288 ++last_used_sequence_number_; 326 ++last_used_sequence_number_;
289 327
290 // Watch out for wrapping to a negative number. 328 // Watch out for wrapping to a negative number.
291 if (last_used_sequence_number_ < 0) 329 if (last_used_sequence_number_ < 0)
292 last_used_sequence_number_ = 1; 330 last_used_sequence_number_ = 1;
293 return last_used_sequence_number_; 331 return last_used_sequence_number_;
294 } 332 }
295 333
296 } // namespace metrics 334 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698