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