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 kMemoryChunkSize = 32 * 1024 * 1024; | |
Primiano Tucci (use gerrit)
2015/10/08 17:34:36
s/kMemoryChunkSize/kMaxChunkSize/
ssid
2015/10/08 18:18:10
Done.
| |
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, kMemoryChunkSize); | |
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, static_cast<char*>(vec.get())); | |
Primiano Tucci (use gerrit)
2015/10/08 17:34:36
static_cast<char*>(vec.get():
no need to cast, th
ssid
2015/10/08 18:18:10
Done.
| |
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, | |
57 static_cast<unsigned char*>(vec.get())); | |
58 DCHECK(!res); | |
59 for (size_t i = 0; i < page_count; i++) | |
60 resident_page_count += vec[i]; | |
61 #endif // defined(OS_MACOSX) || defined(OS_IOS) | |
62 | |
63 total_resident_size += resident_page_count * page_size; | |
64 offset += kMemoryChunkSize; | |
65 } | |
66 return total_resident_size; | |
67 } | |
68 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | |
69 | |
22 ProcessMemoryDump::ProcessMemoryDump( | 70 ProcessMemoryDump::ProcessMemoryDump( |
23 const scoped_refptr<MemoryDumpSessionState>& session_state) | 71 const scoped_refptr<MemoryDumpSessionState>& session_state) |
24 : has_process_totals_(false), | 72 : has_process_totals_(false), |
25 has_process_mmaps_(false), | 73 has_process_mmaps_(false), |
26 session_state_(session_state) { | 74 session_state_(session_state) { |
27 } | 75 } |
28 | 76 |
29 ProcessMemoryDump::~ProcessMemoryDump() { | 77 ProcessMemoryDump::~ProcessMemoryDump() { |
30 } | 78 } |
31 | 79 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 203 |
156 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 204 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
157 const std::string& target_node_name) { | 205 const std::string& target_node_name) { |
158 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 206 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
159 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 207 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
160 AddOwnershipEdge(source, target_child_mad->guid()); | 208 AddOwnershipEdge(source, target_child_mad->guid()); |
161 } | 209 } |
162 | 210 |
163 } // namespace trace_event | 211 } // namespace trace_event |
164 } // namespace base | 212 } // namespace base |
OLD | NEW |