| 6 |
| // running on the system. |
| 7 |
| 8 | #ifndef BASE_PROCESS_PROCESS_METRICS_H_ |
| 9 | #define BASE_PROCESS_PROCESS_METRICS_H_ |
| 10 |
| 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
| 13 |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 |
| 17 | #include "base/base_export.h" |
| 18 | #include "base/gtest_prod_util.h" |
| 19 | #include "base/macros.h" |
| 20 | #include "base/process/process_handle.h" |
| 21 | #include "base/time/time.h" |
| 22 | #include "base/values.h" |
| 23 | #include "build/build_config.h" |
| 24 |
| 25 | #if defined(OS_MACOSX) |
| 26 | #include <mach/mach.h> |
| 27 | #include "base/process/port_provider_mac.h" |
| 28 |
| 29 | #if !defined(OS_IOS) |
| 30 | #include <mach/mach_vm.h> |
| 31 | #endif |
| 32 | #endif |
| 33 |
| 34 | #if defined(OS_WIN) |
| 35 | #include "base/win/scoped_handle.h" |
| 36 | #include "base/win/windows_types.h" |
| 37 | #endif |
| 38 |
| 39 | namespace base { |
| 40 |
| 41 | // Full declaration is in process_metrics_iocounters.h. |
| 42 | struct IoCounters; |
| 43 |
| 44 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 45 | // Minor and major page fault counts since the process creation. |
| 46 | // Both counts are process-wide, and exclude child processes. |
| 47 | // |
| 48 | // minor: Number of page faults that didn't require disk IO. |
| 49 | // major: Number of page faults that required disk IO. |
| 50 | struct PageFaultCounts { |
| 51 | int64_t minor; |
| 52 | int64_t major; |
| 53 | }; |
| 54 | #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 55 |
| 56 | // Convert a POSIX timeval to microseconds. |
| 57 | BASE_EXPORT int64_t TimeValToMicroseconds(const struct timeval& tv); |
| 58 |
| 59 | // Provides performance metrics for a specified process (CPU usage and IO |
| 60 | // counters). Use CreateCurrentProcessMetrics() to get an instance for the |
| 61 | // current process, or CreateProcessMetrics() to get an instance for an |
| 62 | // arbitrary process. Then, access the information with the different get |
| 63 | // methods. |
| 64 | // |
| 65 | // This class exposes a few platform-specific APIs for parsing memory usage, but |
| 66 | // these are not intended to generalize to other platforms, since the memory |
| 67 | // models differ substantially. |
| 68 | // |
| 69 | // To obtain consistent memory metrics, use the memory_instrumentation service. |
| 70 | // |
| 71 | // For further documentation on memory, see |
| 72 | // https://chromium.googlesource.com/chromium/src/+/HEAD/docs/README.md |
| 73 | class BASE_EXPORT ProcessMetrics { |
| 74 | public: |
| 75 | ~ProcessMetrics(); |
| 76 |
| 77 | // Creates a ProcessMetrics for the specified process. |
| 78 | #if !defined(OS_MACOSX) || defined(OS_IOS) |
| 79 | static std::unique_ptr<ProcessMetrics> CreateProcessMetrics( |
| 80 | ProcessHandle process); |
| 81 | #else |
| 82 |
| 83 | // The port provider needs to outlive the ProcessMetrics object returned by |
| 84 | // this function. If NULL is passed as provider, the returned object |
| 85 | // only returns valid metrics if |process| is the current process. |
| 86 | static std::unique_ptr<ProcessMetrics> CreateProcessMetrics( |
| 87 | ProcessHandle process, |
| 88 | PortProvider* port_provider); |
| 89 | #endif // !defined(OS_MACOSX) || defined(OS_IOS) |
| 90 |
| 91 | // Creates a ProcessMetrics for the current process. This a cross-platform |
| 92 | // convenience wrapper for CreateProcessMetrics(). |
| 93 | static std::unique_ptr<ProcessMetrics> CreateCurrentProcessMetrics(); |
| 94 |
| 95 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 96 | // Resident Set Size is a Linux/Android specific memory concept. Do not |
| 97 | // attempt to extend this to other platforms. |
| 98 | BASE_EXPORT size_t GetResidentSetSize() const; |
| 99 | #endif |
| 100 |
| 101 | // Returns the percentage of time spent executing, across all threads of the |
| 102 | // process, in the interval since the last time the method was called. Since |
| 103 | // this considers the total execution time across all threads in a process, |
| 104 | // the result can easily exceed 100% in multi-thread processes running on |
| 105 | // multi-core systems. In general the result is therefore a value in the |
| 106 | // range 0% to SysInfo::NumberOfProcessors() * 100%. |
| 107 | // |
| 108 | // To obtain the percentage of total available CPU resources consumed by this |
| 109 | // process over the interval, the caller must divide by NumberOfProcessors(). |
| 110 | // |
| 111 | // Since this API measures usage over an interval, it will return zero on the |
| 112 | // first call, and an actual value only on the second and subsequent calls. |
| 113 | double GetPlatformIndependentCPUUsage(); |
| 114 |
| 115 | // Returns the cumulative CPU usage across all threads of the process since |
| 116 | // process start. In case of multi-core processors, a process can consume CPU |
| 117 | // at a rate higher than wall-clock time, e.g. two cores at full utilization |
| 118 | // will result in a time delta of 2 seconds/per 1 wall-clock second. |
| 119 | TimeDelta GetCumulativeCPUUsage(); |
| 120 |
| 121 | // Returns the number of average idle cpu wakeups per second since the last |
| 122 | // call. |
| 123 | int GetIdleWakeupsPerSecond(); |
| 124 |
| 125 | #if defined(OS_MACOSX) |
| 126 | // Returns the number of average "package idle exits" per second, which have |
| 127 | // a higher energy impact than a regular wakeup, since the last call. |
| 128 | // |
| 129 | // From the powermetrics man page: |
| 130 | // "With the exception of some Mac Pro systems, Mac and |
| 131 | // iOS systems are typically single package systems, wherein all CPUs are |
| 132 | // part of a single processor complex (typically a single IC die) with shared |
| 133 | // logic that can include (depending on system specifics) shared last level |
| 134 | // caches, an integrated memory controller etc. When all CPUs in the package |
| 135 | // are idle, the hardware can power-gate significant portions of the shared |
| 136 | // logic in addition to each individual processor's logic, as well as take |
| 137 | // measures such as placing DRAM in to self-refresh (also referred to as |
| 138 | // auto-refresh), place interconnects into lower-power states etc" |
| 139 | int GetPackageIdleWakeupsPerSecond(); |
| 140 |
| 141 | // Returns "Energy Impact", a synthetic power estimation metric displayed by |
| 142 | // macOS in Activity Monitor and the battery menu. |
| 143 | int GetEnergyImpact(); |
| 144 | #endif |
| 145 |
| 146 | // Retrieves accounting information for all I/O operations performed by the |
| 147 | // process. |
| 148 | // If IO information is retrieved successfully, the function returns true |
| 149 | // and fills in the IO_COUNTERS passed in. The function returns false |
| 150 | // otherwise. |
| 151 | bool GetIOCounters(IoCounters* io_counters) const; |
| 152 |
| 153 | // Returns the number of bytes transferred to/from disk per second, across all |
| 154 | // threads of the process, in the interval since the last time the method was |
| 155 | // called. |
| 156 | // |
| 157 | // Since this API measures usage over an interval, it will return zero on the |
| 158 | // first call, and an actual value only on the second and subsequent calls. |
| 159 | uint64_t GetDiskUsageBytesPerSecond(); |
| 160 |
| 161 | // Returns the cumulative disk usage in bytes across all threads of the |
| 162 | // process since process start. |
| 163 | uint64_t GetCumulativeDiskUsageInBytes(); |
| 164 |
| 165 | #if defined(OS_POSIX) |
| 166 | // Returns the number of file descriptors currently open by the process, or |
| 167 | // -1 on error. |
| 168 | int GetOpenFdCount() const; |
| 169 |
| 170 | // Returns the soft limit of file descriptors that can be opened by the |
| 171 | // process, or -1 on error. |
| 172 | int GetOpenFdSoftLimit() const; |
| 173 | #endif // defined(OS_POSIX) |
| 174 |
| 175 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 176 | // Bytes of swap as reported by /proc/[pid]/status. |
| 177 | uint64_t GetVmSwapBytes() const; |
| 178 |
| 179 | // Minor and major page fault count as reported by /proc/[pid]/stat. |
| 180 | // Returns true for success. |
| 181 | bool GetPageFaultCounts(PageFaultCounts* counts) const; |
| 182 | #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 183 |
| 184 | // Returns total memory usage of malloc. |
| 185 | size_t GetMallocUsage(); |
| 186 |
| 187 | private: |
| 188 | #if !defined(OS_MACOSX) || defined(OS_IOS) |
| 189 | explicit ProcessMetrics(ProcessHandle process); |
| 190 | #else |
| 191 | ProcessMetrics(ProcessHandle process, PortProvider* port_provider); |
| 192 | #endif // !defined(OS_MACOSX) || defined(OS_IOS) |
| 193 |
| 194 | #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_AIX) |
| 195 | int CalculateIdleWakeupsPerSecond(uint64_t absolute_idle_wakeups); |
| 196 | #endif |
| 197 | #if defined(OS_MACOSX) |
| 198 | // The subset of wakeups that cause a "package exit" can be tracked on macOS. |
| 199 | // See |GetPackageIdleWakeupsForSecond| comment for more info. |
| 200 | int CalculatePackageIdleWakeupsPerSecond( |
| 201 | uint64_t absolute_package_idle_wakeups); |
| 202 | #endif |
| 203 |
| 204 | #if defined(OS_WIN) |
| 205 | win::ScopedHandle process_; |
| 206 | #else |
| 207 | ProcessHandle process_; |
| 208 | #endif |
| 209 |
| 210 | // Used to store the previous times and CPU usage counts so we can |
| 211 | // compute the CPU usage between calls. |
| 212 | TimeTicks last_cpu_time_; |
| 213 | #if !defined(OS_FREEBSD) || !defined(OS_POSIX) |
| 214 | TimeDelta last_cumulative_cpu_; |
| 215 | #endif |
| 216 |
| 217 | // Used to store the previous times and disk usage counts so we can |
| 218 | // compute the disk usage between calls. |
| 219 | TimeTicks last_disk_usage_time_; |
| 220 | // Number of bytes transferred to/from disk in bytes. |
| 221 | uint64_t last_cumulative_disk_usage_ = 0; |
| 222 |
| 223 | #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_AIX) |
| 224 | // Same thing for idle wakeups. |
| 225 | TimeTicks last_idle_wakeups_time_; |
| 226 | uint64_t last_absolute_idle_wakeups_; |
| 227 | #endif |
| 228 |
| 229 | #if defined(OS_MACOSX) |
| 230 | // And same thing for package idle exit wakeups. |
| 231 | TimeTicks last_package_idle_wakeups_time_; |
| 232 | uint64_t last_absolute_package_idle_wakeups_; |
| 233 | double last_energy_impact_; |
| 234 | // In mach_absolute_time units. |
| 235 | uint64_t last_energy_impact_time_; |
| 236 | #endif |
| 237 |
| 238 | #if !defined(OS_IOS) |
| 239 | #if defined(OS_MACOSX) |
| 240 | // Queries the port provider if it's set. |
| 241 | mach_port_t TaskForPid(ProcessHandle process) const; |
| 242 |
| 243 | PortProvider* port_provider_; |
| 244 | #endif // defined(OS_MACOSX) |
| 245 | #endif // !defined(OS_IOS) |
| 246 |
| 247 | DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); |
| 248 | }; |
| 249 |
| 250 | // Returns the memory committed by the system in KBytes. |
| 251 | // Returns 0 if it can't compute the commit charge. |
| 252 | BASE_EXPORT size_t GetSystemCommitCharge(); |
| 253 |
| 254 | // Returns the number of bytes in a memory page. Do not use this to compute |
| 255 | // the number of pages in a block of memory for calling mincore(). On some |
| 256 | // platforms, e.g. iOS, mincore() uses a different page size from what is |
| 257 | // returned by GetPageSize(). |
| 258 | BASE_EXPORT size_t GetPageSize(); |
| 259 |
| 260 | // Returns the maximum number of file descriptors that can be open by a process |
| 261 | // at once. If the number is unavailable, a conservative best guess is returned. |
| 262 | BASE_EXPORT size_t GetMaxFds(); |
| 263 |
| 264 | // Returns the maximum number of handles that can be open at once per process. |
| 265 | BASE_EXPORT size_t GetHandleLimit(); |
| 266 |
| 267 | #if defined(OS_POSIX) |
| 268 | // Increases the file descriptor soft limit to |max_descriptors| or the OS hard |
| 269 | // limit, whichever is lower. If the limit is already higher than |
| 270 | // |max_descriptors|, then nothing happens. |
| 271 | BASE_EXPORT void IncreaseFdLimitTo(unsigned int max_descriptors); |
| 272 | #endif // defined(OS_POSIX) |
| 273 |
| 274 | #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ |
| 275 | defined(OS_ANDROID) || defined(OS_AIX) || defined(OS_FUCHSIA) |
| 276 | // Data about system-wide memory consumption. Values are in KB. Available on |
| 277 | // Windows, Mac, Linux, Android and Chrome OS. |
| 278 | // |
| 279 | // Total memory are available on all platforms that implement |
| 280 | // GetSystemMemoryInfo(). Total/free swap memory are available on all platforms |
| 281 | // except on Mac. Buffers/cached/active_anon/inactive_anon/active_file/ |
| 282 | // inactive_file/dirty/reclaimable/pswpin/pswpout/pgmajfault are available on |
| 283 | // Linux/Android/Chrome OS. Shmem/slab/gem_objects/gem_size are Chrome OS only. |
| 284 | // Speculative/file_backed/purgeable are Mac and iOS only. |
| 285 | // Free is absent on Windows (see "avail_phys" below). |
| 286 | struct BASE_EXPORT SystemMemoryInfoKB { |
| 287 | SystemMemoryInfoKB(); |
| 288 | SystemMemoryInfoKB(const SystemMemoryInfoKB& other); |
| 289 |
| 290 | // Serializes the platform specific fields to value. |
| 291 | std::unique_ptr<DictionaryValue> ToValue() const; |
| 292 |
| 293 | int total = 0; |
| 294 |
| 295 | #if !defined(OS_WIN) |
| 296 | int free = 0; |
| 297 | #endif |
| 298 |
| 299 | #if defined(OS_WIN) |
| 300 | // "This is the amount of physical memory that can be immediately reused |
| 301 | // without having to write its contents to disk first. It is the sum of the |
| 302 | // size of the standby, free, and zero lists." (MSDN). |
| 303 | // Standby: not modified pages of physical ram (file-backed memory) that are |
| 304 | // not actively being used. |
| 305 | int avail_phys = 0; |
| 306 | #endif |
| 307 |
| 308 | #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_AIX) |
| 309 | // This provides an estimate of available memory as described here: |
| 310 | // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 |
| 311 | // NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always |
| 312 | // be 0 in earlier kernel versions. |
| 313 | // Note: it includes _all_ file-backed memory (active + inactive). |
| 314 | int available = 0; |
| 315 | #endif |
| 316 |
| 317 | #if !defined(OS_MACOSX) |
| 318 | int swap_total = 0; |
| 319 | int swap_free = 0; |
| 320 | #endif |
| 321 |
| 322 | #if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX) || \ |
| 323 | defined(OS_FUCHSIA) |
| 324 | int buffers = 0; |
| 325 | int cached = 0; |
| 326 | int active_anon = 0; |
| 327 | int inactive_anon = 0; |
| 328 | int active_file = 0; |
| 329 | int inactive_file = 0; |
| 330 | int dirty = 0; |
| 331 | int reclaimable = 0; |
| 332 | #endif // defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX) || |
| 333 | // defined(OS_FUCHSIA) |
| 334 |
| 335 | #if defined(OS_CHROMEOS) |
| 336 | int shmem = 0; |
| 337 | int slab = 0; |
| 338 | // Gem data will be -1 if not supported. |
| 339 | int gem_objects = -1; |
| 340 | long long gem_size = -1; |
| 341 | #endif // defined(OS_CHROMEOS) |
| 342 |
| 343 | #if defined(OS_MACOSX) |
| 344 | int speculative = 0; |
| 345 | int file_backed = 0; |
| 346 | int purgeable = 0; |
| 347 | #endif // defined(OS_MACOSX) |
| 348 | }; |
| 349 |
| 350 | // On Linux/Android/Chrome OS, system-wide memory consumption data is parsed |
| 351 | // from /proc/meminfo and /proc/vmstat. On Windows/Mac, it is obtained using |
| 352 | // system API calls. |
| 353 | // |
| 354 | // Fills in the provided |meminfo| structure. Returns true on success. |
| 355 | // Exposed for memory debugging widget. |
| 356 | BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); |
| 357 |
| 358 | #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || |
| 359 | // defined(OS_ANDROID) || defined(OS_AIX) || defined(OS_FUCHSIA) |
| 360 |
| 361 | #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_AIX) |
| 362 | // Parse the data found in /proc/<pid>/stat and return the sum of the |
| 363 | // CPU-related ticks. Returns -1 on parse error. |
| 364 | // Exposed for testing. |
| 365 | BASE_EXPORT int ParseProcStatCPU(StringPiece input); |
| 366 |
| 367 | // Get the number of threads of |process| as available in /proc/<pid>/stat. |
| 368 | // This should be used with care as no synchronization with running threads is |
| 369 | // done. This is mostly useful to guarantee being single-threaded. |
| 370 | // Returns 0 on failure. |
| 371 | BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); |
| 372 |
| 373 | // /proc/self/exe refers to the current executable. |
| 374 | BASE_EXPORT extern const char kProcSelfExe[]; |
| 375 |
| 376 | // Parses a string containing the contents of /proc/meminfo |
| 377 | // returns true on success or false for a parsing error |
| 378 | // Exposed for testing. |
| 379 | BASE_EXPORT bool ParseProcMeminfo(StringPiece input, |
| 380 | SystemMemoryInfoKB* meminfo); |
| 381 |
| 382 | // Data from /proc/vmstat. |
| 383 | struct BASE_EXPORT VmStatInfo { |
| 384 | // Serializes the platform specific fields to value. |
| 385 | std::unique_ptr<DictionaryValue> ToValue() const; |
| 386 |
| 387 | unsigned long pswpin = 0; |
| 388 | unsigned long pswpout = 0; |
| 389 | unsigned long pgmajfault = 0; |
| 390 | }; |
| 391 |
| 392 | // Retrieves data from /proc/vmstat about system-wide vm operations. |
| 393 | // Fills in the provided |vmstat| structure. Returns true on success. |
| 394 | BASE_EXPORT bool GetVmStatInfo(VmStatInfo* vmstat); |
| 395 |
| 396 | // Parses a string containing the contents of /proc/vmstat |
| 397 | // returns true on success or false for a parsing error |
| 398 | // Exposed for testing. |
| 399 | BASE_EXPORT bool ParseProcVmstat(StringPiece input, VmStatInfo* vmstat); |
| 400 |
| 401 | // Data from /proc/diskstats about system-wide disk I/O. |
| 402 | struct BASE_EXPORT SystemDiskInfo { |
| 403 | SystemDiskInfo(); |
| 404 | SystemDiskInfo(const SystemDiskInfo& other); |
| 405 |
| 406 | // Serializes the platform specific fields to value. |
| 407 | std::unique_ptr<Value> ToValue() const; |
| 408 |
| 409 | uint64_t reads = 0; |
| 410 | uint64_t reads_merged = 0; |
| 411 | uint64_t sectors_read = 0; |
| 412 | uint64_t read_time = 0; |
| 413 | uint64_t writes = 0; |
| 414 | uint64_t writes_merged = 0; |
| 415 | uint64_t sectors_written = 0; |
| 416 | uint64_t write_time = 0; |
| 417 | uint64_t io = 0; |
| 418 | uint64_t io_time = 0; |
| 419 | uint64_t weighted_io_time = 0; |
| 420 | }; |
| 421 |
| 422 | // Checks whether the candidate string is a valid disk name, [hsv]d[a-z]+ |
| 423 | // for a generic disk or mmcblk[0-9]+ for the MMC case. |
| 424 | // Names of disk partitions (e.g. sda1) are not valid. |
| 425 | BASE_EXPORT bool IsValidDiskName(StringPiece candidate); |
| 426 |
| 427 | // Retrieves data from /proc/diskstats about system-wide disk I/O. |
| 428 | // Fills in the provided |diskinfo| structure. Returns true on success. |
| 429 | BASE_EXPORT bool GetSystemDiskInfo(SystemDiskInfo* diskinfo); |
| 430 |
| 431 | // Returns the amount of time spent in user space since boot across all CPUs. |
| 432 | BASE_EXPORT TimeDelta GetUserCpuTimeSinceBoot(); |
| 433 |
| 434 | #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 435 |
| 436 | #if defined(OS_CHROMEOS) |
| 437 | // Data from files in directory /sys/block/zram0 about ZRAM usage. |
| 438 | struct BASE_EXPORT SwapInfo { |
| 439 | SwapInfo() |
| 440 | : num_reads(0), |
| 441 | num_writes(0), |
| 442 | compr_data_size(0), |
| 443 | orig_data_size(0), |
| 444 | mem_used_total(0) { |
| 445 | } |
| 446 |
| 447 | // Serializes the platform specific fields to value. |
| 448 | std::unique_ptr<Value> ToValue() const; |
| 449 |
| 450 | uint64_t num_reads = 0; |
| 451 | uint64_t num_writes = 0; |
| 452 | uint64_t compr_data_size = 0; |
| 453 | uint64_t orig_data_size = 0; |
| 454 | uint64_t mem_used_total = 0; |
| 455 | }; |
| 456 |
| 457 | // Parses a string containing the contents of /sys/block/zram0/mm_stat. |
| 458 | // This should be used for the new ZRAM sysfs interfaces. |
| 459 | // Returns true on success or false for a parsing error. |
| 460 | // Exposed for testing. |
| 461 | BASE_EXPORT bool ParseZramMmStat(StringPiece mm_stat_data, SwapInfo* swap_info); |
| 462 |
| 463 | // Parses a string containing the contents of /sys/block/zram0/stat |
| 464 | // This should be used for the new ZRAM sysfs interfaces. |
| 465 | // Returns true on success or false for a parsing error. |
| 466 | // Exposed for testing. |
| 467 | BASE_EXPORT bool ParseZramStat(StringPiece stat_data, SwapInfo* swap_info); |
| 468 |
| 469 | // In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data. |
| 470 | // Fills in the provided |swap_data| structure. |
| 471 | // Returns true on success or false for a parsing error. |
| 472 | BASE_EXPORT bool GetSwapInfo(SwapInfo* swap_info); |
| 473 | #endif // defined(OS_CHROMEOS) |
| 474 |
| 475 | struct BASE_EXPORT SystemPerformanceInfo { |
| 476 | SystemPerformanceInfo(); |
| 477 | SystemPerformanceInfo(const SystemPerformanceInfo& other); |
| 478 |
| 479 | // Serializes the platform specific fields to value. |
| 480 | std::unique_ptr<Value> ToValue() const; |
| 481 |
| 482 | // Total idle time of all processes in the system (units of 100 ns). |
| 483 | uint64_t idle_time = 0; |
| 484 | // Number of bytes read. |
| 485 | uint64_t read_transfer_count = 0; |
| 486 | // Number of bytes written. |
| 487 | uint64_t write_transfer_count = 0; |
| 488 | // Number of bytes transferred (e.g. DeviceIoControlFile) |
| 489 | uint64_t other_transfer_count = 0; |
| 490 | // The amount of read operations. |
| 491 | uint64_t read_operation_count = 0; |
| 492 | // The amount of write operations. |
| 493 | uint64_t write_operation_count = 0; |
| 494 | // The amount of other operations. |
| 495 | uint64_t other_operation_count = 0; |
| 496 | // The number of pages written to the system's pagefiles. |
| 497 | uint64_t pagefile_pages_written = 0; |
| 498 | // The number of write operations performed on the system's pagefiles. |
| 499 | uint64_t pagefile_pages_write_ios = 0; |
| 500 | // The number of pages of physical memory available to processes running on |
| 501 | // the system. |
| 502 | uint64_t available_pages = 0; |
| 503 | // The number of pages read from disk to resolve page faults. |
| 504 | uint64_t pages_read = 0; |
| 505 | // The number of read operations initiated to resolve page faults. |
| 506 | uint64_t page_read_ios = 0; |
| 507 | }; |
| 508 |
| 509 | // Retrieves performance counters from the operating system. |
| 510 | // Fills in the provided |info| structure. Returns true on success. |
| 511 | BASE_EXPORT bool GetSystemPerformanceInfo(SystemPerformanceInfo* info); |
| 512 |
| 513 | // Collects and holds performance metrics for system memory and disk. |
| 514 | // Provides functionality to retrieve the data on various platforms and |
| 515 | // to serialize the stored data. |
| 516 | class BASE_EXPORT SystemMetrics { |
| 517 | public: |
| 518 | SystemMetrics(); |
| 519 |
| 520 | static SystemMetrics Sample(); |
| 521 |
| 522 | // Serializes the system metrics to value. |
| 523 | std::unique_ptr<Value> ToValue() const; |
| 524 |
| 525 | private: |
| 526 | FRIEND_TEST_ALL_PREFIXES(SystemMetricsTest, SystemMetrics); |
| 527 |
| 528 | size_t committed_memory_; |
| 529 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 530 | SystemMemoryInfoKB memory_info_; |
| 531 | VmStatInfo vmstat_info_; |
| 532 | SystemDiskInfo disk_info_; |
| 533 | #endif |
| 534 | #if defined(OS_CHROMEOS) |
| 535 | SwapInfo swap_info_; |
| 536 | #endif |
| 537 | #if defined(OS_WIN) |
| 538 | SystemPerformanceInfo performance_; |
| 539 | #endif |
| 540 | }; |
| 541 |
| 542 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 543 | enum class MachVMRegionResult { |
| 544 | // There were no more memory regions between |address| and the end of the |
| 545 | // virtual address space. |
| 546 | Finished, |
| 547 |
| 548 | // All output parameters are invalid. |
| 549 | Error, |
| 550 |
| 551 | // All output parameters are filled in. |
| 552 | Success |
| 553 | }; |
| 554 |
| 555 | // Returns info on the first memory region at or after |address|, including |
| 556 | // resident memory and share mode. On Success, |size| reflects the size of the |
| 557 | // memory region. |
| 558 | // |size| and |info| are output parameters, only valid on Success. |
| 559 | // |address| is an in-out parameter, than represents both the address to start |
| 560 | // looking, and the start address of the memory region. |
| 561 | BASE_EXPORT MachVMRegionResult GetTopInfo(mach_port_t task, |
| 562 | mach_vm_size_t* size, |
| 563 | mach_vm_address_t* address, |
| 564 | vm_region_top_info_data_t* info); |
| 565 |
| 566 | // Returns info on the first memory region at or after |address|, including |
| 567 | // protection values. On Success, |size| reflects the size of the |
| 568 | // memory region. |
| 569 | // Returns info on the first memory region at or after |address|, including |
| 570 | // resident memory and share mode. |
| 571 | // |size| and |info| are output parameters, only valid on Success. |
| 572 | BASE_EXPORT MachVMRegionResult GetBasicInfo(mach_port_t task, |
| 573 | mach_vm_size_t* size, |
| 574 | mach_vm_address_t* address, |
| 575 | vm_region_basic_info_64* info); |
| 576 | #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 577 |
| 578 | } // namespace base |
| 579 |
| 580 | #endif // BASE_PROCESS_PROCESS_METRICS_H_ |
| 581 |