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

Unified Diff: base/debug/activity_tracker.h

Issue 2666653002: Record field-trial information in stability file for crash analysis. (Closed)
Patch Set: rebased Created 3 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: base/debug/activity_tracker.h
diff --git a/base/debug/activity_tracker.h b/base/debug/activity_tracker.h
index 348591957cbd9ed6b414cd91bf57e8453a22220f..f2a8362ee5ed1820ad0467a4c6672e3c218ed266 100644
--- a/base/debug/activity_tracker.h
+++ b/base/debug/activity_tracker.h
@@ -27,6 +27,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"
@@ -342,7 +343,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
@@ -404,6 +405,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);
@@ -437,7 +444,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,
@@ -461,8 +467,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 StaticAtomicSequenceNumber next_id_;
@@ -785,7 +789,20 @@ 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 thread-safe.
+ static void RecordFieldTrial(const std::string& trial_name,
+ const std::string& group_name);
+
+ // Disable all field trial recording. This should be called when its known
+ // that no global tracker will be created so as to not hold field-trial
+ // information that will never be collected. If a global tracker has already
+ // been created, field trials recorded before this call will not be forgotten.
+ static void DisableFieldTrialRecording();
private:
friend class GlobalActivityAnalyzer;
@@ -800,6 +817,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
@@ -904,7 +940,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_;

Powered by Google App Engine
This is Rietveld 408576698