Chromium Code Reviews| Index: base/debug/activity_tracker.h |
| diff --git a/base/debug/activity_tracker.h b/base/debug/activity_tracker.h |
| index 2d3c2bc7dbaf3666540cb9e7dda55e179685235a..dadcb5abdd6bddfa5582548ac2261ab52517fbfe 100644 |
| --- a/base/debug/activity_tracker.h |
| +++ b/base/debug/activity_tracker.h |
| @@ -26,6 +26,7 @@ |
| #include "base/gtest_prod_util.h" |
| #include "base/location.h" |
| #include "base/metrics/persistent_memory_allocator.h" |
| +#include "base/strings/string_piece.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/threading/platform_thread.h" |
| #include "base/threading/thread_checker.h" |
| @@ -340,7 +341,7 @@ class BASE_EXPORT ActivityUserData { |
| using Snapshot = std::map<std::string, TypedValue>; |
| ActivityUserData(void* memory, size_t size); |
| - ~ActivityUserData(); |
| + virtual ~ActivityUserData(); |
| // Gets the unique ID number for this user data. If this changes then the |
| // contents have been overwritten by another thread. The return value is |
| @@ -402,6 +403,12 @@ class BASE_EXPORT ActivityUserData { |
| // Gets the base memory address used for storing data. |
| const void* GetBaseAddress(); |
| + protected: |
| + virtual void Set(StringPiece name, |
| + ValueType type, |
| + const void* memory, |
| + size_t size); |
| + |
| private: |
| FRIEND_TEST_ALL_PREFIXES(ActivityTrackerTest, UserDataTest); |
| @@ -435,7 +442,6 @@ class BASE_EXPORT ActivityUserData { |
| size_t extent; // The total storage of the value, |
| }; // typically rounded up for alignment. |
| - void Set(StringPiece name, ValueType type, const void* memory, size_t size); |
| void SetReference(StringPiece name, |
| ValueType type, |
| const void* memory, |
| @@ -459,8 +465,6 @@ class BASE_EXPORT ActivityUserData { |
| // A pointer to the unique ID for this instance. |
| std::atomic<uint32_t>* const id_; |
| - base::ThreadChecker thread_checker_; |
| - |
| // This ID is used to create unique indentifiers for user data so that it's |
| // possible to tell if the information has been overwritten. |
| static std::atomic<uint32_t> next_id_; |
| @@ -780,7 +784,19 @@ class BASE_EXPORT GlobalActivityTracker { |
| void RecordModuleInfo(const ModuleInfo& info); |
| // Accesses the global data record for storing arbitrary key/value pairs. |
| - ActivityUserData& user_data() { return user_data_; } |
| + ActivityUserData& global_data() { return global_data_; } |
| + |
| + // Record field trial information. This will work even before a global |
| + // tracker has been created, holding that information internally until a |
| + // global tracker is created at which point everything collected will be |
| + // dumped into it. This call is completely thread-safe. |
|
Alexei Svitkine (slow)
2017/02/07 16:14:06
Nit: Remove the word "completely". "thread safe" i
bcwhite
2017/02/07 17:39:30
Done.
|
| + static void RecordFieldTrial(const std::string& trial_name, |
| + const std::string& group_name); |
| + |
| + // Disable all filed trial recording. This should be called when its known |
|
Alexei Svitkine (slow)
2017/02/07 16:14:06
field
bcwhite
2017/02/07 17:39:30
Done.
|
| + // that no global tracker will be created so as to not hold field-trial |
| + // information that will never be collected. |
| + static void DisableFieldTrialRecording(); |
| private: |
| friend class GlobalActivityAnalyzer; |
| @@ -795,6 +811,25 @@ class BASE_EXPORT GlobalActivityTracker { |
| kCachedUserDataMemories = 10, |
| }; |
| + // A wrapper around ActivityUserData that is thread-safe and thus can be used |
| + // in the global scope without the requirement of being called from only one |
| + // thread. |
| + class GlobalUserData : public ActivityUserData { |
| + public: |
| + GlobalUserData(void* memory, size_t size); |
| + ~GlobalUserData() override; |
| + |
| + private: |
| + void Set(StringPiece name, |
| + ValueType type, |
| + const void* memory, |
| + size_t size) override; |
| + |
| + Lock data_lock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GlobalUserData); |
| + }; |
| + |
| // State of a module as stored in persistent memory. This supports a single |
| // loading of a module only. If modules are loaded multiple times at |
| // different addresses, only the last will be recorded and an unload will |
| @@ -899,7 +934,7 @@ class BASE_EXPORT GlobalActivityTracker { |
| // An object for holding global arbitrary key value pairs. Values must always |
| // be written from the main UI thread. |
| - ActivityUserData user_data_; |
| + GlobalUserData global_data_; |
| // A map of global module information, keyed by module path. |
| std::map<const std::string, ModuleInfoRecord*> modules_; |