OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/trace_event/process_memory_dump.h" | 5 #include "base/trace_event/process_memory_dump.h" |
6 | 6 |
7 #include "base/trace_event/process_memory_totals.h" | 7 #include "base/trace_event/process_memory_totals.h" |
8 #include "base/trace_event/trace_event_argument.h" | 8 #include "base/trace_event/trace_event_argument.h" |
9 | 9 |
| 10 #if defined(OS_POSIX) |
| 11 #include <sys/mman.h> |
| 12 #endif |
| 13 |
10 namespace base { | 14 namespace base { |
11 namespace trace_event { | 15 namespace trace_event { |
12 | 16 |
13 namespace { | 17 namespace { |
14 const char kEdgeTypeOwnership[] = "ownership"; | 18 const char kEdgeTypeOwnership[] = "ownership"; |
15 | 19 |
16 std::string GetSharedGlobalAllocatorDumpName( | 20 std::string GetSharedGlobalAllocatorDumpName( |
17 const MemoryAllocatorDumpGuid& guid) { | 21 const MemoryAllocatorDumpGuid& guid) { |
18 return "global/" + guid.ToString(); | 22 return "global/" + guid.ToString(); |
19 } | 23 } |
20 } // namespace | 24 } // namespace |
21 | 25 |
| 26 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 27 // static |
| 28 size_t ProcessMemoryDump::CountResidentBytes(void* start_address, |
| 29 size_t mapped_size) { |
| 30 const size_t page_size = base::GetPageSize(); |
| 31 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); |
| 32 DCHECK_EQ(0u, start_pointer % page_size); |
| 33 |
| 34 // This function allocates a char vector of size number of pages in the given |
| 35 // mapped_size. To avoid allocating a large array, the memory is split into |
| 36 // chunks. Maximum size of vector allocated, will be |
| 37 // kPageChunkSize / page_size. |
| 38 const size_t kMaxChunkSize = 32 * 1024 * 1024; |
| 39 size_t offset = 0; |
| 40 size_t total_resident_size = 0; |
| 41 while (offset < mapped_size) { |
| 42 void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); |
| 43 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); |
| 44 const size_t page_count = (chunk_size + page_size - 1) / page_size; |
| 45 size_t resident_page_count = 0; |
| 46 |
| 47 #if defined(OS_MACOSX) || defined(OS_IOS) |
| 48 scoped_ptr<char[]> vec(new char[page_count + 1]); |
| 49 int res = mincore(chunk_start, chunk_size, &vec.get()[0]); |
| 50 DCHECK(!res); |
| 51 for (size_t i = 0; i < page_count; i++) |
| 52 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; |
| 53 |
| 54 #else // defined(OS_MACOSX) || defined(OS_IOS) |
| 55 scoped_ptr<unsigned char[]> vec(new unsigned char[page_count + 1]); |
| 56 int res = mincore(chunk_start, chunk_size, &vec.get()[0]); |
| 57 DCHECK(!res); |
| 58 for (size_t i = 0; i < page_count; i++) |
| 59 resident_page_count += vec[i]; |
| 60 #endif // defined(OS_MACOSX) || defined(OS_IOS) |
| 61 |
| 62 total_resident_size += resident_page_count * page_size; |
| 63 offset += kMaxChunkSize; |
| 64 } |
| 65 return total_resident_size; |
| 66 } |
| 67 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 68 |
22 ProcessMemoryDump::ProcessMemoryDump( | 69 ProcessMemoryDump::ProcessMemoryDump( |
23 const scoped_refptr<MemoryDumpSessionState>& session_state) | 70 const scoped_refptr<MemoryDumpSessionState>& session_state) |
24 : has_process_totals_(false), | 71 : has_process_totals_(false), |
25 has_process_mmaps_(false), | 72 has_process_mmaps_(false), |
26 session_state_(session_state) { | 73 session_state_(session_state) { |
27 } | 74 } |
28 | 75 |
29 ProcessMemoryDump::~ProcessMemoryDump() { | 76 ProcessMemoryDump::~ProcessMemoryDump() { |
30 } | 77 } |
31 | 78 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 202 |
156 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 203 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
157 const std::string& target_node_name) { | 204 const std::string& target_node_name) { |
158 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 205 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
159 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 206 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
160 AddOwnershipEdge(source, target_child_mad->guid()); | 207 AddOwnershipEdge(source, target_child_mad->guid()); |
161 } | 208 } |
162 | 209 |
163 } // namespace trace_event | 210 } // namespace trace_event |
164 } // namespace base | 211 } // namespace base |
OLD | NEW |