| Index: base/process/process_metrics_mac.cc
|
| diff --git a/base/process/process_metrics_mac.cc b/base/process/process_metrics_mac.cc
|
| index 1b2e61bdb73886e23091d28d28970aaa2752a91a..f97de6da5cf5cf2a6e7f231180ede63b3233796d 100644
|
| --- a/base/process/process_metrics_mac.cc
|
| +++ b/base/process/process_metrics_mac.cc
|
| @@ -11,6 +11,7 @@
|
|
|
| #include "base/containers/hash_tables.h"
|
| #include "base/logging.h"
|
| +#include "base/mac/mach_logging.h"
|
| #include "base/mac/scoped_mach_port.h"
|
| #include "base/sys_info.h"
|
|
|
| @@ -116,7 +117,6 @@ size_t ProcessMetrics::GetPeakWorkingSetSize() const {
|
| // shared_bytes is the size of shared resident memory.
|
| bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
|
| size_t* shared_bytes) {
|
| - kern_return_t kr;
|
| size_t private_pages_count = 0;
|
| size_t shared_pages_count = 0;
|
|
|
| @@ -153,22 +153,23 @@ bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
|
| vm_region_top_info_data_t info;
|
| mach_msg_type_number_t info_count = VM_REGION_TOP_INFO_COUNT;
|
| mach_port_t object_name;
|
| - kr = mach_vm_region(task,
|
| - &address,
|
| - &size,
|
| - VM_REGION_TOP_INFO,
|
| - (vm_region_info_t)&info,
|
| - &info_count,
|
| - &object_name);
|
| + kern_return_t kr = mach_vm_region(task,
|
| + &address,
|
| + &size,
|
| + VM_REGION_TOP_INFO,
|
| + reinterpret_cast<vm_region_info_t>(&info),
|
| + &info_count,
|
| + &object_name);
|
| if (kr == KERN_INVALID_ADDRESS) {
|
| // We're at the end of the address space.
|
| break;
|
| } else if (kr != KERN_SUCCESS) {
|
| - DLOG(ERROR) << "Calling mach_vm_region failed with error: "
|
| - << mach_error_string(kr);
|
| + MACH_DLOG(ERROR, kr) << "mach_vm_region";
|
| return false;
|
| }
|
|
|
| + mach_port_deallocate(mach_task_self(), object_name);
|
| +
|
| if (IsAddressInSharedRegion(address, cpu_type) &&
|
| info.share_mode != SM_PRIVATE)
|
| continue;
|
| @@ -196,18 +197,10 @@ bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
|
| }
|
| }
|
|
|
| - vm_size_t page_size;
|
| - kr = host_page_size(task, &page_size);
|
| - if (kr != KERN_SUCCESS) {
|
| - DLOG(ERROR) << "Failed to fetch host page size, error: "
|
| - << mach_error_string(kr);
|
| - return false;
|
| - }
|
| -
|
| if (private_bytes)
|
| - *private_bytes = private_pages_count * page_size;
|
| + *private_bytes = private_pages_count * PAGE_SIZE;
|
| if (shared_bytes)
|
| - *shared_bytes = shared_pages_count * page_size;
|
| + *shared_bytes = shared_pages_count * PAGE_SIZE;
|
|
|
| return true;
|
| }
|
| @@ -235,16 +228,14 @@ double ProcessMetrics::GetCPUUsage() {
|
| if (task == MACH_PORT_NULL)
|
| return 0;
|
|
|
| - kern_return_t kr;
|
| -
|
| // Libtop explicitly loops over the threads (libtop_pinfo_update_cpu_usage()
|
| // in libtop.c), but this is more concise and gives the same results:
|
| task_thread_times_info thread_info_data;
|
| mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT;
|
| - kr = task_info(task,
|
| - TASK_THREAD_TIMES_INFO,
|
| - reinterpret_cast<task_info_t>(&thread_info_data),
|
| - &thread_info_count);
|
| + kern_return_t kr = task_info(task,
|
| + TASK_THREAD_TIMES_INFO,
|
| + reinterpret_cast<task_info_t>(&thread_info_data),
|
| + &thread_info_count);
|
| if (kr != KERN_SUCCESS) {
|
| // Most likely cause: |task| is a zombie.
|
| return 0;
|
| @@ -294,14 +285,12 @@ int ProcessMetrics::GetIdleWakeupsPerSecond() {
|
| if (task == MACH_PORT_NULL)
|
| return 0;
|
|
|
| - kern_return_t kr;
|
| -
|
| task_power_info power_info_data;
|
| mach_msg_type_number_t power_info_count = TASK_POWER_INFO_COUNT;
|
| - kr = task_info(task,
|
| - TASK_POWER_INFO,
|
| - reinterpret_cast<task_info_t>(&power_info_data),
|
| - &power_info_count);
|
| + kern_return_t kr = task_info(task,
|
| + TASK_POWER_INFO,
|
| + reinterpret_cast<task_info_t>(&power_info_data),
|
| + &power_info_count);
|
| if (kr != KERN_SUCCESS) {
|
| // Most likely cause: |task| is a zombie, or this is on a pre-10.8.4 system
|
| // where TASK_POWER_INFO isn't supported yet.
|
| @@ -362,19 +351,12 @@ size_t GetSystemCommitCharge() {
|
| kern_return_t kr = host_statistics(host, HOST_VM_INFO,
|
| reinterpret_cast<host_info_t>(&data),
|
| &count);
|
| - if (kr) {
|
| - DLOG(WARNING) << "Failed to fetch host statistics.";
|
| - return 0;
|
| - }
|
| -
|
| - vm_size_t page_size;
|
| - kr = host_page_size(host, &page_size);
|
| - if (kr) {
|
| - DLOG(ERROR) << "Failed to fetch host page size.";
|
| + if (kr != KERN_SUCCESS) {
|
| + MACH_DLOG(WARNING, kr) << "host_statistics";
|
| return 0;
|
| }
|
|
|
| - return (data.active_count * page_size) / 1024;
|
| + return (data.active_count * PAGE_SIZE) / 1024;
|
| }
|
|
|
| } // namespace base
|
|
|