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/trace_event/process_memory_totals.h" | 11 #include "base/trace_event/process_memory_totals.h" |
12 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 | 14 |
15 #if defined(OS_IOS) | |
16 #include <sys/sysctl.h> | |
17 #endif | |
18 | |
15 #if defined(OS_POSIX) | 19 #if defined(OS_POSIX) |
16 #include <sys/mman.h> | 20 #include <sys/mman.h> |
17 #endif | 21 #endif |
18 | 22 |
19 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
20 #include <Psapi.h> | 24 #include <Psapi.h> |
21 #endif | 25 #endif |
22 | 26 |
23 namespace base { | 27 namespace base { |
24 namespace trace_event { | 28 namespace trace_event { |
(...skipping 10 matching lines...) Expand all Loading... | |
35 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 39 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
36 size_t GetSystemPageCount(size_t mapped_size, size_t page_size) { | 40 size_t GetSystemPageCount(size_t mapped_size, size_t page_size) { |
37 return (mapped_size + page_size - 1) / page_size; | 41 return (mapped_size + page_size - 1) / page_size; |
38 } | 42 } |
39 #endif | 43 #endif |
40 | 44 |
41 } // namespace | 45 } // namespace |
42 | 46 |
43 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 47 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
44 // static | 48 // static |
49 size_t ProcessMemoryDump::GetSystemPageSize() { | |
50 #if defined(OS_IOS) | |
51 // On iOS, getpagesize() returns the user page sizes, but for allocating | |
52 // arrays for mincore(), kernel page sizes is needed. sysctlbyname() should | |
53 // be used for this. Refer to crbug.com/542671 and Apple rdar://23651782 | |
54 int pagesize; | |
55 size_t pagesize_len; | |
56 int status = sysctlbyname("vm.pagesize", NULL, &pagesize_len, NULL, 0); | |
Primiano Tucci (use gerrit)
2016/03/15 15:50:48
nit: s/NULL/nullptr
same below
pkl (ping after 24h if needed)
2016/03/16 14:24:21
Done.
| |
57 if (!status && pagesize_len == sizeof(pagesize)) { | |
58 if (sysctlbyname("vm.pagesize", &pagesize, &pagesize_len, NULL, 0) == 0) | |
Primiano Tucci (use gerrit)
2016/03/15 15:50:48
nit: consistency, either you check the syscall ret
pkl (ping after 24h if needed)
2016/03/16 14:24:21
Yep, you're right. Thank you!
| |
59 return pagesize; | |
60 } | |
61 LOG(ERROR) << "sysctlbyname(\"vm.pagesize\") failed."; | |
62 // Falls back to getpagesize() although it may be wrong in certain cases. | |
63 #endif // defined(OS_IOS) | |
64 return base::GetPageSize(); | |
65 } | |
66 | |
67 // static | |
45 size_t ProcessMemoryDump::CountResidentBytes(void* start_address, | 68 size_t ProcessMemoryDump::CountResidentBytes(void* start_address, |
46 size_t mapped_size) { | 69 size_t mapped_size) { |
47 const size_t page_size = GetPageSize(); | 70 const size_t page_size = GetSystemPageSize(); |
48 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); | 71 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); |
49 DCHECK_EQ(0u, start_pointer % page_size); | 72 DCHECK_EQ(0u, start_pointer % page_size); |
50 | 73 |
51 size_t offset = 0; | 74 size_t offset = 0; |
52 size_t total_resident_size = 0; | 75 size_t total_resident_size = 0; |
53 bool failure = false; | 76 bool failure = false; |
54 | 77 |
55 // An array as large as number of pages in memory segment needs to be passed | 78 // An array as large as number of pages in memory segment needs to be passed |
56 // to the query function. To avoid allocating a large array, the given block | 79 // to the query function. To avoid allocating a large array, the given block |
57 // of memory is split into chunks of size |kMaxChunkSize|. | 80 // of memory is split into chunks of size |kMaxChunkSize|. |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 | 311 |
289 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 312 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
290 const std::string& target_node_name) { | 313 const std::string& target_node_name) { |
291 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 314 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
292 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 315 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
293 AddOwnershipEdge(source, target_child_mad->guid()); | 316 AddOwnershipEdge(source, target_child_mad->guid()); |
294 } | 317 } |
295 | 318 |
296 } // namespace trace_event | 319 } // namespace trace_event |
297 } // namespace base | 320 } // namespace base |
OLD | NEW |