| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 BASE_EXPORT int ParseProcStatCPU(const std::string& input); | 231 BASE_EXPORT int ParseProcStatCPU(const std::string& input); |
| 232 | 232 |
| 233 // Get the number of threads of |process| as available in /proc/<pid>/stat. | 233 // Get the number of threads of |process| as available in /proc/<pid>/stat. |
| 234 // This should be used with care as no synchronization with running threads is | 234 // This should be used with care as no synchronization with running threads is |
| 235 // done. This is mostly useful to guarantee being single-threaded. | 235 // done. This is mostly useful to guarantee being single-threaded. |
| 236 // Returns 0 on failure. | 236 // Returns 0 on failure. |
| 237 BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); | 237 BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); |
| 238 | 238 |
| 239 // /proc/self/exe refers to the current executable. | 239 // /proc/self/exe refers to the current executable. |
| 240 BASE_EXPORT extern const char kProcSelfExe[]; | 240 BASE_EXPORT extern const char kProcSelfExe[]; |
| 241 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 241 | 242 |
| 242 // Data from /proc/meminfo about system-wide memory consumption. | 243 // Data from /proc/meminfo about system-wide memory consumption. |
| 243 // Values are in KB. | 244 // Values are in KB. |
| 244 struct BASE_EXPORT SystemMemoryInfoKB { | 245 struct BASE_EXPORT SystemMemoryInfoKB { |
| 245 SystemMemoryInfoKB(); | 246 SystemMemoryInfoKB(); |
| 246 | 247 |
| 248 // Serializes the platform specific fields to value. |
| 249 Value* AsValue() const; |
| 250 |
| 251 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 247 int total; | 252 int total; |
| 248 int free; | 253 int free; |
| 249 int buffers; | 254 int buffers; |
| 250 int cached; | 255 int cached; |
| 251 int active_anon; | 256 int active_anon; |
| 252 int inactive_anon; | 257 int inactive_anon; |
| 253 int active_file; | 258 int active_file; |
| 254 int inactive_file; | 259 int inactive_file; |
| 255 int swap_total; | 260 int swap_total; |
| 256 int swap_free; | 261 int swap_free; |
| 257 int dirty; | 262 int dirty; |
| 258 | 263 |
| 259 // vmstats data. | 264 // vmstats data. |
| 260 int pswpin; | 265 int pswpin; |
| 261 int pswpout; | 266 int pswpout; |
| 262 int pgmajfault; | 267 int pgmajfault; |
| 263 int bytes_swpin_per_sec; | 268 int bytes_swpin_per_sec; |
| 264 int bytes_swpout_per_sec; | 269 int bytes_swpout_per_sec; |
| 265 int pgmajfault_per_sec; | 270 int pgmajfault_per_sec; |
| 266 | 271 #endif |
| 267 #ifdef OS_CHROMEOS | 272 #ifdef OS_CHROMEOS |
| 268 int shmem; | 273 int shmem; |
| 269 int slab; | 274 int slab; |
| 270 // Gem data will be -1 if not supported. | 275 // Gem data will be -1 if not supported. |
| 271 int gem_objects; | 276 int gem_objects; |
| 272 long long gem_size; | 277 long long gem_size; |
| 273 #endif | 278 #endif |
| 274 }; | 279 }; |
| 275 | 280 |
| 276 // Retrieves data from /proc/meminfo and /proc/vmstat | 281 // Retrieves data from /proc/meminfo and /proc/vmstat |
| 277 // about system-wide memory consumption. | 282 // about system-wide memory consumption. |
| 278 // Fills in the provided |meminfo| structure. Returns true on success. | 283 // Fills in the provided |meminfo| structure. Returns true on success. |
| 279 // Exposed for memory debugging widget. | 284 // Exposed for memory debugging widget. |
| 280 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); | 285 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); |
| 281 | 286 |
| 282 // Data from /proc/diskstats about system-wide disk I/O. | 287 // Data from /proc/diskstats about system-wide disk I/O. |
| 283 struct BASE_EXPORT SystemDiskInfo { | 288 struct BASE_EXPORT SystemDiskInfo { |
| 284 SystemDiskInfo(); | 289 SystemDiskInfo(); |
| 285 | 290 |
| 291 // Serializes the platform specific fields to value. |
| 292 Value* AsValue() const; |
| 293 |
| 294 #if defined(OS_LINUX) |
| 286 uint64 reads; | 295 uint64 reads; |
| 287 uint64 reads_merged; | 296 uint64 reads_merged; |
| 288 uint64 sectors_read; | 297 uint64 sectors_read; |
| 289 uint64 read_time; | 298 uint64 read_time; |
| 290 uint64 writes; | 299 uint64 writes; |
| 291 uint64 writes_merged; | 300 uint64 writes_merged; |
| 292 uint64 sectors_written; | 301 uint64 sectors_written; |
| 293 uint64 write_time; | 302 uint64 write_time; |
| 294 uint64 io; | 303 uint64 io; |
| 295 uint64 io_time; | 304 uint64 io_time; |
| 296 uint64 weighted_io_time; | 305 uint64 weighted_io_time; |
| 297 uint64 bytes_read_per_sec; | 306 uint64 bytes_read_per_sec; |
| 298 uint64 bytes_written_per_sec; | 307 uint64 bytes_written_per_sec; |
| 308 #endif |
| 299 }; | 309 }; |
| 300 | 310 |
| 301 // Checks whether the candidate string is a valid disk name, [sh]d[a-z]+ | 311 // Checks whether the candidate string is a valid disk name, [sh]d[a-z]+ |
| 302 // for a generic disk or mmcblk[0-9]+ for the MMC case. | 312 // for a generic disk or mmcblk[0-9]+ for the MMC case. |
| 303 // Names of disk partitions (e.g. sda1) are not valid. | 313 // Names of disk partitions (e.g. sda1) are not valid. |
| 304 BASE_EXPORT bool ValidDiskName(const std::string& candidate); | 314 BASE_EXPORT bool ValidDiskName(const std::string& candidate); |
| 305 | 315 |
| 306 // Retrieves data from /proc/diskstats about system-wide disk I/O. | 316 // Retrieves data from /proc/diskstats about system-wide disk I/O. |
| 307 // Fills in the provided |diskinfo| structure. Returns true on success. | 317 // Fills in the provided |diskinfo| structure. Returns true on success. |
| 308 BASE_EXPORT bool GetSystemDiskInfo(SystemDiskInfo* diskinfo); | 318 BASE_EXPORT bool GetSystemDiskInfo(SystemDiskInfo* diskinfo); |
| 309 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | |
| 310 | 319 |
| 311 #if defined(OS_CHROMEOS) | 320 #if defined(OS_CHROMEOS) |
| 312 // Data from files in directory /sys/block/zram0 about ZRAM usage. | 321 // Data from files in directory /sys/block/zram0 about ZRAM usage. |
| 313 struct BASE_EXPORT SwapInfo { | 322 struct BASE_EXPORT SwapInfo { |
| 314 SwapInfo() | 323 SwapInfo() |
| 315 : num_reads(0), | 324 : num_reads(0), |
| 316 num_writes(0), | 325 num_writes(0), |
| 317 compr_data_size(0), | 326 compr_data_size(0), |
| 318 orig_data_size(0), | 327 orig_data_size(0), |
| 319 mem_used_total(0) { | 328 mem_used_total(0) { |
| 320 } | 329 } |
| 321 | 330 |
| 331 // Serializes the platform specific fields to value. |
| 332 Value* AsValue() const; |
| 333 |
| 322 uint64 num_reads; | 334 uint64 num_reads; |
| 323 uint64 num_writes; | 335 uint64 num_writes; |
| 324 uint64 compr_data_size; | 336 uint64 compr_data_size; |
| 325 uint64 orig_data_size; | 337 uint64 orig_data_size; |
| 326 uint64 mem_used_total; | 338 uint64 mem_used_total; |
| 327 }; | 339 }; |
| 328 | 340 |
| 329 // In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data. | 341 // In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data. |
| 330 // Fills in the provided |swap_data| structure. | 342 // Fills in the provided |swap_data| structure. |
| 331 BASE_EXPORT void GetSwapInfo(SwapInfo* swap_info); | 343 BASE_EXPORT void GetSwapInfo(SwapInfo* swap_info); |
| 332 #endif // defined(OS_CHROMEOS) | 344 #endif // defined(OS_CHROMEOS) |
| 333 | 345 |
| 334 // Collects and holds performance metrics for system memory and disk. | 346 // Collects and holds performance metrics for system memory and disk. |
| 335 // Provides functionality to retrieve the data on various platforms and | 347 // Provides functionality to retrieve the data on various platforms and |
| 336 // to serialize the stored data. | 348 // to serialize the stored data. |
| 337 class SystemMetrics { | 349 class SystemMetrics { |
| 338 public: | 350 public: |
| 339 SystemMetrics() : committed_memory_(0) { } | 351 SystemMetrics() : committed_memory_(0) { } |
| 340 | 352 |
| 341 static SystemMetrics GetCurrent(); | 353 static SystemMetrics GetCurrent(); |
| 342 | 354 |
| 355 // Serializes the system metrics to value. |
| 356 Value* AsValue() const; |
| 357 |
| 343 private: | 358 private: |
| 344 FRIEND_TEST_ALL_PREFIXES(SystemMetricsTest, SystemMetrics); | 359 FRIEND_TEST_ALL_PREFIXES(SystemMetricsTest, SystemMetrics); |
| 345 | 360 |
| 346 size_t committed_memory_; | 361 size_t committed_memory_; |
| 347 #if defined(OS_LINUX) || defined(OS_ANDROID) | |
| 348 SystemMemoryInfoKB memory_info_; | 362 SystemMemoryInfoKB memory_info_; |
| 363 SystemDiskInfo disk_info_; |
| 364 #ifdef OS_CHROMEOS |
| 365 SwapInfo swap_info_; |
| 349 #endif | 366 #endif |
| 350 }; | 367 }; |
| 351 | 368 |
| 352 } // namespace base | 369 } // namespace base |
| 353 | 370 |
| 354 #endif // BASE_PROCESS_PROCESS_METRICS_H_ | 371 #endif // BASE_PROCESS_PROCESS_METRICS_H_ |
| OLD | NEW |