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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 CommittedKBytes() : priv(0), mapped(0), image(0) {} | 83 CommittedKBytes() : priv(0), mapped(0), image(0) {} |
84 size_t priv; | 84 size_t priv; |
85 size_t mapped; | 85 size_t mapped; |
86 size_t image; | 86 size_t image; |
87 }; | 87 }; |
88 | 88 |
89 // Convert a POSIX timeval to microseconds. | 89 // Convert a POSIX timeval to microseconds. |
90 BASE_EXPORT int64 TimeValToMicroseconds(const struct timeval& tv); | 90 BASE_EXPORT int64 TimeValToMicroseconds(const struct timeval& tv); |
91 | 91 |
92 // Provides performance metrics for a specified process (CPU usage, memory and | 92 // Provides performance metrics for a specified process (CPU usage, memory and |
93 // IO counters). To use it, invoke CreateProcessMetrics() to get an instance | 93 // IO counters). Use CreateCurrentProcessMetrics() to get an instance for the |
94 // for a specific process, then access the information with the different get | 94 // current process, or CreateProcessMetrics() to get an instance for an |
| 95 // arbitrary process. Then, access the information with the different get |
95 // methods. | 96 // methods. |
96 class BASE_EXPORT ProcessMetrics { | 97 class BASE_EXPORT ProcessMetrics { |
97 public: | 98 public: |
98 ~ProcessMetrics(); | 99 ~ProcessMetrics(); |
99 | 100 |
100 // Creates a ProcessMetrics for the specified process. | 101 // Creates a ProcessMetrics for the specified process. |
101 // The caller owns the returned object. | 102 // The caller owns the returned object. |
102 #if !defined(OS_MACOSX) || defined(OS_IOS) | 103 #if !defined(OS_MACOSX) || defined(OS_IOS) |
103 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); | 104 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); |
104 #else | 105 #else |
105 | 106 |
106 // The port provider needs to outlive the ProcessMetrics object returned by | 107 // The port provider needs to outlive the ProcessMetrics object returned by |
107 // this function. If NULL is passed as provider, the returned object | 108 // this function. If NULL is passed as provider, the returned object |
108 // only returns valid metrics if |process| is the current process. | 109 // only returns valid metrics if |process| is the current process. |
109 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, | 110 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, |
110 PortProvider* port_provider); | 111 PortProvider* port_provider); |
111 #endif // !defined(OS_MACOSX) || defined(OS_IOS) | 112 #endif // !defined(OS_MACOSX) || defined(OS_IOS) |
112 | 113 |
| 114 // Creates a ProcessMetrics for the current process. This a cross-platform |
| 115 // convenience wrapper for CreateProcessMetrics(). |
| 116 // The caller owns the returned object. |
| 117 static ProcessMetrics* CreateCurrentProcessMetrics(); |
| 118 |
113 // Returns the current space allocated for the pagefile, in bytes (these pages | 119 // Returns the current space allocated for the pagefile, in bytes (these pages |
114 // may or may not be in memory). On Linux, this returns the total virtual | 120 // may or may not be in memory). On Linux, this returns the total virtual |
115 // memory size. | 121 // memory size. |
116 size_t GetPagefileUsage() const; | 122 size_t GetPagefileUsage() const; |
117 // Returns the peak space allocated for the pagefile, in bytes. | 123 // Returns the peak space allocated for the pagefile, in bytes. |
118 size_t GetPeakPagefileUsage() const; | 124 size_t GetPeakPagefileUsage() const; |
119 // Returns the current working set size, in bytes. On Linux, this returns | 125 // Returns the current working set size, in bytes. On Linux, this returns |
120 // the resident set size. | 126 // the resident set size. |
121 size_t GetWorkingSetSize() const; | 127 size_t GetWorkingSetSize() const; |
122 // Returns the peak working set size, in bytes. | 128 // Returns the peak working set size, in bytes. |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 SystemDiskInfo disk_info_; | 400 SystemDiskInfo disk_info_; |
395 #endif | 401 #endif |
396 #if defined(OS_CHROMEOS) | 402 #if defined(OS_CHROMEOS) |
397 SwapInfo swap_info_; | 403 SwapInfo swap_info_; |
398 #endif | 404 #endif |
399 }; | 405 }; |
400 | 406 |
401 } // namespace base | 407 } // namespace base |
402 | 408 |
403 #endif // BASE_PROCESS_PROCESS_METRICS_H_ | 409 #endif // BASE_PROCESS_PROCESS_METRICS_H_ |
OLD | NEW |