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 <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/tracked.h" | 14 #include "base/tracked.h" |
15 #include "base/threading/thread_local_storage.h" | 15 #include "base/threading/thread_local_storage.h" |
16 | 16 |
17 // TrackedObjects provides a database of stats about objects (generally Tasks) | 17 // TrackedObjects provides a database of stats about objects (generally Tasks) |
18 // that are tracked. Tracking means their birth, death, duration, birth thread, | 18 // that are tracked. Tracking means their birth, death, duration, birth thread, |
19 // death thread, and birth place are recorded. This data is carefully spread | 19 // death thread, and birth place are recorded. This data is carefully spread |
20 // across a series of objects so that the counts and times can be rapidly | 20 // across a series of objects so that the counts and times can be rapidly |
21 // updated without (usually) having to lock the data, and hence there is usually | 21 // updated without (usually) having to lock the data, and hence there is usually |
22 // very little contention caused by the tracking. The data can be viewed via | 22 // very little contention caused by the tracking. The data can be viewed via |
23 // the about:tasks URL, with a variety of sorting and filtering choices. | 23 // the about:tasks URL, with a variety of sorting and filtering choices. |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // is no longer needed. | 315 // is no longer needed. |
316 int count_of_contributing_threads_; | 316 int count_of_contributing_threads_; |
317 | 317 |
318 // The array that we collect data into. | 318 // The array that we collect data into. |
319 Collection collection_; | 319 Collection collection_; |
320 | 320 |
321 // The total number of births recorded at each location for which we have not | 321 // The total number of births recorded at each location for which we have not |
322 // seen a death count. | 322 // seen a death count. |
323 BirthCount global_birth_count_; | 323 BirthCount global_birth_count_; |
324 | 324 |
325 Lock accumulation_lock_; // Protects access during accumulation phase. | 325 base::Lock accumulation_lock_; // Protects access during accumulation phase. |
326 | 326 |
327 DISALLOW_COPY_AND_ASSIGN(DataCollector); | 327 DISALLOW_COPY_AND_ASSIGN(DataCollector); |
328 }; | 328 }; |
329 | 329 |
330 //------------------------------------------------------------------------------ | 330 //------------------------------------------------------------------------------ |
331 // Aggregation contains summaries (totals and subtotals) of groups of Snapshot | 331 // Aggregation contains summaries (totals and subtotals) of groups of Snapshot |
332 // instances to provide printing of these collections on a single line. | 332 // instances to provide printing of these collections on a single line. |
333 | 333 |
334 class Aggregation: public DeathData { | 334 class Aggregation: public DeathData { |
335 public: | 335 public: |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 // protected by a mutex. Running on all threads guarantees we get the | 570 // protected by a mutex. Running on all threads guarantees we get the |
571 // notification into the memory cache of all possible threads. | 571 // notification into the memory cache of all possible threads. |
572 static void ShutdownDisablingFurtherTracking(); | 572 static void ShutdownDisablingFurtherTracking(); |
573 | 573 |
574 // We use thread local store to identify which ThreadData to interact with. | 574 // We use thread local store to identify which ThreadData to interact with. |
575 static base::ThreadLocalStorage::Slot tls_index_; | 575 static base::ThreadLocalStorage::Slot tls_index_; |
576 | 576 |
577 // Link to the most recently created instance (starts a null terminated list). | 577 // Link to the most recently created instance (starts a null terminated list). |
578 static ThreadData* first_; | 578 static ThreadData* first_; |
579 // Protection for access to first_. | 579 // Protection for access to first_. |
580 static Lock list_lock_; | 580 static base::Lock list_lock_; |
581 | 581 |
582 // We set status_ to SHUTDOWN when we shut down the tracking service. This | 582 // We set status_ to SHUTDOWN when we shut down the tracking service. This |
583 // setting is redundantly established by all participating threads so that we | 583 // setting is redundantly established by all participating threads so that we |
584 // are *guaranteed* (without locking) that all threads can "see" the status | 584 // are *guaranteed* (without locking) that all threads can "see" the status |
585 // and avoid additional calls into the service. | 585 // and avoid additional calls into the service. |
586 static Status status_; | 586 static Status status_; |
587 | 587 |
588 // Link to next instance (null terminated list). Used to globally track all | 588 // Link to next instance (null terminated list). Used to globally track all |
589 // registered instances (corresponds to all registered threads where we keep | 589 // registered instances (corresponds to all registered threads where we keep |
590 // data). | 590 // data). |
(...skipping 15 matching lines...) Expand all Loading... |
606 // It is locked before changing, and hence other threads may access it by | 606 // It is locked before changing, and hence other threads may access it by |
607 // locking before reading it. | 607 // locking before reading it. |
608 DeathMap death_map_; | 608 DeathMap death_map_; |
609 | 609 |
610 // Lock to protect *some* access to BirthMap and DeathMap. The maps are | 610 // Lock to protect *some* access to BirthMap and DeathMap. The maps are |
611 // regularly read and written on this thread, but may only be read from other | 611 // regularly read and written on this thread, but may only be read from other |
612 // threads. To support this, we acquire this lock if we are writing from this | 612 // threads. To support this, we acquire this lock if we are writing from this |
613 // thread, or reading from another thread. For reading from this thread we | 613 // thread, or reading from another thread. For reading from this thread we |
614 // don't need a lock, as there is no potential for a conflict since the | 614 // don't need a lock, as there is no potential for a conflict since the |
615 // writing is only done from this thread. | 615 // writing is only done from this thread. |
616 mutable Lock lock_; | 616 mutable base::Lock lock_; |
617 | 617 |
618 DISALLOW_COPY_AND_ASSIGN(ThreadData); | 618 DISALLOW_COPY_AND_ASSIGN(ThreadData); |
619 }; | 619 }; |
620 | 620 |
621 | 621 |
622 //------------------------------------------------------------------------------ | 622 //------------------------------------------------------------------------------ |
623 // Provide simple way to to start global tracking, and to tear down tracking | 623 // Provide simple way to to start global tracking, and to tear down tracking |
624 // when done. Note that construction and destruction of this object must be | 624 // when done. Note that construction and destruction of this object must be |
625 // done when running in threaded mode (before spawning a lot of threads | 625 // done when running in threaded mode (before spawning a lot of threads |
626 // for construction, and after shutting down all the threads for destruction). | 626 // for construction, and after shutting down all the threads for destruction). |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 }; | 661 }; |
662 static State state_; | 662 static State state_; |
663 | 663 |
664 DISALLOW_COPY_AND_ASSIGN(AutoTracking); | 664 DISALLOW_COPY_AND_ASSIGN(AutoTracking); |
665 }; | 665 }; |
666 | 666 |
667 | 667 |
668 } // namespace tracked_objects | 668 } // namespace tracked_objects |
669 | 669 |
670 #endif // BASE_TRACKED_OBJECTS_H_ | 670 #endif // BASE_TRACKED_OBJECTS_H_ |
OLD | NEW |