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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/trace_event/process_memory_totals.h" | 10 #include "base/trace_event/process_memory_totals.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); | 36 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); |
37 DCHECK_EQ(0u, start_pointer % page_size); | 37 DCHECK_EQ(0u, start_pointer % page_size); |
38 | 38 |
39 // This function allocates a char vector of size number of pages in the given | 39 // This function allocates a char vector of size number of pages in the given |
40 // mapped_size. To avoid allocating a large array, the memory is split into | 40 // mapped_size. To avoid allocating a large array, the memory is split into |
41 // chunks. Maximum size of vector allocated, will be | 41 // chunks. Maximum size of vector allocated, will be |
42 // kPageChunkSize / page_size. | 42 // kPageChunkSize / page_size. |
43 const size_t kMaxChunkSize = 32 * 1024 * 1024; | 43 const size_t kMaxChunkSize = 32 * 1024 * 1024; |
44 size_t offset = 0; | 44 size_t offset = 0; |
45 size_t total_resident_size = 0; | 45 size_t total_resident_size = 0; |
| 46 int result = 0; |
46 while (offset < mapped_size) { | 47 while (offset < mapped_size) { |
47 void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); | 48 void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); |
48 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); | 49 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); |
49 const size_t page_count = (chunk_size + page_size - 1) / page_size; | 50 const size_t page_count = (chunk_size + page_size - 1) / page_size; |
50 size_t resident_page_count = 0; | 51 size_t resident_page_count = 0; |
51 | 52 |
52 #if defined(OS_MACOSX) || defined(OS_IOS) | 53 #if defined(OS_MACOSX) || defined(OS_IOS) |
53 std::vector<char> vec(page_count + 1); | 54 std::vector<char> vec(page_count + 1); |
54 int res = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | 55 // mincore in MAC does not fail with EAGAIN. |
55 DCHECK(!res); | 56 result = mincore(chunk_start, chunk_size, vector_as_array(&vec)); |
| 57 if (result) |
| 58 break; |
| 59 |
56 for (size_t i = 0; i < page_count; i++) | 60 for (size_t i = 0; i < page_count; i++) |
57 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; | 61 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; |
58 #else // defined(OS_MACOSX) || defined(OS_IOS) | 62 #else // defined(OS_MACOSX) || defined(OS_IOS) |
59 std::vector<unsigned char> vec(page_count + 1); | 63 std::vector<unsigned char> vec(page_count + 1); |
60 int res = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | 64 int error_counter = 0; |
61 DCHECK(!res); | 65 // HANDLE_EINTR tries for 100 times. So following the same pattern. |
| 66 do { |
| 67 result = mincore(chunk_start, chunk_size, vector_as_array(&vec)); |
| 68 } while (result == -1 && errno == EAGAIN && error_counter++ < 100); |
| 69 if (result) |
| 70 break; |
| 71 |
62 for (size_t i = 0; i < page_count; i++) | 72 for (size_t i = 0; i < page_count; i++) |
63 resident_page_count += vec[i]; | 73 resident_page_count += vec[i]; |
64 #endif // defined(OS_MACOSX) || defined(OS_IOS) | 74 #endif // defined(OS_MACOSX) || defined(OS_IOS) |
65 | 75 |
66 total_resident_size += resident_page_count * page_size; | 76 total_resident_size += resident_page_count * page_size; |
67 offset += kMaxChunkSize; | 77 offset += kMaxChunkSize; |
68 } | 78 } |
| 79 |
| 80 DCHECK_EQ(0, result); |
| 81 if (result) { |
| 82 total_resident_size = 0; |
| 83 LOG(ERROR) << "mincore() call failed. The resident size is invalid"; |
| 84 } |
69 return total_resident_size; | 85 return total_resident_size; |
70 } | 86 } |
71 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 87 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
72 | 88 |
73 ProcessMemoryDump::ProcessMemoryDump( | 89 ProcessMemoryDump::ProcessMemoryDump( |
74 const scoped_refptr<MemoryDumpSessionState>& session_state) | 90 const scoped_refptr<MemoryDumpSessionState>& session_state) |
75 : has_process_totals_(false), | 91 : has_process_totals_(false), |
76 has_process_mmaps_(false), | 92 has_process_mmaps_(false), |
77 session_state_(session_state) { | 93 session_state_(session_state) { |
78 } | 94 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 228 |
213 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 229 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
214 const std::string& target_node_name) { | 230 const std::string& target_node_name) { |
215 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 231 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
216 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 232 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
217 AddOwnershipEdge(source, target_child_mad->guid()); | 233 AddOwnershipEdge(source, target_child_mad->guid()); |
218 } | 234 } |
219 | 235 |
220 } // namespace trace_event | 236 } // namespace trace_event |
221 } // namespace base | 237 } // namespace base |
OLD | NEW |