| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 | 13 |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include <windows.h> | 15 #include <windows.h> |
| 16 #include <tlhelp32.h> | 16 #include <tlhelp32.h> |
| 17 #elif defined(OS_MACOSX) || defined(OS_OPENBSD) | 17 #elif defined(OS_MACOSX) || defined(OS_BSD) |
| 18 // kinfo_proc is defined in <sys/sysctl.h>, but this forward declaration | 18 // kinfo_proc is defined in <sys/sysctl.h>, but this forward declaration |
| 19 // is sufficient for the vector<kinfo_proc> below. | 19 // is sufficient for the vector<kinfo_proc> below. |
| 20 struct kinfo_proc; | 20 struct kinfo_proc; |
| 21 // malloc_zone_t is defined in <malloc/malloc.h>, but this forward declaration | 21 // malloc_zone_t is defined in <malloc/malloc.h>, but this forward declaration |
| 22 // is sufficient for GetPurgeableZone() below. | 22 // is sufficient for GetPurgeableZone() below. |
| 23 typedef struct _malloc_zone_t malloc_zone_t; | 23 typedef struct _malloc_zone_t malloc_zone_t; |
| 24 #if !defined(OS_OPENBSD) | 24 #if !defined(OS_BSD) |
| 25 #include <mach/mach.h> | 25 #include <mach/mach.h> |
| 26 #endif | 26 #endif |
| 27 #elif defined(OS_POSIX) | 27 #elif defined(OS_POSIX) |
| 28 #include <dirent.h> | 28 #include <dirent.h> |
| 29 #include <limits.h> | 29 #include <limits.h> |
| 30 #include <sys/types.h> | 30 #include <sys/types.h> |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 #include <list> | 33 #include <list> |
| 34 #include <set> | 34 #include <set> |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 ProcessHandle* handle); | 160 ProcessHandle* handle); |
| 161 | 161 |
| 162 // Closes the process handle opened by OpenProcessHandle. | 162 // Closes the process handle opened by OpenProcessHandle. |
| 163 BASE_EXPORT void CloseProcessHandle(ProcessHandle process); | 163 BASE_EXPORT void CloseProcessHandle(ProcessHandle process); |
| 164 | 164 |
| 165 // Returns the unique ID for the specified process. This is functionally the | 165 // Returns the unique ID for the specified process. This is functionally the |
| 166 // same as Windows' GetProcessId(), but works on versions of Windows before | 166 // same as Windows' GetProcessId(), but works on versions of Windows before |
| 167 // Win XP SP1 as well. | 167 // Win XP SP1 as well. |
| 168 BASE_EXPORT ProcessId GetProcId(ProcessHandle process); | 168 BASE_EXPORT ProcessId GetProcId(ProcessHandle process); |
| 169 | 169 |
| 170 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_OPENBSD) | 170 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_BSD) |
| 171 // Returns the path to the executable of the given process. | 171 // Returns the path to the executable of the given process. |
| 172 BASE_EXPORT FilePath GetProcessExecutablePath(ProcessHandle process); | 172 BASE_EXPORT FilePath GetProcessExecutablePath(ProcessHandle process); |
| 173 #endif | 173 #endif |
| 174 | 174 |
| 175 #if defined(OS_LINUX) || defined(OS_ANDROID) | 175 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 176 // Parse the data found in /proc/<pid>/stat and return the sum of the | 176 // Parse the data found in /proc/<pid>/stat and return the sum of the |
| 177 // CPU-related ticks. Returns -1 on parse error. | 177 // CPU-related ticks. Returns -1 on parse error. |
| 178 // Exposed for testing. | 178 // Exposed for testing. |
| 179 BASE_EXPORT int ParseProcStatCPU(const std::string& input); | 179 BASE_EXPORT int ParseProcStatCPU(const std::string& input); |
| 180 | 180 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 // that process's info if there is one, false otherwise. | 561 // that process's info if there is one, false otherwise. |
| 562 bool CheckForNextProcess(); | 562 bool CheckForNextProcess(); |
| 563 | 563 |
| 564 // Initializes a PROCESSENTRY32 data structure so that it's ready for | 564 // Initializes a PROCESSENTRY32 data structure so that it's ready for |
| 565 // use with Process32First/Process32Next. | 565 // use with Process32First/Process32Next. |
| 566 void InitProcessEntry(ProcessEntry* entry); | 566 void InitProcessEntry(ProcessEntry* entry); |
| 567 | 567 |
| 568 #if defined(OS_WIN) | 568 #if defined(OS_WIN) |
| 569 HANDLE snapshot_; | 569 HANDLE snapshot_; |
| 570 bool started_iteration_; | 570 bool started_iteration_; |
| 571 #elif defined(OS_MACOSX) || defined(OS_OPENBSD) | 571 #elif defined(OS_MACOSX) || defined(OS_BSD) |
| 572 std::vector<kinfo_proc> kinfo_procs_; | 572 std::vector<kinfo_proc> kinfo_procs_; |
| 573 size_t index_of_kinfo_proc_; | 573 size_t index_of_kinfo_proc_; |
| 574 #elif defined(OS_POSIX) | 574 #elif defined(OS_POSIX) |
| 575 DIR *procfs_dir_; | 575 DIR *procfs_dir_; |
| 576 #endif | 576 #endif |
| 577 ProcessEntry entry_; | 577 ProcessEntry entry_; |
| 578 const ProcessFilter* filter_; | 578 const ProcessFilter* filter_; |
| 579 | 579 |
| 580 DISALLOW_COPY_AND_ASSIGN(ProcessIterator); | 580 DISALLOW_COPY_AND_ASSIGN(ProcessIterator); |
| 581 }; | 581 }; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 // instance running inside the parent. The parent's Breakpad instance should | 814 // instance running inside the parent. The parent's Breakpad instance should |
| 815 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 815 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
| 816 // in the child after forking will restore the standard exception handler. | 816 // in the child after forking will restore the standard exception handler. |
| 817 // See http://crbug.com/20371/ for more details. | 817 // See http://crbug.com/20371/ for more details. |
| 818 void RestoreDefaultExceptionHandler(); | 818 void RestoreDefaultExceptionHandler(); |
| 819 #endif // defined(OS_MACOSX) | 819 #endif // defined(OS_MACOSX) |
| 820 | 820 |
| 821 } // namespace base | 821 } // namespace base |
| 822 | 822 |
| 823 #endif // BASE_PROCESS_UTIL_H_ | 823 #endif // BASE_PROCESS_UTIL_H_ |
| OLD | NEW |