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

Side by Side Diff: components/tracing/process_metrics_memory_dump_provider.cc

Issue 1921923002: Convert //components/[o-t]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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 "components/tracing/process_metrics_memory_dump_provider.h" 5 #include "components/tracing/process_metrics_memory_dump_provider.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 11
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_file.h" 13 #include "base/files/scoped_file.h"
14 #include "base/format_macros.h" 14 #include "base/format_macros.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ptr_util.h"
17 #include "base/process/process_metrics.h" 18 #include "base/process/process_metrics.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/trace_event/memory_dump_manager.h" 21 #include "base/trace_event/memory_dump_manager.h"
21 #include "base/trace_event/process_memory_dump.h" 22 #include "base/trace_event/process_memory_dump.h"
22 #include "base/trace_event/process_memory_maps.h" 23 #include "base/trace_event/process_memory_maps.h"
23 #include "base/trace_event/process_memory_totals.h" 24 #include "base/trace_event/process_memory_totals.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 26
26 namespace tracing { 27 namespace tracing {
27 28
28 namespace { 29 namespace {
29 30
30 base::LazyInstance< 31 base::LazyInstance<
31 std::map<base::ProcessId, scoped_ptr<ProcessMetricsMemoryDumpProvider>>>:: 32 std::map<base::ProcessId,
32 Leaky g_dump_providers_map = LAZY_INSTANCE_INITIALIZER; 33 std::unique_ptr<ProcessMetricsMemoryDumpProvider>>>::Leaky
34 g_dump_providers_map = LAZY_INSTANCE_INITIALIZER;
33 35
34 #if defined(OS_LINUX) || defined(OS_ANDROID) 36 #if defined(OS_LINUX) || defined(OS_ANDROID)
35 const char kClearPeakRssCommand[] = "5"; 37 const char kClearPeakRssCommand[] = "5";
36 38
37 const uint32_t kMaxLineSize = 4096; 39 const uint32_t kMaxLineSize = 4096;
38 40
39 bool ParseSmapsHeader(const char* header_line, 41 bool ParseSmapsHeader(const char* header_line,
40 base::trace_event::ProcessMemoryMaps::VMRegion* region) { 42 base::trace_event::ProcessMemoryMaps::VMRegion* region) {
41 // e.g., "00400000-00421000 r-xp 00000000 fc:01 1234 /foo.so\n" 43 // e.g., "00400000-00421000 r-xp 00000000 fc:01 1234 /foo.so\n"
42 bool res = true; // Whether this region should be appended or skipped. 44 bool res = true; // Whether this region should be appended or skipped.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 ++num_valid_regions; 150 ++num_valid_regions;
149 should_add_current_region = false; 151 should_add_current_region = false;
150 } 152 }
151 } 153 }
152 } 154 }
153 } 155 }
154 return num_valid_regions; 156 return num_valid_regions;
155 } 157 }
156 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 158 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
157 159
158 scoped_ptr<base::ProcessMetrics> CreateProcessMetrics(base::ProcessId process) { 160 std::unique_ptr<base::ProcessMetrics> CreateProcessMetrics(
161 base::ProcessId process) {
159 if (process == base::kNullProcessId) 162 if (process == base::kNullProcessId)
160 return make_scoped_ptr(base::ProcessMetrics::CreateCurrentProcessMetrics()); 163 return base::WrapUnique(
164 base::ProcessMetrics::CreateCurrentProcessMetrics());
161 #if defined(OS_LINUX) || defined(OS_ANDROID) 165 #if defined(OS_LINUX) || defined(OS_ANDROID)
162 // Just pass ProcessId instead of handle since they are the same in linux and 166 // Just pass ProcessId instead of handle since they are the same in linux and
163 // android. 167 // android.
164 return make_scoped_ptr(base::ProcessMetrics::CreateProcessMetrics(process)); 168 return base::WrapUnique(base::ProcessMetrics::CreateProcessMetrics(process));
165 #else 169 #else
166 // Creating process metrics for child processes in mac or windows requires 170 // Creating process metrics for child processes in mac or windows requires
167 // additional information like ProcessHandle or port provider. This is a non 171 // additional information like ProcessHandle or port provider. This is a non
168 // needed use case. 172 // needed use case.
169 NOTREACHED(); 173 NOTREACHED();
170 return scoped_ptr<base::ProcessMetrics>(); 174 return std::unique_ptr<base::ProcessMetrics>();
171 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 175 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
172 } 176 }
173 177
174 } // namespace 178 } // namespace
175 179
176 // static 180 // static
177 uint64_t ProcessMetricsMemoryDumpProvider::rss_bytes_for_testing = 0; 181 uint64_t ProcessMetricsMemoryDumpProvider::rss_bytes_for_testing = 0;
178 182
179 #if defined(OS_LINUX) || defined(OS_ANDROID) 183 #if defined(OS_LINUX) || defined(OS_ANDROID)
180 184
(...skipping 17 matching lines...) Expand all
198 202
199 if (res) 203 if (res)
200 pmd->set_has_process_mmaps(); 204 pmd->set_has_process_mmaps();
201 return res; 205 return res;
202 } 206 }
203 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 207 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
204 208
205 // static 209 // static
206 void ProcessMetricsMemoryDumpProvider::RegisterForProcess( 210 void ProcessMetricsMemoryDumpProvider::RegisterForProcess(
207 base::ProcessId process) { 211 base::ProcessId process) {
208 scoped_ptr<ProcessMetricsMemoryDumpProvider> metrics_provider( 212 std::unique_ptr<ProcessMetricsMemoryDumpProvider> metrics_provider(
209 new ProcessMetricsMemoryDumpProvider(process)); 213 new ProcessMetricsMemoryDumpProvider(process));
210 base::trace_event::MemoryDumpProvider::Options options; 214 base::trace_event::MemoryDumpProvider::Options options;
211 options.target_pid = process; 215 options.target_pid = process;
212 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 216 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
213 metrics_provider.get(), "ProcessMemoryMetrics", nullptr, options); 217 metrics_provider.get(), "ProcessMemoryMetrics", nullptr, options);
214 bool did_insert = 218 bool did_insert =
215 g_dump_providers_map.Get() 219 g_dump_providers_map.Get()
216 .insert(std::make_pair(process, std::move(metrics_provider))) 220 .insert(std::make_pair(process, std::move(metrics_provider)))
217 .second; 221 .second;
218 if (!did_insert) { 222 if (!did_insert) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 305
302 pmd->process_totals()->set_resident_set_bytes(rss_bytes); 306 pmd->process_totals()->set_resident_set_bytes(rss_bytes);
303 pmd->set_has_process_totals(); 307 pmd->set_has_process_totals();
304 pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes); 308 pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes);
305 309
306 // Returns true even if other metrics failed, since rss is reported. 310 // Returns true even if other metrics failed, since rss is reported.
307 return true; 311 return true;
308 } 312 }
309 313
310 } // namespace tracing 314 } // namespace tracing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698