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

Unified Diff: base/trace_event/process_memory_dump.cc

Issue 1375963007: [tracing] Display the resident size of the discardable memory segments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lock_discardable
Patch Set: Nit. Created 5 years, 2 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') | base/trace_event/process_memory_dump_unittest.cc » ('j') | 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 67118f10e8c0604d6586b0c54e29497ef08c2242..6541d73bdeac436dc3c82d1a5dfb2748db4c6bc9 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 {
@@ -19,6 +23,49 @@ std::string GetSharedGlobalAllocatorDumpName(
}
} // namespace
+#if defined(COUNT_RESIDENT_BYTES_SUPPORTED)
+// static
+size_t ProcessMemoryDump::CountResidentBytes(void* start_address,
+ size_t mapped_size) {
+ const size_t page_size = base::GetPageSize();
+ const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address);
+ DCHECK_EQ(0u, start_pointer % page_size);
+
+ // This function allocates a char vector of size number of pages in the given
+ // mapped_size. To avoid allocating a large array, the memory is split into
+ // chunks. Maximum size of vector allocated, will be
+ // kPageChunkSize / page_size.
+ const size_t kMaxChunkSize = 32 * 1024 * 1024;
+ size_t offset = 0;
+ size_t total_resident_size = 0;
+ while (offset < mapped_size) {
+ void* chunk_start = reinterpret_cast<void*>(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)
+ scoped_ptr<char[]> vec(new char[page_count + 1]);
+ int res = mincore(chunk_start, chunk_size, &vec.get()[0]);
+ 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(chunk_start, chunk_size, &vec.get()[0]);
+ DCHECK(!res);
+ for (size_t i = 0; i < page_count; i++)
+ resident_page_count += vec[i];
+#endif // defined(OS_MACOSX) || defined(OS_IOS)
+
+ total_resident_size += resident_page_count * page_size;
+ offset += kMaxChunkSize;
+ }
+ return total_resident_size;
+}
+#endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED)
+
ProcessMemoryDump::ProcessMemoryDump(
const scoped_refptr<MemoryDumpSessionState>& session_state)
: has_process_totals_(false),
« no previous file with comments | « base/trace_event/process_memory_dump.h ('k') | base/trace_event/process_memory_dump_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698