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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 while (offset < mapped_size) { | 46 while (offset < mapped_size) { |
47 void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); | 47 void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); |
48 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); | 48 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); |
49 const size_t page_count = (chunk_size + page_size - 1) / page_size; | 49 const size_t page_count = (chunk_size + page_size - 1) / page_size; |
50 size_t resident_page_count = 0; | 50 size_t resident_page_count = 0; |
51 | 51 |
52 #if defined(OS_MACOSX) || defined(OS_IOS) | 52 #if defined(OS_MACOSX) || defined(OS_IOS) |
53 std::vector<char> vec(page_count + 1); | 53 std::vector<char> vec(page_count + 1); |
54 // mincore in MAC does not fail with EAGAIN. | |
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 DCHECK(!res); |
57 if (res) { | |
58 LOG(ERROR) | |
59 << "Mincore call failed. The resident size may not be accurate"; | |
Primiano Tucci (use gerrit)
2015/10/15 11:20:18
nit: s/Mincore/mincore()/
also, if you continue he
ssid
2015/10/15 11:23:43
The call to mincore failed only once. The next set
| |
60 continue; | |
61 } | |
62 | |
56 for (size_t i = 0; i < page_count; i++) | 63 for (size_t i = 0; i < page_count; i++) |
57 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; | 64 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; |
58 #else // defined(OS_MACOSX) || defined(OS_IOS) | 65 #else // defined(OS_MACOSX) || defined(OS_IOS) |
59 std::vector<unsigned char> vec(page_count + 1); | 66 std::vector<unsigned char> vec(page_count + 1); |
60 int res = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | 67 int error_counter = 0; |
68 int res = 0; | |
69 // HANDLE_EINTR tries for 100 times. So following the same pattern. | |
70 do { | |
71 res = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | |
72 } while (res == -1 && errno == EAGAIN && error_counter++ < 100); | |
61 DCHECK(!res); | 73 DCHECK(!res); |
74 if (res) { | |
75 LOG(ERROR) | |
76 << "Mincore call failed. The resident size may not be accurate"; | |
Primiano Tucci (use gerrit)
2015/10/15 11:20:18
can we avoid duplicating this and above?
ssid
2015/10/15 11:23:43
I would have to add 3 extra #if defined. that is w
Primiano Tucci (use gerrit)
2015/10/15 11:27:13
??
how about you just add this to before line 87:
ssid
2015/10/15 11:39:30
Yes, sounds good.
| |
77 continue; | |
78 } | |
79 | |
62 for (size_t i = 0; i < page_count; i++) | 80 for (size_t i = 0; i < page_count; i++) |
63 resident_page_count += vec[i]; | 81 resident_page_count += vec[i]; |
64 #endif // defined(OS_MACOSX) || defined(OS_IOS) | 82 #endif // defined(OS_MACOSX) || defined(OS_IOS) |
65 | 83 |
66 total_resident_size += resident_page_count * page_size; | 84 total_resident_size += resident_page_count * page_size; |
67 offset += kMaxChunkSize; | 85 offset += kMaxChunkSize; |
68 } | 86 } |
69 return total_resident_size; | 87 return total_resident_size; |
70 } | 88 } |
71 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 89 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 | 230 |
213 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 231 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
214 const std::string& target_node_name) { | 232 const std::string& target_node_name) { |
215 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 233 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
216 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 234 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
217 AddOwnershipEdge(source, target_child_mad->guid()); | 235 AddOwnershipEdge(source, target_child_mad->guid()); |
218 } | 236 } |
219 | 237 |
220 } // namespace trace_event | 238 } // namespace trace_event |
221 } // namespace base | 239 } // namespace base |
OLD | NEW |