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 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 std::string GetSharedGlobalAllocatorDumpName( | 24 std::string GetSharedGlobalAllocatorDumpName( |
25 const MemoryAllocatorDumpGuid& guid) { | 25 const MemoryAllocatorDumpGuid& guid) { |
26 return "global/" + guid.ToString(); | 26 return "global/" + guid.ToString(); |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 31 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
32 // static | 32 // static |
33 size_t ProcessMemoryDump::CountResidentBytes(void* start_address, | 33 bool ProcessMemoryDump::CountResidentBytes(void* start_address, |
34 size_t mapped_size) { | 34 size_t mapped_size, |
35 size_t* resident_size) { | |
36 *resident_size = 0; | |
35 const size_t page_size = GetPageSize(); | 37 const size_t page_size = GetPageSize(); |
36 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); | 38 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); |
37 DCHECK_EQ(0u, start_pointer % page_size); | 39 DCHECK_EQ(0u, start_pointer % page_size); |
38 | 40 |
39 // This function allocates a char vector of size number of pages in the given | 41 // 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 | 42 // mapped_size. To avoid allocating a large array, the memory is split into |
41 // chunks. Maximum size of vector allocated, will be | 43 // chunks. Maximum size of vector allocated, will be |
42 // kPageChunkSize / page_size. | 44 // kPageChunkSize / page_size. |
43 const size_t kMaxChunkSize = 32 * 1024 * 1024; | 45 const size_t kMaxChunkSize = 32 * 1024 * 1024; |
44 size_t offset = 0; | 46 size_t offset = 0; |
45 size_t total_resident_size = 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 int res = mincore(chunk_start, chunk_size, vector_as_array(&vec)); |
55 DCHECK(!res); | 56 if (res) |
57 return false; | |
58 | |
56 for (size_t i = 0; i < page_count; i++) | 59 for (size_t i = 0; i < page_count; i++) |
57 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; | 60 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; |
58 #else // defined(OS_MACOSX) || defined(OS_IOS) | 61 #else // defined(OS_MACOSX) || defined(OS_IOS) |
59 std::vector<unsigned char> vec(page_count + 1); | 62 std::vector<unsigned char> vec(page_count + 1); |
60 int res = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | 63 int error_counter = 0; |
61 DCHECK(!res); | 64 int res = 0; |
65 do { | |
reveman
2015/10/14 12:31:28
why do we allow retries here but not above?
Primiano Tucci (use gerrit)
2015/10/14 12:41:33
I guess because mac's manpage for mincore says it
ssid
2015/10/14 12:44:29
yes.
reveman
2015/10/14 13:03:53
Got it. Maybe add a comment here or above to expla
ssid
2015/10/14 13:35:55
Done.
| |
66 res = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | |
67 } while (res == -1 && errno == EAGAIN && error_counter++ < 100); | |
Primiano Tucci (use gerrit)
2015/10/14 11:27:08
i'd cap this at 3. Typically either this is a temp
ssid
2015/10/14 12:44:29
Added comment why it is 100.
reveman
2015/10/14 13:03:53
is it worth retrying at all?
ssid
2015/10/14 13:35:55
That is how eagain is handled in code. Like in cas
reveman
2015/10/14 14:17:11
Most of the EAGAIN code I see in the chromium code
| |
68 if (res) | |
69 return false; | |
70 | |
62 for (size_t i = 0; i < page_count; i++) | 71 for (size_t i = 0; i < page_count; i++) |
63 resident_page_count += vec[i]; | 72 resident_page_count += vec[i]; |
64 #endif // defined(OS_MACOSX) || defined(OS_IOS) | 73 #endif // defined(OS_MACOSX) || defined(OS_IOS) |
65 | 74 |
66 total_resident_size += resident_page_count * page_size; | 75 *resident_size += resident_page_count * page_size; |
67 offset += kMaxChunkSize; | 76 offset += kMaxChunkSize; |
68 } | 77 } |
69 return total_resident_size; | 78 return true; |
70 } | 79 } |
71 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 80 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
72 | 81 |
73 ProcessMemoryDump::ProcessMemoryDump( | 82 ProcessMemoryDump::ProcessMemoryDump( |
74 const scoped_refptr<MemoryDumpSessionState>& session_state) | 83 const scoped_refptr<MemoryDumpSessionState>& session_state) |
75 : has_process_totals_(false), | 84 : has_process_totals_(false), |
76 has_process_mmaps_(false), | 85 has_process_mmaps_(false), |
77 session_state_(session_state) { | 86 session_state_(session_state) { |
78 } | 87 } |
79 | 88 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 | 221 |
213 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 222 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
214 const std::string& target_node_name) { | 223 const std::string& target_node_name) { |
215 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 224 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
216 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 225 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
217 AddOwnershipEdge(source, target_child_mad->guid()); | 226 AddOwnershipEdge(source, target_child_mad->guid()); |
218 } | 227 } |
219 | 228 |
220 } // namespace trace_event | 229 } // namespace trace_event |
221 } // namespace base | 230 } // namespace base |
OLD | NEW |