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 |
| 11 #include <stddef.h> |
| 12 #include <stdint.h> |
| 13 |
11 #include <string> | 14 #include <string> |
12 | 15 |
13 #include "base/base_export.h" | 16 #include "base/base_export.h" |
14 #include "base/basictypes.h" | |
15 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" |
16 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
17 #include "base/time/time.h" | 20 #include "base/time/time.h" |
18 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "build/build_config.h" |
19 | 23 |
20 #if defined(OS_MACOSX) | 24 #if defined(OS_MACOSX) |
21 #include <mach/mach.h> | 25 #include <mach/mach.h> |
22 #include "base/process/port_provider_mac.h" | 26 #include "base/process/port_provider_mac.h" |
23 #endif | 27 #endif |
24 | 28 |
25 namespace base { | 29 namespace base { |
26 | 30 |
27 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
28 struct IoCounters : public IO_COUNTERS { | 32 struct IoCounters : public IO_COUNTERS { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // image: These pages are mapped into the view of an image section (backed by | 84 // image: These pages are mapped into the view of an image section (backed by |
81 // file system) | 85 // file system) |
82 struct CommittedKBytes { | 86 struct CommittedKBytes { |
83 CommittedKBytes() : priv(0), mapped(0), image(0) {} | 87 CommittedKBytes() : priv(0), mapped(0), image(0) {} |
84 size_t priv; | 88 size_t priv; |
85 size_t mapped; | 89 size_t mapped; |
86 size_t image; | 90 size_t image; |
87 }; | 91 }; |
88 | 92 |
89 // Convert a POSIX timeval to microseconds. | 93 // Convert a POSIX timeval to microseconds. |
90 BASE_EXPORT int64 TimeValToMicroseconds(const struct timeval& tv); | 94 BASE_EXPORT int64_t TimeValToMicroseconds(const struct timeval& tv); |
91 | 95 |
92 // Provides performance metrics for a specified process (CPU usage, memory and | 96 // Provides performance metrics for a specified process (CPU usage, memory and |
93 // IO counters). Use CreateCurrentProcessMetrics() to get an instance for the | 97 // IO counters). Use CreateCurrentProcessMetrics() to get an instance for the |
94 // current process, or CreateProcessMetrics() to get an instance for an | 98 // current process, or CreateProcessMetrics() to get an instance for an |
95 // arbitrary process. Then, access the information with the different get | 99 // arbitrary process. Then, access the information with the different get |
96 // methods. | 100 // methods. |
97 class BASE_EXPORT ProcessMetrics { | 101 class BASE_EXPORT ProcessMetrics { |
98 public: | 102 public: |
99 ~ProcessMetrics(); | 103 ~ProcessMetrics(); |
100 | 104 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 192 |
189 #if defined(OS_LINUX) || defined(OS_ANDROID) | 193 #if defined(OS_LINUX) || defined(OS_ANDROID) |
190 bool GetWorkingSetKBytesStatm(WorkingSetKBytes* ws_usage) const; | 194 bool GetWorkingSetKBytesStatm(WorkingSetKBytes* ws_usage) const; |
191 #endif | 195 #endif |
192 | 196 |
193 #if defined(OS_CHROMEOS) | 197 #if defined(OS_CHROMEOS) |
194 bool GetWorkingSetKBytesTotmaps(WorkingSetKBytes *ws_usage) const; | 198 bool GetWorkingSetKBytesTotmaps(WorkingSetKBytes *ws_usage) const; |
195 #endif | 199 #endif |
196 | 200 |
197 #if defined(OS_MACOSX) || defined(OS_LINUX) | 201 #if defined(OS_MACOSX) || defined(OS_LINUX) |
198 int CalculateIdleWakeupsPerSecond(uint64 absolute_idle_wakeups); | 202 int CalculateIdleWakeupsPerSecond(uint64_t absolute_idle_wakeups); |
199 #endif | 203 #endif |
200 | 204 |
201 ProcessHandle process_; | 205 ProcessHandle process_; |
202 | 206 |
203 int processor_count_; | 207 int processor_count_; |
204 | 208 |
205 // Used to store the previous times and CPU usage counts so we can | 209 // Used to store the previous times and CPU usage counts so we can |
206 // compute the CPU usage between calls. | 210 // compute the CPU usage between calls. |
207 TimeTicks last_cpu_time_; | 211 TimeTicks last_cpu_time_; |
208 int64 last_system_time_; | 212 int64_t last_system_time_; |
209 | 213 |
210 #if defined(OS_MACOSX) || defined(OS_LINUX) | 214 #if defined(OS_MACOSX) || defined(OS_LINUX) |
211 // Same thing for idle wakeups. | 215 // Same thing for idle wakeups. |
212 TimeTicks last_idle_wakeups_time_; | 216 TimeTicks last_idle_wakeups_time_; |
213 uint64 last_absolute_idle_wakeups_; | 217 uint64_t last_absolute_idle_wakeups_; |
214 #endif | 218 #endif |
215 | 219 |
216 #if !defined(OS_IOS) | 220 #if !defined(OS_IOS) |
217 #if defined(OS_MACOSX) | 221 #if defined(OS_MACOSX) |
218 // Queries the port provider if it's set. | 222 // Queries the port provider if it's set. |
219 mach_port_t TaskForPid(ProcessHandle process) const; | 223 mach_port_t TaskForPid(ProcessHandle process) const; |
220 | 224 |
221 PortProvider* port_provider_; | 225 PortProvider* port_provider_; |
222 #elif defined(OS_POSIX) | 226 #elif defined(OS_POSIX) |
223 // Jiffie count at the last_cpu_time_ we updated. | 227 // Jiffie count at the last_cpu_time_ we updated. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 BASE_EXPORT bool ParseProcVmstat(const std::string& input, | 333 BASE_EXPORT bool ParseProcVmstat(const std::string& input, |
330 SystemMemoryInfoKB* meminfo); | 334 SystemMemoryInfoKB* meminfo); |
331 | 335 |
332 // Data from /proc/diskstats about system-wide disk I/O. | 336 // Data from /proc/diskstats about system-wide disk I/O. |
333 struct BASE_EXPORT SystemDiskInfo { | 337 struct BASE_EXPORT SystemDiskInfo { |
334 SystemDiskInfo(); | 338 SystemDiskInfo(); |
335 | 339 |
336 // Serializes the platform specific fields to value. | 340 // Serializes the platform specific fields to value. |
337 scoped_ptr<Value> ToValue() const; | 341 scoped_ptr<Value> ToValue() const; |
338 | 342 |
339 uint64 reads; | 343 uint64_t reads; |
340 uint64 reads_merged; | 344 uint64_t reads_merged; |
341 uint64 sectors_read; | 345 uint64_t sectors_read; |
342 uint64 read_time; | 346 uint64_t read_time; |
343 uint64 writes; | 347 uint64_t writes; |
344 uint64 writes_merged; | 348 uint64_t writes_merged; |
345 uint64 sectors_written; | 349 uint64_t sectors_written; |
346 uint64 write_time; | 350 uint64_t write_time; |
347 uint64 io; | 351 uint64_t io; |
348 uint64 io_time; | 352 uint64_t io_time; |
349 uint64 weighted_io_time; | 353 uint64_t weighted_io_time; |
350 }; | 354 }; |
351 | 355 |
352 // Checks whether the candidate string is a valid disk name, [hsv]d[a-z]+ | 356 // Checks whether the candidate string is a valid disk name, [hsv]d[a-z]+ |
353 // for a generic disk or mmcblk[0-9]+ for the MMC case. | 357 // for a generic disk or mmcblk[0-9]+ for the MMC case. |
354 // Names of disk partitions (e.g. sda1) are not valid. | 358 // Names of disk partitions (e.g. sda1) are not valid. |
355 BASE_EXPORT bool IsValidDiskName(const std::string& candidate); | 359 BASE_EXPORT bool IsValidDiskName(const std::string& candidate); |
356 | 360 |
357 // Retrieves data from /proc/diskstats about system-wide disk I/O. | 361 // Retrieves data from /proc/diskstats about system-wide disk I/O. |
358 // Fills in the provided |diskinfo| structure. Returns true on success. | 362 // Fills in the provided |diskinfo| structure. Returns true on success. |
359 BASE_EXPORT bool GetSystemDiskInfo(SystemDiskInfo* diskinfo); | 363 BASE_EXPORT bool GetSystemDiskInfo(SystemDiskInfo* diskinfo); |
360 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 364 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
361 | 365 |
362 #if defined(OS_CHROMEOS) | 366 #if defined(OS_CHROMEOS) |
363 // Data from files in directory /sys/block/zram0 about ZRAM usage. | 367 // Data from files in directory /sys/block/zram0 about ZRAM usage. |
364 struct BASE_EXPORT SwapInfo { | 368 struct BASE_EXPORT SwapInfo { |
365 SwapInfo() | 369 SwapInfo() |
366 : num_reads(0), | 370 : num_reads(0), |
367 num_writes(0), | 371 num_writes(0), |
368 compr_data_size(0), | 372 compr_data_size(0), |
369 orig_data_size(0), | 373 orig_data_size(0), |
370 mem_used_total(0) { | 374 mem_used_total(0) { |
371 } | 375 } |
372 | 376 |
373 // Serializes the platform specific fields to value. | 377 // Serializes the platform specific fields to value. |
374 scoped_ptr<Value> ToValue() const; | 378 scoped_ptr<Value> ToValue() const; |
375 | 379 |
376 uint64 num_reads; | 380 uint64_t num_reads; |
377 uint64 num_writes; | 381 uint64_t num_writes; |
378 uint64 compr_data_size; | 382 uint64_t compr_data_size; |
379 uint64 orig_data_size; | 383 uint64_t orig_data_size; |
380 uint64 mem_used_total; | 384 uint64_t mem_used_total; |
381 }; | 385 }; |
382 | 386 |
383 // In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data. | 387 // In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data. |
384 // Fills in the provided |swap_data| structure. | 388 // Fills in the provided |swap_data| structure. |
385 BASE_EXPORT void GetSwapInfo(SwapInfo* swap_info); | 389 BASE_EXPORT void GetSwapInfo(SwapInfo* swap_info); |
386 #endif // defined(OS_CHROMEOS) | 390 #endif // defined(OS_CHROMEOS) |
387 | 391 |
388 // Collects and holds performance metrics for system memory and disk. | 392 // Collects and holds performance metrics for system memory and disk. |
389 // Provides functionality to retrieve the data on various platforms and | 393 // Provides functionality to retrieve the data on various platforms and |
390 // to serialize the stored data. | 394 // to serialize the stored data. |
(...skipping 15 matching lines...) Expand all Loading... |
406 SystemDiskInfo disk_info_; | 410 SystemDiskInfo disk_info_; |
407 #endif | 411 #endif |
408 #if defined(OS_CHROMEOS) | 412 #if defined(OS_CHROMEOS) |
409 SwapInfo swap_info_; | 413 SwapInfo swap_info_; |
410 #endif | 414 #endif |
411 }; | 415 }; |
412 | 416 |
413 } // namespace base | 417 } // namespace base |
414 | 418 |
415 #endif // BASE_PROCESS_PROCESS_METRICS_H_ | 419 #endif // BASE_PROCESS_PROCESS_METRICS_H_ |
OLD | NEW |