Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: base/debug/activity_tracker.h

Issue 2566983009: Support storing information about what modules are loaded in the process. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/debug/activity_tracker.cc » ('j') | base/debug/activity_tracker.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 public: 625 public:
626 // Type identifiers used when storing in persistent memory so they can be 626 // Type identifiers used when storing in persistent memory so they can be
627 // identified during extraction; the first 4 bytes of the SHA1 of the name 627 // identified during extraction; the first 4 bytes of the SHA1 of the name
628 // is used as a unique integer. A "version number" is added to the base 628 // is used as a unique integer. A "version number" is added to the base
629 // so that, if the structure of that object changes, stored older versions 629 // so that, if the structure of that object changes, stored older versions
630 // will be safely ignored. These are public so that an external process 630 // will be safely ignored. These are public so that an external process
631 // can recognize records of this type within an allocator. 631 // can recognize records of this type within an allocator.
632 enum : uint32_t { 632 enum : uint32_t {
633 kTypeIdActivityTracker = 0x5D7381AF + 3, // SHA1(ActivityTracker) v3 633 kTypeIdActivityTracker = 0x5D7381AF + 3, // SHA1(ActivityTracker) v3
634 kTypeIdUserDataRecord = 0x615EDDD7 + 2, // SHA1(UserDataRecord) v2 634 kTypeIdUserDataRecord = 0x615EDDD7 + 2, // SHA1(UserDataRecord) v2
635 kTypeIdModulesRecord = 0x484E2E03 + 1, // SHA1(ModulesRecord) v1
635 kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1 636 kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1
636 kTypeIdGlobalDataRecord = kTypeIdUserDataRecord + 1000, 637 kTypeIdGlobalDataRecord = kTypeIdUserDataRecord + 1000,
637 638
638 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker, 639 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker,
639 kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord, 640 kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord,
640 }; 641 };
641 642
643 struct ModuleInfo {
644 bool is_loaded = false;
645 uintptr_t address = 0;
646 size_t size = 0;
647 std::string file;
648 std::string version;
649 std::string identifier;
650 std::string debug_file;
651 std::string debug_identifier;
652 };
653
642 // This is a thin wrapper around the thread-tracker's ScopedActivity that 654 // This is a thin wrapper around the thread-tracker's ScopedActivity that
643 // accesses the global tracker to provide some of the information, notably 655 // accesses the global tracker to provide some of the information, notably
644 // which thread-tracker to use. It is safe to create even if activity 656 // which thread-tracker to use. It is safe to create even if activity
645 // tracking is not enabled. 657 // tracking is not enabled.
646 class BASE_EXPORT ScopedThreadActivity 658 class BASE_EXPORT ScopedThreadActivity
647 : public ThreadActivityTracker::ScopedActivity { 659 : public ThreadActivityTracker::ScopedActivity {
648 public: 660 public:
649 ScopedThreadActivity(const void* program_counter, 661 ScopedThreadActivity(const void* program_counter,
650 const void* origin, 662 const void* origin,
651 Activity::Type type, 663 Activity::Type type,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 // Creates an activity-tracker for the current thread. 747 // Creates an activity-tracker for the current thread.
736 ThreadActivityTracker* CreateTrackerForCurrentThread(); 748 ThreadActivityTracker* CreateTrackerForCurrentThread();
737 749
738 // Releases the activity-tracker for the current thread (for testing only). 750 // Releases the activity-tracker for the current thread (for testing only).
739 void ReleaseTrackerForCurrentThreadForTesting(); 751 void ReleaseTrackerForCurrentThreadForTesting();
740 752
741 // Records a log message. The current implementation does NOT recycle these 753 // Records a log message. The current implementation does NOT recycle these
742 // only store critical messages such as FATAL ones. 754 // only store critical messages such as FATAL ones.
743 void RecordLogMessage(StringPiece message); 755 void RecordLogMessage(StringPiece message);
744 756
757 // Records a module load/unload event. This is safe to call multiple times
758 // even with the same information.
759 void RecordModuleInfo(const ModuleInfo& info);
760
745 // Accesses the global data record for storing arbitrary key/value pairs. 761 // Accesses the global data record for storing arbitrary key/value pairs.
746 ActivityUserData& user_data() { return user_data_; } 762 ActivityUserData& user_data() { return user_data_; }
747 763
748 private: 764 private:
749 friend class ScopedThreadActivity; 765 friend class ScopedThreadActivity;
750 friend class ActivityTrackerTest; 766 friend class ActivityTrackerTest;
751 767
752 enum : int { 768 enum : int {
753 // The maximum number of threads that can be tracked within a process. If 769 // The maximum number of threads that can be tracked within a process. If
754 // more than this number run concurrently, tracking of new ones may cease. 770 // more than this number run concurrently, tracking of new ones may cease.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 base::Lock thread_tracker_allocator_lock_; 827 base::Lock thread_tracker_allocator_lock_;
812 828
813 // A caching memory allocator for user data attached to activity data. 829 // A caching memory allocator for user data attached to activity data.
814 ActivityTrackerMemoryAllocator user_data_allocator_; 830 ActivityTrackerMemoryAllocator user_data_allocator_;
815 base::Lock user_data_allocator_lock_; 831 base::Lock user_data_allocator_lock_;
816 832
817 // An object for holding global arbitrary key value pairs. Values must always 833 // An object for holding global arbitrary key value pairs. Values must always
818 // be written from the main UI thread. 834 // be written from the main UI thread.
819 ActivityUserData user_data_; 835 ActivityUserData user_data_;
820 836
837 // A map of global module information, keyed by module path.
838 std::map<const std::string, PersistentMemoryAllocator::Reference> modules_;
manzagop (departed) 2016/12/14 20:08:54 I believe it's possible to have the same module lo
bcwhite 2016/12/14 21:59:05 That would be annoying. How about we wait to see
manzagop (departed) 2016/12/16 16:09:31 Totally. :( IIRC Siggi said this is to be expected
bcwhite 2016/12/16 18:35:15 Done. If it comes to it, I'll probably support mu
839 base::Lock modules_lock_;
840
821 // The active global activity tracker. 841 // The active global activity tracker.
822 static GlobalActivityTracker* g_tracker_; 842 static GlobalActivityTracker* g_tracker_;
823 843
824 DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker); 844 DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker);
825 }; 845 };
826 846
827 847
828 // Record entry in to and out of an arbitrary block of code. 848 // Record entry in to and out of an arbitrary block of code.
829 class BASE_EXPORT ScopedActivity 849 class BASE_EXPORT ScopedActivity
830 : public GlobalActivityTracker::ScopedThreadActivity { 850 : public GlobalActivityTracker::ScopedThreadActivity {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 ScopedProcessWaitActivity(const void* program_counter, 968 ScopedProcessWaitActivity(const void* program_counter,
949 const base::Process* process); 969 const base::Process* process);
950 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); 970 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity);
951 }; 971 };
952 #endif 972 #endif
953 973
954 } // namespace debug 974 } // namespace debug
955 } // namespace base 975 } // namespace base
956 976
957 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ 977 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/activity_tracker.cc » ('j') | base/debug/activity_tracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698