OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/debug/activity_analyzer.h" | 5 #include "base/debug/activity_analyzer.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/memory_mapped_file.h" | 9 #include "base/files/memory_mapped_file.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 ThreadActivityAnalyzer::ThreadActivityAnalyzer(void* base, size_t size) | 25 ThreadActivityAnalyzer::ThreadActivityAnalyzer(void* base, size_t size) |
26 : ThreadActivityAnalyzer(ThreadActivityTracker(base, size)) {} | 26 : ThreadActivityAnalyzer(ThreadActivityTracker(base, size)) {} |
27 | 27 |
28 ThreadActivityAnalyzer::ThreadActivityAnalyzer( | 28 ThreadActivityAnalyzer::ThreadActivityAnalyzer( |
29 PersistentMemoryAllocator* allocator, | 29 PersistentMemoryAllocator* allocator, |
30 PersistentMemoryAllocator::Reference reference) | 30 PersistentMemoryAllocator::Reference reference) |
31 : ThreadActivityAnalyzer(allocator->GetAsArray<char>( | 31 : ThreadActivityAnalyzer(allocator->GetAsArray<char>( |
32 reference, | 32 reference, |
33 GlobalActivityTracker::kTypeIdActivityTracker, | 33 GlobalActivityTracker::kTypeIdActivityTracker, |
34 1), | 34 PersistentMemoryAllocator::kSizeAny), |
35 allocator->GetAllocSize(reference)) {} | 35 allocator->GetAllocSize(reference)) {} |
36 | 36 |
37 ThreadActivityAnalyzer::~ThreadActivityAnalyzer() {} | 37 ThreadActivityAnalyzer::~ThreadActivityAnalyzer() {} |
38 | 38 |
39 void ThreadActivityAnalyzer::AddGlobalInformation( | 39 void ThreadActivityAnalyzer::AddGlobalInformation( |
40 GlobalActivityAnalyzer* global) { | 40 GlobalActivityAnalyzer* global) { |
41 if (!IsValid()) | 41 if (!IsValid()) |
42 return; | 42 return; |
43 | 43 |
44 // User-data is held at the global scope even though it's referenced at the | 44 // User-data is held at the global scope even though it's referenced at the |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const char* message = allocator_->GetAsArray<char>( | 152 const char* message = allocator_->GetAsArray<char>( |
153 ref, GlobalActivityTracker::kTypeIdGlobalLogMessage, | 153 ref, GlobalActivityTracker::kTypeIdGlobalLogMessage, |
154 PersistentMemoryAllocator::kSizeAny); | 154 PersistentMemoryAllocator::kSizeAny); |
155 if (message) | 155 if (message) |
156 messages.push_back(message); | 156 messages.push_back(message); |
157 } | 157 } |
158 | 158 |
159 return messages; | 159 return messages; |
160 } | 160 } |
161 | 161 |
| 162 std::vector<GlobalActivityTracker::ModuleInfo> |
| 163 GlobalActivityAnalyzer::GetModules() { |
| 164 std::vector<GlobalActivityTracker::ModuleInfo> modules; |
| 165 |
| 166 PersistentMemoryAllocator::Iterator iter(allocator_.get()); |
| 167 const GlobalActivityTracker::ModuleInfoRecord* record; |
| 168 while ( |
| 169 (record = |
| 170 iter.GetNextOfObject<GlobalActivityTracker::ModuleInfoRecord>()) != |
| 171 nullptr) { |
| 172 GlobalActivityTracker::ModuleInfo info; |
| 173 if (record->DecodeTo(&info, allocator_->GetAllocSize( |
| 174 allocator_->GetAsReference(record)))) { |
| 175 modules.push_back(std::move(info)); |
| 176 } |
| 177 } |
| 178 |
| 179 return modules; |
| 180 } |
| 181 |
162 GlobalActivityAnalyzer::ProgramLocation | 182 GlobalActivityAnalyzer::ProgramLocation |
163 GlobalActivityAnalyzer::GetProgramLocationFromAddress(uint64_t address) { | 183 GlobalActivityAnalyzer::GetProgramLocationFromAddress(uint64_t address) { |
164 // TODO(bcwhite): Implement this. | 184 // TODO(bcwhite): Implement this. |
165 return { 0, 0 }; | 185 return { 0, 0 }; |
166 } | 186 } |
167 | 187 |
168 void GlobalActivityAnalyzer::PrepareAllAnalyzers() { | 188 void GlobalActivityAnalyzer::PrepareAllAnalyzers() { |
169 // Fetch all the records. This will retrieve only ones created since the | 189 // Fetch all the records. This will retrieve only ones created since the |
170 // last run since the PMA iterator will continue from where it left off. | 190 // last run since the PMA iterator will continue from where it left off. |
171 uint32_t type; | 191 uint32_t type; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Add this analyzer to the map of known ones, indexed by a unique thread | 224 // Add this analyzer to the map of known ones, indexed by a unique thread |
205 // identifier. | 225 // identifier. |
206 DCHECK(!base::ContainsKey(analyzers_, analyzer->GetThreadKey())); | 226 DCHECK(!base::ContainsKey(analyzers_, analyzer->GetThreadKey())); |
207 analyzer->allocator_reference_ = ref; | 227 analyzer->allocator_reference_ = ref; |
208 analyzers_[analyzer->GetThreadKey()] = std::move(analyzer); | 228 analyzers_[analyzer->GetThreadKey()] = std::move(analyzer); |
209 } | 229 } |
210 } | 230 } |
211 | 231 |
212 } // namespace debug | 232 } // namespace debug |
213 } // namespace base | 233 } // namespace base |
OLD | NEW |