Index: base/trace_event/process_memory_dump.cc |
diff --git a/base/trace_event/process_memory_dump.cc b/base/trace_event/process_memory_dump.cc |
index 67118f10e8c0604d6586b0c54e29497ef08c2242..cb5f81b41998a1d0835f33bb55e3ea67ed5b3899 100644 |
--- a/base/trace_event/process_memory_dump.cc |
+++ b/base/trace_event/process_memory_dump.cc |
@@ -7,6 +7,10 @@ |
#include "base/trace_event/process_memory_totals.h" |
#include "base/trace_event/trace_event_argument.h" |
+#if defined(OS_POSIX) |
+#include <sys/mman.h> |
+#endif |
+ |
namespace base { |
namespace trace_event { |
@@ -17,8 +21,56 @@ std::string GetSharedGlobalAllocatorDumpName( |
const MemoryAllocatorDumpGuid& guid) { |
return "global/" + guid.ToString(); |
} |
+ |
+#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.
|
+size_t GetResidentSizeOfSegment(void* start_address, const size_t mapped_size) { |
+ const size_t page_size = base::GetPageSize(); |
+ DCHECK_EQ(0u, (reinterpret_cast<uintptr_t>(start_address) % page_size)); |
+ const size_t page_count = (mapped_size + page_size - 1) / page_size; |
+ size_t resident_page_count = 0; |
+ |
+#if defined(OS_MACOSX) || defined(OS_IOS) |
+ scoped_ptr<char[]> vec(new char[page_count + 1]); |
+ int res = mincore(start_address, mapped_size, static_cast<char*>(vec.get())); |
+ DCHECK(!res); |
+ for (size_t i = 0; i < page_count; i++) |
+ resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; |
+ |
+#else // defined(OS_MACOSX) || defined(OS_IOS) |
+ scoped_ptr<unsigned char[]> vec(new unsigned char[page_count + 1]); |
+ int res = mincore(start_address, mapped_size, |
+ static_cast<unsigned char*>(vec.get())); |
+ DCHECK(!res); |
+ for (size_t i = 0; i < page_count; i++) |
+ resident_page_count += vec[i]; |
+#endif // defined(OS_MACOSX) || defined(OS_IOS) |
+ |
+ return resident_page_count * page_size; |
+} |
+#endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
+ |
} // namespace |
+#if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
+// static |
+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
|
+ size_t mapped_size) { |
+ // Maximum size of vector allocated to check is page is resident, will be |
+ // 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.
|
+ const size_t kMemoryChunkSize = 32 * 1024 * 1024; |
+ size_t offset = 0; |
+ size_t total_resident_size = 0; |
+ while (offset < mapped_size) { |
+ 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.
|
+ 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
|
+ offset + kMemoryChunkSize > mapped_size ? mapped_size - offset |
+ : kMemoryChunkSize); |
+ offset += kMemoryChunkSize; |
+ } |
+ return total_resident_size; |
+} |
+#endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
+ |
ProcessMemoryDump::ProcessMemoryDump( |
const scoped_refptr<MemoryDumpSessionState>& session_state) |
: has_process_totals_(false), |