Commit c9e0bc8d authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

Move GetTaskVMInfo from base/ to services/.

The method only had one caller, which required a less specialized version of the
function. No point in unnecessarily exposing the method in base/.

Change-Id: I5286af592168fbf013b515da4cc8010ab3c49584
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637662Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665617}
parent 58fe1e69
......@@ -106,23 +106,6 @@ class BASE_EXPORT ProcessMetrics {
BASE_EXPORT TotalsSummary GetTotalsSummary() const;
#endif
#if defined(OS_MACOSX)
struct TaskVMInfo {
// Only available on macOS 10.12+.
// Anonymous, non-discardable memory, including non-volatile IOKit.
// Measured in bytes.
uint64_t phys_footprint = 0;
// Anonymous, non-discardable, non-compressed memory, excluding IOKit.
// Measured in bytes.
uint64_t internal = 0;
// Compressed memory measured in bytes.
uint64_t compressed = 0;
};
TaskVMInfo GetTaskVMInfo() const;
#endif
// Returns the percentage of time spent executing, across all threads of the
// process, in the interval since the last time the method was called. Since
// this considers the total execution time across all threads in a process,
......
......@@ -25,37 +25,6 @@ namespace base {
namespace {
#if !defined(MAC_OS_X_VERSION_10_11) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
// The |phys_footprint| field was introduced in 10.11.
struct ChromeTaskVMInfo {
mach_vm_size_t virtual_size;
integer_t region_count;
integer_t page_size;
mach_vm_size_t resident_size;
mach_vm_size_t resident_size_peak;
mach_vm_size_t device;
mach_vm_size_t device_peak;
mach_vm_size_t internal;
mach_vm_size_t internal_peak;
mach_vm_size_t external;
mach_vm_size_t external_peak;
mach_vm_size_t reusable;
mach_vm_size_t reusable_peak;
mach_vm_size_t purgeable_volatile_pmap;
mach_vm_size_t purgeable_volatile_resident;
mach_vm_size_t purgeable_volatile_virtual;
mach_vm_size_t compressed;
mach_vm_size_t compressed_peak;
mach_vm_size_t compressed_lifetime;
mach_vm_size_t phys_footprint;
};
#else
using ChromeTaskVMInfo = task_vm_info;
#endif // MAC_OS_X_VERSION_10_11
mach_msg_type_number_t ChromeTaskVMInfoCount =
sizeof(ChromeTaskVMInfo) / sizeof(natural_t);
bool GetTaskInfo(mach_port_t task, task_basic_info_64* task_info_data) {
if (task == MACH_PORT_NULL)
return false;
......@@ -105,23 +74,6 @@ std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
return WrapUnique(new ProcessMetrics(process, port_provider));
}
ProcessMetrics::TaskVMInfo ProcessMetrics::GetTaskVMInfo() const {
TaskVMInfo info;
ChromeTaskVMInfo task_vm_info;
mach_msg_type_number_t count = ChromeTaskVMInfoCount;
kern_return_t result =
task_info(TaskForPid(process_), TASK_VM_INFO,
reinterpret_cast<task_info_t>(&task_vm_info), &count);
if (result != KERN_SUCCESS)
return info;
info.internal = task_vm_info.internal;
info.compressed = task_vm_info.compressed;
if (count == ChromeTaskVMInfoCount)
info.phys_footprint = task_vm_info.phys_footprint;
return info;
}
#define TIME_VALUE_TO_TIMEVAL(a, r) do { \
(r)->tv_sec = (a)->seconds; \
(r)->tv_usec = (a)->microseconds; \
......
......@@ -22,6 +22,37 @@ namespace memory_instrumentation {
namespace {
#if !defined(MAC_OS_X_VERSION_10_11) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
// The |phys_footprint| field was introduced in 10.11.
struct ChromeTaskVMInfo {
mach_vm_size_t virtual_size;
integer_t region_count;
integer_t page_size;
mach_vm_size_t resident_size;
mach_vm_size_t resident_size_peak;
mach_vm_size_t device;
mach_vm_size_t device_peak;
mach_vm_size_t internal;
mach_vm_size_t internal_peak;
mach_vm_size_t external;
mach_vm_size_t external_peak;
mach_vm_size_t reusable;
mach_vm_size_t reusable_peak;
mach_vm_size_t purgeable_volatile_pmap;
mach_vm_size_t purgeable_volatile_resident;
mach_vm_size_t purgeable_volatile_virtual;
mach_vm_size_t compressed;
mach_vm_size_t compressed_peak;
mach_vm_size_t compressed_lifetime;
mach_vm_size_t phys_footprint;
};
#else
using ChromeTaskVMInfo = task_vm_info;
#endif // MAC_OS_X_VERSION_10_11
mach_msg_type_number_t ChromeTaskVMInfoCount =
sizeof(ChromeTaskVMInfo) / sizeof(natural_t);
using VMRegion = mojom::VmRegion;
bool IsAddressInSharedRegion(uint64_t address) {
......@@ -209,14 +240,22 @@ void AddRegionByteStats(VMRegion* dest, const VMRegion& source) {
// static
bool OSMetrics::FillOSMemoryDump(base::ProcessId pid,
mojom::RawOSMemDump* dump) {
// Creating process metrics for child processes in mac or windows requires
// additional information like ProcessHandle or port provider.
DCHECK_EQ(base::kNullProcessId, pid);
auto process_metrics = base::ProcessMetrics::CreateCurrentProcessMetrics();
base::ProcessMetrics::TaskVMInfo info = process_metrics->GetTaskVMInfo();
dump->platform_private_footprint->phys_footprint_bytes = info.phys_footprint;
dump->platform_private_footprint->internal_bytes = info.internal;
dump->platform_private_footprint->compressed_bytes = info.compressed;
ChromeTaskVMInfo task_vm_info;
mach_msg_type_number_t count = ChromeTaskVMInfoCount;
kern_return_t result =
task_info(mach_task_self(), TASK_VM_INFO,
reinterpret_cast<task_info_t>(&task_vm_info), &count);
if (result != KERN_SUCCESS)
return false;
dump->platform_private_footprint->internal_bytes = task_vm_info.internal;
dump->platform_private_footprint->compressed_bytes = task_vm_info.compressed;
if (count == ChromeTaskVMInfoCount) {
dump->platform_private_footprint->phys_footprint_bytes =
task_vm_info.phys_footprint;
}
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment