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 <cctype> | 7 #include <cctype> |
8 #include <fstream> | 8 #include <fstream> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/process/process_metrics.h" | 11 #include "base/process/process_metrics.h" |
12 #include "base/trace_event/process_memory_dump.h" | 12 #include "base/trace_event/process_memory_dump.h" |
13 #include "base/trace_event/process_memory_maps.h" | 13 #include "base/trace_event/process_memory_maps.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 namespace trace_event { | 16 namespace trace_event { |
17 | 17 |
18 namespace { | |
19 const char kDumperFriendlyName[] = "ProcessMemoryMaps"; | |
20 } | |
21 | |
22 #if defined(OS_LINUX) || defined(OS_ANDROID) | 18 #if defined(OS_LINUX) || defined(OS_ANDROID) |
23 // static | 19 // static |
24 std::istream* ProcessMemoryMapsDumpProvider::proc_smaps_for_testing = nullptr; | 20 std::istream* ProcessMemoryMapsDumpProvider::proc_smaps_for_testing = nullptr; |
25 | 21 |
26 namespace { | 22 namespace { |
27 | 23 |
28 const uint32 kMaxLineSize = 4096; | 24 const uint32 kMaxLineSize = 4096; |
29 | 25 |
30 bool ParseSmapsHeader(std::istream* smaps, | 26 bool ParseSmapsHeader(std::istream* smaps, |
31 ProcessMemoryMaps::VMRegion* region) { | 27 ProcessMemoryMaps::VMRegion* region) { |
(...skipping 128 matching lines...) Loading... |
160 } | 156 } |
161 | 157 |
162 ProcessMemoryMapsDumpProvider::ProcessMemoryMapsDumpProvider() { | 158 ProcessMemoryMapsDumpProvider::ProcessMemoryMapsDumpProvider() { |
163 } | 159 } |
164 | 160 |
165 ProcessMemoryMapsDumpProvider::~ProcessMemoryMapsDumpProvider() { | 161 ProcessMemoryMapsDumpProvider::~ProcessMemoryMapsDumpProvider() { |
166 } | 162 } |
167 | 163 |
168 // Called at trace dump point time. Creates a snapshot the memory maps for the | 164 // Called at trace dump point time. Creates a snapshot the memory maps for the |
169 // current process. | 165 // current process. |
170 bool ProcessMemoryMapsDumpProvider::DumpInto(ProcessMemoryDump* pmd) { | 166 bool ProcessMemoryMapsDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) { |
171 uint32 res = 0; | 167 uint32 res = 0; |
172 | 168 |
173 #if defined(OS_LINUX) || defined(OS_ANDROID) | 169 #if defined(OS_LINUX) || defined(OS_ANDROID) |
174 if (UNLIKELY(proc_smaps_for_testing)) { | 170 if (UNLIKELY(proc_smaps_for_testing)) { |
175 res = ReadLinuxProcSmapsFile(proc_smaps_for_testing, pmd->process_mmaps()); | 171 res = ReadLinuxProcSmapsFile(proc_smaps_for_testing, pmd->process_mmaps()); |
176 } else { | 172 } else { |
177 std::ifstream proc_self_smaps("/proc/self/smaps"); | 173 std::ifstream proc_self_smaps("/proc/self/smaps"); |
178 res = ReadLinuxProcSmapsFile(&proc_self_smaps, pmd->process_mmaps()); | 174 res = ReadLinuxProcSmapsFile(&proc_self_smaps, pmd->process_mmaps()); |
179 } | 175 } |
180 #else | 176 #else |
181 LOG(ERROR) << "ProcessMemoryMaps dump provider is supported only on Linux"; | 177 LOG(ERROR) << "ProcessMemoryMaps dump provider is supported only on Linux"; |
182 #endif | 178 #endif |
183 | 179 |
184 if (res > 0) { | 180 if (res > 0) { |
185 pmd->set_has_process_mmaps(); | 181 pmd->set_has_process_mmaps(); |
186 return true; | 182 return true; |
187 } | 183 } |
188 | 184 |
189 return false; | 185 return false; |
190 } | 186 } |
191 | 187 |
192 const char* ProcessMemoryMapsDumpProvider::GetFriendlyName() const { | |
193 return kDumperFriendlyName; | |
194 } | |
195 | |
196 } // namespace trace_event | 188 } // namespace trace_event |
197 } // namespace base | 189 } // namespace base |
OLD | NEW |