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> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 15 #include "base/lazy_instance.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/profiler/tracked_time.h" | 17 #include "base/profiler/tracked_time.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "base/threading/thread_local_storage.h" | 20 #include "base/threading/thread_local_storage.h" |
20 #include "base/tracking_info.h" | 21 #include "base/tracking_info.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 | 23 |
23 // TrackedObjects provides a database of stats about objects (generally Tasks) | 24 // TrackedObjects provides a database of stats about objects (generally Tasks) |
24 // that are tracked. Tracking means their birth, death, duration, birth thread, | 25 // that are tracked. Tracking means their birth, death, duration, birth thread, |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 std::map<const ThreadData*, int> birth_threads_; | 426 std::map<const ThreadData*, int> birth_threads_; |
426 DeathData death_data_; | 427 DeathData death_data_; |
427 std::map<const ThreadData*, int> death_threads_; | 428 std::map<const ThreadData*, int> death_threads_; |
428 | 429 |
429 DISALLOW_COPY_AND_ASSIGN(Aggregation); | 430 DISALLOW_COPY_AND_ASSIGN(Aggregation); |
430 }; | 431 }; |
431 | 432 |
432 //------------------------------------------------------------------------------ | 433 //------------------------------------------------------------------------------ |
433 // Comparator is a class that supports the comparison of Snapshot instances. | 434 // Comparator is a class that supports the comparison of Snapshot instances. |
434 // An instance is actually a list of chained Comparitors, that can provide for | 435 // An instance is actually a list of chained Comparitors, that can provide for |
435 // arbitrary ordering. The path portion of an about:tracking URL is translated | 436 // arbitrary ordering. The path portion of an about:profiler URL is translated |
436 // into such a chain, which is then used to order Snapshot instances in a | 437 // into such a chain, which is then used to order Snapshot instances in a |
437 // vector. It orders them into groups (for aggregation), and can also order | 438 // vector. It orders them into groups (for aggregation), and can also order |
438 // instances within the groups (for detailed rendering of the instances in an | 439 // instances within the groups (for detailed rendering of the instances in an |
439 // aggregation). | 440 // aggregation). |
440 | 441 |
441 class BASE_EXPORT Comparator { | 442 class BASE_EXPORT Comparator { |
442 public: | 443 public: |
443 // Selector enum is the token identifier for each parsed keyword, most of | 444 // Selector enum is the token identifier for each parsed keyword, most of |
444 // which specify a sort order. | 445 // which specify a sort order. |
445 // Since it is not meaningful to sort more than once on a specific key, we | 446 // Since it is not meaningful to sort more than once on a specific key, we |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 // set *before* any births on the threads have taken place. It is generally | 569 // set *before* any births on the threads have taken place. It is generally |
569 // only used by the message loop, which has a well defined thread name. | 570 // only used by the message loop, which has a well defined thread name. |
570 static void InitializeThreadContext(const std::string& suggested_name); | 571 static void InitializeThreadContext(const std::string& suggested_name); |
571 | 572 |
572 // Using Thread Local Store, find the current instance for collecting data. | 573 // Using Thread Local Store, find the current instance for collecting data. |
573 // If an instance does not exist, construct one (and remember it for use on | 574 // If an instance does not exist, construct one (and remember it for use on |
574 // this thread. | 575 // this thread. |
575 // This may return NULL if the system is disabled for any reason. | 576 // This may return NULL if the system is disabled for any reason. |
576 static ThreadData* Get(); | 577 static ThreadData* Get(); |
577 | 578 |
578 // For a given (unescaped) about:tracking query, develop resulting HTML, and | 579 // For a given (unescaped) about:profiler query, develop resulting HTML, and |
579 // append to output. | 580 // append to output. |
580 static void WriteHTML(const std::string& query, std::string* output); | 581 static void WriteHTML(const std::string& query, std::string* output); |
581 | 582 |
582 // For a given accumulated array of results, use the comparator to sort and | 583 // For a given accumulated array of results, use the comparator to sort and |
583 // subtotal, writing the results to the output. | 584 // subtotal, writing the results to the output. |
584 static void WriteHTMLTotalAndSubtotals( | 585 static void WriteHTMLTotalAndSubtotals( |
585 const DataCollector::Collection& match_array, | 586 const DataCollector::Collection& match_array, |
586 const Comparator& comparator, std::string* output); | 587 const Comparator& comparator, std::string* output); |
587 | 588 |
588 // Constructs a DictionaryValue instance containing all recursive results in | 589 // Constructs a DictionaryValue instance containing all recursive results in |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 // The following functions should all be private, and are only public because | 636 // The following functions should all be private, and are only public because |
636 // the collection is done externally. We need to relocate that code from the | 637 // the collection is done externally. We need to relocate that code from the |
637 // collection class into this class, and then all these methods can be made | 638 // collection class into this class, and then all these methods can be made |
638 // private. | 639 // private. |
639 // (Thread safe) Get start of list of all ThreadData instances. | 640 // (Thread safe) Get start of list of all ThreadData instances. |
640 static ThreadData* first(); | 641 static ThreadData* first(); |
641 // Iterate through the null terminated list of ThreadData instances. | 642 // Iterate through the null terminated list of ThreadData instances. |
642 ThreadData* next() const { return next_; } | 643 ThreadData* next() const { return next_; } |
643 // Using our lock, make a copy of the specified maps. These calls may arrive | 644 // Using our lock, make a copy of the specified maps. These calls may arrive |
644 // from non-local threads, and are used to quickly scan data from all threads | 645 // from non-local threads, and are used to quickly scan data from all threads |
645 // in order to build an HTML page for about:tracking. | 646 // in order to build an HTML page for about:profiler. |
646 void SnapshotBirthMap(BirthMap *output) const; | 647 void SnapshotBirthMap(BirthMap *output) const; |
647 void SnapshotDeathMap(DeathMap *output) const; | 648 void SnapshotDeathMap(DeathMap *output) const; |
648 // -------- end of should be private methods. | 649 // -------- end of should be private methods. |
649 | 650 |
650 // Hack: asynchronously clear all birth counts and death tallies data values | 651 // Hack: asynchronously clear all birth counts and death tallies data values |
651 // in all ThreadData instances. The numerical (zeroing) part is done without | 652 // in all ThreadData instances. The numerical (zeroing) part is done without |
652 // use of a locks or atomics exchanges, and may (for int64 values) produce | 653 // use of a locks or atomics exchanges, and may (for int64 values) produce |
653 // bogus counts VERY rarely. | 654 // bogus counts VERY rarely. |
654 static void ResetAllThreadData(); | 655 static void ResetAllThreadData(); |
655 | 656 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 static ThreadDataPool* unregistered_thread_data_pool_; | 741 static ThreadDataPool* unregistered_thread_data_pool_; |
741 // The next available thread number. This should only be accessed when the | 742 // The next available thread number. This should only be accessed when the |
742 // list_lock_ is held. | 743 // list_lock_ is held. |
743 static int thread_number_counter_; | 744 static int thread_number_counter_; |
744 // Incarnation sequence number, indicating how many times (during unittests) | 745 // Incarnation sequence number, indicating how many times (during unittests) |
745 // we've either transitioned out of UNINITIALIZED, or into that state. This | 746 // we've either transitioned out of UNINITIALIZED, or into that state. This |
746 // value is only accessed while the list_lock_ is held. | 747 // value is only accessed while the list_lock_ is held. |
747 static int incarnation_counter_; | 748 static int incarnation_counter_; |
748 // Protection for access to all_thread_data_list_head_, and to | 749 // Protection for access to all_thread_data_list_head_, and to |
749 // unregistered_thread_data_pool_. This lock is leaked at shutdown. | 750 // unregistered_thread_data_pool_. This lock is leaked at shutdown. |
750 static base::Lock* list_lock_; | 751 // The lock is very infrequently used, so we can afford to just make a lazy |
| 752 // instance and be safe. |
| 753 static base::LazyInstance<base::Lock, |
| 754 base::LeakyLazyInstanceTraits<base::Lock> > list_lock_; |
751 | 755 |
752 // Record of what the incarnation_counter_ was when this instance was created. | 756 // Record of what the incarnation_counter_ was when this instance was created. |
753 // If the incarnation_counter_ has changed, then we avoid pushing into the | 757 // If the incarnation_counter_ has changed, then we avoid pushing into the |
754 // pool (this is only critical in tests which go through multiple | 758 // pool (this is only critical in tests which go through multiple |
755 // incarations). | 759 // incarations). |
756 int incarnation_count_for_pool_; | 760 int incarnation_count_for_pool_; |
757 | 761 |
758 // We set status_ to SHUTDOWN when we shut down the tracking service. | 762 // We set status_ to SHUTDOWN when we shut down the tracking service. |
759 static Status status_; | 763 static Status status_; |
760 | 764 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 } | 818 } |
815 | 819 |
816 private: | 820 private: |
817 | 821 |
818 DISALLOW_COPY_AND_ASSIGN(AutoTracking); | 822 DISALLOW_COPY_AND_ASSIGN(AutoTracking); |
819 }; | 823 }; |
820 | 824 |
821 } // namespace tracked_objects | 825 } // namespace tracked_objects |
822 | 826 |
823 #endif // BASE_TRACKED_OBJECTS_H_ | 827 #endif // BASE_TRACKED_OBJECTS_H_ |
OLD | NEW |