Chromium Code Reviews| Index: base/tracked_objects.h |
| diff --git a/base/tracked_objects.h b/base/tracked_objects.h |
| index 7840fecbd1459c10f551a83386b91d43f0e7eaeb..8193add7c9bdddb5b06ff44c3feece3d4fb7cb17 100644 |
| --- a/base/tracked_objects.h |
| +++ b/base/tracked_objects.h |
| @@ -146,10 +146,14 @@ struct TrackingInfo; |
| // TaskSnapshot instances, so that such instances can be sorted and |
| // aggregated (and remain frozen during our processing). |
| // |
| -// The ProcessDataSnapshot struct is a serialized representation of the list |
| -// of ThreadData objects for a process. It holds a set of TaskSnapshots |
| -// and tracks parent/child relationships for the executed tasks. The statistics |
| -// in a snapshot are gathered asynhcronously relative to their ongoing updates. |
| +// Profiling consists of phases. The concrete phase in the sequence of phases is |
| +// identified by its 0-based nubmer. |
| +// |
| +// The ProcessDataPhaseSnapshot struct is a serialized representation of the |
| +// list of ThreadData objects for a process for a concrete profiling phase. It |
| +// holds a set of TaskSnapshots and tracks parent/child relationships for the |
| +// executed tasks. The statistics in a snapshot are gathered asynhcronously |
| +// relative to their ongoing updates. |
| // It is possible, though highly unlikely, that stats could be incorrectly |
| // recorded by this process (all data is held in 32 bit ints, but we are not |
| // atomically collecting all data, so we could have count that does not, for |
| @@ -240,6 +244,9 @@ class BASE_EXPORT Births: public BirthOnThread { |
| // When we have a birth we update the count for this birthplace. |
| void RecordBirth(); |
| + // Subtracts a value from the birth count. |
| + void SubtractBirths(int count); |
| + |
| private: |
| // The number of births on this thread for our location_. |
| int birth_count_; |
| @@ -277,7 +284,7 @@ class BASE_EXPORT DeathData { |
| int32 queue_duration_max() const; |
| int32 queue_duration_sample() const; |
| - // Reset all tallies to zero. This is used as a hack on realtime data. |
| + // Reset all tallies to zero. |
| void Clear(); |
| private: |
| @@ -341,6 +348,11 @@ struct BASE_EXPORT TaskSnapshot { |
| // We also have a linked list of ThreadData instances, and that list is used to |
| // harvest data from all existing instances. |
| +struct ProcessDataPhaseSnapshot; |
| +// Map from profiling phase number to the process-wide snapshotted |
| +// representation of the list of ThreadData objects that died during the given |
| +// phase. |
| +typedef std::map<int, ProcessDataPhaseSnapshot> PhasedProcessDataSnapshots; |
| struct ProcessDataSnapshot; |
| class BASE_EXPORT TaskStopwatch; |
| @@ -358,7 +370,7 @@ class BASE_EXPORT ThreadData { |
| }; |
| typedef std::map<Location, Births*> BirthMap; |
| - typedef std::map<const Births*, DeathData> DeathMap; |
| + typedef std::map<Births*, DeathData> DeathMap; |
| typedef std::pair<const Births*, const Births*> ParentChildPair; |
| typedef std::set<ParentChildPair> ParentChildSet; |
| typedef std::stack<const Births*> ParentStack; |
| @@ -375,8 +387,15 @@ class BASE_EXPORT ThreadData { |
| // This may return NULL if the system is disabled for any reason. |
| static ThreadData* Get(); |
| - // Fills |process_data| with all the recursive results in our process. |
| - static void Snapshot(ProcessDataSnapshot* process_data); |
| + // Fills |process_data_snapshot| with phased snapshots of all profiling |
| + // phases, including the currect one, identified by |current_profiling_phase|. |
|
Alexei Svitkine (slow)
2015/03/06 20:06:40
Nit: currect -> current
I don't understand this.
vadimt
2015/03/06 21:34:58
Correct. This must be the current profiler phase.
|
| + static void GetProcessDataSnapshot( |
| + int current_profiling_phase, |
| + ProcessDataSnapshot* process_data_snapshot); |
| + |
| + // Called when the current profiling phase, identified by |profiling_phase|, |
| + // ends. |
| + static void OnProfilingPhaseCompletion(int profiling_phase); |
| // Finds (or creates) a place to count births from the given location in this |
| // thread, and increment that tally. |
| @@ -402,16 +421,14 @@ class BASE_EXPORT ThreadData { |
| // the task. |
| // The |end_of_run| was just obtained by a call to Now() (just after the task |
| // finished). |
| - static void TallyRunOnWorkerThreadIfTracking( |
| - const Births* birth, |
| - const TrackedTime& time_posted, |
| - const TaskStopwatch& stopwatch); |
| + static void TallyRunOnWorkerThreadIfTracking(const TrackedTime& time_posted, |
| + const TaskStopwatch& stopwatch, |
| + Births* birth); |
| // Record the end of execution in region, generally corresponding to a scope |
| // being exited. |
| - static void TallyRunInAScopedRegionIfTracking( |
| - const Births* birth, |
| - const TaskStopwatch& stopwatch); |
| + static void TallyRunInAScopedRegionIfTracking(const TaskStopwatch& stopwatch, |
| + Births* birth); |
| const std::string& thread_name() const { return thread_name_; } |
| @@ -506,29 +523,41 @@ class BASE_EXPORT ThreadData { |
| Births* TallyABirth(const Location& location); |
| // Find a place to record a death on this thread. |
| - void TallyADeath(const Births& birth, |
| - int32 queue_duration, |
| - const TaskStopwatch& stopwatch); |
| + void TallyADeath(int32 queue_duration, |
| + const TaskStopwatch& stopwatch, |
| + Births* birth); |
| // Snapshot (under a lock) the profiled data for the tasks in each ThreadData |
| // instance. Also updates the |birth_counts| tally for each task to keep |
| - // track of the number of living instances of the task. |
| - static void SnapshotAllExecutedTasks(ProcessDataSnapshot* process_data, |
| - BirthCountMap* birth_counts); |
| + // track of the number of living instances of the task. If |reset| is true, |
| + // remove all recorded deaths. |
| + static void SnapshotAllExecutedTasks( |
| + bool reset, |
| + ProcessDataPhaseSnapshot* process_data_phase, |
| + BirthCountMap* birth_counts); |
| + |
| + // Fills |process_data_phase| with all the recursive results in our process. |
| + // If |reset| is true, remove all recorded deaths. |
| + static void Snapshot(bool reset, |
| + ProcessDataPhaseSnapshot* process_data_phase); |
| // Snapshots (under a lock) the profiled data for the tasks for this thread |
| // and writes all of the executed tasks' data -- i.e. the data for the tasks |
| - // with with entries in the death_map_ -- into |process_data|. Also updates |
| - // the |birth_counts| tally for each task to keep track of the number of |
| - // living instances of the task -- that is, each task maps to the number of |
| - // births for the task that have not yet been balanced by a death. |
| - void SnapshotExecutedTasks(ProcessDataSnapshot* process_data, |
| + // with with entries in the death_map_ -- into |process_data_phase|. Also |
| + // updates the |birth_counts| tally for each task to keep track of the number |
| + // of living instances of the task -- that is, each task maps to the number of |
| + // births for the task that have not yet been balanced by a death. If |reset| |
| + // is true, remove all recorded deaths. |
| + void SnapshotExecutedTasks(bool reset, |
| + ProcessDataPhaseSnapshot* process_data_phase, |
| BirthCountMap* birth_counts); |
| // Using our lock, make a copy of the specified maps. This call may be made |
| // on non-local threads, which necessitate the use of the lock to prevent |
| - // the map(s) from being reallocated while they are copied. |
| - void SnapshotMaps(BirthMap* birth_map, |
| + // the map(s) from being reallocated while they are copied. If |reset| is |
| + // true, remove all recorded deaths. |
| + void SnapshotMaps(bool reset, |
| + BirthMap* birth_map, |
| DeathMap* death_map, |
| ParentChildSet* parent_child_set); |
| @@ -596,6 +625,10 @@ class BASE_EXPORT ThreadData { |
| // We set status_ to SHUTDOWN when we shut down the tracking service. |
| static Status status_; |
| + // Process data snapshots for completed profiling phases. |
| + static base::LazyInstance<PhasedProcessDataSnapshots> |
| + completed_phases_snapshots_; |
| + |
| // Link to next instance (null terminated list). Used to globally track all |
| // registered instances (corresponds to all registered threads where we keep |
| // data). |
| @@ -746,15 +779,28 @@ struct BASE_EXPORT ParentChildPairSnapshot { |
| }; |
| //------------------------------------------------------------------------------ |
| -// A snapshotted representation of the list of ThreadData objects for a process. |
| +// A snapshotted representation of the list of ThreadData objects for a process, |
| +// for a single profiling phase. |
| + |
| +struct BASE_EXPORT ProcessDataPhaseSnapshot { |
| + public: |
| + ProcessDataPhaseSnapshot(); |
| + ~ProcessDataPhaseSnapshot(); |
| + |
| + std::vector<TaskSnapshot> tasks; |
| + std::vector<ParentChildPairSnapshot> descendants; |
| +}; |
| + |
| +//------------------------------------------------------------------------------ |
| +// A snapshotted representation of the list of ThreadData objects for a process, |
| +// for all profiling phases, including the current one. |
| struct BASE_EXPORT ProcessDataSnapshot { |
| public: |
| ProcessDataSnapshot(); |
| ~ProcessDataSnapshot(); |
| - std::vector<TaskSnapshot> tasks; |
| - std::vector<ParentChildPairSnapshot> descendants; |
| + PhasedProcessDataSnapshots phased_process_data_snapshots; |
| int process_id; |
| }; |