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 } |
24 | |
25 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | |
Primiano Tucci (use gerrit)
2015/10/07 13:59:51
I'd probably just put them in one function. This i
ssid
2015/10/07 14:46:44
Done.
| |
26 size_t GetResidentSizeOfSegment(void* start_address, const size_t mapped_size) { | |
27 const size_t page_size = base::GetPageSize(); | |
28 DCHECK_EQ(0u, (reinterpret_cast<uintptr_t>(start_address) % page_size)); | |
29 const size_t page_count = (mapped_size + page_size - 1) / page_size; | |
30 size_t resident_page_count = 0; | |
31 | |
32 #if defined(OS_MACOSX) || defined(OS_IOS) | |
33 scoped_ptr<char[]> vec(new char[page_count + 1]); | |
34 int res = mincore(start_address, mapped_size, static_cast<char*>(vec.get())); | |
35 DCHECK(!res); | |
36 for (size_t i = 0; i < page_count; i++) | |
37 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; | |
38 | |
39 #else // defined(OS_MACOSX) || defined(OS_IOS) | |
40 scoped_ptr<unsigned char[]> vec(new unsigned char[page_count + 1]); | |
41 int res = mincore(start_address, mapped_size, | |
42 static_cast<unsigned char*>(vec.get())); | |
43 DCHECK(!res); | |
44 for (size_t i = 0; i < page_count; i++) | |
45 resident_page_count += vec[i]; | |
46 #endif // defined(OS_MACOSX) || defined(OS_IOS) | |
47 | |
48 return resident_page_count * page_size; | |
49 } | |
50 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | |
51 | |
20 } // namespace | 52 } // namespace |
21 | 53 |
54 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | |
55 // static | |
56 size_t ProcessMemoryDump::CountResidentBytes(void* start_address, | |
Primiano Tucci (use gerrit)
2015/10/07 13:59:51
you have to decide here if you want to accept only
ssid
2015/10/07 14:46:45
Yeah, I did not want to add more complications to
| |
57 size_t mapped_size) { | |
58 // Maximum size of vector allocated to check is page is resident, will be | |
59 // kPageChunkSize / pageSize. | |
Primiano Tucci (use gerrit)
2015/10/07 13:59:51
add a small comment explaining why you are splitti
ssid
2015/10/07 14:46:45
Done.
| |
60 const size_t kMemoryChunkSize = 32 * 1024 * 1024; | |
61 size_t offset = 0; | |
62 size_t total_resident_size = 0; | |
63 while (offset < mapped_size) { | |
64 total_resident_size += GetResidentSizeOfSegment( | |
Primiano Tucci (use gerrit)
2015/10/07 13:59:51
this would be a bit clearer if you add an extra va
ssid
2015/10/07 14:46:44
Done.
| |
65 static_cast<char*>(start_address) + offset, | |
Primiano Tucci (use gerrit)
2015/10/07 13:59:51
I think this should be reinterpret_cast
Not clear
ssid
2015/10/07 14:46:45
I had to do reinterpret_cast twice ot get back a v
| |
66 offset + kMemoryChunkSize > mapped_size ? mapped_size - offset | |
67 : kMemoryChunkSize); | |
68 offset += kMemoryChunkSize; | |
69 } | |
70 return total_resident_size; | |
71 } | |
72 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | |
73 | |
22 ProcessMemoryDump::ProcessMemoryDump( | 74 ProcessMemoryDump::ProcessMemoryDump( |
23 const scoped_refptr<MemoryDumpSessionState>& session_state) | 75 const scoped_refptr<MemoryDumpSessionState>& session_state) |
24 : has_process_totals_(false), | 76 : has_process_totals_(false), |
25 has_process_mmaps_(false), | 77 has_process_mmaps_(false), |
26 session_state_(session_state) { | 78 session_state_(session_state) { |
27 } | 79 } |
28 | 80 |
29 ProcessMemoryDump::~ProcessMemoryDump() { | 81 ProcessMemoryDump::~ProcessMemoryDump() { |
30 } | 82 } |
31 | 83 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 207 |
156 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 208 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
157 const std::string& target_node_name) { | 209 const std::string& target_node_name) { |
158 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 210 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
159 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 211 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
160 AddOwnershipEdge(source, target_child_mad->guid()); | 212 AddOwnershipEdge(source, target_child_mad->guid()); |
161 } | 213 } |
162 | 214 |
163 } // namespace trace_event | 215 } // namespace trace_event |
164 } // namespace base | 216 } // namespace base |
OLD | NEW |