| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/process/process_metrics.h" | 10 #include "base/process/process_metrics.h" |
| 11 #include "base/stl_util.h" | |
| 12 #include "base/trace_event/process_memory_totals.h" | 11 #include "base/trace_event/process_memory_totals.h" |
| 13 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
| 14 | 13 |
| 15 #if defined(OS_POSIX) | 14 #if defined(OS_POSIX) |
| 16 #include <sys/mman.h> | 15 #include <sys/mman.h> |
| 17 #endif | 16 #endif |
| 18 | 17 |
| 19 namespace base { | 18 namespace base { |
| 20 namespace trace_event { | 19 namespace trace_event { |
| 21 | 20 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 48 int result = 0; | 47 int result = 0; |
| 49 while (offset < mapped_size) { | 48 while (offset < mapped_size) { |
| 50 void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); | 49 void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); |
| 51 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); | 50 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); |
| 52 const size_t page_count = (chunk_size + page_size - 1) / page_size; | 51 const size_t page_count = (chunk_size + page_size - 1) / page_size; |
| 53 size_t resident_page_count = 0; | 52 size_t resident_page_count = 0; |
| 54 | 53 |
| 55 #if defined(OS_MACOSX) || defined(OS_IOS) | 54 #if defined(OS_MACOSX) || defined(OS_IOS) |
| 56 std::vector<char> vec(page_count + 1); | 55 std::vector<char> vec(page_count + 1); |
| 57 // mincore in MAC does not fail with EAGAIN. | 56 // mincore in MAC does not fail with EAGAIN. |
| 58 result = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | 57 result = mincore(chunk_start, chunk_size, vec.data()); |
| 59 if (result) | 58 if (result) |
| 60 break; | 59 break; |
| 61 | 60 |
| 62 for (size_t i = 0; i < page_count; i++) | 61 for (size_t i = 0; i < page_count; i++) |
| 63 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; | 62 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; |
| 64 #else // defined(OS_MACOSX) || defined(OS_IOS) | 63 #else // defined(OS_MACOSX) || defined(OS_IOS) |
| 65 std::vector<unsigned char> vec(page_count + 1); | 64 std::vector<unsigned char> vec(page_count + 1); |
| 66 int error_counter = 0; | 65 int error_counter = 0; |
| 67 // HANDLE_EINTR tries for 100 times. So following the same pattern. | 66 // HANDLE_EINTR tries for 100 times. So following the same pattern. |
| 68 do { | 67 do { |
| 69 result = mincore(chunk_start, chunk_size, vector_as_array(&vec)); | 68 result = mincore(chunk_start, chunk_size, vec.data()); |
| 70 } while (result == -1 && errno == EAGAIN && error_counter++ < 100); | 69 } while (result == -1 && errno == EAGAIN && error_counter++ < 100); |
| 71 if (result) | 70 if (result) |
| 72 break; | 71 break; |
| 73 | 72 |
| 74 for (size_t i = 0; i < page_count; i++) | 73 for (size_t i = 0; i < page_count; i++) |
| 75 resident_page_count += vec[i]; | 74 resident_page_count += vec[i]; |
| 76 #endif // defined(OS_MACOSX) || defined(OS_IOS) | 75 #endif // defined(OS_MACOSX) || defined(OS_IOS) |
| 77 | 76 |
| 78 total_resident_size += resident_page_count * page_size; | 77 total_resident_size += resident_page_count * page_size; |
| 79 offset += kMaxChunkSize; | 78 offset += kMaxChunkSize; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 246 |
| 248 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 247 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
| 249 const std::string& target_node_name) { | 248 const std::string& target_node_name) { |
| 250 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 249 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
| 251 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 250 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
| 252 AddOwnershipEdge(source, target_child_mad->guid()); | 251 AddOwnershipEdge(source, target_child_mad->guid()); |
| 253 } | 252 } |
| 254 | 253 |
| 255 } // namespace trace_event | 254 } // namespace trace_event |
| 256 } // namespace base | 255 } // namespace base |
| OLD | NEW |