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

Unified Diff: base/debug/activity_analyzer.cc

Issue 2511043003: Support for extracting user-data from activity tracking. (Closed)
Patch Set: refactored so global information sits in an extended snapshot 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 side-by-side diff with in-line comments
Download patch
Index: base/debug/activity_analyzer.cc
diff --git a/base/debug/activity_analyzer.cc b/base/debug/activity_analyzer.cc
index 0c30d8d0c213c2e973dec707cc439d97e58e3fe7..90714bdd0f871e55759bfea90ea101faa5319265 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 an the
manzagop (departed) 2016/12/02 22:13:33 typo: referenced an -> at
bcwhite 2016/12/08 21:30:56 Done.
+ // 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;
+}
+
GlobalActivityAnalyzer::ProgramLocation
GlobalActivityAnalyzer::GetProgramLocationFromAddress(uint64_t address) {
// TODO(bcwhite): Implement this.
@@ -123,6 +182,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.

Powered by Google App Engine
This is Rietveld 408576698