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