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