| OLD | NEW |
| 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 "base/tracked_objects.h" | 5 #include "base/tracked_objects.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/process_util.h" |
| 11 #include "base/profiler/alternate_timer.h" | 13 #include "base/profiler/alternate_timer.h" |
| 12 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 13 #include "base/third_party/valgrind/memcheck.h" | 15 #include "base/third_party/valgrind/memcheck.h" |
| 14 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 15 #include "build/build_config.h" | |
| 16 #include "base/port.h" | 17 #include "base/port.h" |
| 17 | 18 |
| 18 using base::TimeDelta; | 19 using base::TimeDelta; |
| 19 | 20 |
| 20 namespace tracked_objects { | 21 namespace tracked_objects { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Flag to compile out almost all of the task tracking code. | 25 // Flag to compile out almost all of the task tracking code. |
| 25 const bool kTrackAllTaskObjects = true; | 26 const bool kTrackAllTaskObjects = true; |
| 26 | 27 |
| 28 // TODO(jar): Evaluate the perf impact of enabling this. If the perf impact is |
| 29 // negligible, enable by default. |
| 27 // Flag to compile out parent-child link recording. | 30 // Flag to compile out parent-child link recording. |
| 28 const bool kTrackParentChildLinks = false; | 31 const bool kTrackParentChildLinks = false; |
| 29 | 32 |
| 30 // When ThreadData is first initialized, should we start in an ACTIVE state to | 33 // When ThreadData is first initialized, should we start in an ACTIVE state to |
| 31 // record all of the startup-time tasks, or should we start up DEACTIVATED, so | 34 // record all of the startup-time tasks, or should we start up DEACTIVATED, so |
| 32 // that we only record after parsing the command line flag --enable-tracking. | 35 // that we only record after parsing the command line flag --enable-tracking. |
| 33 // Note that the flag may force either state, so this really controls only the | 36 // Note that the flag may force either state, so this really controls only the |
| 34 // period of time up until that flag is parsed. If there is no flag seen, then | 37 // period of time up until that flag is parsed. If there is no flag seen, then |
| 35 // this state may prevail for much or all of the process lifetime. | 38 // this state may prevail for much or all of the process lifetime. |
| 36 const ThreadData::Status kInitialStartupState = | 39 const ThreadData::Status kInitialStartupState = |
| 37 ThreadData::PROFILING_CHILDREN_ACTIVE; | 40 ThreadData::PROFILING_CHILDREN_ACTIVE; |
| 38 | 41 |
| 39 // Control whether an alternate time source (Now() function) is supported by | 42 // Control whether an alternate time source (Now() function) is supported by |
| 40 // the ThreadData class. This compile time flag should be set to true if we | 43 // the ThreadData class. This compile time flag should be set to true if we |
| 41 // want other modules (such as a memory allocator, or a thread-specific CPU time | 44 // want other modules (such as a memory allocator, or a thread-specific CPU time |
| 42 // clock) to be able to provide a thread-specific Now() function. Without this | 45 // clock) to be able to provide a thread-specific Now() function. Without this |
| 43 // compile-time flag, the code will only support the wall-clock time. This flag | 46 // compile-time flag, the code will only support the wall-clock time. This flag |
| 44 // can be flipped to efficiently disable this path (if there is a performance | 47 // can be flipped to efficiently disable this path (if there is a performance |
| 45 // problem with its presence). | 48 // problem with its presence). |
| 46 static const bool kAllowAlternateTimeSourceHandling = true; | 49 static const bool kAllowAlternateTimeSourceHandling = true; |
| 50 |
| 47 } // namespace | 51 } // namespace |
| 48 | 52 |
| 49 //------------------------------------------------------------------------------ | 53 //------------------------------------------------------------------------------ |
| 50 // DeathData tallies durations when a death takes place. | 54 // DeathData tallies durations when a death takes place. |
| 51 | 55 |
| 52 DeathData::DeathData() { | 56 DeathData::DeathData() { |
| 53 Clear(); | 57 Clear(); |
| 54 } | 58 } |
| 55 | 59 |
| 56 DeathData::DeathData(int count) { | 60 DeathData::DeathData(int count) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 110 } |
| 107 | 111 |
| 108 int32 DeathData::queue_duration_max() const { | 112 int32 DeathData::queue_duration_max() const { |
| 109 return queue_duration_max_; | 113 return queue_duration_max_; |
| 110 } | 114 } |
| 111 | 115 |
| 112 int32 DeathData::queue_duration_sample() const { | 116 int32 DeathData::queue_duration_sample() const { |
| 113 return queue_duration_sample_; | 117 return queue_duration_sample_; |
| 114 } | 118 } |
| 115 | 119 |
| 116 | |
| 117 base::DictionaryValue* DeathData::ToValue() const { | |
| 118 base::DictionaryValue* dictionary = new base::DictionaryValue; | |
| 119 dictionary->Set("count", base::Value::CreateIntegerValue(count_)); | |
| 120 dictionary->Set("run_ms", | |
| 121 base::Value::CreateIntegerValue(run_duration_sum())); | |
| 122 dictionary->Set("run_ms_max", | |
| 123 base::Value::CreateIntegerValue(run_duration_max())); | |
| 124 dictionary->Set("run_ms_sample", | |
| 125 base::Value::CreateIntegerValue(run_duration_sample())); | |
| 126 dictionary->Set("queue_ms", | |
| 127 base::Value::CreateIntegerValue(queue_duration_sum())); | |
| 128 dictionary->Set("queue_ms_max", | |
| 129 base::Value::CreateIntegerValue(queue_duration_max())); | |
| 130 dictionary->Set("queue_ms_sample", | |
| 131 base::Value::CreateIntegerValue(queue_duration_sample())); | |
| 132 return dictionary; | |
| 133 } | |
| 134 | |
| 135 void DeathData::ResetMax() { | 120 void DeathData::ResetMax() { |
| 136 run_duration_max_ = 0; | 121 run_duration_max_ = 0; |
| 137 queue_duration_max_ = 0; | 122 queue_duration_max_ = 0; |
| 138 } | 123 } |
| 139 | 124 |
| 140 void DeathData::Clear() { | 125 void DeathData::Clear() { |
| 141 count_ = 0; | 126 count_ = 0; |
| 142 run_duration_sum_ = 0; | 127 run_duration_sum_ = 0; |
| 143 run_duration_max_ = 0; | 128 run_duration_max_ = 0; |
| 144 run_duration_sample_ = 0; | 129 run_duration_sample_ = 0; |
| 145 queue_duration_sum_ = 0; | 130 queue_duration_sum_ = 0; |
| 146 queue_duration_max_ = 0; | 131 queue_duration_max_ = 0; |
| 147 queue_duration_sample_ = 0; | 132 queue_duration_sample_ = 0; |
| 148 } | 133 } |
| 149 | 134 |
| 150 //------------------------------------------------------------------------------ | 135 //------------------------------------------------------------------------------ |
| 136 DeathDataSnapshot::DeathDataSnapshot() |
| 137 : count(-1), |
| 138 run_duration_sum(-1), |
| 139 run_duration_max(-1), |
| 140 run_duration_sample(-1), |
| 141 queue_duration_sum(-1), |
| 142 queue_duration_max(-1), |
| 143 queue_duration_sample(-1) { |
| 144 } |
| 145 |
| 146 DeathDataSnapshot::DeathDataSnapshot( |
| 147 const tracked_objects::DeathData& death_data) |
| 148 : count(death_data.count()), |
| 149 run_duration_sum(death_data.run_duration_sum()), |
| 150 run_duration_max(death_data.run_duration_max()), |
| 151 run_duration_sample(death_data.run_duration_sample()), |
| 152 queue_duration_sum(death_data.queue_duration_sum()), |
| 153 queue_duration_max(death_data.queue_duration_max()), |
| 154 queue_duration_sample(death_data.queue_duration_sample()) { |
| 155 } |
| 156 |
| 157 DeathDataSnapshot::~DeathDataSnapshot() { |
| 158 } |
| 159 |
| 160 //------------------------------------------------------------------------------ |
| 151 BirthOnThread::BirthOnThread(const Location& location, | 161 BirthOnThread::BirthOnThread(const Location& location, |
| 152 const ThreadData& current) | 162 const ThreadData& current) |
| 153 : location_(location), | 163 : location_(location), |
| 154 birth_thread_(¤t) { | 164 birth_thread_(¤t) { |
| 155 } | 165 } |
| 156 | 166 |
| 157 const Location BirthOnThread::location() const { return location_; } | 167 //------------------------------------------------------------------------------ |
| 158 const ThreadData* BirthOnThread::birth_thread() const { return birth_thread_; } | 168 BirthOnThreadSnapshot::BirthOnThreadSnapshot() { |
| 169 } |
| 159 | 170 |
| 160 void BirthOnThread::ToValue(const std::string& prefix, | 171 BirthOnThreadSnapshot::BirthOnThreadSnapshot( |
| 161 base::DictionaryValue* dictionary) const { | 172 const tracked_objects::BirthOnThread& birth) |
| 162 dictionary->Set(prefix + "_location", location_.ToValue()); | 173 : location(birth.location()), |
| 163 dictionary->Set(prefix + "_thread", | 174 thread_name(birth.birth_thread()->thread_name()) { |
| 164 base::Value::CreateStringValue(birth_thread_->thread_name())); | 175 } |
| 176 |
| 177 BirthOnThreadSnapshot::~BirthOnThreadSnapshot() { |
| 165 } | 178 } |
| 166 | 179 |
| 167 //------------------------------------------------------------------------------ | 180 //------------------------------------------------------------------------------ |
| 168 Births::Births(const Location& location, const ThreadData& current) | 181 Births::Births(const Location& location, const ThreadData& current) |
| 169 : BirthOnThread(location, current), | 182 : BirthOnThread(location, current), |
| 170 birth_count_(1) { } | 183 birth_count_(1) { } |
| 171 | 184 |
| 172 int Births::birth_count() const { return birth_count_; } | 185 int Births::birth_count() const { return birth_count_; } |
| 173 | 186 |
| 174 void Births::RecordBirth() { ++birth_count_; } | 187 void Births::RecordBirth() { ++birth_count_; } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 return; | 340 return; |
| 328 } | 341 } |
| 329 // We must NOT do any allocations during this callback. | 342 // We must NOT do any allocations during this callback. |
| 330 // Using the simple linked lists avoids all allocations. | 343 // Using the simple linked lists avoids all allocations. |
| 331 DCHECK_EQ(this->next_retired_worker_, reinterpret_cast<ThreadData*>(NULL)); | 344 DCHECK_EQ(this->next_retired_worker_, reinterpret_cast<ThreadData*>(NULL)); |
| 332 this->next_retired_worker_ = first_retired_worker_; | 345 this->next_retired_worker_ = first_retired_worker_; |
| 333 first_retired_worker_ = this; | 346 first_retired_worker_ = this; |
| 334 } | 347 } |
| 335 | 348 |
| 336 // static | 349 // static |
| 337 base::DictionaryValue* ThreadData::ToValue(bool reset_max) { | 350 void ThreadData::Snapshot(bool reset_max, ProcessDataSnapshot* process_data) { |
| 338 DataCollector collected_data; // Gather data. | 351 // Add births that have run to completion to |collected_data|. |
| 339 // Request multiple calls to collected_data.Append() for all threads. | 352 // |birth_counts| tracks the total number of births recorded at each location |
| 340 SendAllMaps(reset_max, &collected_data); | 353 // for which we have not seen a death count. |
| 341 collected_data.AddListOfLivingObjects(); // Add births that are still alive. | 354 BirthCountMap birth_counts; |
| 342 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 355 ThreadData::SnapshotAllExecutedTasks(reset_max, process_data, &birth_counts); |
| 343 collected_data.ToValue(dictionary); | 356 |
| 344 return dictionary; | 357 // Add births that are still active -- i.e. objects that have tallied a birth, |
| 358 // but have not yet tallied a matching death, and hence must be either |
| 359 // running, queued up, or being held in limbo for future posting. |
| 360 for (BirthCountMap::const_iterator it = birth_counts.begin(); |
| 361 it != birth_counts.end(); ++it) { |
| 362 if (it->second > 0) { |
| 363 process_data->tasks.push_back( |
| 364 TaskSnapshot(*it->first, DeathData(it->second), "Still_Alive")); |
| 365 } |
| 366 } |
| 345 } | 367 } |
| 346 | 368 |
| 347 Births* ThreadData::TallyABirth(const Location& location) { | 369 Births* ThreadData::TallyABirth(const Location& location) { |
| 348 BirthMap::iterator it = birth_map_.find(location); | 370 BirthMap::iterator it = birth_map_.find(location); |
| 349 Births* child; | 371 Births* child; |
| 350 if (it != birth_map_.end()) { | 372 if (it != birth_map_.end()) { |
| 351 child = it->second; | 373 child = it->second; |
| 352 child->RecordBirth(); | 374 child->RecordBirth(); |
| 353 } else { | 375 } else { |
| 354 child = new Births(location, *this); // Leak this. | 376 child = new Births(location, *this); // Leak this. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 542 |
| 521 int32 queue_duration = 0; | 543 int32 queue_duration = 0; |
| 522 int32 run_duration = 0; | 544 int32 run_duration = 0; |
| 523 if (!start_of_run.is_null() && !end_of_run.is_null()) | 545 if (!start_of_run.is_null() && !end_of_run.is_null()) |
| 524 run_duration = (end_of_run - start_of_run).InMilliseconds(); | 546 run_duration = (end_of_run - start_of_run).InMilliseconds(); |
| 525 current_thread_data->TallyADeath(*birth, queue_duration, run_duration); | 547 current_thread_data->TallyADeath(*birth, queue_duration, run_duration); |
| 526 } | 548 } |
| 527 | 549 |
| 528 const std::string ThreadData::thread_name() const { return thread_name_; } | 550 const std::string ThreadData::thread_name() const { return thread_name_; } |
| 529 | 551 |
| 552 // static |
| 553 void ThreadData::SnapshotAllExecutedTasks(bool reset_max, |
| 554 ProcessDataSnapshot* process_data, |
| 555 BirthCountMap* birth_counts) { |
| 556 if (!kTrackAllTaskObjects) |
| 557 return; // Not compiled in. |
| 558 |
| 559 // Get an unchanging copy of a ThreadData list. |
| 560 ThreadData* my_list = ThreadData::first(); |
| 561 |
| 562 // Gather data serially. |
| 563 // This hackish approach *can* get some slighly corrupt tallies, as we are |
| 564 // grabbing values without the protection of a lock, but it has the advantage |
| 565 // of working even with threads that don't have message loops. If a user |
| 566 // sees any strangeness, they can always just run their stats gathering a |
| 567 // second time. |
| 568 for (ThreadData* thread_data = my_list; |
| 569 thread_data; |
| 570 thread_data = thread_data->next()) { |
| 571 thread_data->SnapshotExecutedTasks(reset_max, process_data, birth_counts); |
| 572 } |
| 573 } |
| 574 |
| 575 void ThreadData::SnapshotExecutedTasks(bool reset_max, |
| 576 ProcessDataSnapshot* process_data, |
| 577 BirthCountMap* birth_counts) { |
| 578 // Get copy of data, so that the data will not change during the iterations |
| 579 // and processing. |
| 580 ThreadData::BirthMap birth_map; |
| 581 ThreadData::DeathMap death_map; |
| 582 ThreadData::ParentChildSet parent_child_set; |
| 583 SnapshotMaps(reset_max, &birth_map, &death_map, &parent_child_set); |
| 584 |
| 585 for (ThreadData::DeathMap::const_iterator it = death_map.begin(); |
| 586 it != death_map.end(); ++it) { |
| 587 process_data->tasks.push_back( |
| 588 TaskSnapshot(*it->first, it->second, thread_name())); |
| 589 (*birth_counts)[it->first] -= it->first->birth_count(); |
| 590 } |
| 591 |
| 592 for (ThreadData::BirthMap::const_iterator it = birth_map.begin(); |
| 593 it != birth_map.end(); ++it) { |
| 594 (*birth_counts)[it->second] += it->second->birth_count(); |
| 595 } |
| 596 |
| 597 if (!kTrackParentChildLinks) |
| 598 return; |
| 599 |
| 600 for (ThreadData::ParentChildSet::const_iterator it = parent_child_set.begin(); |
| 601 it != parent_child_set.end(); ++it) { |
| 602 process_data->descendants.push_back(ParentChildPairSnapshot(*it)); |
| 603 } |
| 604 } |
| 605 |
| 530 // This may be called from another thread. | 606 // This may be called from another thread. |
| 531 void ThreadData::SnapshotMaps(bool reset_max, | 607 void ThreadData::SnapshotMaps(bool reset_max, |
| 532 BirthMap* birth_map, | 608 BirthMap* birth_map, |
| 533 DeathMap* death_map, | 609 DeathMap* death_map, |
| 534 ParentChildSet* parent_child_set) { | 610 ParentChildSet* parent_child_set) { |
| 535 base::AutoLock lock(map_lock_); | 611 base::AutoLock lock(map_lock_); |
| 536 for (BirthMap::const_iterator it = birth_map_.begin(); | 612 for (BirthMap::const_iterator it = birth_map_.begin(); |
| 537 it != birth_map_.end(); ++it) | 613 it != birth_map_.end(); ++it) |
| 538 (*birth_map)[it->first] = it->second; | 614 (*birth_map)[it->first] = it->second; |
| 539 for (DeathMap::iterator it = death_map_.begin(); | 615 for (DeathMap::iterator it = death_map_.begin(); |
| 540 it != death_map_.end(); ++it) { | 616 it != death_map_.end(); ++it) { |
| 541 (*death_map)[it->first] = it->second; | 617 (*death_map)[it->first] = it->second; |
| 542 if (reset_max) | 618 if (reset_max) |
| 543 it->second.ResetMax(); | 619 it->second.ResetMax(); |
| 544 } | 620 } |
| 545 | 621 |
| 546 if (!kTrackParentChildLinks) | 622 if (!kTrackParentChildLinks) |
| 547 return; | 623 return; |
| 548 | 624 |
| 549 for (ParentChildSet::iterator it = parent_child_set_.begin(); | 625 for (ParentChildSet::iterator it = parent_child_set_.begin(); |
| 550 it != parent_child_set_.end(); ++it) | 626 it != parent_child_set_.end(); ++it) |
| 551 parent_child_set->insert(*it); | 627 parent_child_set->insert(*it); |
| 552 } | 628 } |
| 553 | 629 |
| 554 // static | 630 // static |
| 555 void ThreadData::SendAllMaps(bool reset_max, class DataCollector* target) { | |
| 556 if (!kTrackAllTaskObjects) | |
| 557 return; // Not compiled in. | |
| 558 // Get an unchanging copy of a ThreadData list. | |
| 559 ThreadData* my_list = ThreadData::first(); | |
| 560 | |
| 561 // Gather data serially. | |
| 562 // This hackish approach *can* get some slighly corrupt tallies, as we are | |
| 563 // grabbing values without the protection of a lock, but it has the advantage | |
| 564 // of working even with threads that don't have message loops. If a user | |
| 565 // sees any strangeness, they can always just run their stats gathering a | |
| 566 // second time. | |
| 567 for (ThreadData* thread_data = my_list; | |
| 568 thread_data; | |
| 569 thread_data = thread_data->next()) { | |
| 570 // Get copy of data. | |
| 571 ThreadData::BirthMap birth_map; | |
| 572 ThreadData::DeathMap death_map; | |
| 573 ThreadData::ParentChildSet parent_child_set; | |
| 574 thread_data->SnapshotMaps(reset_max, &birth_map, &death_map, | |
| 575 &parent_child_set); | |
| 576 target->Append(*thread_data, birth_map, death_map, parent_child_set); | |
| 577 } | |
| 578 } | |
| 579 | |
| 580 // static | |
| 581 void ThreadData::ResetAllThreadData() { | 631 void ThreadData::ResetAllThreadData() { |
| 582 ThreadData* my_list = first(); | 632 ThreadData* my_list = first(); |
| 583 | 633 |
| 584 for (ThreadData* thread_data = my_list; | 634 for (ThreadData* thread_data = my_list; |
| 585 thread_data; | 635 thread_data; |
| 586 thread_data = thread_data->next()) | 636 thread_data = thread_data->next()) |
| 587 thread_data->Reset(); | 637 thread_data->Reset(); |
| 588 } | 638 } |
| 589 | 639 |
| 590 void ThreadData::Reset() { | 640 void ThreadData::Reset() { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 thread_data_list = thread_data_list->next(); | 828 thread_data_list = thread_data_list->next(); |
| 779 | 829 |
| 780 for (BirthMap::iterator it = next_thread_data->birth_map_.begin(); | 830 for (BirthMap::iterator it = next_thread_data->birth_map_.begin(); |
| 781 next_thread_data->birth_map_.end() != it; ++it) | 831 next_thread_data->birth_map_.end() != it; ++it) |
| 782 delete it->second; // Delete the Birth Records. | 832 delete it->second; // Delete the Birth Records. |
| 783 delete next_thread_data; // Includes all Death Records. | 833 delete next_thread_data; // Includes all Death Records. |
| 784 } | 834 } |
| 785 } | 835 } |
| 786 | 836 |
| 787 //------------------------------------------------------------------------------ | 837 //------------------------------------------------------------------------------ |
| 788 // Individual 3-tuple of birth (place and thread) along with death thread, and | 838 TaskSnapshot::TaskSnapshot() { |
| 789 // the accumulated stats for instances (DeathData). | |
| 790 | |
| 791 Snapshot::Snapshot(const BirthOnThread& birth_on_thread, | |
| 792 const ThreadData& death_thread, | |
| 793 const DeathData& death_data) | |
| 794 : birth_(&birth_on_thread), | |
| 795 death_thread_(&death_thread), | |
| 796 death_data_(death_data) { | |
| 797 } | 839 } |
| 798 | 840 |
| 799 Snapshot::Snapshot(const BirthOnThread& birth_on_thread, int count) | 841 TaskSnapshot::TaskSnapshot(const BirthOnThread& birth, |
| 800 : birth_(&birth_on_thread), | 842 const DeathData& death_data, |
| 801 death_thread_(NULL), | 843 const std::string& death_thread_name) |
| 802 death_data_(DeathData(count)) { | 844 : birth(birth), |
| 845 death_data(death_data), |
| 846 death_thread_name(death_thread_name) { |
| 803 } | 847 } |
| 804 | 848 |
| 805 const std::string Snapshot::DeathThreadName() const { | 849 TaskSnapshot::~TaskSnapshot() { |
| 806 if (death_thread_) | |
| 807 return death_thread_->thread_name(); | |
| 808 return "Still_Alive"; | |
| 809 } | |
| 810 | |
| 811 base::DictionaryValue* Snapshot::ToValue() const { | |
| 812 base::DictionaryValue* dictionary = new base::DictionaryValue; | |
| 813 // TODO(jar): Switch the next two lines to: | |
| 814 // birth_->ToValue("birth", dictionary); | |
| 815 // ...but that will require fixing unit tests, and JS to take | |
| 816 // "birth_location" rather than "location" | |
| 817 dictionary->Set("birth_thread", | |
| 818 base::Value::CreateStringValue(birth_->birth_thread()->thread_name())); | |
| 819 dictionary->Set("location", birth_->location().ToValue()); | |
| 820 | |
| 821 dictionary->Set("death_data", death_data_.ToValue()); | |
| 822 dictionary->Set("death_thread", | |
| 823 base::Value::CreateStringValue(DeathThreadName())); | |
| 824 return dictionary; | |
| 825 } | 850 } |
| 826 | 851 |
| 827 //------------------------------------------------------------------------------ | 852 //------------------------------------------------------------------------------ |
| 828 // DataCollector | 853 // ParentChildPairSnapshot |
| 829 | 854 |
| 830 DataCollector::DataCollector() {} | 855 ParentChildPairSnapshot::ParentChildPairSnapshot(){ |
| 831 | |
| 832 DataCollector::~DataCollector() { | |
| 833 } | 856 } |
| 834 | 857 |
| 835 void DataCollector::Append(const ThreadData& thread_data, | 858 ParentChildPairSnapshot::ParentChildPairSnapshot( |
| 836 const ThreadData::BirthMap& birth_map, | 859 const ThreadData::ParentChildPair& parent_child) |
| 837 const ThreadData::DeathMap& death_map, | 860 : parent(*parent_child.first), |
| 838 const ThreadData::ParentChildSet& parent_child_set) { | 861 child(*parent_child.second) { |
| 839 for (ThreadData::DeathMap::const_iterator it = death_map.begin(); | |
| 840 it != death_map.end(); ++it) { | |
| 841 collection_.push_back(Snapshot(*it->first, thread_data, it->second)); | |
| 842 global_birth_count_[it->first] -= it->first->birth_count(); | |
| 843 } | |
| 844 | |
| 845 for (ThreadData::BirthMap::const_iterator it = birth_map.begin(); | |
| 846 it != birth_map.end(); ++it) { | |
| 847 global_birth_count_[it->second] += it->second->birth_count(); | |
| 848 } | |
| 849 | |
| 850 if (!kTrackParentChildLinks) | |
| 851 return; | |
| 852 | |
| 853 for (ThreadData::ParentChildSet::const_iterator it = parent_child_set.begin(); | |
| 854 it != parent_child_set.end(); ++it) { | |
| 855 parent_child_set_.insert(*it); | |
| 856 } | |
| 857 } | 862 } |
| 858 | 863 |
| 859 DataCollector::Collection* DataCollector::collection() { | 864 ParentChildPairSnapshot::~ParentChildPairSnapshot() { |
| 860 return &collection_; | |
| 861 } | 865 } |
| 862 | 866 |
| 863 void DataCollector::AddListOfLivingObjects() { | 867 //------------------------------------------------------------------------------ |
| 864 for (BirthCount::iterator it = global_birth_count_.begin(); | 868 // ProcessDataSnapshot |
| 865 it != global_birth_count_.end(); ++it) { | 869 |
| 866 if (it->second > 0) | 870 ProcessDataSnapshot::ProcessDataSnapshot() |
| 867 collection_.push_back(Snapshot(*it->first, it->second)); | 871 : process_id(base::GetCurrentProcId()) { |
| 868 } | |
| 869 } | 872 } |
| 870 | 873 |
| 871 void DataCollector::ToValue(base::DictionaryValue* dictionary) const { | 874 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 872 base::ListValue* list = new base::ListValue; | |
| 873 for (size_t i = 0; i < collection_.size(); ++i) { | |
| 874 list->Append(collection_[i].ToValue()); | |
| 875 } | |
| 876 dictionary->Set("list", list); | |
| 877 | |
| 878 base::ListValue* descendants = new base::ListValue; | |
| 879 for (ThreadData::ParentChildSet::const_iterator it = | |
| 880 parent_child_set_.begin(); | |
| 881 it != parent_child_set_.end(); | |
| 882 ++it) { | |
| 883 base::DictionaryValue* parent_child = new base::DictionaryValue; | |
| 884 it->first->ToValue("parent", parent_child); | |
| 885 it->second->ToValue("child", parent_child); | |
| 886 descendants->Append(parent_child); | |
| 887 } | |
| 888 dictionary->Set("descendants", descendants); | |
| 889 } | 875 } |
| 890 | 876 |
| 891 } // namespace tracked_objects | 877 } // namespace tracked_objects |
| OLD | NEW |