Chromium Code Reviews| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 // Sets the file descriptor soft limit to |max_descriptors| or the OS hard | 254 // Sets the file descriptor soft limit to |max_descriptors| or the OS hard |
| 255 // limit, whichever is lower. | 255 // limit, whichever is lower. |
| 256 BASE_EXPORT void SetFdLimit(unsigned int max_descriptors); | 256 BASE_EXPORT void SetFdLimit(unsigned int max_descriptors); |
| 257 #endif // defined(OS_POSIX) | 257 #endif // defined(OS_POSIX) |
| 258 | 258 |
| 259 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ | 259 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ |
| 260 defined(OS_ANDROID) | 260 defined(OS_ANDROID) |
| 261 // Data about system-wide memory consumption. Values are in KB. Available on | 261 // Data about system-wide memory consumption. Values are in KB. Available on |
| 262 // Windows, Mac, Linux, Android and Chrome OS. | 262 // Windows, Mac, Linux, Android and Chrome OS. |
| 263 // | 263 // |
| 264 // Total/free memory are available on all platforms that implement | 264 // Total memory are available on all platforms that implement |
| 265 // GetSystemMemoryInfo(). Total/free swap memory are available on all platforms | 265 // GetSystemMemoryInfo(). Total/free swap memory are available on all platforms |
| 266 // except on Mac. Buffers/cached/active_anon/inactive_anon/active_file/ | 266 // except on Mac. Buffers/cached/active_anon/inactive_anon/active_file/ |
| 267 // inactive_file/dirty/pswpin/pswpout/pgmajfault are available on | 267 // inactive_file/dirty/reclaimable/pswpin/pswpout/pgmajfault are available on |
| 268 // Linux/Android/Chrome OS. Shmem/slab/gem_objects/gem_size are Chrome OS only. | 268 // Linux/Android/Chrome OS. Shmem/slab/gem_objects/gem_size are Chrome OS only. |
| 269 // Speculative/file_backed/purgeable are Mac and iOS only. | |
| 270 // Free is absent on Windows (see "avail_phys" below). | |
| 269 struct BASE_EXPORT SystemMemoryInfoKB { | 271 struct BASE_EXPORT SystemMemoryInfoKB { |
| 270 SystemMemoryInfoKB(); | 272 SystemMemoryInfoKB(); |
| 271 SystemMemoryInfoKB(const SystemMemoryInfoKB& other); | 273 SystemMemoryInfoKB(const SystemMemoryInfoKB& other); |
|
danakj
2017/03/13 16:01:20
btw I think you can just omit this and you'll get
Michael K. (Yandex Team)
2017/03/14 03:49:09
Done.
Michael K. (Yandex Team)
2017/03/14 04:50:37
It doesn't work. So I'll revert.
(chromium-style p
dcheng
2017/03/14 05:10:09
Note: a struct isn't a POD if it has in-class memb
| |
| 272 | 274 |
| 273 // Serializes the platform specific fields to value. | 275 // Serializes the platform specific fields to value. |
| 274 std::unique_ptr<Value> ToValue() const; | 276 std::unique_ptr<Value> ToValue() const; |
| 275 | 277 |
| 276 int total; | 278 int total = 0; |
| 277 int free; | |
| 278 | 279 |
| 279 #if defined(OS_LINUX) | 280 #if !defined(OS_WIN) |
| 281 int free = 0; | |
| 282 #endif | |
| 283 | |
| 284 #if defined(OS_WIN) | |
| 285 // "This is the amount of physical memory that can be immediately reused | |
| 286 // without having to write its contents to disk first. It is the sum of the | |
| 287 // size of the standby, free, and zero lists." (MSDN). | |
| 288 // Standby: not modified pages of physical ram (file-backed memory) that are | |
| 289 // not actively being used. | |
| 290 // Note: on Windows this field has a bit different meaning from the Linux one | |
|
danakj
2017/03/13 16:01:20
This line no longer needed? Or at least reworded
Michael K. (Yandex Team)
2017/03/14 03:49:09
Done.
| |
| 291 // (see below). | |
| 292 int avail_phys = 0; | |
| 293 #endif | |
| 294 | |
| 295 #if defined(OS_LINUX) || defined(OS_ANDROID) | |
| 280 // This provides an estimate of available memory as described here: | 296 // This provides an estimate of available memory as described here: |
| 281 // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id= 34e431b0ae398fc54ea69ff85ec700722c9da773 | 297 // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id= 34e431b0ae398fc54ea69ff85ec700722c9da773 |
| 282 // NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always | 298 // NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always |
| 283 // be 0 in earlier kernel versions. | 299 // be 0 in earlier kernel versions. |
| 284 int available; | 300 // Note: on Linux "available" includes _all_ file-backed memory |
| 301 // (active + inactive). It is different from the Windows one (see above). | |
| 302 int available = 0; | |
| 285 #endif | 303 #endif |
| 286 | 304 |
| 287 #if !defined(OS_MACOSX) | 305 #if !defined(OS_MACOSX) |
| 288 int swap_total; | 306 int swap_total = 0; |
| 289 int swap_free; | 307 int swap_free = 0; |
| 290 #endif | 308 #endif |
| 291 | 309 |
| 292 #if defined(OS_ANDROID) || defined(OS_LINUX) | 310 #if defined(OS_ANDROID) || defined(OS_LINUX) |
| 293 int buffers; | 311 int buffers = 0; |
| 294 int cached; | 312 int cached = 0; |
| 295 int active_anon; | 313 int active_anon = 0; |
| 296 int inactive_anon; | 314 int inactive_anon = 0; |
| 297 int active_file; | 315 int active_file = 0; |
| 298 int inactive_file; | 316 int inactive_file = 0; |
| 299 int dirty; | 317 int dirty = 0; |
| 318 int reclaimable = 0; | |
| 300 | 319 |
| 301 // vmstats data. | 320 // vmstats data. |
| 302 unsigned long pswpin; | 321 unsigned long pswpin = 0; |
| 303 unsigned long pswpout; | 322 unsigned long pswpout = 0; |
| 304 unsigned long pgmajfault; | 323 unsigned long pgmajfault = 0; |
| 305 #endif // defined(OS_ANDROID) || defined(OS_LINUX) | 324 #endif // defined(OS_ANDROID) || defined(OS_LINUX) |
| 306 | 325 |
| 307 #if defined(OS_CHROMEOS) | 326 #if defined(OS_CHROMEOS) |
| 308 int shmem; | 327 int shmem = 0; |
| 309 int slab; | 328 int slab = 0; |
| 310 // Gem data will be -1 if not supported. | 329 // Gem data will be -1 if not supported. |
| 311 int gem_objects; | 330 int gem_objects = -1; |
| 312 long long gem_size; | 331 long long gem_size = -1; |
| 313 #endif // defined(OS_CHROMEOS) | 332 #endif // defined(OS_CHROMEOS) |
| 333 | |
| 334 #if defined(OS_MACOSX) | |
| 335 int speculative = 0; | |
| 336 int file_backed = 0; | |
| 337 int purgeable = 0; | |
| 338 #endif // defined(OS_MACOSX) | |
| 314 }; | 339 }; |
| 315 | 340 |
| 316 // On Linux/Android/Chrome OS, system-wide memory consumption data is parsed | 341 // On Linux/Android/Chrome OS, system-wide memory consumption data is parsed |
| 317 // from /proc/meminfo and /proc/vmstat. On Windows/Mac, it is obtained using | 342 // from /proc/meminfo and /proc/vmstat. On Windows/Mac, it is obtained using |
| 318 // system API calls. | 343 // system API calls. |
| 319 // | 344 // |
| 320 // Fills in the provided |meminfo| structure. Returns true on success. | 345 // Fills in the provided |meminfo| structure. Returns true on success. |
| 321 // Exposed for memory debugging widget. | 346 // Exposed for memory debugging widget. |
| 322 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); | 347 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); |
| 323 | 348 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 SystemDiskInfo disk_info_; | 455 SystemDiskInfo disk_info_; |
| 431 #endif | 456 #endif |
| 432 #if defined(OS_CHROMEOS) | 457 #if defined(OS_CHROMEOS) |
| 433 SwapInfo swap_info_; | 458 SwapInfo swap_info_; |
| 434 #endif | 459 #endif |
| 435 }; | 460 }; |
| 436 | 461 |
| 437 } // namespace base | 462 } // namespace base |
| 438 | 463 |
| 439 #endif // BASE_PROCESS_PROCESS_METRICS_H_ | 464 #endif // BASE_PROCESS_PROCESS_METRICS_H_ |
| OLD | NEW |