| 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 <set> |
| 10 #include <stack> | 11 #include <stack> |
| 11 #include <string> | 12 #include <string> |
| 13 #include <utility> |
| 12 #include <vector> | 14 #include <vector> |
| 13 | 15 |
| 14 #include "base/base_export.h" | 16 #include "base/base_export.h" |
| 15 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 16 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 17 #include "base/location.h" | 19 #include "base/location.h" |
| 18 #include "base/profiler/tracked_time.h" | 20 #include "base/profiler/tracked_time.h" |
| 19 #include "base/time.h" | 21 #include "base/time.h" |
| 20 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
| 21 #include "base/threading/thread_local_storage.h" | 23 #include "base/threading/thread_local_storage.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // For a specific thread, and a specific birth place, the collection of all | 193 // For a specific thread, and a specific birth place, the collection of all |
| 192 // death info (with tallies for each death thread, to prevent access conflicts). | 194 // death info (with tallies for each death thread, to prevent access conflicts). |
| 193 class ThreadData; | 195 class ThreadData; |
| 194 class BASE_EXPORT BirthOnThread { | 196 class BASE_EXPORT BirthOnThread { |
| 195 public: | 197 public: |
| 196 BirthOnThread(const Location& location, const ThreadData& current); | 198 BirthOnThread(const Location& location, const ThreadData& current); |
| 197 | 199 |
| 198 const Location location() const; | 200 const Location location() const; |
| 199 const ThreadData* birth_thread() const; | 201 const ThreadData* birth_thread() const; |
| 200 | 202 |
| 203 // Insert our state (location, and thread name) into the dictionary. |
| 204 // Use the supplied |prefix| in front of "thread_name" and "location" |
| 205 // respectively when defining keys. |
| 206 void ToValue(const std::string& prefix, |
| 207 base::DictionaryValue* dictionary) const; |
| 208 |
| 201 private: | 209 private: |
| 202 // File/lineno of birth. This defines the essence of the task, as the context | 210 // File/lineno of birth. This defines the essence of the task, as the context |
| 203 // of the birth (construction) often tell what the item is for. This field | 211 // of the birth (construction) often tell what the item is for. This field |
| 204 // is const, and hence safe to access from any thread. | 212 // is const, and hence safe to access from any thread. |
| 205 const Location location_; | 213 const Location location_; |
| 206 | 214 |
| 207 // The thread that records births into this object. Only this thread is | 215 // The thread that records births into this object. Only this thread is |
| 208 // allowed to update birth_count_ (which changes over time). | 216 // allowed to update birth_count_ (which changes over time). |
| 209 const ThreadData* const birth_thread_; | 217 const ThreadData* const birth_thread_; |
| 210 | 218 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 //------------------------------------------------------------------------------ | 306 //------------------------------------------------------------------------------ |
| 299 // A temporary collection of data that can be sorted and summarized. It is | 307 // A temporary collection of data that can be sorted and summarized. It is |
| 300 // gathered (carefully) from many threads. Instances are held in arrays and | 308 // gathered (carefully) from many threads. Instances are held in arrays and |
| 301 // processed, filtered, and rendered. | 309 // processed, filtered, and rendered. |
| 302 // The source of this data was collected on many threads, and is asynchronously | 310 // The source of this data was collected on many threads, and is asynchronously |
| 303 // changing. The data in this instance is not asynchronously changing. | 311 // changing. The data in this instance is not asynchronously changing. |
| 304 | 312 |
| 305 class BASE_EXPORT Snapshot { | 313 class BASE_EXPORT Snapshot { |
| 306 public: | 314 public: |
| 307 // When snapshotting a full life cycle set (birth-to-death), use this: | 315 // When snapshotting a full life cycle set (birth-to-death), use this: |
| 308 Snapshot(const BirthOnThread& birth_on_thread, const ThreadData& death_thread, | 316 Snapshot(const BirthOnThread& birth_on_thread, |
| 317 const ThreadData& death_thread, |
| 309 const DeathData& death_data); | 318 const DeathData& death_data); |
| 310 | 319 |
| 311 // When snapshotting a birth, with no death yet, use this: | 320 // When snapshotting a birth, with no death yet, use this: |
| 312 Snapshot(const BirthOnThread& birth_on_thread, int count); | 321 Snapshot(const BirthOnThread& birth_on_thread, int count); |
| 313 | 322 |
| 314 // Accessor, that provides default value when there is no death thread. | 323 // Accessor, that provides default value when there is no death thread. |
| 315 const std::string DeathThreadName() const; | 324 const std::string DeathThreadName() const; |
| 316 | 325 |
| 317 // Construct a DictionaryValue instance containing all our data recursively. | 326 // Construct a DictionaryValue instance containing all our data recursively. |
| 318 // The caller assumes ownership of the memory in the returned instance. | 327 // The caller assumes ownership of the memory in the returned instance. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 329 // on this thread. This prevents the need for locking as data accumulates. | 338 // on this thread. This prevents the need for locking as data accumulates. |
| 330 // We use ThreadLocalStorage to quickly identfy the current ThreadData context. | 339 // We use ThreadLocalStorage to quickly identfy the current ThreadData context. |
| 331 // We also have a linked list of ThreadData instances, and that list is used to | 340 // We also have a linked list of ThreadData instances, and that list is used to |
| 332 // harvest data from all existing instances. | 341 // harvest data from all existing instances. |
| 333 | 342 |
| 334 class BASE_EXPORT ThreadData { | 343 class BASE_EXPORT ThreadData { |
| 335 public: | 344 public: |
| 336 // Current allowable states of the tracking system. The states can vary | 345 // Current allowable states of the tracking system. The states can vary |
| 337 // between ACTIVE and DEACTIVATED, but can never go back to UNINITIALIZED. | 346 // between ACTIVE and DEACTIVATED, but can never go back to UNINITIALIZED. |
| 338 enum Status { | 347 enum Status { |
| 339 UNINITIALIZED, | 348 UNINITIALIZED, // PRistine, link-time state before running. |
| 340 ACTIVE, | 349 DORMANT_DURING_TESTS, // Only used during testing. |
| 341 DEACTIVATED, | 350 DEACTIVATED, // No longer recording profling. |
| 351 PROFILING_ACTIVE, // Recording profiles (no parent-child links). |
| 352 PROFILING_CHILDREN_ACTIVE, // Fully active, recording parent-child links. |
| 342 }; | 353 }; |
| 343 | 354 |
| 344 typedef std::map<Location, Births*> BirthMap; | 355 typedef std::map<Location, Births*> BirthMap; |
| 345 typedef std::map<const Births*, DeathData> DeathMap; | 356 typedef std::map<const Births*, DeathData> DeathMap; |
| 357 typedef std::pair<const Births*, const Births*> ParentChildPair; |
| 358 typedef std::set<ParentChildPair> ParentChildSet; |
| 359 typedef std::stack<const Births*> ParentStack; |
| 346 | 360 |
| 347 // Initialize the current thread context with a new instance of ThreadData. | 361 // Initialize the current thread context with a new instance of ThreadData. |
| 348 // This is used by all threads that have names, and should be explicitly | 362 // This is used by all threads that have names, and should be explicitly |
| 349 // set *before* any births on the threads have taken place. It is generally | 363 // set *before* any births on the threads have taken place. It is generally |
| 350 // only used by the message loop, which has a well defined thread name. | 364 // only used by the message loop, which has a well defined thread name. |
| 351 static void InitializeThreadContext(const std::string& suggested_name); | 365 static void InitializeThreadContext(const std::string& suggested_name); |
| 352 | 366 |
| 353 // Using Thread Local Store, find the current instance for collecting data. | 367 // Using Thread Local Store, find the current instance for collecting data. |
| 354 // If an instance does not exist, construct one (and remember it for use on | 368 // If an instance does not exist, construct one (and remember it for use on |
| 355 // this thread. | 369 // this thread. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // Record the end of execution in region, generally corresponding to a scope | 410 // Record the end of execution in region, generally corresponding to a scope |
| 397 // being exited. | 411 // being exited. |
| 398 static void TallyRunInAScopedRegionIfTracking( | 412 static void TallyRunInAScopedRegionIfTracking( |
| 399 const Births* birth, | 413 const Births* birth, |
| 400 const TrackedTime& start_of_run, | 414 const TrackedTime& start_of_run, |
| 401 const TrackedTime& end_of_run); | 415 const TrackedTime& end_of_run); |
| 402 | 416 |
| 403 const std::string thread_name() const; | 417 const std::string thread_name() const; |
| 404 | 418 |
| 405 // Snapshot (under a lock) copies of the maps in each ThreadData instance. For | 419 // Snapshot (under a lock) copies of the maps in each ThreadData instance. For |
| 406 // each set of maps (BirthMap and DeathMap) call the Append() method of the | 420 // each set of maps (BirthMap, DeathMap, and ParentChildSet) call the Append() |
| 407 // |target| DataCollector. If |reset_max| is true, then the max values in | 421 // method of the |target| DataCollector. If |reset_max| is true, then the max |
| 408 // each DeathData instance should be reset during the scan. | 422 // values in each DeathData instance should be reset during the scan. |
| 409 static void SendAllMaps(bool reset_max, class DataCollector* target); | 423 static void SendAllMaps(bool reset_max, class DataCollector* target); |
| 410 | 424 |
| 411 // Hack: asynchronously clear all birth counts and death tallies data values | 425 // Hack: asynchronously clear all birth counts and death tallies data values |
| 412 // in all ThreadData instances. The numerical (zeroing) part is done without | 426 // in all ThreadData instances. The numerical (zeroing) part is done without |
| 413 // use of a locks or atomics exchanges, and may (for int64 values) produce | 427 // use of a locks or atomics exchanges, and may (for int64 values) produce |
| 414 // bogus counts VERY rarely. | 428 // bogus counts VERY rarely. |
| 415 static void ResetAllThreadData(); | 429 static void ResetAllThreadData(); |
| 416 | 430 |
| 417 // Initializes all statics if needed (this initialization call should be made | 431 // Initializes all statics if needed (this initialization call should be made |
| 418 // while we are single threaded). Returns false if unable to initialize. | 432 // while we are single threaded). Returns false if unable to initialize. |
| 419 static bool Initialize(); | 433 static bool Initialize(); |
| 420 | 434 |
| 421 // Sets internal status_ to either become ACTIVE, or DEACTIVATED, | 435 // Sets internal status_. |
| 422 // based on argument being true or false respectively. | 436 // If |status| is false, then status_ is set to DEACTIVATED. |
| 437 // If |status| is true, then status_ is set to, PROFILING_ACTIVE, or |
| 438 // PROFILING_CHILDREN_ACTIVE. |
| 423 // If tracking is not compiled in, this function will return false. | 439 // If tracking is not compiled in, this function will return false. |
| 440 // If parent-child tracking is not compiled in, then an attempt to set the |
| 441 // status to PROFILING_CHILDREN_ACTIVE will only result in a status of |
| 442 // PROFILING_ACTIVE (i.e., it can't be set to a higher level than what is |
| 443 // compiled into the binary, and parent-child tracking at the |
| 444 // PROFILING_CHILDREN_ACTIVE level might not be compiled in). |
| 424 static bool InitializeAndSetTrackingStatus(bool status); | 445 static bool InitializeAndSetTrackingStatus(bool status); |
| 446 |
| 447 // Indicate if any sort of profiling is being done (i.e., we are more than |
| 448 // DEACTIVATED). |
| 425 static bool tracking_status(); | 449 static bool tracking_status(); |
| 426 | 450 |
| 451 // For testing only, indicate if the status of parent-child tracking is turned |
| 452 // on. This is currently a compiled option, atop tracking_status(). |
| 453 static bool tracking_parent_child_status(); |
| 454 |
| 427 // Special versions of Now() for getting times at start and end of a tracked | 455 // Special versions of Now() for getting times at start and end of a tracked |
| 428 // run. They are super fast when tracking is disabled, and have some internal | 456 // run. They are super fast when tracking is disabled, and have some internal |
| 429 // side effects when we are tracking, so that we can deduce the amount of time | 457 // side effects when we are tracking, so that we can deduce the amount of time |
| 430 // accumulated outside of execution of tracked runs. | 458 // accumulated outside of execution of tracked runs. |
| 431 static TrackedTime NowForStartOfRun(); | 459 // The task that will be tracked is passed in as |parent| so that parent-child |
| 460 // relationships can be (optionally) calculated. |
| 461 static TrackedTime NowForStartOfRun(const Births* parent); |
| 432 static TrackedTime NowForEndOfRun(); | 462 static TrackedTime NowForEndOfRun(); |
| 433 | 463 |
| 434 // Provide a time function that does nothing (runs fast) when we don't have | 464 // Provide a time function that does nothing (runs fast) when we don't have |
| 435 // the profiler enabled. It will generally be optimized away when it is | 465 // the profiler enabled. It will generally be optimized away when it is |
| 436 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of | 466 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of |
| 437 // the code). | 467 // the code). |
| 438 static TrackedTime Now(); | 468 static TrackedTime Now(); |
| 439 | 469 |
| 440 // This function can be called at process termination to validate that thread | 470 // This function can be called at process termination to validate that thread |
| 441 // cleanup routines have been called for at least some number of named | 471 // cleanup routines have been called for at least some number of named |
| 442 // threads. | 472 // threads. |
| 443 static void EnsureCleanupWasCalled(int major_threads_shutdown_count); | 473 static void EnsureCleanupWasCalled(int major_threads_shutdown_count); |
| 444 | 474 |
| 445 private: | 475 private: |
| 446 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it | 476 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it |
| 447 // in production code. | 477 // in production code. |
| 448 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a | 478 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a |
| 449 // better change of optimizing (inlining? etc.) private methods (knowing that | 479 // better change of optimizing (inlining? etc.) private methods (knowing that |
| 450 // there will be no need for an external entry point). | 480 // there will be no need for an external entry point). |
| 451 friend class TrackedObjectsTest; | 481 friend class TrackedObjectsTest; |
| 452 FRIEND_TEST_ALL_PREFIXES(TrackedObjectsTest, MinimalStartupShutdown); | 482 FRIEND_TEST_ALL_PREFIXES(TrackedObjectsTest, MinimalStartupShutdown); |
| 453 FRIEND_TEST_ALL_PREFIXES(TrackedObjectsTest, TinyStartupShutdown); | 483 FRIEND_TEST_ALL_PREFIXES(TrackedObjectsTest, TinyStartupShutdown); |
| 484 FRIEND_TEST_ALL_PREFIXES(TrackedObjectsTest, ParentChildTest); |
| 454 | 485 |
| 455 // Worker thread construction creates a name since there is none. | 486 // Worker thread construction creates a name since there is none. |
| 456 explicit ThreadData(int thread_number); | 487 explicit ThreadData(int thread_number); |
| 457 | 488 |
| 458 // Message loop based construction should provide a name. | 489 // Message loop based construction should provide a name. |
| 459 explicit ThreadData(const std::string& suggested_name); | 490 explicit ThreadData(const std::string& suggested_name); |
| 460 | 491 |
| 461 ~ThreadData(); | 492 ~ThreadData(); |
| 462 | 493 |
| 463 // Push this instance to the head of all_thread_data_list_head_, linking it to | 494 // Push this instance to the head of all_thread_data_list_head_, linking it to |
| (...skipping 16 matching lines...) Expand all Loading... |
| 480 DurationInt queue_duration, | 511 DurationInt queue_duration, |
| 481 DurationInt duration); | 512 DurationInt duration); |
| 482 | 513 |
| 483 // Using our lock, make a copy of the specified maps. This call may be made | 514 // Using our lock, make a copy of the specified maps. This call may be made |
| 484 // on non-local threads, which necessitate the use of the lock to prevent | 515 // on non-local threads, which necessitate the use of the lock to prevent |
| 485 // the map(s) from being reallocaed while they are copied. If |reset_max| is | 516 // the map(s) from being reallocaed while they are copied. If |reset_max| is |
| 486 // true, then, just after we copy the DeathMap, we will set the max values to | 517 // true, then, just after we copy the DeathMap, we will set the max values to |
| 487 // zero in the active DeathMap (not the snapshot). | 518 // zero in the active DeathMap (not the snapshot). |
| 488 void SnapshotMaps(bool reset_max, | 519 void SnapshotMaps(bool reset_max, |
| 489 BirthMap* birth_map, | 520 BirthMap* birth_map, |
| 490 DeathMap* death_map); | 521 DeathMap* death_map, |
| 522 ParentChildSet* parent_child_set); |
| 491 | 523 |
| 492 // Using our lock to protect the iteration, Clear all birth and death data. | 524 // Using our lock to protect the iteration, Clear all birth and death data. |
| 493 void Reset(); | 525 void Reset(); |
| 494 | 526 |
| 495 // This method is called by the TLS system when a thread terminates. | 527 // This method is called by the TLS system when a thread terminates. |
| 496 // The argument may be NULL if this thread has never tracked a birth or death. | 528 // The argument may be NULL if this thread has never tracked a birth or death. |
| 497 static void OnThreadTermination(void* thread_data); | 529 static void OnThreadTermination(void* thread_data); |
| 498 | 530 |
| 499 // This method should be called when a worker thread terminates, so that we | 531 // This method should be called when a worker thread terminates, so that we |
| 500 // can save all the thread data into a cache of reusable ThreadData instances. | 532 // can save all the thread data into a cache of reusable ThreadData instances. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 // value is only accessed while the list_lock_ is held. | 571 // value is only accessed while the list_lock_ is held. |
| 540 static int incarnation_counter_; | 572 static int incarnation_counter_; |
| 541 | 573 |
| 542 // Protection for access to all_thread_data_list_head_, and to | 574 // Protection for access to all_thread_data_list_head_, and to |
| 543 // unregistered_thread_data_pool_. This lock is leaked at shutdown. | 575 // unregistered_thread_data_pool_. This lock is leaked at shutdown. |
| 544 // The lock is very infrequently used, so we can afford to just make a lazy | 576 // The lock is very infrequently used, so we can afford to just make a lazy |
| 545 // instance and be safe. | 577 // instance and be safe. |
| 546 static base::LazyInstance<base::Lock, | 578 static base::LazyInstance<base::Lock, |
| 547 base::LeakyLazyInstanceTraits<base::Lock> > list_lock_; | 579 base::LeakyLazyInstanceTraits<base::Lock> > list_lock_; |
| 548 | 580 |
| 549 // Record of what the incarnation_counter_ was when this instance was created. | |
| 550 // If the incarnation_counter_ has changed, then we avoid pushing into the | |
| 551 // pool (this is only critical in tests which go through multiple | |
| 552 // incarations). | |
| 553 int incarnation_count_for_pool_; | |
| 554 | |
| 555 // We set status_ to SHUTDOWN when we shut down the tracking service. | 581 // We set status_ to SHUTDOWN when we shut down the tracking service. |
| 556 static Status status_; | 582 static Status status_; |
| 557 | 583 |
| 558 // Link to next instance (null terminated list). Used to globally track all | 584 // Link to next instance (null terminated list). Used to globally track all |
| 559 // registered instances (corresponds to all registered threads where we keep | 585 // registered instances (corresponds to all registered threads where we keep |
| 560 // data). | 586 // data). |
| 561 ThreadData* next_; | 587 ThreadData* next_; |
| 562 | 588 |
| 563 // Pointer to another ThreadData instance for a Worker-Thread that has been | 589 // Pointer to another ThreadData instance for a Worker-Thread that has been |
| 564 // retired (its thread was terminated). This value is non-NULL only for a | 590 // retired (its thread was terminated). This value is non-NULL only for a |
| (...skipping 15 matching lines...) Expand all Loading... |
| 580 // When a snapshot is needed, this structure can be locked in place for the | 606 // When a snapshot is needed, this structure can be locked in place for the |
| 581 // duration of the snapshotting activity. | 607 // duration of the snapshotting activity. |
| 582 BirthMap birth_map_; | 608 BirthMap birth_map_; |
| 583 | 609 |
| 584 // Similar to birth_map_, this records informations about death of tracked | 610 // Similar to birth_map_, this records informations about death of tracked |
| 585 // instances (i.e., when a tracked instance was destroyed on this thread). | 611 // instances (i.e., when a tracked instance was destroyed on this thread). |
| 586 // It is locked before changing, and hence other threads may access it by | 612 // It is locked before changing, and hence other threads may access it by |
| 587 // locking before reading it. | 613 // locking before reading it. |
| 588 DeathMap death_map_; | 614 DeathMap death_map_; |
| 589 | 615 |
| 616 // A set of parents that created children tasks on this thread. Each pair |
| 617 // corresponds to potentially non-local Births (location and thread), and a |
| 618 // local Births (that took place on this thread). |
| 619 ParentChildSet parent_child_set_; |
| 620 |
| 590 // Lock to protect *some* access to BirthMap and DeathMap. The maps are | 621 // Lock to protect *some* access to BirthMap and DeathMap. The maps are |
| 591 // regularly read and written on this thread, but may only be read from other | 622 // regularly read and written on this thread, but may only be read from other |
| 592 // threads. To support this, we acquire this lock if we are writing from this | 623 // threads. To support this, we acquire this lock if we are writing from this |
| 593 // thread, or reading from another thread. For reading from this thread we | 624 // thread, or reading from another thread. For reading from this thread we |
| 594 // don't need a lock, as there is no potential for a conflict since the | 625 // don't need a lock, as there is no potential for a conflict since the |
| 595 // writing is only done from this thread. | 626 // writing is only done from this thread. |
| 596 mutable base::Lock map_lock_; | 627 mutable base::Lock map_lock_; |
| 597 | 628 |
| 629 // The stack of parents that are currently being profiled. This includes only |
| 630 // tasks that have started a timer recently via NowForStartOfRun(), but not |
| 631 // yet concluded with a NowForEndOfRun(). Usually this stack is one deep, but |
| 632 // if a scoped region is profiled, or <sigh> a task runs a nested-message |
| 633 // loop, then the stack can grow larger. Note that we don't try to deduct |
| 634 // time in nested porfiles, as our current timer is based on wall-clock time, |
| 635 // and not CPU time (and we're hopeful that nested timing won't be a |
| 636 // significant additional cost). |
| 637 ParentStack parent_stack_; |
| 638 |
| 598 // A random number that we used to select decide which sample to keep as a | 639 // A random number that we used to select decide which sample to keep as a |
| 599 // representative sample in each DeathData instance. We can't start off with | 640 // representative sample in each DeathData instance. We can't start off with |
| 600 // much randomness (because we can't call RandInt() on all our threads), so | 641 // much randomness (because we can't call RandInt() on all our threads), so |
| 601 // we stir in more and more as we go. | 642 // we stir in more and more as we go. |
| 602 int32 random_number_; | 643 int32 random_number_; |
| 603 | 644 |
| 645 // Record of what the incarnation_counter_ was when this instance was created. |
| 646 // If the incarnation_counter_ has changed, then we avoid pushing into the |
| 647 // pool (this is only critical in tests which go through multiple |
| 648 // incarnations). |
| 649 int incarnation_count_for_pool_; |
| 650 |
| 604 DISALLOW_COPY_AND_ASSIGN(ThreadData); | 651 DISALLOW_COPY_AND_ASSIGN(ThreadData); |
| 605 }; | 652 }; |
| 606 | 653 |
| 607 //------------------------------------------------------------------------------ | 654 //------------------------------------------------------------------------------ |
| 608 // DataCollector is a container class for Snapshot and BirthOnThread count | 655 // DataCollector is a container class for Snapshot and BirthOnThread count |
| 609 // items. | 656 // items. |
| 610 | 657 |
| 611 class BASE_EXPORT DataCollector { | 658 class BASE_EXPORT DataCollector { |
| 612 public: | 659 public: |
| 613 typedef std::vector<Snapshot> Collection; | 660 typedef std::vector<Snapshot> Collection; |
| 614 | 661 |
| 615 // Construct with a list of how many threads should contribute. This helps us | 662 // Construct with a list of how many threads should contribute. This helps us |
| 616 // determine (in the async case) when we are done with all contributions. | 663 // determine (in the async case) when we are done with all contributions. |
| 617 DataCollector(); | 664 DataCollector(); |
| 618 ~DataCollector(); | 665 ~DataCollector(); |
| 619 | 666 |
| 620 // Adds all stats from the indicated thread into our arrays. Accepts copies | 667 // Adds all stats from the indicated thread into our arrays. Accepts copies |
| 621 // of the birth_map and death_map, so that the data will not change during the | 668 // of the birth_map and death_map, so that the data will not change during the |
| 622 // iterations and processing. | 669 // iterations and processing. |
| 623 void Append(const ThreadData &thread_data, | 670 void Append(const ThreadData &thread_data, |
| 624 const ThreadData::BirthMap &birth_map, | 671 const ThreadData::BirthMap& birth_map, |
| 625 const ThreadData::DeathMap &death_map); | 672 const ThreadData::DeathMap& death_map, |
| 673 const ThreadData::ParentChildSet& parent_child_set); |
| 626 | 674 |
| 627 // After the accumulation phase, the following accessor is used to process the | 675 // After the accumulation phase, the following accessor is used to process the |
| 628 // data (i.e., sort it, filter it, etc.). | 676 // data (i.e., sort it, filter it, etc.). |
| 629 Collection* collection(); | 677 Collection* collection(); |
| 630 | 678 |
| 631 // Adds entries for all the remaining living objects (objects that have | 679 // Adds entries for all the remaining living objects (objects that have |
| 632 // tallied a birth, but have not yet tallied a matching death, and hence must | 680 // tallied a birth, but have not yet tallied a matching death, and hence must |
| 633 // be either running, queued up, or being held in limbo for future posting). | 681 // be either running, queued up, or being held in limbo for future posting). |
| 634 // This should be called after all known ThreadData instances have been | 682 // This should be called after all known ThreadData instances have been |
| 635 // processed using Append(). | 683 // processed using Append(). |
| 636 void AddListOfLivingObjects(); | 684 void AddListOfLivingObjects(); |
| 637 | 685 |
| 638 // Generates a ListValue representation of the vector of snapshots. The caller | 686 // Generates a ListValue representation of the vector of snapshots, and |
| 639 // assumes ownership of the memory in the returned instance. | 687 // inserts the results into |dictionary|. |
| 640 base::ListValue* ToValue() const; | 688 void ToValue(base::DictionaryValue* dictionary) const; |
| 641 | 689 |
| 642 private: | 690 private: |
| 643 typedef std::map<const BirthOnThread*, int> BirthCount; | 691 typedef std::map<const BirthOnThread*, int> BirthCount; |
| 644 | 692 |
| 645 // The array that we collect data into. | 693 // The array that we collect data into. |
| 646 Collection collection_; | 694 Collection collection_; |
| 647 | 695 |
| 648 // The total number of births recorded at each location for which we have not | 696 // The total number of births recorded at each location for which we have not |
| 649 // seen a death count. This map changes as we do Append() calls, and is later | 697 // seen a death count. This map changes as we do Append() calls, and is later |
| 650 // used by AddListOfLivingObjects() to gather up unaccounted for births. | 698 // used by AddListOfLivingObjects() to gather up unaccounted for births. |
| 651 BirthCount global_birth_count_; | 699 BirthCount global_birth_count_; |
| 652 | 700 |
| 701 // The complete list of parent-child relationships among tasks. |
| 702 ThreadData::ParentChildSet parent_child_set_; |
| 703 |
| 653 DISALLOW_COPY_AND_ASSIGN(DataCollector); | 704 DISALLOW_COPY_AND_ASSIGN(DataCollector); |
| 654 }; | 705 }; |
| 655 | 706 |
| 656 //------------------------------------------------------------------------------ | 707 //------------------------------------------------------------------------------ |
| 657 // Provide simple way to to start global tracking, and to tear down tracking | 708 // Provide simple way to to start global tracking, and to tear down tracking |
| 658 // when done. The design has evolved to *not* do any teardown (and just leak | 709 // when done. The design has evolved to *not* do any teardown (and just leak |
| 659 // all allocated data structures). As a result, we don't have any code in this | 710 // all allocated data structures). As a result, we don't have any code in this |
| 660 // destructor, and perhaps this whole class should go away. | 711 // destructor, and perhaps this whole class should go away. |
| 661 | 712 |
| 662 class BASE_EXPORT AutoTracking { | 713 class BASE_EXPORT AutoTracking { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 673 } | 724 } |
| 674 | 725 |
| 675 private: | 726 private: |
| 676 | 727 |
| 677 DISALLOW_COPY_AND_ASSIGN(AutoTracking); | 728 DISALLOW_COPY_AND_ASSIGN(AutoTracking); |
| 678 }; | 729 }; |
| 679 | 730 |
| 680 } // namespace tracked_objects | 731 } // namespace tracked_objects |
| 681 | 732 |
| 682 #endif // BASE_TRACKED_OBJECTS_H_ | 733 #endif // BASE_TRACKED_OBJECTS_H_ |
| OLD | NEW |