Remove 'global' user-data in favor of 'process' user-data.
There's (currently) no cross-process thread safety possible for the ActivityUserData structure so it's not feasible to have a "global" entry.
BUG=620813
Review-Url: https://codereview.chromium.org/2753573002
Cr-Commit-Position: refs/heads/master@{#463663}
CrOS-Libchrome-Original-Commit: 8ffd39048b78f37e10e5bc2cf50f5f338b304e87
diff --git a/base/debug/activity_analyzer.cc b/base/debug/activity_analyzer.cc
index 0ab7c3d..3c67234 100644
--- a/base/debug/activity_analyzer.cc
+++ b/base/debug/activity_analyzer.cc
@@ -172,25 +172,6 @@
return iter->second.data;
}
-const ActivityUserData::Snapshot&
-GlobalActivityAnalyzer::GetGlobalDataSnapshot() {
- global_data_snapshot_.clear();
-
- PersistentMemoryAllocator::Reference ref =
- PersistentMemoryAllocator::Iterator(allocator_.get())
- .GetNextOfType(GlobalActivityTracker::kTypeIdGlobalDataRecord);
- void* memory = allocator_->GetAsArray<char>(
- ref, GlobalActivityTracker::kTypeIdGlobalDataRecord,
- PersistentMemoryAllocator::kSizeAny);
- if (memory) {
- size_t size = allocator_->GetAllocSize(ref);
- const ActivityUserData global_data(memory, size);
- global_data.CreateSnapshot(&global_data_snapshot_);
- }
-
- return global_data_snapshot_;
-}
-
std::vector<std::string> GlobalActivityAnalyzer::GetLogMessages() {
std::vector<std::string> messages;
PersistentMemoryAllocator::Reference ref;
diff --git a/base/debug/activity_analyzer.h b/base/debug/activity_analyzer.h
index 2200537..e98046e 100644
--- a/base/debug/activity_analyzer.h
+++ b/base/debug/activity_analyzer.h
@@ -176,9 +176,6 @@
// returned if the process is not known.
const ActivityUserData::Snapshot& GetProcessDataSnapshot(int64_t pid);
- // Extract the global data.
- const ActivityUserData::Snapshot& GetGlobalDataSnapshot();
-
// Gets all log messages stored within.
std::vector<std::string> GetLogMessages();
@@ -236,9 +233,6 @@
AnalyzerMap::iterator analyzers_iterator_;
int64_t analyzers_iterator_pid_;
- // Snapshot of the global data.
- ActivityUserData::Snapshot global_data_snapshot_;
-
DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer);
};
diff --git a/base/debug/activity_analyzer_unittest.cc b/base/debug/activity_analyzer_unittest.cc
index 82889dc..31871f5 100644
--- a/base/debug/activity_analyzer_unittest.cc
+++ b/base/debug/activity_analyzer_unittest.cc
@@ -314,6 +314,7 @@
}
TEST_F(ActivityAnalyzerTest, GlobalUserDataTest) {
+ const int64_t pid = GetCurrentProcId();
GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0);
const char string1[] = "foo";
@@ -324,18 +325,21 @@
GlobalActivityAnalyzer global_analyzer(MakeUnique<PersistentMemoryAllocator>(
const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
- ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data();
- global_data.Set("raw", "foo", 3);
- global_data.SetString("string", "bar");
- global_data.SetChar("char", '9');
- global_data.SetInt("int", -9999);
- global_data.SetUint("uint", 9999);
- global_data.SetBool("bool", true);
- global_data.SetReference("ref", string1, sizeof(string1));
- global_data.SetStringReference("sref", string2);
+ ActivityUserData& process_data = GlobalActivityTracker::Get()->process_data();
+ ASSERT_NE(0U, process_data.id());
+ process_data.Set("raw", "foo", 3);
+ process_data.SetString("string", "bar");
+ process_data.SetChar("char", '9');
+ process_data.SetInt("int", -9999);
+ process_data.SetUint("uint", 9999);
+ process_data.SetBool("bool", true);
+ process_data.SetReference("ref", string1, sizeof(string1));
+ process_data.SetStringReference("sref", string2);
+ int64_t first_pid = global_analyzer.GetFirstProcess();
+ DCHECK_EQ(pid, first_pid);
const ActivityUserData::Snapshot& snapshot =
- global_analyzer.GetGlobalDataSnapshot();
+ global_analyzer.GetProcessDataSnapshot(pid);
ASSERT_TRUE(ContainsKey(snapshot, "raw"));
EXPECT_EQ("foo", snapshot.at("raw").Get().as_string());
ASSERT_TRUE(ContainsKey(snapshot, "string"));
diff --git a/base/debug/activity_tracker.cc b/base/debug/activity_tracker.cc
index f25ac97..0e8db93 100644
--- a/base/debug/activity_tracker.cc
+++ b/base/debug/activity_tracker.cc
@@ -38,7 +38,6 @@
// pairs) globally or associated with ActivityData entries.
const size_t kUserDataSize = 1 << 10; // 1 KiB
const size_t kProcessDataSize = 4 << 10; // 4 KiB
-const size_t kGlobalDataSize = 16 << 10; // 16 KiB
const size_t kMaxUserDataNameLength =
static_cast<size_t>(std::numeric_limits<uint8_t>::max());
@@ -1599,7 +1598,7 @@
void GlobalActivityTracker::RecordFieldTrial(const std::string& trial_name,
StringPiece group_name) {
const std::string key = std::string("FieldTrial.") + trial_name;
- global_data_.SetString(key, group_name);
+ process_data_.SetString(key, group_name);
}
GlobalActivityTracker::GlobalActivityTracker(
@@ -1631,14 +1630,7 @@
kTypeIdProcessDataRecord,
kProcessDataSize),
kProcessDataSize,
- process_id_),
- global_data_(
- allocator_->GetAsArray<char>(
- allocator_->Allocate(kGlobalDataSize, kTypeIdGlobalDataRecord),
- kTypeIdGlobalDataRecord,
- kGlobalDataSize),
- kGlobalDataSize,
- process_id_) {
+ process_id_) {
DCHECK_NE(0, process_id_);
// Ensure that there is no other global object and then make this one such.
@@ -1648,8 +1640,6 @@
// The data records must be iterable in order to be found by an analyzer.
allocator_->MakeIterable(allocator_->GetAsReference(
process_data_.GetBaseAddress(), kTypeIdProcessDataRecord));
- allocator_->MakeIterable(allocator_->GetAsReference(
- global_data_.GetBaseAddress(), kTypeIdGlobalDataRecord));
// Note that this process has launched.
SetProcessPhase(PROCESS_LAUNCHED);
diff --git a/base/debug/activity_tracker.h b/base/debug/activity_tracker.h
index c8cf1e9..c968f38 100644
--- a/base/debug/activity_tracker.h
+++ b/base/debug/activity_tracker.h
@@ -764,7 +764,6 @@
kTypeIdUserDataRecord = 0x615EDDD7 + 3, // SHA1(UserDataRecord) v3
kTypeIdGlobalLogMessage = 0x4CF434F9 + 1, // SHA1(GlobalLogMessage) v1
kTypeIdProcessDataRecord = kTypeIdUserDataRecord + 0x100,
- kTypeIdGlobalDataRecord = kTypeIdUserDataRecord + 0x200,
kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker,
kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord,
@@ -826,9 +825,8 @@
};
// This is a thin wrapper around the thread-tracker's ScopedActivity that
- // accesses the global tracker to provide some of the information, notably
- // which thread-tracker to use. It is safe to create even if activity
- // tracking is not enabled.
+ // allows thread-safe access to data values. It is safe to use even if
+ // activity tracking is not enabled.
class BASE_EXPORT ScopedThreadActivity
: public ThreadActivityTracker::ScopedActivity {
public:
@@ -1032,10 +1030,6 @@
// Updates to this are thread-safe.
ActivityUserData& process_data() { return process_data_; }
- // Accesses the global data record for storing arbitrary key/value pairs.
- // Updates to this are thread-safe.
- ActivityUserData& global_data() { return global_data_; }
-
private:
friend class GlobalActivityAnalyzer;
friend class ScopedThreadActivity;
@@ -1190,7 +1184,6 @@
// An object for holding arbitrary key value pairs with thread-safe access.
ThreadSafeUserData process_data_;
- ThreadSafeUserData global_data_;
// A map of global module information, keyed by module path.
std::map<const std::string, ModuleInfoRecord*> modules_;
diff --git a/base/debug/activity_tracker_unittest.cc b/base/debug/activity_tracker_unittest.cc
index 4271d11..372d6ac 100644
--- a/base/debug/activity_tracker_unittest.cc
+++ b/base/debug/activity_tracker_unittest.cc
@@ -306,8 +306,6 @@
// Ensure the data repositories have backing store, indicated by non-zero ID.
EXPECT_NE(0U, global->process_data().id());
- EXPECT_NE(0U, global->global_data().id());
- EXPECT_NE(global->process_data().id(), global->global_data().id());
}
class SimpleActivityThread : public SimpleThread {