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 ae60bb06b152639c0e80ab2226a6a96b65699351..19cc05471a90db3aef8137e4d1ae3eb7d10e35ba 100644 |
--- a/base/trace_event/process_memory_dump.cc |
+++ b/base/trace_event/process_memory_dump.cc |
@@ -16,6 +16,10 @@ |
#include <sys/mman.h> |
#endif |
+#if defined(OS_WIN) |
+#include <Psapi.h> |
+#endif |
+ |
namespace base { |
namespace trace_event { |
@@ -45,9 +49,9 @@ size_t ProcessMemoryDump::CountResidentBytes(void* start_address, |
const size_t kMaxChunkSize = 32 * 1024 * 1024; |
size_t offset = 0; |
size_t total_resident_size = 0; |
- int result = 0; |
+ int result = 0; // 0 on success. |
while (offset < mapped_size) { |
- void* chunk_start = reinterpret_cast<void*>(start_pointer + offset); |
+ uintptr_t chunk_start = (start_pointer + offset); |
const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); |
const size_t page_count = (chunk_size + page_size - 1) / page_size; |
size_t resident_page_count = 0; |
@@ -55,18 +59,33 @@ size_t ProcessMemoryDump::CountResidentBytes(void* start_address, |
#if defined(OS_MACOSX) || defined(OS_IOS) |
std::vector<char> vec(page_count + 1); |
// mincore in MAC does not fail with EAGAIN. |
- result = mincore(chunk_start, chunk_size, vec.data()); |
+ result = |
+ mincore(reinterpret_cast<void*>(chunk_start), chunk_size, vec.data()); |
if (result) |
break; |
for (size_t i = 0; i < page_count; i++) |
resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0; |
+#elif defined(OS_WIN) |
+ std::vector<PSAPI_WORKING_SET_EX_INFORMATION> vec(page_count + 1); |
brucedawson
2016/01/19 19:39:08
Why is there a "+ 1" here?
ssid
2016/01/19 19:58:16
I was anticipating to count for non-aligned memory
|
+ for (size_t i = 0; i < page_count; i++) { |
+ vec[i].VirtualAddress = |
+ reinterpret_cast<void*>(chunk_start + i * page_size); |
+ } |
+ DWORD vec_size = static_cast<DWORD>( |
+ page_count * sizeof(PSAPI_WORKING_SET_EX_INFORMATION)); |
+ result = !QueryWorkingSetEx(GetCurrentProcess(), vec.data(), vec_size); |
+ if (result) |
+ break; |
+ for (size_t i = 0; i < page_count; i++) |
+ resident_page_count += vec[i].VirtualAttributes.Valid; |
brucedawson
2016/01/19 19:39:08
I *think* this is correct, but the documentation i
ssid
2016/01/19 19:58:16
Yes, I had the same doubt. So, I tried experimenti
|
#else // defined(OS_MACOSX) || defined(OS_IOS) |
std::vector<unsigned char> vec(page_count + 1); |
int error_counter = 0; |
// HANDLE_EINTR tries for 100 times. So following the same pattern. |
do { |
- result = mincore(chunk_start, chunk_size, vec.data()); |
+ result = |
+ mincore(reinterpret_cast<void*>(chunk_start), chunk_size, vec.data()); |
} while (result == -1 && errno == EAGAIN && error_counter++ < 100); |
if (result) |
break; |