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

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: Move the attribute to global dump. 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
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..ece65c44d26b9494d67938b5a166f78dd8aa92e4 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,50 @@ 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 kMemoryChunkSize = 32 * 1024 * 1024;
Primiano Tucci (use gerrit) 2015/10/08 17:34:36 s/kMemoryChunkSize/kMaxChunkSize/
ssid 2015/10/08 18:18:10 Done.
+ 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, kMemoryChunkSize);
+ 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, static_cast<char*>(vec.get()));
Primiano Tucci (use gerrit) 2015/10/08 17:34:36 static_cast<char*>(vec.get(): no need to cast, th
ssid 2015/10/08 18:18:10 Done.
+ 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,
+ 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)
+
+ total_resident_size += resident_page_count * page_size;
+ offset += kMemoryChunkSize;
+ }
+ return total_resident_size;
+}
+#endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED)
+
ProcessMemoryDump::ProcessMemoryDump(
const scoped_refptr<MemoryDumpSessionState>& session_state)
: has_process_totals_(false),

Powered by Google App Engine
This is Rietveld 408576698