Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3005)

Unified Diff: base/trace_event/process_memory_dump.cc

Issue 1573313002: Add support for CountResidentBytes in windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove +1 Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/process_memory_dump.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..76da89d433a81eb780617ccc746cd9113fe6bb89 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,28 +49,43 @@ 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.
brucedawson 2016/01/19 20:16:43 Reusing "int result" as a success/error code acros
ssid 2016/01/20 13:03:59 Done.
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;
#if defined(OS_MACOSX) || defined(OS_IOS)
- std::vector<char> vec(page_count + 1);
+ std::vector<char> vec(page_count);
// 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);
brucedawson 2016/01/19 20:16:43 Possibly out of scope for this change, but the std
ssid 2016/01/20 13:03:59 I will add a follow up to this CL.
+ 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;
#else // defined(OS_MACOSX) || defined(OS_IOS)
brucedawson 2016/01/19 20:16:43 This comment is no longer meaningful. Consider cha
ssid 2016/01/20 13:03:59 Done.
- std::vector<unsigned char> vec(page_count + 1);
+ std::vector<unsigned char> vec(page_count);
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;
« no previous file with comments | « base/trace_event/process_memory_dump.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698