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

Side by Side Diff: base/tracked_objects.h

Issue 1021053003: Delivering the FIRST_NONEMPTY_PAINT phase changing event to base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@phase_splitting
Patch Set: 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
« no previous file with comments | « base/threading/worker_pool_win.cc ('k') | base/tracked_objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef BASE_TRACKED_OBJECTS_H_ 5 #ifndef BASE_TRACKED_OBJECTS_H_
6 #define BASE_TRACKED_OBJECTS_H_ 6 #define BASE_TRACKED_OBJECTS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <stack> 10 #include <stack>
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 class BASE_EXPORT Births: public BirthOnThread { 239 class BASE_EXPORT Births: public BirthOnThread {
240 public: 240 public:
241 Births(const Location& location, const ThreadData& current); 241 Births(const Location& location, const ThreadData& current);
242 242
243 int birth_count() const; 243 int birth_count() const;
244 244
245 // When we have a birth we update the count for this birthplace. 245 // When we have a birth we update the count for this birthplace.
246 void RecordBirth(); 246 void RecordBirth();
247 247
248 // Subtracts a value from the birth count.
249 void SubtractBirths(int count);
250
248 private: 251 private:
249 // The number of births on this thread for our location_. 252 // The number of births on this thread for our location_.
250 int birth_count_; 253 int birth_count_;
251 254
252 DISALLOW_COPY_AND_ASSIGN(Births); 255 DISALLOW_COPY_AND_ASSIGN(Births);
253 }; 256 };
254 257
255 //------------------------------------------------------------------------------ 258 //------------------------------------------------------------------------------
256 // Basic info summarizing multiple destructions of a tracked object with a 259 // Basic info summarizing multiple destructions of a tracked object with a
257 // single birthplace (fixed Location). Used both on specific threads, and also 260 // single birthplace (fixed Location). Used both on specific threads, and also
(...skipping 17 matching lines...) Expand all
275 278
276 // Metrics accessors, used only for serialization and in tests. 279 // Metrics accessors, used only for serialization and in tests.
277 int count() const; 280 int count() const;
278 int32 run_duration_sum() const; 281 int32 run_duration_sum() const;
279 int32 run_duration_max() const; 282 int32 run_duration_max() const;
280 int32 run_duration_sample() const; 283 int32 run_duration_sample() const;
281 int32 queue_duration_sum() const; 284 int32 queue_duration_sum() const;
282 int32 queue_duration_max() const; 285 int32 queue_duration_max() const;
283 int32 queue_duration_sample() const; 286 int32 queue_duration_sample() const;
284 287
285 // Reset all tallies to zero. This is used as a hack on realtime data. 288 // Reset all tallies to zero.
286 void Clear(); 289 void Clear();
287 290
288 private: 291 private:
289 // Members are ordered from most regularly read and updated, to least 292 // Members are ordered from most regularly read and updated, to least
290 // frequently used. This might help a bit with cache lines. 293 // frequently used. This might help a bit with cache lines.
291 // Number of runs seen (divisor for calculating averages). 294 // Number of runs seen (divisor for calculating averages).
292 int count_; 295 int count_;
293 // Basic tallies, used to compute averages. 296 // Basic tallies, used to compute averages.
294 int32 run_duration_sum_; 297 int32 run_duration_sum_;
295 int32 queue_duration_sum_; 298 int32 queue_duration_sum_;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 enum Status { 365 enum Status {
363 UNINITIALIZED, // PRistine, link-time state before running. 366 UNINITIALIZED, // PRistine, link-time state before running.
364 DORMANT_DURING_TESTS, // Only used during testing. 367 DORMANT_DURING_TESTS, // Only used during testing.
365 DEACTIVATED, // No longer recording profiling. 368 DEACTIVATED, // No longer recording profiling.
366 PROFILING_ACTIVE, // Recording profiles (no parent-child links). 369 PROFILING_ACTIVE, // Recording profiles (no parent-child links).
367 PROFILING_CHILDREN_ACTIVE, // Fully active, recording parent-child links. 370 PROFILING_CHILDREN_ACTIVE, // Fully active, recording parent-child links.
368 STATUS_LAST = PROFILING_CHILDREN_ACTIVE 371 STATUS_LAST = PROFILING_CHILDREN_ACTIVE
369 }; 372 };
370 373
371 typedef std::map<Location, Births*> BirthMap; 374 typedef std::map<Location, Births*> BirthMap;
372 typedef std::map<const Births*, DeathData> DeathMap; 375 typedef std::map<Births*, DeathData> DeathMap;
373 typedef std::pair<const Births*, const Births*> ParentChildPair; 376 typedef std::pair<const Births*, const Births*> ParentChildPair;
374 typedef std::set<ParentChildPair> ParentChildSet; 377 typedef std::set<ParentChildPair> ParentChildSet;
375 typedef std::stack<const Births*> ParentStack; 378 typedef std::stack<const Births*> ParentStack;
376 379
377 // Initialize the current thread context with a new instance of ThreadData. 380 // Initialize the current thread context with a new instance of ThreadData.
378 // This is used by all threads that have names, and should be explicitly 381 // This is used by all threads that have names, and should be explicitly
379 // set *before* any births on the threads have taken place. It is generally 382 // set *before* any births on the threads have taken place. It is generally
380 // only used by the message loop, which has a well defined thread name. 383 // only used by the message loop, which has a well defined thread name.
381 static void InitializeThreadContext(const std::string& suggested_name); 384 static void InitializeThreadContext(const std::string& suggested_name);
382 385
383 // Using Thread Local Store, find the current instance for collecting data. 386 // Using Thread Local Store, find the current instance for collecting data.
384 // If an instance does not exist, construct one (and remember it for use on 387 // If an instance does not exist, construct one (and remember it for use on
385 // this thread. 388 // this thread.
386 // This may return NULL if the system is disabled for any reason. 389 // This may return NULL if the system is disabled for any reason.
387 static ThreadData* Get(); 390 static ThreadData* Get();
388 391
389 // Fills |process_data_snapshot| with phased snapshots of all profiling 392 // Fills |process_data_snapshot| with phased snapshots of all profiling
390 // phases, including the current one. 393 // phases, including the current one, identified by |current_profiling_phase|.
391 static void Snapshot(ProcessDataSnapshot* process_data_snapshot); 394 static void Snapshot(int current_profiling_phase,
395 ProcessDataSnapshot* process_data_snapshot);
396
397 // Called when the current profiling phase, identified by |profiling_phase|,
398 // ends.
399 static void OnProfilingPhaseCompletion(int profiling_phase);
392 400
393 // Finds (or creates) a place to count births from the given location in this 401 // Finds (or creates) a place to count births from the given location in this
394 // thread, and increment that tally. 402 // thread, and increment that tally.
395 // TallyABirthIfActive will returns NULL if the birth cannot be tallied. 403 // TallyABirthIfActive will returns NULL if the birth cannot be tallied.
396 static Births* TallyABirthIfActive(const Location& location); 404 static Births* TallyABirthIfActive(const Location& location);
397 405
398 // Records the end of a timed run of an object. The |completed_task| contains 406 // Records the end of a timed run of an object. The |completed_task| contains
399 // a pointer to a Births, the time_posted, and a delayed_start_time if any. 407 // a pointer to a Births, the time_posted, and a delayed_start_time if any.
400 // The |start_of_run| indicates when we started to perform the run of the 408 // The |start_of_run| indicates when we started to perform the run of the
401 // task. The delayed_start_time is non-null for tasks that were posted as 409 // task. The delayed_start_time is non-null for tasks that were posted as
402 // delayed tasks, and it indicates when the task should have run (i.e., when 410 // delayed tasks, and it indicates when the task should have run (i.e., when
403 // it should have posted out of the timer queue, and into the work queue. 411 // it should have posted out of the timer queue, and into the work queue.
404 // The |end_of_run| was just obtained by a call to Now() (just after the task 412 // The |end_of_run| was just obtained by a call to Now() (just after the task
405 // finished). It is provided as an argument to help with testing. 413 // finished). It is provided as an argument to help with testing.
406 static void TallyRunOnNamedThreadIfTracking( 414 static void TallyRunOnNamedThreadIfTracking(
407 const base::TrackingInfo& completed_task, 415 const base::TrackingInfo& completed_task,
408 const TaskStopwatch& stopwatch); 416 const TaskStopwatch& stopwatch);
409 417
410 // Record the end of a timed run of an object. The |birth| is the record for 418 // Record the end of a timed run of an object. The |birth| is the record for
411 // the instance, the |time_posted| records that instant, which is presumed to 419 // the instance, the |time_posted| records that instant, which is presumed to
412 // be when the task was posted into a queue to run on a worker thread. 420 // be when the task was posted into a queue to run on a worker thread.
413 // The |start_of_run| is when the worker thread started to perform the run of 421 // The |start_of_run| is when the worker thread started to perform the run of
414 // the task. 422 // the task.
415 // The |end_of_run| was just obtained by a call to Now() (just after the task 423 // The |end_of_run| was just obtained by a call to Now() (just after the task
416 // finished). 424 // finished).
417 static void TallyRunOnWorkerThreadIfTracking(const Births* birth, 425 static void TallyRunOnWorkerThreadIfTracking(const TrackedTime& time_posted,
418 const TrackedTime& time_posted, 426 const TaskStopwatch& stopwatch,
419 const TaskStopwatch& stopwatch); 427 Births* birth);
420 428
421 // Record the end of execution in region, generally corresponding to a scope 429 // Record the end of execution in region, generally corresponding to a scope
422 // being exited. 430 // being exited.
423 static void TallyRunInAScopedRegionIfTracking(const Births* birth, 431 static void TallyRunInAScopedRegionIfTracking(const TaskStopwatch& stopwatch,
424 const TaskStopwatch& stopwatch); 432 Births* birth);
425 433
426 const std::string& thread_name() const { return thread_name_; } 434 const std::string& thread_name() const { return thread_name_; }
427 435
428 // Initializes all statics if needed (this initialization call should be made 436 // Initializes all statics if needed (this initialization call should be made
429 // while we are single threaded). Returns false if unable to initialize. 437 // while we are single threaded). Returns false if unable to initialize.
430 static bool Initialize(); 438 static bool Initialize();
431 439
432 // Sets internal status_. 440 // Sets internal status_.
433 // If |status| is false, then status_ is set to DEACTIVATED. 441 // If |status| is false, then status_ is set to DEACTIVATED.
434 // If |status| is true, then status_ is set to, PROFILING_ACTIVE, or 442 // If |status| is true, then status_ is set to, PROFILING_ACTIVE, or
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 static ThreadData* first(); 517 static ThreadData* first();
510 518
511 // Iterate through the null terminated list of ThreadData instances. 519 // Iterate through the null terminated list of ThreadData instances.
512 ThreadData* next() const; 520 ThreadData* next() const;
513 521
514 522
515 // In this thread's data, record a new birth. 523 // In this thread's data, record a new birth.
516 Births* TallyABirth(const Location& location); 524 Births* TallyABirth(const Location& location);
517 525
518 // Find a place to record a death on this thread. 526 // Find a place to record a death on this thread.
519 void TallyADeath(const Births& birth, 527 void TallyADeath(int32 queue_duration,
520 int32 queue_duration, 528 const TaskStopwatch& stopwatch,
521 const TaskStopwatch& stopwatch); 529 Births* birth);
522 530
523 // Snapshot (under a lock) the profiled data for the tasks in each ThreadData 531 // Snapshot (under a lock) the profiled data for the tasks in each ThreadData
524 // instance. Also updates the |birth_counts| tally for each task to keep 532 // instance. Also updates the |birth_counts| tally for each task to keep
525 // track of the number of living instances of the task. 533 // track of the number of living instances of the task. If |reset| is true,
534 // remove all recorded deaths.
526 static void SnapshotAllExecutedTasks( 535 static void SnapshotAllExecutedTasks(
536 bool reset,
527 ProcessDataPhaseSnapshot* process_data_phase, 537 ProcessDataPhaseSnapshot* process_data_phase,
528 BirthCountMap* birth_counts); 538 BirthCountMap* birth_counts);
529 539
530 // Fills |process_data_phase| with all the recursive results in our process. 540 // Fills |process_data_phase| with all the recursive results in our process.
541 // If |reset| is true, remove all recorded deaths.
531 static void SnapshotCurrentPhase( 542 static void SnapshotCurrentPhase(
543 bool reset,
532 ProcessDataPhaseSnapshot* process_data_phase); 544 ProcessDataPhaseSnapshot* process_data_phase);
533 545
534 // Snapshots (under a lock) the profiled data for the tasks for this thread 546 // Snapshots (under a lock) the profiled data for the tasks for this thread
535 // and writes all of the executed tasks' data -- i.e. the data for the tasks 547 // and writes all of the executed tasks' data -- i.e. the data for the tasks
536 // with with entries in the death_map_ -- into |process_data_phase|. Also 548 // with with entries in the death_map_ -- into |process_data_phase|. Also
537 // updates the |birth_counts| tally for each task to keep track of the number 549 // updates the |birth_counts| tally for each task to keep track of the number
538 // of living instances of the task -- that is, each task maps to the number of 550 // of living instances of the task -- that is, each task maps to the number of
539 // births for the task that have not yet been balanced by a death. 551 // births for the task that have not yet been balanced by a death. If |reset|
540 void SnapshotExecutedTasks(ProcessDataPhaseSnapshot* process_data_phase, 552 // is true, remove all recorded deaths.
553 void SnapshotExecutedTasks(bool reset,
554 ProcessDataPhaseSnapshot* process_data_phase,
541 BirthCountMap* birth_counts); 555 BirthCountMap* birth_counts);
542 556
543 // Using our lock, make a copy of the specified maps. This call may be made 557 // Using our lock, make a copy of the specified maps. This call may be made
544 // on non-local threads, which necessitate the use of the lock to prevent 558 // on non-local threads, which necessitate the use of the lock to prevent
545 // the map(s) from being reallocated while they are copied. 559 // the map(s) from being reallocated while they are copied. If |reset| is
546 void SnapshotMaps(BirthMap* birth_map, 560 // true, remove all recorded deaths.
561 void SnapshotMaps(bool reset,
562 BirthMap* birth_map,
547 DeathMap* death_map, 563 DeathMap* death_map,
548 ParentChildSet* parent_child_set); 564 ParentChildSet* parent_child_set);
549 565
550 // This method is called by the TLS system when a thread terminates. 566 // This method is called by the TLS system when a thread terminates.
551 // The argument may be NULL if this thread has never tracked a birth or death. 567 // The argument may be NULL if this thread has never tracked a birth or death.
552 static void OnThreadTermination(void* thread_data); 568 static void OnThreadTermination(void* thread_data);
553 569
554 // This method should be called when a worker thread terminates, so that we 570 // This method should be called when a worker thread terminates, so that we
555 // can save all the thread data into a cache of reusable ThreadData instances. 571 // can save all the thread data into a cache of reusable ThreadData instances.
556 void OnThreadTerminationCleanup(); 572 void OnThreadTerminationCleanup();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 620
605 // Protection for access to all_thread_data_list_head_, and to 621 // Protection for access to all_thread_data_list_head_, and to
606 // unregistered_thread_data_pool_. This lock is leaked at shutdown. 622 // unregistered_thread_data_pool_. This lock is leaked at shutdown.
607 // The lock is very infrequently used, so we can afford to just make a lazy 623 // The lock is very infrequently used, so we can afford to just make a lazy
608 // instance and be safe. 624 // instance and be safe.
609 static base::LazyInstance<base::Lock>::Leaky list_lock_; 625 static base::LazyInstance<base::Lock>::Leaky list_lock_;
610 626
611 // We set status_ to SHUTDOWN when we shut down the tracking service. 627 // We set status_ to SHUTDOWN when we shut down the tracking service.
612 static Status status_; 628 static Status status_;
613 629
630 // Process data snapshots for completed profiling phases.
631 static base::LazyInstance<PhasedProcessDataSnapshotMap>
632 completed_phases_snapshots_;
633
614 // Link to next instance (null terminated list). Used to globally track all 634 // Link to next instance (null terminated list). Used to globally track all
615 // registered instances (corresponds to all registered threads where we keep 635 // registered instances (corresponds to all registered threads where we keep
616 // data). 636 // data).
617 ThreadData* next_; 637 ThreadData* next_;
618 638
619 // Pointer to another ThreadData instance for a Worker-Thread that has been 639 // Pointer to another ThreadData instance for a Worker-Thread that has been
620 // retired (its thread was terminated). This value is non-NULL only for a 640 // retired (its thread was terminated). This value is non-NULL only for a
621 // retired ThreadData associated with a Worker-Thread. 641 // retired ThreadData associated with a Worker-Thread.
622 ThreadData* next_retired_worker_; 642 ThreadData* next_retired_worker_;
623 643
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 ProcessDataSnapshot(); 802 ProcessDataSnapshot();
783 ~ProcessDataSnapshot(); 803 ~ProcessDataSnapshot();
784 804
785 PhasedProcessDataSnapshotMap phased_process_data_snapshots; 805 PhasedProcessDataSnapshotMap phased_process_data_snapshots;
786 base::ProcessId process_id; 806 base::ProcessId process_id;
787 }; 807 };
788 808
789 } // namespace tracked_objects 809 } // namespace tracked_objects
790 810
791 #endif // BASE_TRACKED_OBJECTS_H_ 811 #endif // BASE_TRACKED_OBJECTS_H_
OLDNEW
« no previous file with comments | « base/threading/worker_pool_win.cc ('k') | base/tracked_objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698