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

Unified Diff: base/process/process_metrics_mac.cc

Issue 2766623002: Revert of Fix free memory calculation. (Closed)
Patch Set: Created 3 years, 9 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/process_metrics_linux.cc ('k') | base/process/process_metrics_unittest.cc » ('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 6ab43a8289582f1488000f0e4e738d307438374a..a3c2d6a14aa6acbd2e07e9afd6a55a836bbb3f10 100644
--- a/base/process/process_metrics_mac.cc
+++ b/base/process/process_metrics_mac.cc
@@ -16,7 +16,6 @@
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_port.h"
#include "base/memory/ptr_util.h"
-#include "base/numerics/safe_conversions.h"
#include "base/sys_info.h"
#if !defined(TASK_POWER_INFO)
@@ -80,6 +79,11 @@
}
} // namespace
+
+SystemMemoryInfoKB::SystemMemoryInfoKB() : total(0), free(0) {}
+
+SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) =
+ default;
// Getting a mach task from a pid for another process requires permissions in
// general, so there doesn't really seem to be a way to do these (and spinning
@@ -373,6 +377,7 @@
return (data.active_count * PAGE_SIZE) / 1024;
}
+// On Mac, We only get total memory and free memory from the system.
bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
struct host_basic_info hostinfo;
mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
@@ -385,25 +390,17 @@
DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
meminfo->total = static_cast<int>(hostinfo.max_mem / 1024);
- vm_statistics64_data_t vm_info;
- count = HOST_VM_INFO64_COUNT;
-
- if (host_statistics64(host.get(), HOST_VM_INFO64,
- reinterpret_cast<host_info64_t>(&vm_info),
- &count) != KERN_SUCCESS) {
- return false;
- }
- DCHECK_EQ(HOST_VM_INFO64_COUNT, count);
-
- static_assert(PAGE_SIZE % 1024 == 0, "Invalid page size");
- meminfo->free = saturated_cast<int>(
- PAGE_SIZE / 1024 * (vm_info.free_count - vm_info.speculative_count));
- meminfo->speculative =
- saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.speculative_count);
- meminfo->file_backed =
- saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.external_page_count);
- meminfo->purgeable =
- saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.purgeable_count);
+ vm_statistics_data_t vm_info;
+ count = HOST_VM_INFO_COUNT;
+
+ if (host_statistics(host.get(), HOST_VM_INFO,
+ reinterpret_cast<host_info_t>(&vm_info),
+ &count) != KERN_SUCCESS) {
+ return false;
+ }
+
+ meminfo->free = static_cast<int>(
+ (vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE / 1024);
return true;
}
« no previous file with comments | « base/process/process_metrics_linux.cc ('k') | base/process/process_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698