| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/process_util.h" | 5 #include "base/process/memory.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <new> |
| 8 #include <malloc.h> | |
| 9 #include <sys/time.h> | |
| 10 #include <sys/types.h> | |
| 11 #include <unistd.h> | |
| 12 | 8 |
| 13 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" | 11 #include "base/logging.h" |
| 15 #include "base/process/internal_linux.h" | 12 #include "base/process/internal_linux.h" |
| 16 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_split.h" | |
| 18 #include "base/strings/string_util.h" | |
| 19 #include "base/sys_info.h" | |
| 20 #include "base/threading/thread_restrictions.h" | |
| 21 | 14 |
| 22 namespace base { | 15 namespace base { |
| 23 | 16 |
| 24 #if defined(USE_LINUX_BREAKPAD) | |
| 25 size_t g_oom_size = 0U; | |
| 26 #endif | |
| 27 | |
| 28 const char kProcSelfExe[] = "/proc/self/exe"; | |
| 29 | |
| 30 ProcessId GetParentProcessId(ProcessHandle process) { | |
| 31 ProcessId pid = | |
| 32 internal::ReadProcStatsAndGetFieldAsInt(process, internal::VM_PPID); | |
| 33 if (pid) | |
| 34 return pid; | |
| 35 return -1; | |
| 36 } | |
| 37 | |
| 38 FilePath GetProcessExecutablePath(ProcessHandle process) { | |
| 39 FilePath stat_file = internal::GetProcPidDir(process).Append("exe"); | |
| 40 FilePath exe_name; | |
| 41 if (!file_util::ReadSymbolicLink(stat_file, &exe_name)) { | |
| 42 // No such process. Happens frequently in e.g. TerminateAllChromeProcesses | |
| 43 return FilePath(); | |
| 44 } | |
| 45 return exe_name; | |
| 46 } | |
| 47 | |
| 48 int GetNumberOfThreads(ProcessHandle process) { | |
| 49 return internal::ReadProcStatsAndGetFieldAsInt(process, | |
| 50 internal::VM_NUMTHREADS); | |
| 51 } | |
| 52 | |
| 53 namespace { | 17 namespace { |
| 54 | 18 |
| 55 void OnNoMemorySize(size_t size) { | 19 void OnNoMemorySize(size_t size) { |
| 56 #if defined(USE_LINUX_BREAKPAD) | 20 #if defined(USE_LINUX_BREAKPAD) |
| 57 g_oom_size = size; | 21 g_oom_size = size; |
| 58 #endif | 22 #endif |
| 59 | 23 |
| 60 if (size != 0) | 24 if (size != 0) |
| 61 LOG(FATAL) << "Out of memory, size = " << size; | 25 LOG(FATAL) << "Out of memory, size = " << size; |
| 62 LOG(FATAL) << "Out of memory."; | 26 LOG(FATAL) << "Out of memory."; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 int score_len = static_cast<int>(score_str.length()); | 174 int score_len = static_cast<int>(score_str.length()); |
| 211 return (score_len == file_util::WriteFile(oom_file, | 175 return (score_len == file_util::WriteFile(oom_file, |
| 212 score_str.c_str(), | 176 score_str.c_str(), |
| 213 score_len)); | 177 score_len)); |
| 214 } | 178 } |
| 215 | 179 |
| 216 return false; | 180 return false; |
| 217 } | 181 } |
| 218 | 182 |
| 219 } // namespace base | 183 } // namespace base |
| OLD | NEW |