Chromium Code Reviews| Index: base/tracked_objects.cc |
| diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc |
| index 5359d892116577750cacff82a8522322c0b0b04b..b3f3c7edcb93d065a92da0b6af36c4e8c1eddbf0 100644 |
| --- a/base/tracked_objects.cc |
| +++ b/base/tracked_objects.cc |
| @@ -390,23 +390,9 @@ void ThreadData::OnThreadTerminationCleanup() { |
| } |
| // static |
| -void ThreadData::Snapshot(ProcessDataSnapshot* process_data) { |
| - // Add births that have run to completion to |collected_data|. |
| - // |birth_counts| tracks the total number of births recorded at each location |
| - // for which we have not seen a death count. |
| - BirthCountMap birth_counts; |
| - ThreadData::SnapshotAllExecutedTasks(process_data, &birth_counts); |
| - |
| - // Add births that are still active -- i.e. objects that have tallied a birth, |
| - // but have not yet tallied a matching death, and hence must be either |
| - // running, queued up, or being held in limbo for future posting. |
| - for (BirthCountMap::const_iterator it = birth_counts.begin(); |
| - it != birth_counts.end(); ++it) { |
| - if (it->second > 0) { |
| - process_data->tasks.push_back( |
| - TaskSnapshot(*it->first, DeathData(it->second), "Still_Alive")); |
| - } |
| - } |
| +void ThreadData::Snapshot(ProcessDataSnapshot* process_data_snapshot) { |
| + ThreadData::SnapshotCurrentPhase( |
| + &process_data_snapshot->phased_process_data_snapshots[0]); |
| } |
| Births* ThreadData::TallyABirth(const Location& location) { |
| @@ -578,8 +564,9 @@ void ThreadData::TallyRunInAScopedRegionIfTracking( |
| } |
| // static |
| -void ThreadData::SnapshotAllExecutedTasks(ProcessDataSnapshot* process_data, |
| - BirthCountMap* birth_counts) { |
| +void ThreadData::SnapshotAllExecutedTasks( |
| + ProcessDataPhaseSnapshot* process_data_phase, |
| + BirthCountMap* birth_counts) { |
| if (!kTrackAllTaskObjects) |
| return; // Not compiled in. |
| @@ -595,12 +582,33 @@ void ThreadData::SnapshotAllExecutedTasks(ProcessDataSnapshot* process_data, |
| for (ThreadData* thread_data = my_list; |
| thread_data; |
| thread_data = thread_data->next()) { |
| - thread_data->SnapshotExecutedTasks(process_data, birth_counts); |
| + thread_data->SnapshotExecutedTasks(process_data_phase, birth_counts); |
| + } |
| +} |
| + |
| +// static |
| +void ThreadData::SnapshotCurrentPhase( |
| + ProcessDataPhaseSnapshot* process_data_phase) { |
| + // Add births that have run to completion to |collected_data|. |
| + // |birth_counts| tracks the total number of births recorded at each location |
| + // for which we have not seen a death count. |
| + BirthCountMap birth_counts; |
| + ThreadData::SnapshotAllExecutedTasks(process_data_phase, &birth_counts); |
| + |
| + // Add births that are still active -- i.e. objects that have tallied a birth, |
| + // but have not yet tallied a matching death, and hence must be either |
| + // running, queued up, or being held in limbo for future posting. |
| + for (const auto& birth_count : birth_counts) { |
| + if (birth_count.second > 0) { |
| + process_data_phase->tasks.push_back(TaskSnapshot( |
| + *birth_count.first, DeathData(birth_count.second), "Still_Alive")); |
| + } |
| } |
| } |
| -void ThreadData::SnapshotExecutedTasks(ProcessDataSnapshot* process_data, |
| - BirthCountMap* birth_counts) { |
| +void ThreadData::SnapshotExecutedTasks( |
| + ProcessDataPhaseSnapshot* process_data_phase, |
| + BirthCountMap* birth_counts) { |
| // Get copy of data, so that the data will not change during the iterations |
| // and processing. |
| ThreadData::BirthMap birth_map; |
| @@ -608,24 +616,22 @@ void ThreadData::SnapshotExecutedTasks(ProcessDataSnapshot* process_data, |
| ThreadData::ParentChildSet parent_child_set; |
| SnapshotMaps(&birth_map, &death_map, &parent_child_set); |
| - for (ThreadData::DeathMap::const_iterator it = death_map.begin(); |
| - it != death_map.end(); ++it) { |
| - process_data->tasks.push_back( |
| - TaskSnapshot(*it->first, it->second, thread_name())); |
| - (*birth_counts)[it->first] -= it->first->birth_count(); |
| + for (const auto& death : death_map) { |
| + process_data_phase->tasks.push_back( |
| + TaskSnapshot(*death.first, death.second, thread_name())); |
| + (*birth_counts)[death.first] -= death.first->birth_count(); |
| } |
| - for (ThreadData::BirthMap::const_iterator it = birth_map.begin(); |
| - it != birth_map.end(); ++it) { |
| - (*birth_counts)[it->second] += it->second->birth_count(); |
| + for (const auto& birth : birth_map) { |
| + (*birth_counts)[birth.second] += birth.second->birth_count(); |
| } |
| if (!kTrackParentChildLinks) |
| return; |
| - for (ThreadData::ParentChildSet::const_iterator it = parent_child_set.begin(); |
| - it != parent_child_set.end(); ++it) { |
| - process_data->descendants.push_back(ParentChildPairSnapshot(*it)); |
| + for (const auto& parent_child : parent_child_set) { |
| + process_data_phase->descendants.push_back( |
| + ParentChildPairSnapshot(parent_child)); |
| } |
| } |
| @@ -634,20 +640,16 @@ void ThreadData::SnapshotMaps(BirthMap* birth_map, |
| DeathMap* death_map, |
| ParentChildSet* parent_child_set) { |
| base::AutoLock lock(map_lock_); |
| - for (BirthMap::const_iterator it = birth_map_.begin(); |
| - it != birth_map_.end(); ++it) |
| - (*birth_map)[it->first] = it->second; |
| - for (DeathMap::iterator it = death_map_.begin(); |
| - it != death_map_.end(); ++it) { |
| - (*death_map)[it->first] = it->second; |
| - } |
| + for (const auto& birth : birth_map_) |
| + (*birth_map)[birth.first] = birth.second; |
| + for (auto& death : death_map_) |
|
dcheng
2015/03/27 08:36:36
Slightly weird that 643 is const and this one is n
vadimt
2015/03/27 20:12:34
Done.
|
| + (*death_map)[death.first] = death.second; |
| if (!kTrackParentChildLinks) |
| return; |
| - for (ParentChildSet::iterator it = parent_child_set_.begin(); |
| - it != parent_child_set_.end(); ++it) |
| - parent_child_set->insert(*it); |
| + for (const auto& parent_child : parent_child_set_) |
| + parent_child_set->insert(parent_child); |
| } |
| static void OptionallyInitializeAlternateTimer() { |
| @@ -959,13 +961,22 @@ ParentChildPairSnapshot::~ParentChildPairSnapshot() { |
| } |
| //------------------------------------------------------------------------------ |
| -// ProcessDataSnapshot |
| +// ProcessDataPhaseSnapshot |
| + |
| +ProcessDataPhaseSnapshot::ProcessDataPhaseSnapshot() { |
| +} |
| + |
| +ProcessDataPhaseSnapshot::~ProcessDataPhaseSnapshot() { |
| +} |
| + |
| +//------------------------------------------------------------------------------ |
| +// ProcessDataPhaseSnapshot |
| ProcessDataSnapshot::ProcessDataSnapshot() |
| #if !defined(OS_NACL) |
| : process_id(base::GetCurrentProcId()) { |
| #else |
| - : process_id(0) { |
| + : process_id(base::kNullProcessId) { |
| #endif |
| } |