OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef BASE_TRACKED_OBJECTS_H_ | 5 #ifndef BASE_TRACKED_OBJECTS_H_ |
6 #define BASE_TRACKED_OBJECTS_H_ | 6 #define BASE_TRACKED_OBJECTS_H_ |
7 | 7 |
8 //------------------------------------------------------------------------------ | 8 //------------------------------------------------------------------------------ |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 class DeathData { | 73 class DeathData { |
74 public: | 74 public: |
75 // Default initializer. | 75 // Default initializer. |
76 DeathData() : count_(0), square_duration_(0) {} | 76 DeathData() : count_(0), square_duration_(0) {} |
77 | 77 |
78 // When deaths have not yet taken place, and we gather data from all the | 78 // When deaths have not yet taken place, and we gather data from all the |
79 // threads, we create DeathData stats that tally the number of births without | 79 // threads, we create DeathData stats that tally the number of births without |
80 // a corrosponding death. | 80 // a corrosponding death. |
81 explicit DeathData(int count) : count_(count), square_duration_(0) {} | 81 explicit DeathData(int count) : count_(count), square_duration_(0) {} |
82 | 82 |
83 void RecordDeath(const TimeDelta& duration); | 83 void RecordDeath(const base::TimeDelta& duration); |
84 | 84 |
85 // Metrics accessors. | 85 // Metrics accessors. |
86 int count() const { return count_; } | 86 int count() const { return count_; } |
87 TimeDelta life_duration() const { return life_duration_; } | 87 base::TimeDelta life_duration() const { return life_duration_; } |
88 int64 square_duration() const { return square_duration_; } | 88 int64 square_duration() const { return square_duration_; } |
89 int AverageMsDuration() const; | 89 int AverageMsDuration() const; |
90 double StandardDeviation() const; | 90 double StandardDeviation() const; |
91 | 91 |
92 // Accumulate metrics from other into this. | 92 // Accumulate metrics from other into this. |
93 void AddDeathData(const DeathData& other); | 93 void AddDeathData(const DeathData& other); |
94 | 94 |
95 // Simple print of internal state. | 95 // Simple print of internal state. |
96 void Write(std::string* output) const; | 96 void Write(std::string* output) const; |
97 | 97 |
98 void Clear(); | 98 void Clear(); |
99 | 99 |
100 private: | 100 private: |
101 int count_; // Number of destructions. | 101 int count_; // Number of destructions. |
102 TimeDelta life_duration_; // Sum of all lifetime durations. | 102 base::TimeDelta life_duration_; // Sum of all lifetime durations. |
103 int64 square_duration_; // Sum of squares in milliseconds. | 103 int64 square_duration_; // Sum of squares in milliseconds. |
104 }; | 104 }; |
105 | 105 |
106 //------------------------------------------------------------------------------ | 106 //------------------------------------------------------------------------------ |
107 // A temporary collection of data that can be sorted and summarized. It is | 107 // A temporary collection of data that can be sorted and summarized. It is |
108 // gathered (carefully) from many threads. Instances are held in arrays and | 108 // gathered (carefully) from many threads. Instances are held in arrays and |
109 // processed, filtered, and rendered. | 109 // processed, filtered, and rendered. |
110 // The source of this data was collected on many threads, and is asynchronously | 110 // The source of this data was collected on many threads, and is asynchronously |
111 // changing. The data in this instance is not asynchronously changing. | 111 // changing. The data in this instance is not asynchronously changing. |
112 | 112 |
113 class Snapshot { | 113 class Snapshot { |
114 public: | 114 public: |
115 // When snapshotting a full life cycle set (birth-to-death), use this: | 115 // When snapshotting a full life cycle set (birth-to-death), use this: |
116 Snapshot(const BirthOnThread& birth_on_thread, const ThreadData& death_thread, | 116 Snapshot(const BirthOnThread& birth_on_thread, const ThreadData& death_thread, |
117 const DeathData& death_data); | 117 const DeathData& death_data); |
118 | 118 |
119 // When snapshotting a birth, with no death yet, use this: | 119 // When snapshotting a birth, with no death yet, use this: |
120 Snapshot(const BirthOnThread& birth_on_thread, int count); | 120 Snapshot(const BirthOnThread& birth_on_thread, int count); |
121 | 121 |
122 | 122 |
123 const ThreadData* birth_thread() const { return birth_->birth_thread(); } | 123 const ThreadData* birth_thread() const { return birth_->birth_thread(); } |
124 const Location location() const { return birth_->location(); } | 124 const Location location() const { return birth_->location(); } |
125 const BirthOnThread& birth() const { return *birth_; } | 125 const BirthOnThread& birth() const { return *birth_; } |
126 const ThreadData* death_thread() const {return death_thread_; } | 126 const ThreadData* death_thread() const {return death_thread_; } |
127 const DeathData& death_data() const { return death_data_; } | 127 const DeathData& death_data() const { return death_data_; } |
128 const std::string DeathThreadName() const; | 128 const std::string DeathThreadName() const; |
129 | 129 |
130 int count() const { return death_data_.count(); } | 130 int count() const { return death_data_.count(); } |
131 TimeDelta life_duration() const { return death_data_.life_duration(); } | 131 base::TimeDelta life_duration() const { return death_data_.life_duration(); } |
132 int64 square_duration() const { return death_data_.square_duration(); } | 132 int64 square_duration() const { return death_data_.square_duration(); } |
133 int AverageMsDuration() const { return death_data_.AverageMsDuration(); } | 133 int AverageMsDuration() const { return death_data_.AverageMsDuration(); } |
134 | 134 |
135 void Write(std::string* output) const; | 135 void Write(std::string* output) const; |
136 | 136 |
137 void Add(const Snapshot& other); | 137 void Add(const Snapshot& other); |
138 | 138 |
139 private: | 139 private: |
140 const BirthOnThread* birth_; // Includes Location and birth_thread. | 140 const BirthOnThread* birth_; // Includes Location and birth_thread. |
141 const ThreadData* death_thread_; | 141 const ThreadData* death_thread_; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // For a given accumulated array of results, use the comparator to sort and | 332 // For a given accumulated array of results, use the comparator to sort and |
333 // subtotal, writing the results to the output. | 333 // subtotal, writing the results to the output. |
334 static void WriteHTMLTotalAndSubtotals( | 334 static void WriteHTMLTotalAndSubtotals( |
335 const DataCollector::Collection& match_array, | 335 const DataCollector::Collection& match_array, |
336 const Comparator& comparator, std::string* output); | 336 const Comparator& comparator, std::string* output); |
337 | 337 |
338 // In this thread's data, find a place to record a new birth. | 338 // In this thread's data, find a place to record a new birth. |
339 Births* FindLifetime(const Location& location); | 339 Births* FindLifetime(const Location& location); |
340 | 340 |
341 // Find a place to record a death on this thread. | 341 // Find a place to record a death on this thread. |
342 void TallyADeath(const Births& lifetimes, const TimeDelta& duration); | 342 void TallyADeath(const Births& lifetimes, const base::TimeDelta& duration); |
343 | 343 |
344 // (Thread safe) Get start of list of instances. | 344 // (Thread safe) Get start of list of instances. |
345 static ThreadData* first(); | 345 static ThreadData* first(); |
346 // Iterate through the null terminated list of instances. | 346 // Iterate through the null terminated list of instances. |
347 ThreadData* next() const { return next_; } | 347 ThreadData* next() const { return next_; } |
348 | 348 |
349 MessageLoop* message_loop() const { return message_loop_; } | 349 MessageLoop* message_loop() const { return message_loop_; } |
350 const std::string ThreadName() const; | 350 const std::string ThreadName() const; |
351 | 351 |
352 // Using our lock, make a copy of the specified maps. These calls may arrive | 352 // Using our lock, make a copy of the specified maps. These calls may arrive |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // data, but that is considered acceptable errors (mis-information). | 480 // data, but that is considered acceptable errors (mis-information). |
481 Lock lock_; | 481 Lock lock_; |
482 | 482 |
483 DISALLOW_EVIL_CONSTRUCTORS(ThreadData); | 483 DISALLOW_EVIL_CONSTRUCTORS(ThreadData); |
484 }; | 484 }; |
485 | 485 |
486 } // namespace tracked_objects | 486 } // namespace tracked_objects |
487 | 487 |
488 #endif // BASE_TRACKED_OBJECTS_H_ | 488 #endif // BASE_TRACKED_OBJECTS_H_ |
489 | 489 |
OLD | NEW |