OLD | NEW |
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_maps_dump_provider.h" | 5 #include "base/trace_event/process_memory_maps_dump_provider.h" |
6 | 6 |
7 #include "base/files/scoped_file.h" | 7 #include "base/files/scoped_file.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 } | 130 } |
131 } | 131 } |
132 } | 132 } |
133 return num_valid_regions; | 133 return num_valid_regions; |
134 } | 134 } |
135 | 135 |
136 } // namespace | 136 } // namespace |
137 | 137 |
138 // static | 138 // static |
139 ProcessMemoryMapsDumpProvider* ProcessMemoryMapsDumpProvider::GetInstance() { | 139 scoped_ptr<ProcessMemoryMapsDumpProvider> |
140 return Singleton<ProcessMemoryMapsDumpProvider, | 140 ProcessMemoryMapsDumpProvider::CreateForProcess(ProcessHandle process) { |
141 LeakySingletonTraits<ProcessMemoryMapsDumpProvider>>::get(); | 141 return make_scoped_ptr(new ProcessMemoryMapsDumpProvider(process)); |
142 } | 142 } |
143 | 143 |
144 ProcessMemoryMapsDumpProvider::ProcessMemoryMapsDumpProvider() { | 144 ProcessMemoryMapsDumpProvider::ProcessMemoryMapsDumpProvider( |
145 } | 145 ProcessHandle process) |
| 146 : process_(process) {} |
146 | 147 |
147 ProcessMemoryMapsDumpProvider::~ProcessMemoryMapsDumpProvider() { | 148 ProcessMemoryMapsDumpProvider::~ProcessMemoryMapsDumpProvider() { |
148 } | 149 } |
149 | 150 |
150 // Called at trace dump point time. Creates a snapshot of the memory maps for | 151 // Called at trace dump point time. Creates a snapshot of the memory maps for |
151 // the current process. | 152 // the current process. |
152 bool ProcessMemoryMapsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, | 153 bool ProcessMemoryMapsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, |
153 ProcessMemoryDump* pmd) { | 154 ProcessMemoryDump* pmd) { |
154 // Snapshot of memory maps is not taken for light dump requests. | 155 // Snapshot of memory maps is not taken for light dump requests. |
155 if (args.level_of_detail == MemoryDumpLevelOfDetail::LIGHT) | 156 if (args.level_of_detail == MemoryDumpLevelOfDetail::LIGHT) |
156 return true; | 157 return true; |
157 | 158 |
158 uint32 res = 0; | 159 uint32 res = 0; |
159 if (UNLIKELY(proc_smaps_for_testing)) { | 160 if (UNLIKELY(proc_smaps_for_testing)) { |
160 res = ReadLinuxProcSmapsFile(proc_smaps_for_testing, pmd->process_mmaps()); | 161 res = ReadLinuxProcSmapsFile(proc_smaps_for_testing, pmd->process_mmaps()); |
161 } else { | 162 } else { |
162 ScopedFILE smaps_file(fopen("/proc/self/smaps", "r")); | 163 ScopedFILE smaps_file(fopen("/proc/self/smaps", "r")); |
163 res = ReadLinuxProcSmapsFile(smaps_file.get(), pmd->process_mmaps()); | 164 res = ReadLinuxProcSmapsFile(smaps_file.get(), pmd->process_mmaps()); |
164 } | 165 } |
165 | 166 |
166 if (res > 0) { | 167 if (res > 0) { |
167 pmd->set_has_process_mmaps(); | 168 pmd->set_has_process_mmaps(); |
168 return true; | 169 return true; |
169 } | 170 } |
170 return false; | 171 return false; |
171 } | 172 } |
172 | 173 |
173 } // namespace trace_event | 174 } // namespace trace_event |
174 } // namespace base | 175 } // namespace base |
OLD | NEW |