OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <stack> | 10 #include <stack> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // in snapshots when integrating assembled data. | 225 // in snapshots when integrating assembled data. |
226 | 226 |
227 class BASE_EXPORT DeathData { | 227 class BASE_EXPORT DeathData { |
228 public: | 228 public: |
229 // Default initializer. | 229 // Default initializer. |
230 DeathData() : count_(0) {} | 230 DeathData() : count_(0) {} |
231 | 231 |
232 // When deaths have not yet taken place, and we gather data from all the | 232 // When deaths have not yet taken place, and we gather data from all the |
233 // threads, we create DeathData stats that tally the number of births without | 233 // threads, we create DeathData stats that tally the number of births without |
234 // a corrosponding death. | 234 // a corrosponding death. |
235 explicit DeathData(int count) : count_(count) {} | 235 explicit DeathData(int count) |
| 236 : count_(count) {} |
236 | 237 |
237 // Update stats for a task destruction (death) that had a Run() time of | 238 // Update stats for a task destruction (death) that had a Run() time of |
238 // |duration|, and has had a queueing delay of |queue_duration|. | 239 // |duration|, and has had a queueing delay of |queue_duration|. |
239 void RecordDeath(const Duration& queue_duration, | 240 void RecordDeath(DurationInt queue_duration, |
240 const Duration& run_duration); | 241 DurationInt run_duration); |
241 | 242 |
242 // Metrics accessors. | 243 // Metrics accessors. |
243 int count() const { return count_; } | 244 int count() const { return count_; } |
244 Duration run_duration() const { return run_time_.duration(); } | 245 DurationInt run_duration() const { return run_time_.duration(); } |
245 int AverageMsRunDuration() const; | 246 DurationInt AverageMsRunDuration() const; |
246 Duration run_duration_max() const { return run_time_.max(); } | 247 DurationInt run_duration_max() const { return run_time_.max(); } |
247 Duration queue_duration() const { return queue_time_.duration(); } | 248 DurationInt queue_duration() const { return queue_time_.duration(); } |
248 int AverageMsQueueDuration() const; | 249 DurationInt AverageMsQueueDuration() const; |
249 Duration queue_duration_max() const { return queue_time_.max(); } | 250 DurationInt queue_duration_max() const { return queue_time_.max(); } |
250 | 251 |
251 // Accumulate metrics from other into this. This method is never used on | 252 // Accumulate metrics from other into this. This method is never used on |
252 // realtime statistics, and only used in snapshots and aggregatinos. | 253 // realtime statistics, and only used in snapshots and aggregatinos. |
253 void AddDeathData(const DeathData& other); | 254 void AddDeathData(const DeathData& other); |
254 | 255 |
255 // Simple print of internal state for use in line of HTML. | 256 // Simple print of internal state for use in line of HTML. |
256 void WriteHTML(std::string* output) const; | 257 void WriteHTML(std::string* output) const; |
257 | 258 |
258 // Construct a DictionaryValue instance containing all our stats. The caller | 259 // Construct a DictionaryValue instance containing all our stats. The caller |
259 // assumes ownership of the returned instance. | 260 // assumes ownership of the returned instance. |
260 base::DictionaryValue* ToValue() const; | 261 base::DictionaryValue* ToValue() const; |
261 | 262 |
262 // Reset all tallies to zero. This is used as a hack on realtime data. | 263 // Reset all tallies to zero. This is used as a hack on realtime data. |
263 void Clear(); | 264 void Clear(); |
264 | 265 |
265 private: | 266 private: |
266 // DeathData::Data is a helper class, useful when different metrics need to be | 267 // DeathData::Data is a helper class, useful when different metrics need to be |
267 // aggregated, such as queueing times, or run times. | 268 // aggregated, such as queueing times, or run times. |
268 class Data { | 269 class Data { |
269 public: | 270 public: |
270 Data() {} | 271 Data() : duration_(0), max_(0) {} |
271 ~Data() {} | 272 ~Data() {} |
272 | 273 |
273 Duration duration() const { return duration_; } | 274 DurationInt duration() const { return duration_; } |
274 Duration max() const { return max_; } | 275 DurationInt max() const { return max_; } |
275 | 276 |
276 // Emits HTML formated description of members, assuming |count| instances | 277 // Emits HTML formated description of members, assuming |count| instances |
277 // when calculating averages. | 278 // when calculating averages. |
278 void WriteHTML(int count, std::string* output) const; | 279 void WriteHTML(int count, std::string* output) const; |
279 | 280 |
280 // Agggegate data into our state. | 281 // Agggegate data into our state. |
281 void AddData(const Data& other); | 282 void AddData(const Data& other); |
282 void AddDuration(const Duration& duration); | 283 void AddDuration(DurationInt duration); |
283 | 284 |
284 // Central helper function for calculating averages (correctly, in only one | 285 // Central helper function for calculating averages (correctly, in only one |
285 // place). | 286 // place). |
286 int AverageMsDuration(int count) const; | 287 DurationInt AverageMsDuration(int count) const; |
287 | 288 |
288 // Resets all members to zero. | 289 // Resets all members to zero. |
289 void Clear(); | 290 void Clear(); |
290 | 291 |
291 private: | 292 private: |
292 Duration duration_; // Sum of all durations seen. | 293 DurationInt duration_; // Sum of all durations seen. |
293 Duration max_; // Largest singular duration seen. | 294 DurationInt max_; // Largest singular duration seen. |
294 }; | 295 }; |
295 | 296 |
296 | 297 |
297 int count_; // Number of deaths seen. | 298 int count_; // Number of deaths seen. |
298 Data run_time_; // Data about run time durations. | 299 Data run_time_; // Data about run time durations. |
299 Data queue_time_; // Data about queueing times durations. | 300 Data queue_time_; // Data about queueing times durations. |
300 }; | 301 }; |
301 | 302 |
302 //------------------------------------------------------------------------------ | 303 //------------------------------------------------------------------------------ |
303 // A temporary collection of data that can be sorted and summarized. It is | 304 // A temporary collection of data that can be sorted and summarized. It is |
(...skipping 12 matching lines...) Expand all Loading... |
316 Snapshot(const BirthOnThread& birth_on_thread, int count); | 317 Snapshot(const BirthOnThread& birth_on_thread, int count); |
317 | 318 |
318 const ThreadData* birth_thread() const { return birth_->birth_thread(); } | 319 const ThreadData* birth_thread() const { return birth_->birth_thread(); } |
319 const Location location() const { return birth_->location(); } | 320 const Location location() const { return birth_->location(); } |
320 const BirthOnThread& birth() const { return *birth_; } | 321 const BirthOnThread& birth() const { return *birth_; } |
321 const ThreadData* death_thread() const {return death_thread_; } | 322 const ThreadData* death_thread() const {return death_thread_; } |
322 const DeathData& death_data() const { return death_data_; } | 323 const DeathData& death_data() const { return death_data_; } |
323 const std::string DeathThreadName() const; | 324 const std::string DeathThreadName() const; |
324 | 325 |
325 int count() const { return death_data_.count(); } | 326 int count() const { return death_data_.count(); } |
326 Duration run_duration() const { return death_data_.run_duration(); } | 327 DurationInt run_duration() const { return death_data_.run_duration(); } |
327 int AverageMsRunDuration() const { | 328 DurationInt AverageMsRunDuration() const { |
328 return death_data_.AverageMsRunDuration(); | 329 return death_data_.AverageMsRunDuration(); |
329 } | 330 } |
330 Duration run_duration_max() const { | 331 DurationInt run_duration_max() const { |
331 return death_data_.run_duration_max(); | 332 return death_data_.run_duration_max(); |
332 } | 333 } |
333 Duration queue_duration() const { return death_data_.queue_duration(); } | 334 DurationInt queue_duration() const { return death_data_.queue_duration(); } |
334 int AverageMsQueueDuration() const { | 335 DurationInt AverageMsQueueDuration() const { |
335 return death_data_.AverageMsQueueDuration(); | 336 return death_data_.AverageMsQueueDuration(); |
336 } | 337 } |
337 Duration queue_duration_max() const { | 338 DurationInt queue_duration_max() const { |
338 return death_data_.queue_duration_max(); | 339 return death_data_.queue_duration_max(); |
339 } | 340 } |
340 | 341 |
341 // Emit contents for use in a line of HTML | 342 // Emit contents for use in a line of HTML |
342 void WriteHTML(std::string* output) const; | 343 void WriteHTML(std::string* output) const; |
343 | 344 |
344 // Construct a DictionaryValue instance containing all our data recursively. | 345 // Construct a DictionaryValue instance containing all our data recursively. |
345 // The caller assumes ownership of the memory in the returned instance. | 346 // The caller assumes ownership of the memory in the returned instance. |
346 base::DictionaryValue* ToValue() const; | 347 base::DictionaryValue* ToValue() const; |
347 | 348 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 // Push this instance to the head of all_thread_data_list_head_, linking it to | 686 // Push this instance to the head of all_thread_data_list_head_, linking it to |
686 // the previous head. This is performed after each construction, and leaves | 687 // the previous head. This is performed after each construction, and leaves |
687 // the instance permanently on that list. | 688 // the instance permanently on that list. |
688 void PushToHeadOfList(); | 689 void PushToHeadOfList(); |
689 | 690 |
690 // In this thread's data, record a new birth. | 691 // In this thread's data, record a new birth. |
691 Births* TallyABirth(const Location& location); | 692 Births* TallyABirth(const Location& location); |
692 | 693 |
693 // Find a place to record a death on this thread. | 694 // Find a place to record a death on this thread. |
694 void TallyADeath(const Births& birth, | 695 void TallyADeath(const Births& birth, |
695 const Duration& queue_duration, | 696 DurationInt queue_duration, |
696 const Duration& duration); | 697 DurationInt duration); |
697 | 698 |
698 // Using our lock to protect the iteration, Clear all birth and death data. | 699 // Using our lock to protect the iteration, Clear all birth and death data. |
699 void Reset(); | 700 void Reset(); |
700 | 701 |
701 // This method is called by the TLS system when a thread terminates. | 702 // This method is called by the TLS system when a thread terminates. |
702 // The argument may be NULL if this thread has never tracked a birth or death. | 703 // The argument may be NULL if this thread has never tracked a birth or death. |
703 static void OnThreadTermination(void* thread_data); | 704 static void OnThreadTermination(void* thread_data); |
704 | 705 |
705 // This method should be called when a worker thread terminates, so that we | 706 // This method should be called when a worker thread terminates, so that we |
706 // can save all the thread data into a cache of reusable ThreadData instances. | 707 // can save all the thread data into a cache of reusable ThreadData instances. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 } | 807 } |
807 | 808 |
808 private: | 809 private: |
809 | 810 |
810 DISALLOW_COPY_AND_ASSIGN(AutoTracking); | 811 DISALLOW_COPY_AND_ASSIGN(AutoTracking); |
811 }; | 812 }; |
812 | 813 |
813 } // namespace tracked_objects | 814 } // namespace tracked_objects |
814 | 815 |
815 #endif // BASE_TRACKED_OBJECTS_H_ | 816 #endif // BASE_TRACKED_OBJECTS_H_ |
OLD | NEW |