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

Side by Side Diff: base/trace_event/process_memory_dump.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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 <errno.h> 7 #include <errno.h>
8
8 #include <vector> 9 #include <vector>
9 10
11 #include "base/memory/ptr_util.h"
10 #include "base/process/process_metrics.h" 12 #include "base/process/process_metrics.h"
11 #include "base/trace_event/process_memory_totals.h" 13 #include "base/trace_event/process_memory_totals.h"
12 #include "base/trace_event/trace_event_argument.h" 14 #include "base/trace_event/trace_event_argument.h"
13 #include "build/build_config.h" 15 #include "build/build_config.h"
14 16
15 #if defined(OS_IOS) 17 #if defined(OS_IOS)
16 #include <sys/sysctl.h> 18 #include <sys/sysctl.h>
17 #endif 19 #endif
18 20
19 #if defined(OS_POSIX) 21 #if defined(OS_POSIX)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 size_t total_resident_size = 0; 77 size_t total_resident_size = 0;
76 bool failure = false; 78 bool failure = false;
77 79
78 // An array as large as number of pages in memory segment needs to be passed 80 // An array as large as number of pages in memory segment needs to be passed
79 // to the query function. To avoid allocating a large array, the given block 81 // to the query function. To avoid allocating a large array, the given block
80 // of memory is split into chunks of size |kMaxChunkSize|. 82 // of memory is split into chunks of size |kMaxChunkSize|.
81 const size_t kMaxChunkSize = 8 * 1024 * 1024; 83 const size_t kMaxChunkSize = 8 * 1024 * 1024;
82 size_t max_vec_size = 84 size_t max_vec_size =
83 GetSystemPageCount(std::min(mapped_size, kMaxChunkSize), page_size); 85 GetSystemPageCount(std::min(mapped_size, kMaxChunkSize), page_size);
84 #if defined(OS_MACOSX) || defined(OS_IOS) 86 #if defined(OS_MACOSX) || defined(OS_IOS)
85 scoped_ptr<char[]> vec(new char[max_vec_size]); 87 std::unique_ptr<char[]> vec(new char[max_vec_size]);
86 #elif defined(OS_WIN) 88 #elif defined(OS_WIN)
87 scoped_ptr<PSAPI_WORKING_SET_EX_INFORMATION[]> vec( 89 std::unique_ptr<PSAPI_WORKING_SET_EX_INFORMATION[]> vec(
88 new PSAPI_WORKING_SET_EX_INFORMATION[max_vec_size]); 90 new PSAPI_WORKING_SET_EX_INFORMATION[max_vec_size]);
89 #elif defined(OS_POSIX) 91 #elif defined(OS_POSIX)
90 scoped_ptr<unsigned char[]> vec(new unsigned char[max_vec_size]); 92 std::unique_ptr<unsigned char[]> vec(new unsigned char[max_vec_size]);
91 #endif 93 #endif
92 94
93 while (offset < mapped_size) { 95 while (offset < mapped_size) {
94 uintptr_t chunk_start = (start_pointer + offset); 96 uintptr_t chunk_start = (start_pointer + offset);
95 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize); 97 const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize);
96 const size_t page_count = GetSystemPageCount(chunk_size, page_size); 98 const size_t page_count = GetSystemPageCount(chunk_size, page_size);
97 size_t resident_page_count = 0; 99 size_t resident_page_count = 0;
98 100
99 #if defined(OS_MACOSX) || defined(OS_IOS) 101 #if defined(OS_MACOSX) || defined(OS_IOS)
100 // mincore in MAC does not fail with EAGAIN. 102 // mincore in MAC does not fail with EAGAIN.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 scoped_refptr<MemoryDumpSessionState> session_state) 149 scoped_refptr<MemoryDumpSessionState> session_state)
148 : has_process_totals_(false), 150 : has_process_totals_(false),
149 has_process_mmaps_(false), 151 has_process_mmaps_(false),
150 session_state_(std::move(session_state)) {} 152 session_state_(std::move(session_state)) {}
151 153
152 ProcessMemoryDump::~ProcessMemoryDump() {} 154 ProcessMemoryDump::~ProcessMemoryDump() {}
153 155
154 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( 156 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump(
155 const std::string& absolute_name) { 157 const std::string& absolute_name) {
156 return AddAllocatorDumpInternal( 158 return AddAllocatorDumpInternal(
157 make_scoped_ptr(new MemoryAllocatorDump(absolute_name, this))); 159 WrapUnique(new MemoryAllocatorDump(absolute_name, this)));
158 } 160 }
159 161
160 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( 162 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump(
161 const std::string& absolute_name, 163 const std::string& absolute_name,
162 const MemoryAllocatorDumpGuid& guid) { 164 const MemoryAllocatorDumpGuid& guid) {
163 return AddAllocatorDumpInternal( 165 return AddAllocatorDumpInternal(
164 make_scoped_ptr(new MemoryAllocatorDump(absolute_name, this, guid))); 166 WrapUnique(new MemoryAllocatorDump(absolute_name, this, guid)));
165 } 167 }
166 168
167 MemoryAllocatorDump* ProcessMemoryDump::AddAllocatorDumpInternal( 169 MemoryAllocatorDump* ProcessMemoryDump::AddAllocatorDumpInternal(
168 scoped_ptr<MemoryAllocatorDump> mad) { 170 std::unique_ptr<MemoryAllocatorDump> mad) {
169 auto insertion_result = allocator_dumps_.insert( 171 auto insertion_result = allocator_dumps_.insert(
170 std::make_pair(mad->absolute_name(), std::move(mad))); 172 std::make_pair(mad->absolute_name(), std::move(mad)));
171 DCHECK(insertion_result.second) << "Duplicate name: " << mad->absolute_name(); 173 DCHECK(insertion_result.second) << "Duplicate name: " << mad->absolute_name();
172 return insertion_result.first->second.get(); 174 return insertion_result.first->second.get();
173 } 175 }
174 176
175 MemoryAllocatorDump* ProcessMemoryDump::GetAllocatorDump( 177 MemoryAllocatorDump* ProcessMemoryDump::GetAllocatorDump(
176 const std::string& absolute_name) const { 178 const std::string& absolute_name) const {
177 auto it = allocator_dumps_.find(absolute_name); 179 auto it = allocator_dumps_.find(absolute_name);
178 return it == allocator_dumps_.end() ? nullptr : it->second.get(); 180 return it == allocator_dumps_.end() ? nullptr : it->second.get();
(...skipping 28 matching lines...) Expand all
207 mad->set_flags(MemoryAllocatorDump::Flags::WEAK); 209 mad->set_flags(MemoryAllocatorDump::Flags::WEAK);
208 return mad; 210 return mad;
209 } 211 }
210 212
211 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( 213 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump(
212 const MemoryAllocatorDumpGuid& guid) const { 214 const MemoryAllocatorDumpGuid& guid) const {
213 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); 215 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid));
214 } 216 }
215 217
216 void ProcessMemoryDump::AddHeapDump(const std::string& absolute_name, 218 void ProcessMemoryDump::AddHeapDump(const std::string& absolute_name,
217 scoped_ptr<TracedValue> heap_dump) { 219 std::unique_ptr<TracedValue> heap_dump) {
218 DCHECK_EQ(0ul, heap_dumps_.count(absolute_name)); 220 DCHECK_EQ(0ul, heap_dumps_.count(absolute_name));
219 heap_dumps_[absolute_name] = std::move(heap_dump); 221 heap_dumps_[absolute_name] = std::move(heap_dump);
220 } 222 }
221 223
222 void ProcessMemoryDump::Clear() { 224 void ProcessMemoryDump::Clear() {
223 if (has_process_totals_) { 225 if (has_process_totals_) {
224 process_totals_.Clear(); 226 process_totals_.Clear();
225 has_process_totals_ = false; 227 has_process_totals_ = false;
226 } 228 }
227 229
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 313
312 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, 314 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source,
313 const std::string& target_node_name) { 315 const std::string& target_node_name) {
314 std::string child_mad_name = target_node_name + "/__" + source.ToString(); 316 std::string child_mad_name = target_node_name + "/__" + source.ToString();
315 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); 317 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name);
316 AddOwnershipEdge(source, target_child_mad->guid()); 318 AddOwnershipEdge(source, target_child_mad->guid());
317 } 319 }
318 320
319 } // namespace trace_event 321 } // namespace trace_event
320 } // namespace base 322 } // namespace base
OLDNEW
« 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