Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: base/process/process_metrics_mac.cc

Issue 274193007: Back out r269483 and the line of fixes that followed it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/memory_mac.mm ('k') | base/threading/platform_thread_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_mac.cc
diff --git a/base/process/process_metrics_mac.cc b/base/process/process_metrics_mac.cc
index ee79583700ab382c0266b8a77ab14a808b817501..1b2e61bdb73886e23091d28d28970aaa2752a91a 100644
--- a/base/process/process_metrics_mac.cc
+++ b/base/process/process_metrics_mac.cc
@@ -11,7 +11,6 @@
#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"
@@ -117,6 +116,7 @@ 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,26 +153,22 @@ 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;
- 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);
+ kr = mach_vm_region(task,
+ &address,
+ &size,
+ VM_REGION_TOP_INFO,
+ (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) {
- MACH_DLOG(ERROR, kr) << "mach_vm_region";
+ DLOG(ERROR) << "Calling mach_vm_region failed with error: "
+ << mach_error_string(kr);
return false;
}
- // The kernel always returns a null object for VM_REGION_TOP_INFO, but
- // balance it with a deallocate in case this ever changes. See 10.9.2
- // xnu-2422.90.20/osfmk/vm/vm_map.c vm_map_region.
- mach_port_deallocate(mach_task_self(), object_name);
-
if (IsAddressInSharedRegion(address, cpu_type) &&
info.share_mode != SM_PRIVATE)
continue;
@@ -200,10 +196,18 @@ 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;
}
@@ -231,14 +235,16 @@ 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;
- kern_return_t kr = task_info(task,
- TASK_THREAD_TIMES_INFO,
- reinterpret_cast<task_info_t>(&thread_info_data),
- &thread_info_count);
+ 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;
@@ -288,12 +294,14 @@ 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;
- kern_return_t kr = task_info(task,
- TASK_POWER_INFO,
- reinterpret_cast<task_info_t>(&power_info_data),
- &power_info_count);
+ 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.
@@ -354,12 +362,19 @@ size_t GetSystemCommitCharge() {
kern_return_t kr = host_statistics(host, HOST_VM_INFO,
reinterpret_cast<host_info_t>(&data),
&count);
- if (kr != KERN_SUCCESS) {
- MACH_DLOG(WARNING, kr) << "host_statistics";
+ 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.";
return 0;
}
- return (data.active_count * PAGE_SIZE) / 1024;
+ return (data.active_count * page_size) / 1024;
}
} // namespace base
« no previous file with comments | « base/process/memory_mac.mm ('k') | base/threading/platform_thread_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698