Chromium Code Reviews| Index: base/tracked_objects.h |
| diff --git a/base/tracked_objects.h b/base/tracked_objects.h |
| index 964326511b23355f0bca71b1671919d8cb3e8548..6c881039633c810b3cd09b1fd18d30cb0f8d3ccb 100644 |
| --- a/base/tracked_objects.h |
| +++ b/base/tracked_objects.h |
| @@ -258,6 +258,18 @@ class BASE_EXPORT Births: public BirthOnThread { |
| // single birthplace (fixed Location). Used both on specific threads, and also |
| // in snapshots when integrating assembled data. |
| +struct DeathDataPhaseSnapshot; |
| + |
| +//------------------------------------------------------------------------------ |
| +// Information about deaths of a task on a given thread, called "death thread". |
| +// Access to members of this class is never protected by the lock. The fields |
| +// are accessed in such a way that corruptions resulting from race conditions |
| +// are not significant, and don't accumulate as a result of multiple accesses. |
| +// All snapshots and phase change notifications must be called from the same |
| +// thread. It doesn't matter what thread it is, but it's important the same |
| +// thread is used as a snapshot thread during the whole process lifetime. |
| +// All fields except sample_probability_count_ can be snapshotted. |
| + |
| class BASE_EXPORT DeathData { |
| public: |
| // Default initializer. |
| @@ -268,13 +280,16 @@ class BASE_EXPORT DeathData { |
| // a corresponding death. |
| explicit DeathData(int count); |
| + ~DeathData(); |
| + |
| // Update stats for a task destruction (death) that had a Run() time of |
| // |duration|, and has had a queueing delay of |queue_duration|. |
| void RecordDeath(const int32 queue_duration, |
| const int32 run_duration, |
| const uint32 random_number); |
| - // Metrics accessors, used only for serialization and in tests. |
| + // Metrics and past snapshots accessors, used only for serialization and in |
| + // tests. |
| int count() const; |
| int32 run_duration_sum() const; |
| int32 run_duration_max() const; |
| @@ -282,26 +297,47 @@ class BASE_EXPORT DeathData { |
| int32 queue_duration_sum() const; |
| int32 queue_duration_max() const; |
| int32 queue_duration_sample() const; |
| + DeathDataPhaseSnapshot* last_phase_snapshot() const; |
| - // Reset all tallies to zero. This is used as a hack on realtime data. |
| - void Clear(); |
| + // Called when the current profiling phase, identified by |profiling_phase|, |
| + // ends. |
| + // Must be called only on the snapshot thread. |
|
Alexei Svitkine (slow)
2015/04/08 21:57:50
Is there a way to enforce these threading requirem
vadimt
2015/04/08 23:31:24
Speaking of birth and death threads, I’d not bothe
|
| + void OnProfilingPhaseCompleted(int profiling_phase); |
| private: |
| // Members are ordered from most regularly read and updated, to least |
| // frequently used. This might help a bit with cache lines. |
| // Number of runs seen (divisor for calculating averages). |
| + // Can be incremented only on the death thread. |
| int count_; |
| - // Basic tallies, used to compute averages. |
| + |
| + // Count used in determining probability of selecting exec/queue times from a |
| + // recorded death as samples. |
| + // Gets incremented only on the death thread, but can be set to 0 by |
| + // OnProfilingPhaseCompleted() on the snapshot thread. |
| + int sample_probability_count_; |
| + |
| + // Basic tallies, used to compute averages. Can be incremented only on the |
| + // death thread. |
| int32 run_duration_sum_; |
| int32 queue_duration_sum_; |
| // Max values, used by local visualization routines. These are often read, |
| - // but rarely updated. |
| + // but rarely updated. The max values get assigned only on the death thread, |
| + // but these fields can be set to 0 by OnProfilingPhaseCompleted() on the |
| + // snapshot thread. |
| int32 run_duration_max_; |
| int32 queue_duration_max_; |
| // Samples, used by crowd sourcing gatherers. These are almost never read, |
| - // and rarely updated. |
| + // and rarely updated. They can be modified only on the death thread. |
| int32 run_duration_sample_; |
| int32 queue_duration_sample_; |
| + |
| + // Snapshot of this death data made at the last profiling phase completion, if |
| + // any. DeathData owns the whole list starting with this pointer. |
| + // Can be accessed only on the snapshot thread. |
| + DeathDataPhaseSnapshot* last_phase_snapshot_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DeathData); |
| }; |
| //------------------------------------------------------------------------------ |
| @@ -312,6 +348,10 @@ struct BASE_EXPORT DeathDataSnapshot { |
| explicit DeathDataSnapshot(const DeathData& death_data); |
| ~DeathDataSnapshot(); |
| + // Calculates delta between this snapshot and an earlier snapshot of the same |
| + // task |older| and assigns it back to this object. |
| + void CalculateDelta(const DeathDataSnapshot& older); |
| + |
| int count; |
| int32 run_duration_sum; |
| int32 run_duration_max; |
| @@ -322,6 +362,21 @@ struct BASE_EXPORT DeathDataSnapshot { |
| }; |
| //------------------------------------------------------------------------------ |
| +// A "snapshotted" representation of the DeathData for a particular profiling |
| +// phase. Used as an element of the list of phase snapshots owned by DeathData. |
| + |
| +struct DeathDataPhaseSnapshot { |
| + DeathDataPhaseSnapshot(int profiling_phase, const DeathData& death_data); |
| + |
| + // Profiling phase at which completion this snapshot was taken. |
| + int profiling_phase; |
| + // Death data snapshot. |
| + DeathDataSnapshot death_data; |
| + // Pointer to a snapshot from the previous phase. |
| + DeathDataPhaseSnapshot* prev; |
| +}; |
| + |
| +//------------------------------------------------------------------------------ |
| // A temporary collection of data that can be sorted and summarized. It is |
| // gathered (carefully) from many threads. Instances are held in arrays and |
| // processed, filtered, and rendered. |
| @@ -330,12 +385,14 @@ struct BASE_EXPORT DeathDataSnapshot { |
| struct BASE_EXPORT TaskSnapshot { |
| TaskSnapshot(); |
| - TaskSnapshot(const BirthOnThread& birth, |
| - const DeathData& death_data, |
| + TaskSnapshot(const BirthOnThreadSnapshot& birth, |
| + const DeathDataSnapshot& death_data, |
| const std::string& death_thread_name); |
| ~TaskSnapshot(); |
| BirthOnThreadSnapshot birth; |
| + // Delta between death data for a thread for a certain profiling phase and the |
| + // snapshot for the pervious phase, if any. Otherwise, just a snapshot. |
| DeathDataSnapshot death_data; |
| std::string death_thread_name; |
| }; |
| @@ -388,8 +445,21 @@ class BASE_EXPORT ThreadData { |
| static ThreadData* Get(); |
| // Fills |process_data_snapshot| with phased snapshots of all profiling |
| - // phases, including the current one. |
| - static void Snapshot(ProcessDataSnapshot* process_data_snapshot); |
| + // phases, including the current one, identified by |current_profiling_phase|. |
| + // |current_profiling_phase| is necessary because a child process can start |
| + // after several phase-changing events, so it needs to receive the current |
| + // phase number from the browser process to fill the correct entry for the |
| + // current phase in the |process_data_snapshot| map. |
| + static void Snapshot(int current_profiling_phase, |
| + ProcessDataSnapshot* process_data_snapshot); |
| + |
| + // Called when the current profiling phase, identified by |profiling_phase|, |
| + // ends. |
| + // |profiling_phase| is necessary because a child process can start after |
| + // several phase-changing events, so it needs to receive the phase number from |
| + // the browser process to fill the correct entry in the |
| + // completed_phases_snapshots_ map. |
| + static void OnProfilingPhaseCompleted(int profiling_phase); |
| // Finds (or creates) a place to count births from the given location in this |
| // thread, and increment that tally. |
| @@ -415,13 +485,13 @@ 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, |
| + static void TallyRunOnWorkerThreadIfTracking(const Births* births, |
| const TrackedTime& time_posted, |
| const TaskStopwatch& stopwatch); |
| // Record the end of execution in region, generally corresponding to a scope |
| // being exited. |
| - static void TallyRunInAScopedRegionIfTracking(const Births* birth, |
| + static void TallyRunInAScopedRegionIfTracking(const Births* births, |
| const TaskStopwatch& stopwatch); |
| const std::string& thread_name() const { return thread_name_; } |
| @@ -493,6 +563,9 @@ class BASE_EXPORT ThreadData { |
| typedef std::map<const BirthOnThread*, int> BirthCountMap; |
| + typedef std::vector<std::pair<const Births*, DeathDataPhaseSnapshot>> |
| + DeathsSnapshot; |
| + |
| // Worker thread construction creates a name since there is none. |
| explicit ThreadData(int thread_number); |
| @@ -517,37 +590,35 @@ class BASE_EXPORT ThreadData { |
| Births* TallyABirth(const Location& location); |
| // Find a place to record a death on this thread. |
| - void TallyADeath(const Births& birth, |
| + void TallyADeath(const Births& births, |
| int32 queue_duration, |
| const TaskStopwatch& stopwatch); |
| - // 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( |
| - ProcessDataPhaseSnapshot* process_data_phase, |
| - BirthCountMap* birth_counts); |
| - |
| - // Fills |process_data_phase| with all the recursive results in our process. |
| - static void SnapshotCurrentPhase( |
| - 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_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. |
| - void SnapshotExecutedTasks(ProcessDataPhaseSnapshot* process_data_phase, |
| - BirthCountMap* birth_counts); |
| + // and writes all of the executed tasks' data -- i.e. the data for all |
| + // profiling phases (including the current one: |current_profiling_phase|) for |
| + // the tasks with with entries in the death_map_ -- into |
| + // |return_of_snapshot_hrenina|. 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( |
| + int current_profiling_phase, |
| + PhasedProcessDataSnapshotMap* phased_process_data_snapshots, |
| + 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, |
| - DeathMap* death_map, |
| + void SnapshotMaps(int profiling_phase, |
| + BirthMap* birth_map, |
| + DeathsSnapshot* deaths, |
| ParentChildSet* parent_child_set); |
| + // Called for this thread when the current profiling phase, identified by |
| + // |profiling_phase|, ends. |
| + void OnProfilingPhaseCompletionOnThread(int profiling_phase); |
| + |
| // This method is called by the TLS system when a thread terminates. |
| // The argument may be NULL if this thread has never tracked a birth or death. |
| static void OnThreadTermination(void* thread_data); |