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 #pragma once | 10 #pragma once |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 // Provides performance metrics for a specified process (CPU usage, memory and | 692 // Provides performance metrics for a specified process (CPU usage, memory and |
693 // IO counters). To use it, invoke CreateProcessMetrics() to get an instance | 693 // IO counters). To use it, invoke CreateProcessMetrics() to get an instance |
694 // for a specific process, then access the information with the different get | 694 // for a specific process, then access the information with the different get |
695 // methods. | 695 // methods. |
696 class BASE_EXPORT ProcessMetrics { | 696 class BASE_EXPORT ProcessMetrics { |
697 public: | 697 public: |
698 ~ProcessMetrics(); | 698 ~ProcessMetrics(); |
699 | 699 |
700 // Creates a ProcessMetrics for the specified process. | 700 // Creates a ProcessMetrics for the specified process. |
701 // The caller owns the returned object. | 701 // The caller owns the returned object. |
702 #if !defined(OS_MACOSX) | 702 #if !defined(OS_MACOSX) || defined(OS_IOS) |
703 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); | 703 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); |
704 #else | 704 #else |
705 class PortProvider { | 705 class PortProvider { |
706 public: | 706 public: |
707 // Should return the mach task for |process| if possible, or else | 707 // Should return the mach task for |process| if possible, or else |
708 // |MACH_PORT_NULL|. Only processes that this returns tasks for will have | 708 // |MACH_PORT_NULL|. Only processes that this returns tasks for will have |
709 // metrics on OS X (except for the current process, which always gets | 709 // metrics on OS X (except for the current process, which always gets |
710 // metrics). | 710 // metrics). |
711 virtual mach_port_t TaskForPid(ProcessHandle process) const = 0; | 711 virtual mach_port_t TaskForPid(ProcessHandle process) const = 0; |
712 }; | 712 }; |
713 | 713 |
714 // The port provider needs to outlive the ProcessMetrics object returned by | 714 // The port provider needs to outlive the ProcessMetrics object returned by |
715 // this function. If NULL is passed as provider, the returned object | 715 // this function. If NULL is passed as provider, the returned object |
716 // only returns valid metrics if |process| is the current process. | 716 // only returns valid metrics if |process| is the current process. |
717 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, | 717 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, |
718 PortProvider* port_provider); | 718 PortProvider* port_provider); |
719 #endif // !defined(OS_MACOSX) | 719 #endif // !defined(OS_MACOSX) || defined(OS_IOS) |
720 | 720 |
721 // Returns the current space allocated for the pagefile, in bytes (these pages | 721 // Returns the current space allocated for the pagefile, in bytes (these pages |
722 // may or may not be in memory). On Linux, this returns the total virtual | 722 // may or may not be in memory). On Linux, this returns the total virtual |
723 // memory size. | 723 // memory size. |
724 size_t GetPagefileUsage() const; | 724 size_t GetPagefileUsage() const; |
725 // Returns the peak space allocated for the pagefile, in bytes. | 725 // Returns the peak space allocated for the pagefile, in bytes. |
726 size_t GetPeakPagefileUsage() const; | 726 size_t GetPeakPagefileUsage() const; |
727 // Returns the current working set size, in bytes. On Linux, this returns | 727 // Returns the current working set size, in bytes. On Linux, this returns |
728 // the resident set size. | 728 // the resident set size. |
729 size_t GetWorkingSetSize() const; | 729 size_t GetWorkingSetSize() const; |
(...skipping 27 matching lines...) Expand all Loading... |
757 double GetCPUUsage(); | 757 double GetCPUUsage(); |
758 | 758 |
759 // Retrieves accounting information for all I/O operations performed by the | 759 // Retrieves accounting information for all I/O operations performed by the |
760 // process. | 760 // process. |
761 // If IO information is retrieved successfully, the function returns true | 761 // If IO information is retrieved successfully, the function returns true |
762 // and fills in the IO_COUNTERS passed in. The function returns false | 762 // and fills in the IO_COUNTERS passed in. The function returns false |
763 // otherwise. | 763 // otherwise. |
764 bool GetIOCounters(IoCounters* io_counters) const; | 764 bool GetIOCounters(IoCounters* io_counters) const; |
765 | 765 |
766 private: | 766 private: |
767 #if !defined(OS_MACOSX) | 767 #if !defined(OS_MACOSX) || defined(OS_IOS) |
768 explicit ProcessMetrics(ProcessHandle process); | 768 explicit ProcessMetrics(ProcessHandle process); |
769 #else | 769 #else |
770 ProcessMetrics(ProcessHandle process, PortProvider* port_provider); | 770 ProcessMetrics(ProcessHandle process, PortProvider* port_provider); |
771 #endif // defined(OS_MACOSX) | 771 #endif // !defined(OS_MACOSX) || defined(OS_IOS) |
772 | 772 |
773 ProcessHandle process_; | 773 ProcessHandle process_; |
774 | 774 |
775 int processor_count_; | 775 int processor_count_; |
776 | 776 |
777 // Used to store the previous times and CPU usage counts so we can | 777 // Used to store the previous times and CPU usage counts so we can |
778 // compute the CPU usage between calls. | 778 // compute the CPU usage between calls. |
779 int64 last_time_; | 779 int64 last_time_; |
780 int64 last_system_time_; | 780 int64 last_system_time_; |
781 | 781 |
| 782 #if !defined(OS_IOS) |
782 #if defined(OS_MACOSX) | 783 #if defined(OS_MACOSX) |
783 // Queries the port provider if it's set. | 784 // Queries the port provider if it's set. |
784 mach_port_t TaskForPid(ProcessHandle process) const; | 785 mach_port_t TaskForPid(ProcessHandle process) const; |
785 | 786 |
786 PortProvider* port_provider_; | 787 PortProvider* port_provider_; |
787 #elif defined(OS_POSIX) | 788 #elif defined(OS_POSIX) |
788 // Jiffie count at the last_time_ we updated. | 789 // Jiffie count at the last_time_ we updated. |
789 int last_cpu_; | 790 int last_cpu_; |
790 #endif // defined(OS_POSIX) | 791 #endif // defined(OS_POSIX) |
| 792 #endif // !defined(OS_IOS) |
791 | 793 |
792 DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); | 794 DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); |
793 }; | 795 }; |
794 | 796 |
795 #if defined(OS_LINUX) || defined(OS_ANDROID) | 797 #if defined(OS_LINUX) || defined(OS_ANDROID) |
796 // Data from /proc/meminfo about system-wide memory consumption. | 798 // Data from /proc/meminfo about system-wide memory consumption. |
797 // Values are in KB. | 799 // Values are in KB. |
798 struct BASE_EXPORT SystemMemoryInfoKB { | 800 struct BASE_EXPORT SystemMemoryInfoKB { |
799 SystemMemoryInfoKB(); | 801 SystemMemoryInfoKB(); |
800 | 802 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 // instance running inside the parent. The parent's Breakpad instance should | 856 // instance running inside the parent. The parent's Breakpad instance should |
855 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 857 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
856 // in the child after forking will restore the standard exception handler. | 858 // in the child after forking will restore the standard exception handler. |
857 // See http://crbug.com/20371/ for more details. | 859 // See http://crbug.com/20371/ for more details. |
858 void RestoreDefaultExceptionHandler(); | 860 void RestoreDefaultExceptionHandler(); |
859 #endif // defined(OS_MACOSX) | 861 #endif // defined(OS_MACOSX) |
860 | 862 |
861 } // namespace base | 863 } // namespace base |
862 | 864 |
863 #endif // BASE_PROCESS_UTIL_H_ | 865 #endif // BASE_PROCESS_UTIL_H_ |
OLD | NEW |