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

Side by Side Diff: base/tracked_objects.cc

Issue 9702014: [UMA] Use proper C++ objects to serialize tracked_objects across process boundaries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
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 #include "base/tracked_objects.h" 5 #include "base/tracked_objects.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.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" 17 #include "build/build_config.h"
16 #include "base/port.h" 18 #include "base/port.h"
17 19
20 using base::DictionaryValue;
18 using base::TimeDelta; 21 using base::TimeDelta;
22 using base::Value;
19 23
20 namespace tracked_objects { 24 namespace tracked_objects {
21 25
22 namespace { 26 namespace {
23 27
24 // Flag to compile out almost all of the task tracking code. 28 // Flag to compile out almost all of the task tracking code.
25 const bool kTrackAllTaskObjects = true; 29 const bool kTrackAllTaskObjects = true;
26 30
27 // Flag to compile out parent-child link recording. 31 // Flag to compile out parent-child link recording.
28 const bool kTrackParentChildLinks = false; 32 const bool kTrackParentChildLinks = false;
29 33
30 // When ThreadData is first initialized, should we start in an ACTIVE state to 34 // 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 35 // 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. 36 // 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 37 // 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 38 // 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. 39 // this state may prevail for much or all of the process lifetime.
36 const ThreadData::Status kInitialStartupState = 40 const ThreadData::Status kInitialStartupState =
37 ThreadData::PROFILING_CHILDREN_ACTIVE; 41 ThreadData::PROFILING_CHILDREN_ACTIVE;
38 42
39 // Control whether an alternate time source (Now() function) is supported by 43 // 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 44 // 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 45 // 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 46 // 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 47 // 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 48 // can be flipped to efficiently disable this path (if there is a performance
45 // problem with its presence). 49 // problem with its presence).
46 static const bool kAllowAlternateTimeSourceHandling = true; 50 static const bool kAllowAlternateTimeSourceHandling = true;
51
47 } // namespace 52 } // namespace
48 53
49 //------------------------------------------------------------------------------ 54 //------------------------------------------------------------------------------
50 // DeathData tallies durations when a death takes place. 55 // DeathData tallies durations when a death takes place.
51 56
52 DeathData::DeathData() { 57 DeathData::DeathData() {
53 Clear(); 58 Clear();
54 } 59 }
55 60
56 DeathData::DeathData(int count) { 61 DeathData::DeathData(int count) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 111 }
107 112
108 DurationInt DeathData::queue_duration_max() const { 113 DurationInt DeathData::queue_duration_max() const {
109 return queue_duration_max_; 114 return queue_duration_max_;
110 } 115 }
111 116
112 DurationInt DeathData::queue_duration_sample() const { 117 DurationInt DeathData::queue_duration_sample() const {
113 return queue_duration_sample_; 118 return queue_duration_sample_;
114 } 119 }
115 120
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() { 121 void DeathData::ResetMax() {
136 run_duration_max_ = 0; 122 run_duration_max_ = 0;
137 queue_duration_max_ = 0; 123 queue_duration_max_ = 0;
138 } 124 }
139 125
140 void DeathData::Clear() { 126 void DeathData::Clear() {
141 count_ = 0; 127 count_ = 0;
142 run_duration_sum_ = 0; 128 run_duration_sum_ = 0;
143 run_duration_max_ = 0; 129 run_duration_max_ = 0;
144 run_duration_sample_ = 0; 130 run_duration_sample_ = 0;
145 queue_duration_sum_ = 0; 131 queue_duration_sum_ = 0;
146 queue_duration_max_ = 0; 132 queue_duration_max_ = 0;
147 queue_duration_sample_ = 0; 133 queue_duration_sample_ = 0;
148 } 134 }
149 135
150 //------------------------------------------------------------------------------ 136 //------------------------------------------------------------------------------
137 SerializedDeathData::SerializedDeathData() {
138 }
139
140 SerializedDeathData::SerializedDeathData(
141 const tracked_objects::DeathData& death_data)
142 : count(death_data.count()),
143 run_duration_sum(death_data.run_duration_sum()),
144 run_duration_max(death_data.run_duration_max()),
145 run_duration_sample(death_data.run_duration_sample()),
146 queue_duration_sum(death_data.queue_duration_sum()),
147 queue_duration_max(death_data.queue_duration_max()),
148 queue_duration_sample(death_data.queue_duration_sample()) {
149 }
150
151 SerializedDeathData::~SerializedDeathData() {
152 }
153
154 void SerializedDeathData::ToValue(DictionaryValue* dictionary) const {
155 dictionary->Set("count", Value::CreateIntegerValue(count));
156 dictionary->Set("run_ms", Value::CreateIntegerValue(run_duration_sum));
157 dictionary->Set("run_ms_max", Value::CreateIntegerValue(run_duration_max));
158 dictionary->Set("run_ms_sample",
159 Value::CreateIntegerValue(run_duration_sample));
160 dictionary->Set("queue_ms", Value::CreateIntegerValue(queue_duration_sum));
161 dictionary->Set("queue_ms_max",
162 Value::CreateIntegerValue(queue_duration_max));
163 dictionary->Set("queue_ms_sample",
164 Value::CreateIntegerValue(queue_duration_sample));
165 }
166
167 //------------------------------------------------------------------------------
151 BirthOnThread::BirthOnThread(const Location& location, 168 BirthOnThread::BirthOnThread(const Location& location,
152 const ThreadData& current) 169 const ThreadData& current)
153 : location_(location), 170 : location_(location),
154 birth_thread_(&current) { 171 birth_thread_(&current) {
155 } 172 }
156 173
157 const Location BirthOnThread::location() const { return location_; } 174 //------------------------------------------------------------------------------
158 const ThreadData* BirthOnThread::birth_thread() const { return birth_thread_; } 175 SerializedBirthOnThread::SerializedBirthOnThread() {
176 }
159 177
160 void BirthOnThread::ToValue(const std::string& prefix, 178 SerializedBirthOnThread::SerializedBirthOnThread(
161 base::DictionaryValue* dictionary) const { 179 const tracked_objects::BirthOnThread& birth)
162 dictionary->Set(prefix + "_location", location_.ToValue()); 180 : location(birth.location()),
163 dictionary->Set(prefix + "_thread", 181 thread_name(birth.birth_thread()->thread_name()) {
164 base::Value::CreateStringValue(birth_thread_->thread_name())); 182 }
183
184 SerializedBirthOnThread::~SerializedBirthOnThread() {
185 }
186
187 void SerializedBirthOnThread::ToValue(const std::string& prefix,
188 DictionaryValue* dictionary) const {
189 scoped_ptr<DictionaryValue> location_value(new DictionaryValue);
190 location.ToValue(location_value.get());
191
192 // TODO(jar): Remove the if/else below and disallow passing an empty prefix,
193 // but that will require fixing unit tests, and JS to take "birth_location"
194 // rather than "location".
195 std::string location_key = "location";
196 std::string thread_name_key = "thread";
197 if (!prefix.empty()) {
198 location_key = prefix + "_" + location_key;
199 thread_name_key = prefix + "_" + thread_name_key;
200 } else {
201 // For not we special-case the birth thread, as the renderer code expects
202 // "location" rather than "birth_location".
203 thread_name_key = "birth_" + thread_name_key;
204 }
205
206 dictionary->Set(location_key, location_value.release());
207 dictionary->Set(thread_name_key, Value::CreateStringValue(thread_name));
165 } 208 }
166 209
167 //------------------------------------------------------------------------------ 210 //------------------------------------------------------------------------------
168 Births::Births(const Location& location, const ThreadData& current) 211 Births::Births(const Location& location, const ThreadData& current)
169 : BirthOnThread(location, current), 212 : BirthOnThread(location, current),
170 birth_count_(1) { } 213 birth_count_(1) { }
171 214
172 int Births::birth_count() const { return birth_count_; } 215 int Births::birth_count() const { return birth_count_; }
173 216
174 void Births::RecordBirth() { ++birth_count_; } 217 void Births::RecordBirth() { ++birth_count_; }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return; 370 return;
328 } 371 }
329 // We must NOT do any allocations during this callback. 372 // We must NOT do any allocations during this callback.
330 // Using the simple linked lists avoids all allocations. 373 // Using the simple linked lists avoids all allocations.
331 DCHECK_EQ(this->next_retired_worker_, reinterpret_cast<ThreadData*>(NULL)); 374 DCHECK_EQ(this->next_retired_worker_, reinterpret_cast<ThreadData*>(NULL));
332 this->next_retired_worker_ = first_retired_worker_; 375 this->next_retired_worker_ = first_retired_worker_;
333 first_retired_worker_ = this; 376 first_retired_worker_ = this;
334 } 377 }
335 378
336 // static 379 // static
337 base::DictionaryValue* ThreadData::ToValue(bool reset_max) { 380 void ThreadData::ToSerializedProcessData(bool reset_max,
338 DataCollector collected_data; // Gather data. 381 SerializedProcessData* process_data) {
339 // Request multiple calls to collected_data.Append() for all threads. 382 // Add births that have run to completion to |collected_data|.
340 SendAllMaps(reset_max, &collected_data); 383 // |birth_counts| tracks the total number of births recorded at each location
341 collected_data.AddListOfLivingObjects(); // Add births that are still alive. 384 // for which we have not seen a death count.
342 base::DictionaryValue* dictionary = new base::DictionaryValue(); 385 std::map<const BirthOnThread*, int> birth_counts;
343 collected_data.ToValue(dictionary); 386 ThreadData::SerializeAllExecutedTasks(reset_max, process_data, &birth_counts);
344 return dictionary; 387
388 // Add births that are still active -- i.e. objects that have tallied a birth,
389 // but have not yet tallied a matching death, and hence must be either
390 // running, queued up, or being held in limbo for future posting.
391 for (std::map<const BirthOnThread*, int>::const_iterator it =
392 birth_counts.begin();
393 it != birth_counts.end(); ++it) {
394 if (it->second > 0) {
395 process_data->snapshots.push_back(
396 SerializedSnapshot(*it->first,
397 DeathData(it->second),
398 "Still_Alive"));
399 }
400 }
345 } 401 }
346 402
347 Births* ThreadData::TallyABirth(const Location& location) { 403 Births* ThreadData::TallyABirth(const Location& location) {
348 BirthMap::iterator it = birth_map_.find(location); 404 BirthMap::iterator it = birth_map_.find(location);
349 Births* child; 405 Births* child;
350 if (it != birth_map_.end()) { 406 if (it != birth_map_.end()) {
351 child = it->second; 407 child = it->second;
352 child->RecordBirth(); 408 child->RecordBirth();
353 } else { 409 } else {
354 child = new Births(location, *this); // Leak this. 410 child = new Births(location, *this); // Leak this.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 576
521 DurationInt queue_duration = 0; 577 DurationInt queue_duration = 0;
522 DurationInt run_duration = 0; 578 DurationInt run_duration = 0;
523 if (!start_of_run.is_null() && !end_of_run.is_null()) 579 if (!start_of_run.is_null() && !end_of_run.is_null())
524 run_duration = (end_of_run - start_of_run).InMilliseconds(); 580 run_duration = (end_of_run - start_of_run).InMilliseconds();
525 current_thread_data->TallyADeath(*birth, queue_duration, run_duration); 581 current_thread_data->TallyADeath(*birth, queue_duration, run_duration);
526 } 582 }
527 583
528 const std::string ThreadData::thread_name() const { return thread_name_; } 584 const std::string ThreadData::thread_name() const { return thread_name_; }
529 585
586 // static
587 void ThreadData::SerializeAllExecutedTasks(
588 bool reset_max,
589 SerializedProcessData* process_data,
590 std::map<const BirthOnThread*, int>* birth_counts) {
591 if (!kTrackAllTaskObjects)
592 return; // Not compiled in.
593
594 // Get an unchanging copy of a ThreadData list.
595 ThreadData* my_list = ThreadData::first();
596
597 // Gather data serially.
598 // This hackish approach *can* get some slighly corrupt tallies, as we are
599 // grabbing values without the protection of a lock, but it has the advantage
600 // of working even with threads that don't have message loops. If a user
601 // sees any strangeness, they can always just run their stats gathering a
602 // second time.
603 for (ThreadData* thread_data = my_list;
604 thread_data;
605 thread_data = thread_data->next()) {
606 thread_data->SerializeExecutedTasks(reset_max, process_data, birth_counts);
607 }
608 }
609
610 void ThreadData::SerializeExecutedTasks(
611 bool reset_max,
612 SerializedProcessData* process_data,
613 std::map<const BirthOnThread*, int>* birth_counts) {
614 // Get copy of data, so that the data will not change during the iterations
615 // and processing.
616 ThreadData::BirthMap birth_map;
617 ThreadData::DeathMap death_map;
618 ThreadData::ParentChildSet parent_child_set;
619 SnapshotMaps(reset_max, &birth_map, &death_map, &parent_child_set);
620
621 for (ThreadData::DeathMap::const_iterator it = death_map.begin();
622 it != death_map.end(); ++it) {
623 process_data->snapshots.push_back(
624 SerializedSnapshot(*it->first, it->second, thread_name()));
625 (*birth_counts)[it->first] -= it->first->birth_count();
626 }
627
628 for (ThreadData::BirthMap::const_iterator it = birth_map.begin();
629 it != birth_map.end(); ++it) {
630 (*birth_counts)[it->second] += it->second->birth_count();
631 }
632
633 if (!kTrackParentChildLinks)
634 return;
635
636 for (ThreadData::ParentChildSet::const_iterator it = parent_child_set.begin();
637 it != parent_child_set.end(); ++it) {
638 process_data->descendants.push_back(SerializedParentChildPair(*it));
639 }
640 }
641
530 // This may be called from another thread. 642 // This may be called from another thread.
531 void ThreadData::SnapshotMaps(bool reset_max, 643 void ThreadData::SnapshotMaps(bool reset_max,
532 BirthMap* birth_map, 644 BirthMap* birth_map,
533 DeathMap* death_map, 645 DeathMap* death_map,
534 ParentChildSet* parent_child_set) { 646 ParentChildSet* parent_child_set) {
535 base::AutoLock lock(map_lock_); 647 base::AutoLock lock(map_lock_);
536 for (BirthMap::const_iterator it = birth_map_.begin(); 648 for (BirthMap::const_iterator it = birth_map_.begin();
537 it != birth_map_.end(); ++it) 649 it != birth_map_.end(); ++it)
538 (*birth_map)[it->first] = it->second; 650 (*birth_map)[it->first] = it->second;
539 for (DeathMap::iterator it = death_map_.begin(); 651 for (DeathMap::iterator it = death_map_.begin();
540 it != death_map_.end(); ++it) { 652 it != death_map_.end(); ++it) {
541 (*death_map)[it->first] = it->second; 653 (*death_map)[it->first] = it->second;
542 if (reset_max) 654 if (reset_max)
543 it->second.ResetMax(); 655 it->second.ResetMax();
544 } 656 }
545 657
546 if (!kTrackParentChildLinks) 658 if (!kTrackParentChildLinks)
547 return; 659 return;
548 660
549 for (ParentChildSet::iterator it = parent_child_set_.begin(); 661 for (ParentChildSet::iterator it = parent_child_set_.begin();
550 it != parent_child_set_.end(); ++it) 662 it != parent_child_set_.end(); ++it)
551 parent_child_set->insert(*it); 663 parent_child_set->insert(*it);
552 } 664 }
553 665
554 // static 666 // 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() { 667 void ThreadData::ResetAllThreadData() {
582 ThreadData* my_list = first(); 668 ThreadData* my_list = first();
583 669
584 for (ThreadData* thread_data = my_list; 670 for (ThreadData* thread_data = my_list;
585 thread_data; 671 thread_data;
586 thread_data = thread_data->next()) 672 thread_data = thread_data->next())
587 thread_data->Reset(); 673 thread_data->Reset();
588 } 674 }
589 675
590 void ThreadData::Reset() { 676 void ThreadData::Reset() {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 thread_data_list = thread_data_list->next(); 864 thread_data_list = thread_data_list->next();
779 865
780 for (BirthMap::iterator it = next_thread_data->birth_map_.begin(); 866 for (BirthMap::iterator it = next_thread_data->birth_map_.begin();
781 next_thread_data->birth_map_.end() != it; ++it) 867 next_thread_data->birth_map_.end() != it; ++it)
782 delete it->second; // Delete the Birth Records. 868 delete it->second; // Delete the Birth Records.
783 delete next_thread_data; // Includes all Death Records. 869 delete next_thread_data; // Includes all Death Records.
784 } 870 }
785 } 871 }
786 872
787 //------------------------------------------------------------------------------ 873 //------------------------------------------------------------------------------
788 // Individual 3-tuple of birth (place and thread) along with death thread, and 874 SerializedSnapshot::SerializedSnapshot() {
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 } 875 }
798 876
799 Snapshot::Snapshot(const BirthOnThread& birth_on_thread, int count) 877 SerializedSnapshot::SerializedSnapshot(const BirthOnThread& birth,
800 : birth_(&birth_on_thread), 878 const DeathData& death_data,
801 death_thread_(NULL), 879 const std::string& death_thread_name)
802 death_data_(DeathData(count)) { 880 : birth(birth),
881 death_data(death_data),
882 death_thread_name(death_thread_name) {
803 } 883 }
804 884
805 const std::string Snapshot::DeathThreadName() const { 885 SerializedSnapshot::~SerializedSnapshot() {
806 if (death_thread_)
807 return death_thread_->thread_name();
808 return "Still_Alive";
809 } 886 }
810 887
811 base::DictionaryValue* Snapshot::ToValue() const { 888 void SerializedSnapshot::ToValue(DictionaryValue* dictionary) const {
812 base::DictionaryValue* dictionary = new base::DictionaryValue; 889 // TODO(jar): Update the first argument below to be "birth" rather than an
813 // TODO(jar): Switch the next two lines to: 890 // empty string, but that will require fixing unit tests, and JS to take
814 // birth_->ToValue("birth", dictionary); 891 // "birth_location" rather than "location".
815 // ...but that will require fixing unit tests, and JS to take 892 birth.ToValue(std::string(), dictionary);
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 893
821 dictionary->Set("death_data", death_data_.ToValue()); 894 scoped_ptr<DictionaryValue> death_value(new DictionaryValue);
822 dictionary->Set("death_thread", 895 death_data.ToValue(death_value.get());
823 base::Value::CreateStringValue(DeathThreadName())); 896 dictionary->Set("death_data", death_value.release());
824 return dictionary; 897
898 dictionary->Set("death_thread", Value::CreateStringValue(death_thread_name));
825 } 899 }
826 900
827 //------------------------------------------------------------------------------ 901 //------------------------------------------------------------------------------
828 // DataCollector 902 // SerializedParentChildPair
829 903
830 DataCollector::DataCollector() {} 904 SerializedParentChildPair::SerializedParentChildPair(){
831
832 DataCollector::~DataCollector() {
833 } 905 }
834 906
835 void DataCollector::Append(const ThreadData& thread_data, 907 SerializedParentChildPair::SerializedParentChildPair(
836 const ThreadData::BirthMap& birth_map, 908 const ThreadData::ParentChildPair& parent_child)
837 const ThreadData::DeathMap& death_map, 909 : parent(*parent_child.first),
838 const ThreadData::ParentChildSet& parent_child_set) { 910 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 } 911 }
858 912
859 DataCollector::Collection* DataCollector::collection() { 913 SerializedParentChildPair::~SerializedParentChildPair() {
860 return &collection_;
861 } 914 }
862 915
863 void DataCollector::AddListOfLivingObjects() { 916 void SerializedParentChildPair::ToValue(
864 for (BirthCount::iterator it = global_birth_count_.begin(); 917 base::DictionaryValue* dictionary) const {
865 it != global_birth_count_.end(); ++it) { 918 parent.ToValue("parent", dictionary);
866 if (it->second > 0) 919 child.ToValue("child", dictionary);
867 collection_.push_back(Snapshot(*it->first, it->second));
868 }
869 } 920 }
870 921
871 void DataCollector::ToValue(base::DictionaryValue* dictionary) const { 922
872 base::ListValue* list = new base::ListValue; 923 //------------------------------------------------------------------------------
873 for (size_t i = 0; i < collection_.size(); ++i) { 924 // SerializedProcessData
874 list->Append(collection_[i].ToValue()); 925
926 SerializedProcessData::SerializedProcessData()
927 : process_id(base::GetCurrentProcId()) {
928 }
929
930 SerializedProcessData::~SerializedProcessData() {
931 }
932
933 void SerializedProcessData::ToValue(DictionaryValue* dictionary) const {
934 scoped_ptr<base::ListValue> snapshots_list(new base::ListValue);
935 for (std::vector<tracked_objects::SerializedSnapshot>::const_iterator it =
936 snapshots.begin();
937 it != snapshots.end(); ++it) {
938 scoped_ptr<DictionaryValue> snapshot(new DictionaryValue);
939 it->ToValue(snapshot.get());
940 snapshots_list->Append(snapshot.release());
875 } 941 }
876 dictionary->Set("list", list); 942 dictionary->Set("list", snapshots_list.release());
877 943
878 base::ListValue* descendants = new base::ListValue; 944 dictionary->SetInteger("process_id", process_id);
879 for (ThreadData::ParentChildSet::const_iterator it = 945
880 parent_child_set_.begin(); 946 scoped_ptr<base::ListValue> descendants_list(new base::ListValue);
881 it != parent_child_set_.end(); 947 for (std::vector<SerializedParentChildPair>::const_iterator it =
882 ++it) { 948 descendants.begin();
883 base::DictionaryValue* parent_child = new base::DictionaryValue; 949 it != descendants.end(); ++it) {
884 it->first->ToValue("parent", parent_child); 950 scoped_ptr<base::DictionaryValue> parent_child(new base::DictionaryValue);
885 it->second->ToValue("child", parent_child); 951 it->ToValue(parent_child.get());
886 descendants->Append(parent_child); 952 descendants_list->Append(parent_child.release());
887 } 953 }
888 dictionary->Set("descendants", descendants); 954 dictionary->Set("descendants", descendants_list.release());
889 } 955 }
890 956
891 } // namespace tracked_objects 957 } // namespace tracked_objects
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698