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

Side by Side 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: Fixes. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/process_memory_dump.h" 5 #include "base/trace_event/process_memory_dump.h"
6 6
7 #include "base/trace_event/process_memory_totals.h" 7 #include "base/trace_event/process_memory_totals.h"
8 #include "base/trace_event/trace_event_argument.h" 8 #include "base/trace_event/trace_event_argument.h"
9 9
10 #if defined(OS_POSIX)
11 #include <sys/mman.h>
12 #endif
13
10 namespace base { 14 namespace base {
11 namespace trace_event { 15 namespace trace_event {
12 16
13 namespace { 17 namespace {
14 const char kEdgeTypeOwnership[] = "ownership"; 18 const char kEdgeTypeOwnership[] = "ownership";
15 19
16 std::string GetSharedGlobalAllocatorDumpName( 20 std::string GetSharedGlobalAllocatorDumpName(
17 const MemoryAllocatorDumpGuid& guid) { 21 const MemoryAllocatorDumpGuid& guid) {
18 return "global/" + guid.ToString(); 22 return "global/" + guid.ToString();
19 } 23 }
24
25 #if defined(OS_POSIX) && !defined(OS_NACL)
26 int64 GetResidentSizeOfSegment(void* start_address, const size_t mapped_size) {
27 const size_t page_size = base::GetPageSize();
28 DCHECK_EQ(0u, (reinterpret_cast<uintptr_t>(start_address) % page_size));
29 const size_t page_count = (mapped_size + page_size - 1) / page_size;
30 size_t resident_page_count = 0;
31
32 #if defined(OS_MACOSX) || defined(OS_IOS)
33 scoped_ptr<char[]> vec(new char[page_count + 1]);
34 if (mincore(start_address, mapped_size, static_cast<char*>(vec.get())))
35 return -1;
36 for (size_t i = 0; i < page_count; i++)
37 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0;
38
39 #else // defined(OS_MACOSX) || defined(OS_IOS)
40 scoped_ptr<unsigned char[]> vec(new unsigned char[page_count + 1]);
41 if (mincore(start_address, mapped_size,
42 static_cast<unsigned char*>(vec.get())))
43 return -1;
44 for (size_t i = 0; i < page_count; i++)
45 resident_page_count += vec[i];
46 #endif // defined(OS_MACOSX) || defined(OS_IOS)
47
48 return resident_page_count * page_size;
49 }
50 #endif // defined(OS_POSIX) && !defined(OS_NACL)
51
20 } // namespace 52 } // namespace
21 53
54 // static
55 int64 ProcessMemoryDump::CountResidentBytes(void* start_address,
56 size_t mapped_size) {
57 #if defined(OS_POSIX) && !defined(OS_NACL)
58 // Maximum size of vector allocated to check is page is resident, will be
59 // kPageChunkSize / pageSize.
60 const size_t kMemoryChunkSize = 32 * 1024 * 1024;
61 size_t offset = 0;
62 size_t total_resident_size = 0;
63 while (offset < mapped_size) {
64 int64 res = GetResidentSizeOfSegment(
65 static_cast<char*>(start_address) + offset,
66 offset + kMemoryChunkSize > mapped_size ? mapped_size - offset
67 : kMemoryChunkSize);
68 if (res < 0)
69 return -1;
70 total_resident_size += res;
71 offset += kMemoryChunkSize;
72 }
73 return total_resident_size;
74 #else // defined(OS_POSIX) && !defined(OS_NACL)
75 return -1;
76 #endif // defined(OS_POSIX) && !defined(OS_NACL)
77 }
78
22 ProcessMemoryDump::ProcessMemoryDump( 79 ProcessMemoryDump::ProcessMemoryDump(
23 const scoped_refptr<MemoryDumpSessionState>& session_state) 80 const scoped_refptr<MemoryDumpSessionState>& session_state)
24 : has_process_totals_(false), 81 : has_process_totals_(false),
25 has_process_mmaps_(false), 82 has_process_mmaps_(false),
26 session_state_(session_state) { 83 session_state_(session_state) {
27 } 84 }
28 85
29 ProcessMemoryDump::~ProcessMemoryDump() { 86 ProcessMemoryDump::~ProcessMemoryDump() {
30 } 87 }
31 88
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 212
156 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, 213 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source,
157 const std::string& target_node_name) { 214 const std::string& target_node_name) {
158 std::string child_mad_name = target_node_name + "/__" + source.ToString(); 215 std::string child_mad_name = target_node_name + "/__" + source.ToString();
159 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); 216 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name);
160 AddOwnershipEdge(source, target_child_mad->guid()); 217 AddOwnershipEdge(source, target_child_mad->guid());
161 } 218 }
162 219
163 } // namespace trace_event 220 } // namespace trace_event
164 } // namespace base 221 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698