| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // priv (private): These pages (kbytes) cannot be shared with any other process. | 310 // priv (private): These pages (kbytes) cannot be shared with any other process. |
| 311 // shareable: These pages (kbytes) can be shared with other processes under | 311 // shareable: These pages (kbytes) can be shared with other processes under |
| 312 // the right circumstances. | 312 // the right circumstances. |
| 313 // shared : These pages (kbytes) are currently shared with at least one | 313 // shared : These pages (kbytes) are currently shared with at least one |
| 314 // other process. | 314 // other process. |
| 315 // | 315 // |
| 316 // On Linux: | 316 // On Linux: |
| 317 // priv: Pages mapped only by this process | 317 // priv: Pages mapped only by this process |
| 318 // shared: PSS or 0 if the kernel doesn't support this | 318 // shared: PSS or 0 if the kernel doesn't support this |
| 319 // shareable: 0 | 319 // shareable: 0 |
| 320 // | |
| 321 // On OS X: TODO(thakis): Revise. | |
| 322 // priv: Memory. | |
| 323 // shared: 0 | |
| 324 // shareable: 0 | |
| 325 struct WorkingSetKBytes { | 320 struct WorkingSetKBytes { |
| 326 WorkingSetKBytes() : priv(0), shareable(0), shared(0) {} | 321 WorkingSetKBytes() : priv(0), shareable(0), shared(0) {} |
| 327 size_t priv; | 322 size_t priv; |
| 328 size_t shareable; | 323 size_t shareable; |
| 329 size_t shared; | 324 size_t shared; |
| 330 }; | 325 }; |
| 331 | 326 |
| 332 // Committed (resident + paged) memory usage broken down by | 327 // Committed (resident + paged) memory usage broken down by |
| 333 // private: These pages cannot be shared with any other process. | 328 // private: These pages cannot be shared with any other process. |
| 334 // mapped: These pages are mapped into the view of a section (backed by | 329 // mapped: These pages are mapped into the view of a section (backed by |
| (...skipping 22 matching lines...) Expand all Loading... |
| 357 int64 TimeValToMicroseconds(const struct timeval& tv); | 352 int64 TimeValToMicroseconds(const struct timeval& tv); |
| 358 | 353 |
| 359 // Provides performance metrics for a specified process (CPU usage, memory and | 354 // Provides performance metrics for a specified process (CPU usage, memory and |
| 360 // IO counters). To use it, invoke CreateProcessMetrics() to get an instance | 355 // IO counters). To use it, invoke CreateProcessMetrics() to get an instance |
| 361 // for a specific process, then access the information with the different get | 356 // for a specific process, then access the information with the different get |
| 362 // methods. | 357 // methods. |
| 363 class ProcessMetrics { | 358 class ProcessMetrics { |
| 364 public: | 359 public: |
| 365 // Creates a ProcessMetrics for the specified process. | 360 // Creates a ProcessMetrics for the specified process. |
| 366 // The caller owns the returned object. | 361 // The caller owns the returned object. |
| 367 #if !defined(OS_MACOSX) | |
| 368 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); | 362 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); |
| 369 #else | |
| 370 class PortProvider { | |
| 371 public: | |
| 372 // Should return the mach task for |process| if possible, or else 0. Only | |
| 373 // processes that this returns tasks for will have metrics on OS X (except | |
| 374 // for the current process, which always gets metrics). | |
| 375 virtual mach_port_t TaskForPid(ProcessHandle process) const = 0; | |
| 376 }; | |
| 377 | |
| 378 // The port provider needs to outlive the ProcessMetrics object returned by | |
| 379 // this function. If NULL is passed as provider, the returned object | |
| 380 // only returns valid metrics if |process| is the current process. | |
| 381 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, | |
| 382 PortProvider* port_provider); | |
| 383 #endif | |
| 384 | 363 |
| 385 ~ProcessMetrics(); | 364 ~ProcessMetrics(); |
| 386 | 365 |
| 387 // Returns the current space allocated for the pagefile, in bytes (these pages | 366 // Returns the current space allocated for the pagefile, in bytes (these pages |
| 388 // may or may not be in memory). On Linux, this returns the total virtual | 367 // may or may not be in memory). On Linux, this returns the total virtual |
| 389 // memory size. | 368 // memory size. |
| 390 size_t GetPagefileUsage() const; | 369 size_t GetPagefileUsage() const; |
| 391 // Returns the peak space allocated for the pagefile, in bytes. | 370 // Returns the peak space allocated for the pagefile, in bytes. |
| 392 size_t GetPeakPagefileUsage() const; | 371 size_t GetPeakPagefileUsage() const; |
| 393 // Returns the current working set size, in bytes. On Linux, this returns | 372 // Returns the current working set size, in bytes. On Linux, this returns |
| (...skipping 27 matching lines...) Expand all Loading... |
| 421 int GetCPUUsage(); | 400 int GetCPUUsage(); |
| 422 | 401 |
| 423 // Retrieves accounting information for all I/O operations performed by the | 402 // Retrieves accounting information for all I/O operations performed by the |
| 424 // process. | 403 // process. |
| 425 // If IO information is retrieved successfully, the function returns true | 404 // If IO information is retrieved successfully, the function returns true |
| 426 // and fills in the IO_COUNTERS passed in. The function returns false | 405 // and fills in the IO_COUNTERS passed in. The function returns false |
| 427 // otherwise. | 406 // otherwise. |
| 428 bool GetIOCounters(IoCounters* io_counters) const; | 407 bool GetIOCounters(IoCounters* io_counters) const; |
| 429 | 408 |
| 430 private: | 409 private: |
| 431 #if !defined(OS_MACOSX) | |
| 432 explicit ProcessMetrics(ProcessHandle process); | 410 explicit ProcessMetrics(ProcessHandle process); |
| 433 #else | |
| 434 ProcessMetrics(ProcessHandle process, PortProvider* port_provider); | |
| 435 #endif | |
| 436 | 411 |
| 437 ProcessHandle process_; | 412 ProcessHandle process_; |
| 438 | 413 |
| 439 int processor_count_; | 414 int processor_count_; |
| 440 | 415 |
| 441 // Used to store the previous times and CPU usage counts so we can | 416 // Used to store the previous times and CPU usage counts so we can |
| 442 // compute the CPU usage between calls. | 417 // compute the CPU usage between calls. |
| 443 int64 last_time_; | 418 int64 last_time_; |
| 444 int64 last_system_time_; | 419 int64 last_system_time_; |
| 445 | 420 |
| 446 #if defined(OS_LINUX) | 421 #if defined(OS_LINUX) |
| 447 // Jiffie count at the last_time_ we updated. | 422 // Jiffie count at the last_time_ we updated. |
| 448 int last_cpu_; | 423 int last_cpu_; |
| 449 #endif | 424 #endif |
| 450 | 425 |
| 451 #if defined(OS_MACOSX) | |
| 452 // Queries the port provider if it's set. | |
| 453 mach_port_t TaskForPid(ProcessHandle process) const; | |
| 454 | |
| 455 PortProvider* port_provider_; | |
| 456 #endif | |
| 457 | |
| 458 DISALLOW_EVIL_CONSTRUCTORS(ProcessMetrics); | 426 DISALLOW_EVIL_CONSTRUCTORS(ProcessMetrics); |
| 459 }; | 427 }; |
| 460 | 428 |
| 461 // Returns the memory commited by the system in KBytes. | 429 // Returns the memory commited by the system in KBytes. |
| 462 // Returns 0 if it can't compute the commit charge. | 430 // Returns 0 if it can't compute the commit charge. |
| 463 size_t GetSystemCommitCharge(); | 431 size_t GetSystemCommitCharge(); |
| 464 | 432 |
| 465 // Enables low fragmentation heap (LFH) for every heaps of this process. This | 433 // Enables low fragmentation heap (LFH) for every heaps of this process. This |
| 466 // won't have any effect on heaps created after this function call. It will not | 434 // won't have any effect on heaps created after this function call. It will not |
| 467 // modify data allocated in the heaps before calling this function. So it is | 435 // modify data allocated in the heaps before calling this function. So it is |
| (...skipping 30 matching lines...) Expand all Loading... |
| 498 // instance running inside the parent. The parent's Breakpad instance should | 466 // instance running inside the parent. The parent's Breakpad instance should |
| 499 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 467 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
| 500 // in the child after forking will restore the standard exception handler. | 468 // in the child after forking will restore the standard exception handler. |
| 501 // See http://crbug.com/20371/ for more details. | 469 // See http://crbug.com/20371/ for more details. |
| 502 void RestoreDefaultExceptionHandler(); | 470 void RestoreDefaultExceptionHandler(); |
| 503 #endif | 471 #endif |
| 504 | 472 |
| 505 } // namespace base | 473 } // namespace base |
| 506 | 474 |
| 507 #endif // BASE_PROCESS_UTIL_H_ | 475 #endif // BASE_PROCESS_UTIL_H_ |
| OLD | NEW |