| OLD | NEW |
| 1 // Copyright (c) 2013 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 // This file contains routines for gathering resource statistics for processes | 5 // This file contains routines for gathering resource statistics for processes |
| 6 // running on the system. | 6 // running on the system. |
| 7 | 7 |
| 8 #ifndef BASE_PROCESS_PROCESS_METRICS_H_ | 8 #ifndef BASE_PROCESS_PROCESS_METRICS_H_ |
| 9 #define BASE_PROCESS_PROCESS_METRICS_H_ | 9 #define BASE_PROCESS_PROCESS_METRICS_H_ |
| 10 | 10 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // the range of 0 to (100 * numCPUCores) everywhere. | 198 // the range of 0 to (100 * numCPUCores) everywhere. |
| 199 double GetPlatformIndependentCPUUsage(); | 199 double GetPlatformIndependentCPUUsage(); |
| 200 | 200 |
| 201 // Retrieves accounting information for all I/O operations performed by the | 201 // Retrieves accounting information for all I/O operations performed by the |
| 202 // process. | 202 // process. |
| 203 // If IO information is retrieved successfully, the function returns true | 203 // If IO information is retrieved successfully, the function returns true |
| 204 // and fills in the IO_COUNTERS passed in. The function returns false | 204 // and fills in the IO_COUNTERS passed in. The function returns false |
| 205 // otherwise. | 205 // otherwise. |
| 206 bool GetIOCounters(IoCounters* io_counters) const; | 206 bool GetIOCounters(IoCounters* io_counters) const; |
| 207 | 207 |
| 208 #if defined(OS_LINUX) | 208 #if defined(OS_LINUX) || defined(OS_AIX) |
| 209 // Returns the number of file descriptors currently open by the process, or | 209 // Returns the number of file descriptors currently open by the process, or |
| 210 // -1 on error. | 210 // -1 on error. |
| 211 int GetOpenFdCount() const; | 211 int GetOpenFdCount() const; |
| 212 | 212 |
| 213 // Returns the soft limit of file descriptors that can be opened by the | 213 // Returns the soft limit of file descriptors that can be opened by the |
| 214 // process, or -1 on error. | 214 // process, or -1 on error. |
| 215 int GetOpenFdSoftLimit() const; | 215 int GetOpenFdSoftLimit() const; |
| 216 #endif // defined(OS_LINUX) | 216 #endif // defined(OS_LINUX) || defined(OS_AIX) |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 #if !defined(OS_MACOSX) || defined(OS_IOS) | 219 #if !defined(OS_MACOSX) || defined(OS_IOS) |
| 220 explicit ProcessMetrics(ProcessHandle process); | 220 explicit ProcessMetrics(ProcessHandle process); |
| 221 #else | 221 #else |
| 222 ProcessMetrics(ProcessHandle process, PortProvider* port_provider); | 222 ProcessMetrics(ProcessHandle process, PortProvider* port_provider); |
| 223 #endif // !defined(OS_MACOSX) || defined(OS_IOS) | 223 #endif // !defined(OS_MACOSX) || defined(OS_IOS) |
| 224 | 224 |
| 225 #if defined(OS_LINUX) || defined(OS_ANDROID) | 225 #if defined(OS_LINUX) || defined(OS_ANDROID) | defined(OS_AIX) |
| 226 bool GetWorkingSetKBytesStatm(WorkingSetKBytes* ws_usage) const; | 226 bool GetWorkingSetKBytesStatm(WorkingSetKBytes* ws_usage) const; |
| 227 #endif | 227 #endif |
| 228 | 228 |
| 229 #if defined(OS_CHROMEOS) | 229 #if defined(OS_CHROMEOS) |
| 230 bool GetWorkingSetKBytesTotmaps(WorkingSetKBytes *ws_usage) const; | 230 bool GetWorkingSetKBytesTotmaps(WorkingSetKBytes *ws_usage) const; |
| 231 #endif | 231 #endif |
| 232 | 232 |
| 233 #if defined(OS_MACOSX) || defined(OS_LINUX) | 233 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_AIX) |
| 234 int CalculateIdleWakeupsPerSecond(uint64_t absolute_idle_wakeups); | 234 int CalculateIdleWakeupsPerSecond(uint64_t absolute_idle_wakeups); |
| 235 #endif | 235 #endif |
| 236 | 236 |
| 237 #if defined(OS_WIN) | 237 #if defined(OS_WIN) |
| 238 win::ScopedHandle process_; | 238 win::ScopedHandle process_; |
| 239 #else | 239 #else |
| 240 ProcessHandle process_; | 240 ProcessHandle process_; |
| 241 #endif | 241 #endif |
| 242 | 242 |
| 243 int processor_count_; | 243 int processor_count_; |
| 244 | 244 |
| 245 // Used to store the previous times and CPU usage counts so we can | 245 // Used to store the previous times and CPU usage counts so we can |
| 246 // compute the CPU usage between calls. | 246 // compute the CPU usage between calls. |
| 247 TimeTicks last_cpu_time_; | 247 TimeTicks last_cpu_time_; |
| 248 int64_t last_system_time_; | 248 int64_t last_system_time_; |
| 249 | 249 |
| 250 #if defined(OS_MACOSX) || defined(OS_LINUX) | 250 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_AIX) |
| 251 // Same thing for idle wakeups. | 251 // Same thing for idle wakeups. |
| 252 TimeTicks last_idle_wakeups_time_; | 252 TimeTicks last_idle_wakeups_time_; |
| 253 uint64_t last_absolute_idle_wakeups_; | 253 uint64_t last_absolute_idle_wakeups_; |
| 254 #endif | 254 #endif |
| 255 | 255 |
| 256 #if !defined(OS_IOS) | 256 #if !defined(OS_IOS) |
| 257 #if defined(OS_MACOSX) | 257 #if defined(OS_MACOSX) |
| 258 // Queries the port provider if it's set. | 258 // Queries the port provider if it's set. |
| 259 mach_port_t TaskForPid(ProcessHandle process) const; | 259 mach_port_t TaskForPid(ProcessHandle process) const; |
| 260 | 260 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 282 // Returns the maximum number of file descriptors that can be open by a process | 282 // Returns the maximum number of file descriptors that can be open by a process |
| 283 // at once. If the number is unavailable, a conservative best guess is returned. | 283 // at once. If the number is unavailable, a conservative best guess is returned. |
| 284 BASE_EXPORT size_t GetMaxFds(); | 284 BASE_EXPORT size_t GetMaxFds(); |
| 285 | 285 |
| 286 // Sets the file descriptor soft limit to |max_descriptors| or the OS hard | 286 // Sets the file descriptor soft limit to |max_descriptors| or the OS hard |
| 287 // limit, whichever is lower. | 287 // limit, whichever is lower. |
| 288 BASE_EXPORT void SetFdLimit(unsigned int max_descriptors); | 288 BASE_EXPORT void SetFdLimit(unsigned int max_descriptors); |
| 289 #endif // defined(OS_POSIX) | 289 #endif // defined(OS_POSIX) |
| 290 | 290 |
| 291 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ | 291 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ |
| 292 defined(OS_ANDROID) | 292 defined(OS_ANDROID) || defined(OS_AIX) |
| 293 // Data about system-wide memory consumption. Values are in KB. Available on | 293 // Data about system-wide memory consumption. Values are in KB. Available on |
| 294 // Windows, Mac, Linux, Android and Chrome OS. | 294 // Windows, Mac, Linux, Android and Chrome OS. |
| 295 // | 295 // |
| 296 // Total memory are available on all platforms that implement | 296 // Total memory are available on all platforms that implement |
| 297 // GetSystemMemoryInfo(). Total/free swap memory are available on all platforms | 297 // GetSystemMemoryInfo(). Total/free swap memory are available on all platforms |
| 298 // except on Mac. Buffers/cached/active_anon/inactive_anon/active_file/ | 298 // except on Mac. Buffers/cached/active_anon/inactive_anon/active_file/ |
| 299 // inactive_file/dirty/reclaimable/pswpin/pswpout/pgmajfault are available on | 299 // inactive_file/dirty/reclaimable/pswpin/pswpout/pgmajfault are available on |
| 300 // Linux/Android/Chrome OS. Shmem/slab/gem_objects/gem_size are Chrome OS only. | 300 // Linux/Android/Chrome OS. Shmem/slab/gem_objects/gem_size are Chrome OS only. |
| 301 // Speculative/file_backed/purgeable are Mac and iOS only. | 301 // Speculative/file_backed/purgeable are Mac and iOS only. |
| 302 // Free is absent on Windows (see "avail_phys" below). | 302 // Free is absent on Windows (see "avail_phys" below). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 315 | 315 |
| 316 #if defined(OS_WIN) | 316 #if defined(OS_WIN) |
| 317 // "This is the amount of physical memory that can be immediately reused | 317 // "This is the amount of physical memory that can be immediately reused |
| 318 // without having to write its contents to disk first. It is the sum of the | 318 // without having to write its contents to disk first. It is the sum of the |
| 319 // size of the standby, free, and zero lists." (MSDN). | 319 // size of the standby, free, and zero lists." (MSDN). |
| 320 // Standby: not modified pages of physical ram (file-backed memory) that are | 320 // Standby: not modified pages of physical ram (file-backed memory) that are |
| 321 // not actively being used. | 321 // not actively being used. |
| 322 int avail_phys = 0; | 322 int avail_phys = 0; |
| 323 #endif | 323 #endif |
| 324 | 324 |
| 325 #if defined(OS_LINUX) || defined(OS_ANDROID) | 325 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_AIX) |
| 326 // This provides an estimate of available memory as described here: | 326 // This provides an estimate of available memory as described here: |
| 327 // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=
34e431b0ae398fc54ea69ff85ec700722c9da773 | 327 // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=
34e431b0ae398fc54ea69ff85ec700722c9da773 |
| 328 // NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always | 328 // NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always |
| 329 // be 0 in earlier kernel versions. | 329 // be 0 in earlier kernel versions. |
| 330 // Note: it includes _all_ file-backed memory (active + inactive). | 330 // Note: it includes _all_ file-backed memory (active + inactive). |
| 331 int available = 0; | 331 int available = 0; |
| 332 #endif | 332 #endif |
| 333 | 333 |
| 334 #if !defined(OS_MACOSX) | 334 #if !defined(OS_MACOSX) |
| 335 int swap_total = 0; | 335 int swap_total = 0; |
| 336 int swap_free = 0; | 336 int swap_free = 0; |
| 337 #endif | 337 #endif |
| 338 | 338 |
| 339 #if defined(OS_ANDROID) || defined(OS_LINUX) | 339 #if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX) |
| 340 int buffers = 0; | 340 int buffers = 0; |
| 341 int cached = 0; | 341 int cached = 0; |
| 342 int active_anon = 0; | 342 int active_anon = 0; |
| 343 int inactive_anon = 0; | 343 int inactive_anon = 0; |
| 344 int active_file = 0; | 344 int active_file = 0; |
| 345 int inactive_file = 0; | 345 int inactive_file = 0; |
| 346 int dirty = 0; | 346 int dirty = 0; |
| 347 int reclaimable = 0; | 347 int reclaimable = 0; |
| 348 | 348 |
| 349 // vmstats data. | 349 // vmstats data. |
| 350 unsigned long pswpin = 0; | 350 unsigned long pswpin = 0; |
| 351 unsigned long pswpout = 0; | 351 unsigned long pswpout = 0; |
| 352 unsigned long pgmajfault = 0; | 352 unsigned long pgmajfault = 0; |
| 353 #endif // defined(OS_ANDROID) || defined(OS_LINUX) | 353 #endif // defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX) |
| 354 | 354 |
| 355 #if defined(OS_CHROMEOS) | 355 #if defined(OS_CHROMEOS) |
| 356 int shmem = 0; | 356 int shmem = 0; |
| 357 int slab = 0; | 357 int slab = 0; |
| 358 // Gem data will be -1 if not supported. | 358 // Gem data will be -1 if not supported. |
| 359 int gem_objects = -1; | 359 int gem_objects = -1; |
| 360 long long gem_size = -1; | 360 long long gem_size = -1; |
| 361 #endif // defined(OS_CHROMEOS) | 361 #endif // defined(OS_CHROMEOS) |
| 362 | 362 |
| 363 #if defined(OS_MACOSX) | 363 #if defined(OS_MACOSX) |
| 364 int speculative = 0; | 364 int speculative = 0; |
| 365 int file_backed = 0; | 365 int file_backed = 0; |
| 366 int purgeable = 0; | 366 int purgeable = 0; |
| 367 #endif // defined(OS_MACOSX) | 367 #endif // defined(OS_MACOSX) |
| 368 }; | 368 }; |
| 369 | 369 |
| 370 // On Linux/Android/Chrome OS, system-wide memory consumption data is parsed | 370 // On Linux/Android/Chrome OS, system-wide memory consumption data is parsed |
| 371 // from /proc/meminfo and /proc/vmstat. On Windows/Mac, it is obtained using | 371 // from /proc/meminfo and /proc/vmstat. On Windows/Mac, it is obtained using |
| 372 // system API calls. | 372 // system API calls. |
| 373 // | 373 // |
| 374 // Fills in the provided |meminfo| structure. Returns true on success. | 374 // Fills in the provided |meminfo| structure. Returns true on success. |
| 375 // Exposed for memory debugging widget. | 375 // Exposed for memory debugging widget. |
| 376 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); | 376 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); |
| 377 | 377 |
| 378 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || | 378 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || |
| 379 // defined(OS_ANDROID) | 379 // defined(OS_ANDROID) |
| 380 | 380 |
| 381 #if defined(OS_LINUX) || defined(OS_ANDROID) | 381 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_AIX) |
| 382 // Parse the data found in /proc/<pid>/stat and return the sum of the | 382 // Parse the data found in /proc/<pid>/stat and return the sum of the |
| 383 // CPU-related ticks. Returns -1 on parse error. | 383 // CPU-related ticks. Returns -1 on parse error. |
| 384 // Exposed for testing. | 384 // Exposed for testing. |
| 385 BASE_EXPORT int ParseProcStatCPU(const std::string& input); | 385 BASE_EXPORT int ParseProcStatCPU(const std::string& input); |
| 386 | 386 |
| 387 // Get the number of threads of |process| as available in /proc/<pid>/stat. | 387 // Get the number of threads of |process| as available in /proc/<pid>/stat. |
| 388 // This should be used with care as no synchronization with running threads is | 388 // This should be used with care as no synchronization with running threads is |
| 389 // done. This is mostly useful to guarantee being single-threaded. | 389 // done. This is mostly useful to guarantee being single-threaded. |
| 390 // Returns 0 on failure. | 390 // Returns 0 on failure. |
| 391 BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); | 391 BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // |size| and |info| are output parameters, only valid on Success. | 520 // |size| and |info| are output parameters, only valid on Success. |
| 521 BASE_EXPORT MachVMRegionResult GetBasicInfo(mach_port_t task, | 521 BASE_EXPORT MachVMRegionResult GetBasicInfo(mach_port_t task, |
| 522 mach_vm_size_t* size, | 522 mach_vm_size_t* size, |
| 523 mach_vm_address_t* address, | 523 mach_vm_address_t* address, |
| 524 vm_region_basic_info_64* info); | 524 vm_region_basic_info_64* info); |
| 525 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 525 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 526 | 526 |
| 527 } // namespace base | 527 } // namespace base |
| 528 | 528 |
| 529 #endif // BASE_PROCESS_PROCESS_METRICS_H_ | 529 #endif // BASE_PROCESS_PROCESS_METRICS_H_ |
| OLD | NEW |