| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
| 6 | 6 |
| 7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
| 8 #include <mach/mach_vm.h> | 8 #include <mach/mach_vm.h> |
| 9 #include <mach/shared_region.h> | 9 #include <mach/shared_region.h> |
| 10 #include <sys/sysctl.h> | 10 #include <sys/sysctl.h> |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (task == MACH_PORT_NULL && process_ == getpid()) | 345 if (task == MACH_PORT_NULL && process_ == getpid()) |
| 346 task = mach_task_self(); | 346 task = mach_task_self(); |
| 347 return task; | 347 return task; |
| 348 } | 348 } |
| 349 | 349 |
| 350 // Bytes committed by the system. | 350 // Bytes committed by the system. |
| 351 size_t GetSystemCommitCharge() { | 351 size_t GetSystemCommitCharge() { |
| 352 base::mac::ScopedMachSendRight host(mach_host_self()); | 352 base::mac::ScopedMachSendRight host(mach_host_self()); |
| 353 mach_msg_type_number_t count = HOST_VM_INFO_COUNT; | 353 mach_msg_type_number_t count = HOST_VM_INFO_COUNT; |
| 354 vm_statistics_data_t data; | 354 vm_statistics_data_t data; |
| 355 kern_return_t kr = host_statistics(host, HOST_VM_INFO, | 355 kern_return_t kr = host_statistics(host.get(), HOST_VM_INFO, |
| 356 reinterpret_cast<host_info_t>(&data), | 356 reinterpret_cast<host_info_t>(&data), |
| 357 &count); | 357 &count); |
| 358 if (kr != KERN_SUCCESS) { | 358 if (kr != KERN_SUCCESS) { |
| 359 MACH_DLOG(WARNING, kr) << "host_statistics"; | 359 MACH_DLOG(WARNING, kr) << "host_statistics"; |
| 360 return 0; | 360 return 0; |
| 361 } | 361 } |
| 362 | 362 |
| 363 return (data.active_count * PAGE_SIZE) / 1024; | 363 return (data.active_count * PAGE_SIZE) / 1024; |
| 364 } | 364 } |
| 365 | 365 |
| 366 // On Mac, We only get total memory and free memory from the system. | 366 // On Mac, We only get total memory and free memory from the system. |
| 367 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 367 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
| 368 struct host_basic_info hostinfo; | 368 struct host_basic_info hostinfo; |
| 369 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; | 369 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
| 370 base::mac::ScopedMachSendRight host(mach_host_self()); | 370 base::mac::ScopedMachSendRight host(mach_host_self()); |
| 371 int result = host_info(host, HOST_BASIC_INFO, | 371 int result = host_info(host.get(), HOST_BASIC_INFO, |
| 372 reinterpret_cast<host_info_t>(&hostinfo), &count); | 372 reinterpret_cast<host_info_t>(&hostinfo), &count); |
| 373 if (result != KERN_SUCCESS) | 373 if (result != KERN_SUCCESS) |
| 374 return false; | 374 return false; |
| 375 | 375 |
| 376 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | 376 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
| 377 meminfo->total = static_cast<int>(hostinfo.max_mem / 1024); | 377 meminfo->total = static_cast<int>(hostinfo.max_mem / 1024); |
| 378 | 378 |
| 379 vm_statistics_data_t vm_info; | 379 vm_statistics_data_t vm_info; |
| 380 count = HOST_VM_INFO_COUNT; | 380 count = HOST_VM_INFO_COUNT; |
| 381 | 381 |
| 382 if (host_statistics(host.get(), HOST_VM_INFO, | 382 if (host_statistics(host.get(), HOST_VM_INFO, |
| 383 reinterpret_cast<host_info_t>(&vm_info), | 383 reinterpret_cast<host_info_t>(&vm_info), |
| 384 &count) != KERN_SUCCESS) { | 384 &count) != KERN_SUCCESS) { |
| 385 return false; | 385 return false; |
| 386 } | 386 } |
| 387 | 387 |
| 388 meminfo->free = static_cast<int>( | 388 meminfo->free = static_cast<int>( |
| 389 (vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE / 1024); | 389 (vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE / 1024); |
| 390 | 390 |
| 391 return true; | 391 return true; |
| 392 } | 392 } |
| 393 | 393 |
| 394 } // namespace base | 394 } // namespace base |
| OLD | NEW |