[Lldb-commits] [lldb] r240728 - rdar://problem/21469556
Han Ming Ong
hanming at apple.com
Thu Jun 25 16:39:57 PDT 2015
Author: hanming
Date: Thu Jun 25 18:39:56 2015
New Revision: 240728
URL: http://llvm.org/viewvc/llvm-project?rev=240728&view=rev
Log:
rdar://problem/21469556
Make sure that the memory report is correct for 64-bit devices.
Modified:
lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm
lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp
lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm?rev=240728&r1=240727&r2=240728&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm Thu Jun 25 18:39:56 2015
@@ -382,7 +382,11 @@ MachTask::GetProfileData (DNBProfileData
get_threads_profile_data(scanType, task, pid, threads_id, threads_name, threads_used_usec);
}
- struct vm_statistics vm_stats;
+#if defined (HOST_VM_INFO64_COUNT)
+ vm_statistics64_data_t vminfo;
+#elif
+ struct vm_statistics vminfo;
+#endif
uint64_t physical_memory;
mach_vm_size_t rprvt = 0;
mach_vm_size_t rsize = 0;
@@ -391,7 +395,7 @@ MachTask::GetProfileData (DNBProfileData
mach_vm_size_t dirty_size = 0;
mach_vm_size_t purgeable = 0;
mach_vm_size_t anonymous = 0;
- if (m_vm_memory.GetMemoryProfile(scanType, task, task_info, m_process->GetCPUType(), pid, vm_stats, physical_memory, rprvt, rsize, vprvt, vsize, dirty_size, purgeable, anonymous))
+ if (m_vm_memory.GetMemoryProfile(scanType, task, task_info, m_process->GetCPUType(), pid, vminfo, physical_memory, rprvt, rsize, vprvt, vsize, dirty_size, purgeable, anonymous))
{
std::ostringstream profile_data_stream;
@@ -444,6 +448,9 @@ MachTask::GetProfileData (DNBProfileData
if (scanType & eProfileMemory)
{
+#if defined (HOST_VM_INFO64_COUNT)
+ static vm_size_t pagesize = vm_kernel_page_size;
+#elif
static vm_size_t pagesize;
static bool calculated = false;
if (!calculated)
@@ -451,16 +458,22 @@ MachTask::GetProfileData (DNBProfileData
calculated = true;
pagesize = PageSize();
}
+#endif
/* Unused values. Optimized out for transfer performance.
- profile_data_stream << "wired:" << vm_stats.wire_count * pagesize << ';';
- profile_data_stream << "active:" << vm_stats.active_count * pagesize << ';';
- profile_data_stream << "inactive:" << vm_stats.inactive_count * pagesize << ';';
+ profile_data_stream << "wired:" << vminfo.wire_count * pagesize << ';';
+ profile_data_stream << "active:" << vminfo.active_count * pagesize << ';';
+ profile_data_stream << "inactive:" << vminfo.inactive_count * pagesize << ';';
*/
- uint64_t total_used_count = vm_stats.wire_count + vm_stats.inactive_count + vm_stats.active_count;
+#if defined (HOST_VM_INFO64_COUNT)
+ // This mimicks Activity Monitor.
+ uint64_t total_used_count = (physical_memory / vm_kernel_page_size) - (vminfo.free_count - vminfo.speculative_count) - vminfo.external_page_count - vminfo.purgeable_count;
+#elif
+ uint64_t total_used_count = vminfo.wire_count + vminfo.inactive_count + vminfo.active_count;
+#endif
profile_data_stream << "used:" << total_used_count * pagesize << ';';
/* Unused values. Optimized out for transfer performance.
- profile_data_stream << "free:" << vm_stats.free_count * pagesize << ';';
+ profile_data_stream << "free:" << vminfo.free_count * pagesize << ';';
*/
profile_data_stream << "rprvt:" << rprvt << ';';
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp?rev=240728&r1=240727&r2=240728&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp Thu Jun 25 18:39:56 2015
@@ -236,11 +236,10 @@ static uint64_t GetPhysicalMemory()
static bool calculated = false;
if (calculated) return physical_memory;
- int mib[2];
- mib[0] = CTL_HW;
- mib[1] = HW_MEMSIZE;
size_t len = sizeof(physical_memory);
- sysctl(mib, 2, &physical_memory, &len, NULL, 0);
+ sysctlbyname("hw.memsize", &physical_memory, &len, NULL, 0);
+
+ calculated = true;
return physical_memory;
}
@@ -418,8 +417,13 @@ GetPurgeableAndAnonymous(task_t task, ui
#endif
}
+#if defined (HOST_VM_INFO64_COUNT)
+nub_bool_t
+MachVMMemory::GetMemoryProfile(DNBProfileDataScanType scanType, task_t task, struct task_basic_info ti, cpu_type_t cputype, nub_process_t pid, vm_statistics64_data_t &vminfo, uint64_t &physical_memory, mach_vm_size_t &rprvt, mach_vm_size_t &rsize, mach_vm_size_t &vprvt, mach_vm_size_t &vsize, mach_vm_size_t &dirty_size, mach_vm_size_t &purgeable, mach_vm_size_t &anonymous)
+#elif
nub_bool_t
-MachVMMemory::GetMemoryProfile(DNBProfileDataScanType scanType, task_t task, struct task_basic_info ti, cpu_type_t cputype, nub_process_t pid, vm_statistics_data_t &vm_stats, uint64_t &physical_memory, mach_vm_size_t &rprvt, mach_vm_size_t &rsize, mach_vm_size_t &vprvt, mach_vm_size_t &vsize, mach_vm_size_t &dirty_size, mach_vm_size_t &purgeable, mach_vm_size_t &anonymous)
+MachVMMemory::GetMemoryProfile(DNBProfileDataScanType scanType, task_t task, struct task_basic_info ti, cpu_type_t cputype, nub_process_t pid, vm_statistics_data_t &vminfo, uint64_t &physical_memory, mach_vm_size_t &rprvt, mach_vm_size_t &rsize, mach_vm_size_t &vprvt, mach_vm_size_t &vsize, mach_vm_size_t &dirty_size, mach_vm_size_t &purgeable, mach_vm_size_t &anonymous)
+#endif
{
if (scanType & eProfileHostMemory)
physical_memory = GetPhysicalMemory();
@@ -427,12 +431,17 @@ MachVMMemory::GetMemoryProfile(DNBProfil
if (scanType & eProfileMemory)
{
static mach_port_t localHost = mach_host_self();
+#if defined (HOST_VM_INFO64_COUNT)
+ mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
+ host_statistics64(localHost, HOST_VM_INFO64, (host_info64_t)&vminfo, &count);
+#elif
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
- host_statistics(localHost, HOST_VM_INFO, (host_info_t)&vm_stats, &count);
- vm_stats.wire_count += GetStolenPages(task);
-
+ host_statistics(localHost, HOST_VM_INFO, (host_info_t)&vminfo, &count);
+ vminfo.wire_count += GetStolenPages(task);
+#endif
+
+ /* We are no longer reporting these. Let's not waste time.
GetMemorySizes(task, cputype, pid, rprvt, vprvt);
-
rsize = ti.resident_size;
vsize = ti.virtual_size;
@@ -441,6 +450,7 @@ MachVMMemory::GetMemoryProfile(DNBProfil
// This uses vmmap strategy. We don't use the returned rsize for now. We prefer to match top's version since that's what we do for the rest of the metrics.
GetRegionSizes(task, rsize, dirty_size);
}
+ */
if (scanType & eProfileMemoryAnonymous)
{
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h?rev=240728&r1=240727&r2=240728&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h Thu Jun 25 18:39:56 2015
@@ -28,7 +28,11 @@ public:
nub_size_t Write(task_t task, nub_addr_t address, const void *data, nub_size_t data_count);
nub_size_t PageSize(task_t task);
nub_bool_t GetMemoryRegionInfo(task_t task, nub_addr_t address, DNBRegionInfo *region_info);
- nub_bool_t GetMemoryProfile(DNBProfileDataScanType scanType, task_t task, struct task_basic_info ti, cpu_type_t cputype, nub_process_t pid, vm_statistics_data_t &vm_stats, uint64_t &physical_memory, mach_vm_size_t &rprvt, mach_vm_size_t &rsize, mach_vm_size_t &vprvt, mach_vm_size_t &vsize, mach_vm_size_t &dirty_size, mach_vm_size_t &purgable, mach_vm_size_t &anonymous);
+#if defined (HOST_VM_INFO64_COUNT)
+ nub_bool_t GetMemoryProfile(DNBProfileDataScanType scanType, task_t task, struct task_basic_info ti, cpu_type_t cputype, nub_process_t pid, vm_statistics64_data_t &vminfo, uint64_t &physical_memory, mach_vm_size_t &rprvt, mach_vm_size_t &rsize, mach_vm_size_t &vprvt, mach_vm_size_t &vsize, mach_vm_size_t &dirty_size, mach_vm_size_t &purgeable, mach_vm_size_t &anonymous);
+#elif
+ nub_bool_t GetMemoryProfile(DNBProfileDataScanType scanType, task_t task, struct task_basic_info ti, cpu_type_t cputype, nub_process_t pid, vm_statistics_data_t &vminfo, uint64_t &physical_memory, mach_vm_size_t &rprvt, mach_vm_size_t &rsize, mach_vm_size_t &vprvt, mach_vm_size_t &vsize, mach_vm_size_t &dirty_size, mach_vm_size_t &purgeable, mach_vm_size_t &anonymous);
+#endif
protected:
nub_size_t MaxBytesLeftInPage(task_t task, nub_addr_t addr, nub_size_t count);
More information about the lldb-commits
mailing list