OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // Activity tracking provides a low-overhead method of collecting information | 5 // Activity tracking provides a low-overhead method of collecting information |
6 // about the state of the application for analysis both while it is running | 6 // about the state of the application for analysis both while it is running |
7 // and after it has terminated unexpectedly. Its primary purpose is to help | 7 // and after it has terminated unexpectedly. Its primary purpose is to help |
8 // locate reasons the browser becomes unresponsive by providing insight into | 8 // locate reasons the browser becomes unresponsive by providing insight into |
9 // what all the various threads and processes are (or were) doing. | 9 // what all the various threads and processes are (or were) doing. |
10 | 10 |
11 #ifndef BASE_DEBUG_ACTIVITY_TRACKER_H_ | 11 #ifndef BASE_DEBUG_ACTIVITY_TRACKER_H_ |
12 #define BASE_DEBUG_ACTIVITY_TRACKER_H_ | 12 #define BASE_DEBUG_ACTIVITY_TRACKER_H_ |
13 | 13 |
14 // std::atomic is undesired due to performance issues when used as global | 14 // std::atomic is undesired due to performance issues when used as global |
15 // variables. There are no such instances here. This module uses the | 15 // variables. There are no such instances here. This module uses the |
16 // PersistentMemoryAllocator which also uses std::atomic and is written | 16 // PersistentMemoryAllocator which also uses std::atomic and is written |
17 // by the same author. | 17 // by the same author. |
18 #include <atomic> | 18 #include <atomic> |
19 #include <map> | 19 #include <map> |
20 #include <memory> | 20 #include <memory> |
21 #include <string> | 21 #include <string> |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
24 #include "base/atomicops.h" | 24 #include "base/atomicops.h" |
25 #include "base/base_export.h" | 25 #include "base/base_export.h" |
26 #include "base/compiler_specific.h" | 26 #include "base/compiler_specific.h" |
27 #include "base/gtest_prod_util.h" | 27 #include "base/gtest_prod_util.h" |
28 #include "base/location.h" | 28 #include "base/location.h" |
29 #include "base/metrics/persistent_memory_allocator.h" | 29 #include "base/metrics/persistent_memory_allocator.h" |
30 #include "base/process/process_handle.h" | |
30 #include "base/strings/string_piece.h" | 31 #include "base/strings/string_piece.h" |
31 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
33 #include "base/task_runner.h" | |
32 #include "base/threading/platform_thread.h" | 34 #include "base/threading/platform_thread.h" |
33 #include "base/threading/thread_checker.h" | 35 #include "base/threading/thread_checker.h" |
34 #include "base/threading/thread_local_storage.h" | 36 #include "base/threading/thread_local_storage.h" |
35 | 37 |
36 namespace base { | 38 namespace base { |
37 | 39 |
38 struct PendingTask; | 40 struct PendingTask; |
39 | 41 |
40 class FilePath; | 42 class FilePath; |
41 class Lock; | 43 class Lock; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 | 344 |
343 using Snapshot = std::map<std::string, TypedValue>; | 345 using Snapshot = std::map<std::string, TypedValue>; |
344 | 346 |
345 ActivityUserData(void* memory, size_t size); | 347 ActivityUserData(void* memory, size_t size); |
346 virtual ~ActivityUserData(); | 348 virtual ~ActivityUserData(); |
347 | 349 |
348 // Gets the unique ID number for this user data. If this changes then the | 350 // Gets the unique ID number for this user data. If this changes then the |
349 // contents have been overwritten by another thread. The return value is | 351 // contents have been overwritten by another thread. The return value is |
350 // always non-zero unless it's actually just a data "sink". | 352 // always non-zero unless it's actually just a data "sink". |
351 uint32_t id() const { | 353 uint32_t id() const { |
352 return memory_ ? id_->load(std::memory_order_relaxed) : 0; | 354 return header_ ? header_->data_id.load(std::memory_order_relaxed) : 0; |
353 } | 355 } |
354 | 356 |
355 // Writes a |value| (as part of a key/value pair) that will be included with | 357 // Writes a |value| (as part of a key/value pair) that will be included with |
356 // the activity in any reports. The same |name| can be written multiple times | 358 // the activity in any reports. The same |name| can be written multiple times |
357 // with each successive call overwriting the previously stored |value|. For | 359 // with each successive call overwriting the previously stored |value|. For |
358 // raw and string values, the maximum size of successive writes is limited by | 360 // raw and string values, the maximum size of successive writes is limited by |
359 // the first call. The length of "name" is limited to 255 characters. | 361 // the first call. The length of "name" is limited to 255 characters. |
360 // | 362 // |
361 // This information is stored on a "best effort" basis. It may be dropped if | 363 // This information is stored on a "best effort" basis. It may be dropped if |
362 // the memory buffer is full or the associated activity is beyond the maximum | 364 // the memory buffer is full or the associated activity is beyond the maximum |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 // Creates a snapshot of the key/value pairs contained within. The returned | 400 // Creates a snapshot of the key/value pairs contained within. The returned |
399 // data will be fixed, independent of whatever changes afterward. There is | 401 // data will be fixed, independent of whatever changes afterward. There is |
400 // protection against concurrent modification of the values but no protection | 402 // protection against concurrent modification of the values but no protection |
401 // against a complete overwrite of the contents; the caller must ensure that | 403 // against a complete overwrite of the contents; the caller must ensure that |
402 // the memory segment is not going to be re-initialized while this runs. | 404 // the memory segment is not going to be re-initialized while this runs. |
403 bool CreateSnapshot(Snapshot* output_snapshot) const; | 405 bool CreateSnapshot(Snapshot* output_snapshot) const; |
404 | 406 |
405 // Gets the base memory address used for storing data. | 407 // Gets the base memory address used for storing data. |
406 const void* GetBaseAddress(); | 408 const void* GetBaseAddress(); |
407 | 409 |
410 // Explicitly sets the process ID. | |
411 void SetOwningProcessIdForTesting(ProcessId id, int64_t stamp); | |
412 | |
413 // Gets the associated process ID, in native form, and the creation timestamp | |
414 // from tracker memory without loading the entire structure for analysis. This | |
415 // will return false if no valid process ID is available. | |
416 static bool OwningProcessId(const void* memory, | |
417 ProcessId* out_id, | |
418 int64_t* out_stamp); | |
419 | |
408 protected: | 420 protected: |
409 virtual void Set(StringPiece name, | 421 virtual void Set(StringPiece name, |
410 ValueType type, | 422 ValueType type, |
411 const void* memory, | 423 const void* memory, |
412 size_t size); | 424 size_t size); |
413 | 425 |
414 private: | 426 private: |
415 FRIEND_TEST_ALL_PREFIXES(ActivityTrackerTest, UserDataTest); | 427 FRIEND_TEST_ALL_PREFIXES(ActivityTrackerTest, UserDataTest); |
416 | 428 |
417 enum : size_t { kMemoryAlignment = sizeof(uint64_t) }; | 429 enum : size_t { kMemoryAlignment = sizeof(uint64_t) }; |
418 | 430 |
431 // A structure that defines the structure header in memory. | |
432 struct MemoryHeader { | |
433 MemoryHeader(); | |
434 ~MemoryHeader(); | |
435 | |
436 std::atomic<uint32_t> data_id; // A unique identifier for this data. | |
437 uint32_t padding; // Ensure constant alignment. | |
438 int64_t process_id; // The associated process ID. | |
439 int64_t create_stamp; // The time of creation. | |
manzagop (departed)
2017/02/17 19:39:54
Is this the creation time of the process or of the
bcwhite
2017/02/17 20:31:53
Of the ActivityData.
manzagop (departed)
2017/02/17 20:45:21
I remember Siggi saying process id is not unique d
| |
440 }; | |
441 | |
419 // A structure used to reference data held outside of persistent memory. | 442 // A structure used to reference data held outside of persistent memory. |
420 struct ReferenceRecord { | 443 struct ReferenceRecord { |
421 uint64_t address; | 444 uint64_t address; |
422 uint64_t size; | 445 uint64_t size; |
423 }; | 446 }; |
424 | 447 |
425 // Header to a key/value record held in persistent memory. | 448 // Header to a key/value record held in persistent memory. |
426 struct Header { | 449 struct FieldHeader { |
450 FieldHeader(); | |
451 ~FieldHeader(); | |
452 | |
427 std::atomic<uint8_t> type; // Encoded ValueType | 453 std::atomic<uint8_t> type; // Encoded ValueType |
428 uint8_t name_size; // Length of "name" key. | 454 uint8_t name_size; // Length of "name" key. |
429 std::atomic<uint16_t> value_size; // Actual size of of the stored value. | 455 std::atomic<uint16_t> value_size; // Actual size of of the stored value. |
430 uint16_t record_size; // Total storage of name, value, header. | 456 uint16_t record_size; // Total storage of name, value, header. |
431 }; | 457 }; |
432 | 458 |
433 // This record is used to hold known value is a map so that they can be | 459 // This record is used to hold known value is a map so that they can be |
434 // found and overwritten later. | 460 // found and overwritten later. |
435 struct ValueInfo { | 461 struct ValueInfo { |
436 ValueInfo(); | 462 ValueInfo(); |
(...skipping 20 matching lines...) Expand all Loading... | |
457 // updates of the values. This is "mutable" because it changes on "const" | 483 // updates of the values. This is "mutable" because it changes on "const" |
458 // objects even when the actual data values can't change. | 484 // objects even when the actual data values can't change. |
459 mutable std::map<StringPiece, ValueInfo> values_; | 485 mutable std::map<StringPiece, ValueInfo> values_; |
460 | 486 |
461 // Information about the memory block in which new data can be stored. These | 487 // Information about the memory block in which new data can be stored. These |
462 // are "mutable" because they change even on "const" objects that are just | 488 // are "mutable" because they change even on "const" objects that are just |
463 // skipping already set values. | 489 // skipping already set values. |
464 mutable char* memory_; | 490 mutable char* memory_; |
465 mutable size_t available_; | 491 mutable size_t available_; |
466 | 492 |
467 // A pointer to the unique ID for this instance. | 493 // A pointer to the memory header for this instance. |
468 std::atomic<uint32_t>* const id_; | 494 MemoryHeader* const header_; |
469 | 495 |
470 // This ID is used to create unique indentifiers for user data so that it's | 496 // This ID is used to create unique indentifiers for user data so that it's |
471 // possible to tell if the information has been overwritten. | 497 // possible to tell if the information has been overwritten. |
472 static StaticAtomicSequenceNumber next_id_; | 498 static StaticAtomicSequenceNumber next_id_; |
473 | 499 |
474 DISALLOW_COPY_AND_ASSIGN(ActivityUserData); | 500 DISALLOW_COPY_AND_ASSIGN(ActivityUserData); |
475 }; | 501 }; |
476 | 502 |
477 // This class manages tracking a stack of activities for a single thread in | 503 // This class manages tracking a stack of activities for a single thread in |
478 // a persistent manner, implementing a bounded-size stack in a fixed-size | 504 // a persistent manner, implementing a bounded-size stack in a fixed-size |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 // Returns whether the current data is valid or not. It is not valid if | 631 // Returns whether the current data is valid or not. It is not valid if |
606 // corruption has been detected in the header or other data structures. | 632 // corruption has been detected in the header or other data structures. |
607 bool IsValid() const; | 633 bool IsValid() const; |
608 | 634 |
609 // Gets a copy of the tracker contents for analysis. Returns false if a | 635 // Gets a copy of the tracker contents for analysis. Returns false if a |
610 // snapshot was not possible, perhaps because the data is not valid; the | 636 // snapshot was not possible, perhaps because the data is not valid; the |
611 // contents of |output_snapshot| are undefined in that case. The current | 637 // contents of |output_snapshot| are undefined in that case. The current |
612 // implementation does not support concurrent snapshot operations. | 638 // implementation does not support concurrent snapshot operations. |
613 bool CreateSnapshot(Snapshot* output_snapshot) const; | 639 bool CreateSnapshot(Snapshot* output_snapshot) const; |
614 | 640 |
641 // Gets the base memory address used for storing data. | |
642 const void* GetBaseAddress(); | |
643 | |
644 // Explicitly sets the process ID. | |
645 void SetOwningProcessIdForTesting(ProcessId id, int64_t stamp); | |
646 | |
647 // Gets the associated process ID, in native form, and the creation timestamp | |
648 // from tracker memory without loading the entire structure for analysis. This | |
649 // will return false if no valid process ID is available. | |
650 static bool OwningProcessId(const void* memory, | |
651 ProcessId* out_id, | |
652 int64_t* out_stamp); | |
653 | |
615 // Calculates the memory size required for a given stack depth, including | 654 // Calculates the memory size required for a given stack depth, including |
616 // the internal header structure for the stack. | 655 // the internal header structure for the stack. |
617 static size_t SizeForStackDepth(int stack_depth); | 656 static size_t SizeForStackDepth(int stack_depth); |
618 | 657 |
619 private: | 658 private: |
620 friend class ActivityTrackerTest; | 659 friend class ActivityTrackerTest; |
621 | 660 |
622 Header* const header_; // Pointer to the Header structure. | 661 Header* const header_; // Pointer to the Header structure. |
623 Activity* const stack_; // The stack of activities. | 662 Activity* const stack_; // The stack of activities. |
624 const uint32_t stack_slots_; // The total number of stack slots. | 663 const uint32_t stack_slots_; // The total number of stack slots. |
(...skipping 12 matching lines...) Expand all Loading... | |
637 class BASE_EXPORT GlobalActivityTracker { | 676 class BASE_EXPORT GlobalActivityTracker { |
638 public: | 677 public: |
639 // Type identifiers used when storing in persistent memory so they can be | 678 // Type identifiers used when storing in persistent memory so they can be |
640 // identified during extraction; the first 4 bytes of the SHA1 of the name | 679 // identified during extraction; the first 4 bytes of the SHA1 of the name |
641 // is used as a unique integer. A "version number" is added to the base | 680 // is used as a unique integer. A "version number" is added to the base |
642 // so that, if the structure of that object changes, stored older versions | 681 // so that, if the structure of that object changes, stored older versions |
643 // will be safely ignored. These are public so that an external process | 682 // will be safely ignored. These are public so that an external process |
644 // can recognize records of this type within an allocator. | 683 // can recognize records of this type within an allocator. |
645 enum : uint32_t { | 684 enum : uint32_t { |
646 kTypeIdActivityTracker = 0x5D7381AF + 3, // SHA1(ActivityTracker) v3 | 685 kTypeIdActivityTracker = 0x5D7381AF + 3, // SHA1(ActivityTracker) v3 |
647 kTypeIdUserDataRecord = 0x615EDDD7 + 2, // SHA1(UserDataRecord) v2 | 686 kTypeIdUserDataRecord = 0x615EDDD7 + 3, // SHA1(UserDataRecord) v3 |
648 kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1 | 687 kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1 |
649 kTypeIdGlobalDataRecord = kTypeIdUserDataRecord + 1000, | 688 kTypeIdProcessDataRecord = kTypeIdUserDataRecord + 0x100, |
689 kTypeIdGlobalDataRecord = kTypeIdUserDataRecord + 0x200, | |
650 | 690 |
651 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker, | 691 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker, |
652 kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord, | 692 kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord, |
693 kTypeIdProcessDataRecordFree = ~kTypeIdProcessDataRecord, | |
653 }; | 694 }; |
654 | 695 |
655 // This structure contains information about a loaded module, as shown to | 696 // This structure contains information about a loaded module, as shown to |
656 // users of the tracker. | 697 // users of the tracker. |
657 struct BASE_EXPORT ModuleInfo { | 698 struct BASE_EXPORT ModuleInfo { |
658 ModuleInfo(); | 699 ModuleInfo(); |
659 ModuleInfo(ModuleInfo&& rhs); | 700 ModuleInfo(ModuleInfo&& rhs); |
660 ModuleInfo(const ModuleInfo& rhs); | 701 ModuleInfo(const ModuleInfo& rhs); |
661 ~ModuleInfo(); | 702 ~ModuleInfo(); |
662 | 703 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 return tracker; | 814 return tracker; |
774 return CreateTrackerForCurrentThread(); | 815 return CreateTrackerForCurrentThread(); |
775 } | 816 } |
776 | 817 |
777 // Creates an activity-tracker for the current thread. | 818 // Creates an activity-tracker for the current thread. |
778 ThreadActivityTracker* CreateTrackerForCurrentThread(); | 819 ThreadActivityTracker* CreateTrackerForCurrentThread(); |
779 | 820 |
780 // Releases the activity-tracker for the current thread (for testing only). | 821 // Releases the activity-tracker for the current thread (for testing only). |
781 void ReleaseTrackerForCurrentThreadForTesting(); | 822 void ReleaseTrackerForCurrentThreadForTesting(); |
782 | 823 |
824 // Sets a task-runner that can be used for background work. | |
825 void SetBackgroundTaskRunner(const scoped_refptr<TaskRunner>& runner); | |
826 | |
827 // Manages process lifetimes. | |
828 void RecordProcessLaunch(ProcessId process_id); | |
829 void RecordProcessExit(ProcessId process_id, int exit_code); | |
830 static void RecordProcessLaunchIfEnabled(ProcessId process_id) { | |
831 GlobalActivityTracker* tracker = Get(); | |
832 if (tracker) | |
833 tracker->RecordProcessLaunch(process_id); | |
834 } | |
835 static void RecordProcessExitIfEnabled(ProcessId process_id, int exit_code) { | |
836 GlobalActivityTracker* tracker = Get(); | |
837 if (tracker) | |
838 tracker->RecordProcessExit(process_id, exit_code); | |
839 } | |
840 | |
783 // Records a log message. The current implementation does NOT recycle these | 841 // Records a log message. The current implementation does NOT recycle these |
784 // only store critical messages such as FATAL ones. | 842 // only store critical messages such as FATAL ones. |
785 void RecordLogMessage(StringPiece message); | 843 void RecordLogMessage(StringPiece message); |
786 | 844 |
787 // Records a module load/unload event. This is safe to call multiple times | 845 // Records a module load/unload event. This is safe to call multiple times |
788 // even with the same information. | 846 // even with the same information. |
789 void RecordModuleInfo(const ModuleInfo& info); | 847 void RecordModuleInfo(const ModuleInfo& info); |
790 | 848 |
791 // Record field trial information. This call is thread-safe. In addition to | 849 // Record field trial information. This call is thread-safe. In addition to |
792 // this, construction of a GlobalActivityTracker will cause all existing | 850 // this, construction of a GlobalActivityTracker will cause all existing |
793 // active field trials to be fetched and recorded. | 851 // active field trials to be fetched and recorded. |
794 void RecordFieldTrial(const std::string& trial_name, StringPiece group_name); | 852 void RecordFieldTrial(const std::string& trial_name, StringPiece group_name); |
795 | 853 |
854 // Accesses the process data record for storing arbitrary key/value pairs. | |
855 // Updates to this are thread-safe. | |
856 ActivityUserData& process_data() { return process_data_; } | |
857 | |
796 // Accesses the global data record for storing arbitrary key/value pairs. | 858 // Accesses the global data record for storing arbitrary key/value pairs. |
859 // Updates to this are thread-safe. | |
797 ActivityUserData& global_data() { return global_data_; } | 860 ActivityUserData& global_data() { return global_data_; } |
798 | 861 |
799 private: | 862 private: |
800 friend class GlobalActivityAnalyzer; | 863 friend class GlobalActivityAnalyzer; |
801 friend class ScopedThreadActivity; | 864 friend class ScopedThreadActivity; |
802 friend class ActivityTrackerTest; | 865 friend class ActivityTrackerTest; |
803 | 866 |
804 enum : int { | 867 enum : int { |
805 // The maximum number of threads that can be tracked within a process. If | 868 // The maximum number of threads that can be tracked within a process. If |
806 // more than this number run concurrently, tracking of new ones may cease. | 869 // more than this number run concurrently, tracking of new ones may cease. |
807 kMaxThreadCount = 100, | 870 kMaxThreadCount = 100, |
808 kCachedThreadMemories = 10, | 871 kCachedThreadMemories = 10, |
809 kCachedUserDataMemories = 10, | 872 kCachedUserDataMemories = 10, |
810 }; | 873 }; |
811 | 874 |
812 // A wrapper around ActivityUserData that is thread-safe and thus can be used | 875 // A wrapper around ActivityUserData that is thread-safe and thus can be used |
813 // in the global scope without the requirement of being called from only one | 876 // in the global scope without the requirement of being called from only one |
814 // thread. | 877 // thread. |
815 class GlobalUserData : public ActivityUserData { | 878 class ThreadSafeUserData : public ActivityUserData { |
816 public: | 879 public: |
817 GlobalUserData(void* memory, size_t size); | 880 ThreadSafeUserData(void* memory, size_t size); |
818 ~GlobalUserData() override; | 881 ~ThreadSafeUserData() override; |
819 | 882 |
820 private: | 883 private: |
821 void Set(StringPiece name, | 884 void Set(StringPiece name, |
822 ValueType type, | 885 ValueType type, |
823 const void* memory, | 886 const void* memory, |
824 size_t size) override; | 887 size_t size) override; |
825 | 888 |
826 Lock data_lock_; | 889 Lock data_lock_; |
827 | 890 |
828 DISALLOW_COPY_AND_ASSIGN(GlobalUserData); | 891 DISALLOW_COPY_AND_ASSIGN(ThreadSafeUserData); |
829 }; | 892 }; |
830 | 893 |
831 // State of a module as stored in persistent memory. This supports a single | 894 // State of a module as stored in persistent memory. This supports a single |
832 // loading of a module only. If modules are loaded multiple times at | 895 // loading of a module only. If modules are loaded multiple times at |
833 // different addresses, only the last will be recorded and an unload will | 896 // different addresses, only the last will be recorded and an unload will |
834 // not revert to the information of any other addresses. | 897 // not revert to the information of any other addresses. |
835 struct BASE_EXPORT ModuleInfoRecord { | 898 struct BASE_EXPORT ModuleInfoRecord { |
836 // SHA1(ModuleInfoRecord): Increment this if structure changes! | 899 // SHA1(ModuleInfoRecord): Increment this if structure changes! |
837 static constexpr uint32_t kPersistentTypeId = 0x05DB5F41 + 1; | 900 static constexpr uint32_t kPersistentTypeId = 0x05DB5F41 + 1; |
838 | 901 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 | 964 |
902 // Returns the memory used by an activity-tracker managed by this class. | 965 // Returns the memory used by an activity-tracker managed by this class. |
903 // It is called during the destruction of a ManagedActivityTracker object. | 966 // It is called during the destruction of a ManagedActivityTracker object. |
904 void ReturnTrackerMemory(ManagedActivityTracker* tracker); | 967 void ReturnTrackerMemory(ManagedActivityTracker* tracker); |
905 | 968 |
906 // Releases the activity-tracker associcated with thread. It is called | 969 // Releases the activity-tracker associcated with thread. It is called |
907 // automatically when a thread is joined and thus there is nothing more to | 970 // automatically when a thread is joined and thus there is nothing more to |
908 // be tracked. |value| is a pointer to a ManagedActivityTracker. | 971 // be tracked. |value| is a pointer to a ManagedActivityTracker. |
909 static void OnTLSDestroy(void* value); | 972 static void OnTLSDestroy(void* value); |
910 | 973 |
974 // Does process-exit work. This can be run on any thread. | |
975 void RecordProcessExitImpl(ProcessId process_id, | |
976 int exit_code, | |
977 int64_t exit_stamp); | |
978 | |
911 // The persistent-memory allocator from which the memory for all trackers | 979 // The persistent-memory allocator from which the memory for all trackers |
912 // is taken. | 980 // is taken. |
913 std::unique_ptr<PersistentMemoryAllocator> allocator_; | 981 std::unique_ptr<PersistentMemoryAllocator> allocator_; |
914 | 982 |
915 // The size (in bytes) of memory required by a ThreadActivityTracker to | 983 // The size (in bytes) of memory required by a ThreadActivityTracker to |
916 // provide the stack-depth requested during construction. | 984 // provide the stack-depth requested during construction. |
917 const size_t stack_memory_size_; | 985 const size_t stack_memory_size_; |
918 | 986 |
919 // The activity tracker for the currently executing thread. | 987 // The activity tracker for the currently executing thread. |
920 base::ThreadLocalStorage::Slot this_thread_tracker_; | 988 base::ThreadLocalStorage::Slot this_thread_tracker_; |
921 | 989 |
922 // The number of thread trackers currently active. | 990 // The number of thread trackers currently active. |
923 std::atomic<int> thread_tracker_count_; | 991 std::atomic<int> thread_tracker_count_; |
924 | 992 |
925 // A caching memory allocator for thread-tracker objects. | 993 // A caching memory allocator for thread-tracker objects. |
926 ActivityTrackerMemoryAllocator thread_tracker_allocator_; | 994 ActivityTrackerMemoryAllocator thread_tracker_allocator_; |
927 base::Lock thread_tracker_allocator_lock_; | 995 base::Lock thread_tracker_allocator_lock_; |
928 | 996 |
929 // A caching memory allocator for user data attached to activity data. | 997 // A caching memory allocator for user data attached to activity data. |
930 ActivityTrackerMemoryAllocator user_data_allocator_; | 998 ActivityTrackerMemoryAllocator user_data_allocator_; |
931 base::Lock user_data_allocator_lock_; | 999 base::Lock user_data_allocator_lock_; |
932 | 1000 |
933 // An object for holding global arbitrary key value pairs. Values must always | 1001 // An object for holding arbitrary key value pairs with thread-safe access. |
934 // be written from the main UI thread. | 1002 ThreadSafeUserData process_data_; |
935 GlobalUserData global_data_; | 1003 ThreadSafeUserData global_data_; |
936 | 1004 |
937 // A map of global module information, keyed by module path. | 1005 // A map of global module information, keyed by module path. |
938 std::map<const std::string, ModuleInfoRecord*> modules_; | 1006 std::map<const std::string, ModuleInfoRecord*> modules_; |
939 base::Lock modules_lock_; | 1007 base::Lock modules_lock_; |
940 | 1008 |
941 // The active global activity tracker. | 1009 // The active global activity tracker. |
942 static subtle::AtomicWord g_tracker_; | 1010 static subtle::AtomicWord g_tracker_; |
943 | 1011 |
1012 // A lock that is used to procect access to the following fields. | |
1013 base::Lock global_tracker_lock_; | |
1014 | |
1015 // A task-runner that can be used for doing background processing. | |
1016 scoped_refptr<TaskRunner> background_task_runner_; | |
1017 | |
944 DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker); | 1018 DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker); |
945 }; | 1019 }; |
946 | 1020 |
947 | 1021 |
948 // Record entry in to and out of an arbitrary block of code. | 1022 // Record entry in to and out of an arbitrary block of code. |
949 class BASE_EXPORT ScopedActivity | 1023 class BASE_EXPORT ScopedActivity |
950 : public GlobalActivityTracker::ScopedThreadActivity { | 1024 : public GlobalActivityTracker::ScopedThreadActivity { |
951 public: | 1025 public: |
952 // Track activity at the specified FROM_HERE location for an arbitrary | 1026 // Track activity at the specified FROM_HERE location for an arbitrary |
953 // 4-bit |action|, an arbitrary 32-bit |id|, and 32-bits of arbitrary | 1027 // 4-bit |action|, an arbitrary 32-bit |id|, and 32-bits of arbitrary |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1068 ScopedProcessWaitActivity(const void* program_counter, | 1142 ScopedProcessWaitActivity(const void* program_counter, |
1069 const base::Process* process); | 1143 const base::Process* process); |
1070 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); | 1144 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); |
1071 }; | 1145 }; |
1072 #endif | 1146 #endif |
1073 | 1147 |
1074 } // namespace debug | 1148 } // namespace debug |
1075 } // namespace base | 1149 } // namespace base |
1076 | 1150 |
1077 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ | 1151 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ |
OLD | NEW |