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

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: Fix mac. 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 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 AddOwnershipEdge(source, target, 0 /* importance */); 157 AddOwnershipEdge(source, target, 0 /* importance */);
154 } 158 }
155 159
156 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, 160 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source,
157 const std::string& target_node_name) { 161 const std::string& target_node_name) {
158 std::string child_mad_name = target_node_name + "/__" + source.ToString(); 162 std::string child_mad_name = target_node_name + "/__" + source.ToString();
159 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); 163 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name);
160 AddOwnershipEdge(source, target_child_mad->guid()); 164 AddOwnershipEdge(source, target_child_mad->guid());
161 } 165 }
162 166
167 // static
168 ssize_t ProcessMemoryDump::CountResidentBytes(void* start_address,
169 size_t mapped_size) {
170 #if defined(OS_POSIX)
171 const size_t page_size = base::GetPageSize();
Primiano Tucci (use gerrit) 2015/10/06 17:14:09 I think we need to make this a bit smarter and ope
ssid 2015/10/07 09:13:19 Done.
172 DCHECK_EQ(0u, (reinterpret_cast<uintptr_t>(start_address) % page_size));
173 const size_t page_count = (mapped_size + page_size - 1) / page_size;
174 #if defined(OS_LINUX) || defined(OS_ANDROID)
175 unsigned char vec[page_count + 1];
Primiano Tucci (use gerrit) 2015/10/06 17:14:09 From [1]. "We do not allow variable-length arrays
ssid 2015/10/07 09:13:19 Done.
176 int res =
177 mincore(start_address, mapped_size, static_cast<unsigned char*>(vec));
178 #else // defined(OS_LINUX) || defined(OS_ANDROID)
179 char vec[page_count + 1];
180 int res = mincore(start_address, mapped_size, static_cast<char*>(vec));
181 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
182
183 if (res) {
184 return -1;
185 }
186
187 size_t resident_page_count = 0;
188 for (size_t i = 0; i < page_count; i++) {
189 #if defined(OS_LINUX) || defined(OS_ANDROID)
190 resident_page_count += vec[i];
191 #else
192 resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0;
193 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
194 }
195 return resident_page_count * page_size;
196
197 #else // defined(OS_POSIX)
198 return -1;
199 #endif // defined(OS_POSIX)
200 }
201
163 } // namespace trace_event 202 } // namespace trace_event
164 } // namespace base 203 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698