| Index: base/debug/activity_analyzer.cc
|
| diff --git a/base/debug/activity_analyzer.cc b/base/debug/activity_analyzer.cc
|
| index 469ec5106a8d4500effcdb26cbfb1ec115c5306b..6a483f38fba78dd6c06e7b4c2b8517d4be1f43a4 100644
|
| --- a/base/debug/activity_analyzer.cc
|
| +++ b/base/debug/activity_analyzer.cc
|
| @@ -15,9 +15,12 @@
|
| namespace base {
|
| namespace debug {
|
|
|
| +ThreadActivityAnalyzer::Snapshot::Snapshot() {}
|
| +ThreadActivityAnalyzer::Snapshot::~Snapshot() {}
|
| +
|
| ThreadActivityAnalyzer::ThreadActivityAnalyzer(
|
| const ThreadActivityTracker& tracker)
|
| - : activity_snapshot_valid_(tracker.Snapshot(&activity_snapshot_)) {}
|
| + : activity_snapshot_valid_(tracker.CreateSnapshot(&activity_snapshot_)) {}
|
|
|
| ThreadActivityAnalyzer::ThreadActivityAnalyzer(void* base, size_t size)
|
| : ThreadActivityAnalyzer(ThreadActivityTracker(base, size)) {}
|
| @@ -33,6 +36,22 @@ ThreadActivityAnalyzer::ThreadActivityAnalyzer(
|
|
|
| ThreadActivityAnalyzer::~ThreadActivityAnalyzer() {}
|
|
|
| +void ThreadActivityAnalyzer::AddGlobalInformation(
|
| + GlobalActivityAnalyzer* global) {
|
| + if (!IsValid())
|
| + return;
|
| +
|
| + // User-data is held at the global scope even though it's referenced at the
|
| + // thread scope.
|
| + activity_snapshot_.user_data_stack.clear();
|
| + for (auto& activity : activity_snapshot_.activity_stack) {
|
| + // The global GetUserDataSnapshot will return an empty snapshot if the ref
|
| + // or id is not valid.
|
| + activity_snapshot_.user_data_stack.push_back(global->GetUserDataSnapshot(
|
| + activity.user_data_ref, activity.user_data_id));
|
| + }
|
| +}
|
| +
|
| GlobalActivityAnalyzer::GlobalActivityAnalyzer(
|
| std::unique_ptr<PersistentMemoryAllocator> allocator)
|
| : allocator_(std::move(allocator)), allocator_iterator_(allocator_.get()) {}
|
| @@ -83,6 +102,46 @@ ThreadActivityAnalyzer* GlobalActivityAnalyzer::GetAnalyzerForThread(
|
| return found->second.get();
|
| }
|
|
|
| +ActivityUserData::Snapshot GlobalActivityAnalyzer::GetUserDataSnapshot(
|
| + uint32_t ref,
|
| + uint32_t id) {
|
| + ActivityUserData::Snapshot snapshot;
|
| +
|
| + void* memory = allocator_->GetAsArray<char>(
|
| + ref, GlobalActivityTracker::kTypeIdUserDataRecord,
|
| + PersistentMemoryAllocator::kSizeAny);
|
| + if (memory) {
|
| + size_t size = allocator_->GetAllocSize(ref);
|
| + const ActivityUserData user_data(memory, size);
|
| + user_data.CreateSnapshot(&snapshot);
|
| + if (user_data.id() != id) {
|
| + // This allocation has been overwritten since it was created. Return an
|
| + // empty snapshot because whatever was captured is incorrect.
|
| + snapshot.clear();
|
| + }
|
| + }
|
| +
|
| + return snapshot;
|
| +}
|
| +
|
| +ActivityUserData::Snapshot GlobalActivityAnalyzer::GetGlobalUserDataSnapshot() {
|
| + ActivityUserData::Snapshot snapshot;
|
| +
|
| + 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(&snapshot);
|
| + }
|
| +
|
| + return snapshot;
|
| +}
|
| +
|
| std::vector<std::string> GlobalActivityAnalyzer::GetLogMessages() {
|
| std::vector<std::string> messages;
|
| PersistentMemoryAllocator::Reference ref;
|
| @@ -140,6 +199,7 @@ void GlobalActivityAnalyzer::PrepareAllAnalyzers() {
|
| base, allocator_->GetAllocSize(tracker_ref)));
|
| if (!analyzer->IsValid())
|
| continue;
|
| + analyzer->AddGlobalInformation(this);
|
|
|
| // Add this analyzer to the map of known ones, indexed by a unique thread
|
| // identifier.
|
|
|