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 <string> | 11 #include <string> |
12 | 12 |
13 #include "base/base_export.h" | 13 #include "base/base_export.h" |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/values.h" | |
18 | 19 |
19 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
20 #include <mach/mach.h> | 21 #include <mach/mach.h> |
21 #endif | 22 #endif |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 | 25 |
25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
26 struct IoCounters : public IO_COUNTERS { | 27 struct IoCounters : public IO_COUNTERS { |
27 }; | 28 }; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); | 237 BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); |
237 | 238 |
238 // /proc/self/exe refers to the current executable. | 239 // /proc/self/exe refers to the current executable. |
239 BASE_EXPORT extern const char kProcSelfExe[]; | 240 BASE_EXPORT extern const char kProcSelfExe[]; |
240 | 241 |
241 // Data from /proc/meminfo about system-wide memory consumption. | 242 // Data from /proc/meminfo about system-wide memory consumption. |
242 // Values are in KB. | 243 // Values are in KB. |
243 struct BASE_EXPORT SystemMemoryInfoKB { | 244 struct BASE_EXPORT SystemMemoryInfoKB { |
244 SystemMemoryInfoKB(); | 245 SystemMemoryInfoKB(); |
245 | 246 |
247 // Serializes the platform specific fields to value. | |
248 Value* AsValue() const; | |
darin (slow to review)
2013/08/31 03:45:12
nit: this should return scoped_ptr<Value>
nit: th
jwmak
2013/09/04 18:49:18
Done.
| |
249 | |
246 int total; | 250 int total; |
247 int free; | 251 int free; |
248 int buffers; | 252 int buffers; |
249 int cached; | 253 int cached; |
250 int active_anon; | 254 int active_anon; |
251 int inactive_anon; | 255 int inactive_anon; |
252 int active_file; | 256 int active_file; |
253 int inactive_file; | 257 int inactive_file; |
254 int swap_total; | 258 int swap_total; |
255 int swap_free; | 259 int swap_free; |
(...skipping 18 matching lines...) Expand all Loading... | |
274 // Retrieves data from /proc/meminfo and /proc/vmstat | 278 // Retrieves data from /proc/meminfo and /proc/vmstat |
275 // about system-wide memory consumption. | 279 // about system-wide memory consumption. |
276 // Fills in the provided |meminfo| structure. Returns true on success. | 280 // Fills in the provided |meminfo| structure. Returns true on success. |
277 // Exposed for memory debugging widget. | 281 // Exposed for memory debugging widget. |
278 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); | 282 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); |
279 | 283 |
280 // Data from /proc/diskstats about system-wide disk I/O. | 284 // Data from /proc/diskstats about system-wide disk I/O. |
281 struct BASE_EXPORT SystemDiskInfo { | 285 struct BASE_EXPORT SystemDiskInfo { |
282 SystemDiskInfo(); | 286 SystemDiskInfo(); |
283 | 287 |
288 // Serializes the platform specific fields to value. | |
289 Value* AsValue() const; | |
darin (slow to review)
2013/08/31 03:45:12
ditto, same nits.
jwmak
2013/09/04 18:49:18
Done.
| |
290 | |
284 uint64 reads; | 291 uint64 reads; |
285 uint64 reads_merged; | 292 uint64 reads_merged; |
286 uint64 sectors_read; | 293 uint64 sectors_read; |
287 uint64 read_time; | 294 uint64 read_time; |
288 uint64 writes; | 295 uint64 writes; |
289 uint64 writes_merged; | 296 uint64 writes_merged; |
290 uint64 sectors_written; | 297 uint64 sectors_written; |
291 uint64 write_time; | 298 uint64 write_time; |
292 uint64 io; | 299 uint64 io; |
293 uint64 io_time; | 300 uint64 io_time; |
(...skipping 14 matching lines...) Expand all Loading... | |
308 // Data from files in directory /sys/block/zram0 about ZRAM usage. | 315 // Data from files in directory /sys/block/zram0 about ZRAM usage. |
309 struct BASE_EXPORT SwapInfo { | 316 struct BASE_EXPORT SwapInfo { |
310 SwapInfo() | 317 SwapInfo() |
311 : num_reads(0), | 318 : num_reads(0), |
312 num_writes(0), | 319 num_writes(0), |
313 compr_data_size(0), | 320 compr_data_size(0), |
314 orig_data_size(0), | 321 orig_data_size(0), |
315 mem_used_total(0) { | 322 mem_used_total(0) { |
316 } | 323 } |
317 | 324 |
325 // Serializes the platform specific fields to value. | |
326 Value* AsValue() const; | |
327 | |
318 uint64 num_reads; | 328 uint64 num_reads; |
319 uint64 num_writes; | 329 uint64 num_writes; |
320 uint64 compr_data_size; | 330 uint64 compr_data_size; |
321 uint64 orig_data_size; | 331 uint64 orig_data_size; |
322 uint64 mem_used_total; | 332 uint64 mem_used_total; |
323 }; | 333 }; |
324 | 334 |
325 // In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data. | 335 // In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data. |
326 // Fills in the provided |swap_data| structure. | 336 // Fills in the provided |swap_data| structure. |
327 BASE_EXPORT void GetSwapInfo(SwapInfo* swap_info); | 337 BASE_EXPORT void GetSwapInfo(SwapInfo* swap_info); |
328 #endif // defined(OS_CHROMEOS) | 338 #endif // defined(OS_CHROMEOS) |
329 | 339 |
330 // Collects and holds performance metrics for system memory and disk. | 340 // Collects and holds performance metrics for system memory and disk. |
331 // Provides functionality to retrieve the data on various platforms and | 341 // Provides functionality to retrieve the data on various platforms and |
332 // to serialize the stored data. | 342 // to serialize the stored data. |
333 class SystemMetrics { | 343 class SystemMetrics { |
334 public: | 344 public: |
335 SystemMetrics() : committed_memory_(0) { } | 345 SystemMetrics() : committed_memory_(0) { } |
336 | 346 |
337 static SystemMetrics Sample(); | 347 static SystemMetrics Sample(); |
338 | 348 |
349 // Serializes the system metrics to value. | |
350 Value* AsValue() const; | |
351 | |
339 private: | 352 private: |
340 FRIEND_TEST_ALL_PREFIXES(SystemMetricsTest, SystemMetrics); | 353 FRIEND_TEST_ALL_PREFIXES(SystemMetricsTest, SystemMetrics); |
341 | 354 |
342 size_t committed_memory_; | 355 size_t committed_memory_; |
343 #if defined(OS_LINUX) || defined(OS_ANDROID) | 356 #if defined(OS_LINUX) || defined(OS_ANDROID) |
344 SystemMemoryInfoKB memory_info_; | 357 SystemMemoryInfoKB memory_info_; |
345 #endif | 358 #endif |
346 #if defined(OS_LINUX) | 359 #if defined(OS_LINUX) |
347 SystemDiskInfo disk_info_; | 360 SystemDiskInfo disk_info_; |
348 #endif | 361 #endif |
349 #if defined(OS_CHROMEOS) | 362 #if defined(OS_CHROMEOS) |
350 SwapInfo swap_info_; | 363 SwapInfo swap_info_; |
351 #endif | 364 #endif |
352 }; | 365 }; |
353 | 366 |
354 } // namespace base | 367 } // namespace base |
355 | 368 |
356 #endif // BASE_PROCESS_PROCESS_METRICS_H_ | 369 #endif // BASE_PROCESS_PROCESS_METRICS_H_ |
OLD | NEW |