OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file/namespace contains utility functions for enumerating, ending and | 5 // This file/namespace contains utility functions for enumerating, ending and |
6 // computing statistics of processes. | 6 // computing statistics of processes. |
7 | 7 |
8 #ifndef BASE_PROCESS_UTIL_H_ | 8 #ifndef BASE_PROCESS_UTIL_H_ |
9 #define BASE_PROCESS_UTIL_H_ | 9 #define BASE_PROCESS_UTIL_H_ |
10 | 10 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 const int kMaxOomScore = 1000; | 198 const int kMaxOomScore = 1000; |
199 | 199 |
200 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will | 200 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will |
201 // prefer to kill certain process types over others. The range for the | 201 // prefer to kill certain process types over others. The range for the |
202 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. | 202 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. |
203 // If the Linux system doesn't support the newer oom_score_adj range | 203 // If the Linux system doesn't support the newer oom_score_adj range |
204 // of [0, 1000], then we revert to using the older oom_adj, and | 204 // of [0, 1000], then we revert to using the older oom_adj, and |
205 // translate the given value into [0, 15]. Some aliasing of values | 205 // translate the given value into [0, 15]. Some aliasing of values |
206 // may occur in that case, of course. | 206 // may occur in that case, of course. |
207 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); | 207 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); |
| 208 |
| 209 // /proc/self/exe refers to the current executable. |
| 210 BASE_EXPORT extern const char kProcSelfExe[]; |
208 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 211 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
209 | 212 |
210 #if defined(OS_POSIX) | 213 #if defined(OS_POSIX) |
211 // Returns the ID for the parent of the given process. | 214 // Returns the ID for the parent of the given process. |
212 BASE_EXPORT ProcessId GetParentProcessId(ProcessHandle process); | 215 BASE_EXPORT ProcessId GetParentProcessId(ProcessHandle process); |
213 | 216 |
214 // Close all file descriptors, except those which are a destination in the | 217 // Close all file descriptors, except those which are a destination in the |
215 // given multimap. Only call this function in a child process where you know | 218 // given multimap. Only call this function in a child process where you know |
216 // that there aren't any other threads. | 219 // that there aren't any other threads. |
217 BASE_EXPORT void CloseSuperfluousFds(const InjectiveMultimap& saved_map); | 220 BASE_EXPORT void CloseSuperfluousFds(const InjectiveMultimap& saved_map); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 public: | 696 public: |
694 ~ProcessMetrics(); | 697 ~ProcessMetrics(); |
695 | 698 |
696 // Creates a ProcessMetrics for the specified process. | 699 // Creates a ProcessMetrics for the specified process. |
697 // The caller owns the returned object. | 700 // The caller owns the returned object. |
698 #if !defined(OS_MACOSX) || defined(OS_IOS) | 701 #if !defined(OS_MACOSX) || defined(OS_IOS) |
699 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); | 702 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); |
700 #else | 703 #else |
701 class PortProvider { | 704 class PortProvider { |
702 public: | 705 public: |
| 706 virtual ~PortProvider() {} |
| 707 |
703 // Should return the mach task for |process| if possible, or else | 708 // Should return the mach task for |process| if possible, or else |
704 // |MACH_PORT_NULL|. Only processes that this returns tasks for will have | 709 // |MACH_PORT_NULL|. Only processes that this returns tasks for will have |
705 // metrics on OS X (except for the current process, which always gets | 710 // metrics on OS X (except for the current process, which always gets |
706 // metrics). | 711 // metrics). |
707 virtual mach_port_t TaskForPid(ProcessHandle process) const = 0; | 712 virtual mach_port_t TaskForPid(ProcessHandle process) const = 0; |
708 }; | 713 }; |
709 | 714 |
710 // The port provider needs to outlive the ProcessMetrics object returned by | 715 // The port provider needs to outlive the ProcessMetrics object returned by |
711 // this function. If NULL is passed as provider, the returned object | 716 // this function. If NULL is passed as provider, the returned object |
712 // only returns valid metrics if |process| is the current process. | 717 // only returns valid metrics if |process| is the current process. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 // instance running inside the parent. The parent's Breakpad instance should | 857 // instance running inside the parent. The parent's Breakpad instance should |
853 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 858 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
854 // in the child after forking will restore the standard exception handler. | 859 // in the child after forking will restore the standard exception handler. |
855 // See http://crbug.com/20371/ for more details. | 860 // See http://crbug.com/20371/ for more details. |
856 void RestoreDefaultExceptionHandler(); | 861 void RestoreDefaultExceptionHandler(); |
857 #endif // defined(OS_MACOSX) | 862 #endif // defined(OS_MACOSX) |
858 | 863 |
859 } // namespace base | 864 } // namespace base |
860 | 865 |
861 #endif // BASE_PROCESS_UTIL_H_ | 866 #endif // BASE_PROCESS_UTIL_H_ |
OLD | NEW |