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 <stddef.h> | 10 #include <stddef.h> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } else if (type == CPU_TYPE_X86_64) { | 73 } else if (type == CPU_TYPE_X86_64) { |
74 return addr >= SHARED_REGION_BASE_X86_64 && | 74 return addr >= SHARED_REGION_BASE_X86_64 && |
75 addr < (SHARED_REGION_BASE_X86_64 + SHARED_REGION_SIZE_X86_64); | 75 addr < (SHARED_REGION_BASE_X86_64 + SHARED_REGION_SIZE_X86_64); |
76 } else { | 76 } else { |
77 return false; | 77 return false; |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 SystemMemoryInfoKB::SystemMemoryInfoKB() : total(0), free(0) {} | 83 SystemMemoryInfoKB::SystemMemoryInfoKB() |
| 84 : total(0), free(0), speculative(0), file_backed(0), purgeable(0) {} |
84 | 85 |
85 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = | 86 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = |
86 default; | 87 default; |
87 | 88 |
88 // Getting a mach task from a pid for another process requires permissions in | 89 // Getting a mach task from a pid for another process requires permissions in |
89 // general, so there doesn't really seem to be a way to do these (and spinning | 90 // general, so there doesn't really seem to be a way to do these (and spinning |
90 // up ps to fetch each stats seems dangerous to put in a base api for anyone to | 91 // up ps to fetch each stats seems dangerous to put in a base api for anyone to |
91 // call). Child processes ipc their port, so return something if available, | 92 // call). Child processes ipc their port, so return something if available, |
92 // otherwise return 0. | 93 // otherwise return 0. |
93 | 94 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 reinterpret_cast<host_info_t>(&data), | 371 reinterpret_cast<host_info_t>(&data), |
371 &count); | 372 &count); |
372 if (kr != KERN_SUCCESS) { | 373 if (kr != KERN_SUCCESS) { |
373 MACH_DLOG(WARNING, kr) << "host_statistics"; | 374 MACH_DLOG(WARNING, kr) << "host_statistics"; |
374 return 0; | 375 return 0; |
375 } | 376 } |
376 | 377 |
377 return (data.active_count * PAGE_SIZE) / 1024; | 378 return (data.active_count * PAGE_SIZE) / 1024; |
378 } | 379 } |
379 | 380 |
380 // On Mac, We only get total memory and free memory from the system. | |
381 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 381 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
382 struct host_basic_info hostinfo; | 382 struct host_basic_info hostinfo; |
383 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; | 383 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
384 base::mac::ScopedMachSendRight host(mach_host_self()); | 384 base::mac::ScopedMachSendRight host(mach_host_self()); |
385 int result = host_info(host.get(), HOST_BASIC_INFO, | 385 int result = host_info(host.get(), HOST_BASIC_INFO, |
386 reinterpret_cast<host_info_t>(&hostinfo), &count); | 386 reinterpret_cast<host_info_t>(&hostinfo), &count); |
387 if (result != KERN_SUCCESS) | 387 if (result != KERN_SUCCESS) |
388 return false; | 388 return false; |
389 | 389 |
390 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | 390 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
391 meminfo->total = static_cast<int>(hostinfo.max_mem / 1024); | 391 meminfo->total = static_cast<int>(hostinfo.max_mem / 1024); |
392 | 392 |
393 vm_statistics_data_t vm_info; | 393 vm_statistics64_data_t vm_info; |
394 count = HOST_VM_INFO_COUNT; | 394 count = HOST_VM_INFO64_COUNT; |
395 | 395 |
396 if (host_statistics(host.get(), HOST_VM_INFO, | 396 if (host_statistics64(host.get(), HOST_VM_INFO64, |
397 reinterpret_cast<host_info_t>(&vm_info), | 397 reinterpret_cast<host_info64_t>(&vm_info), |
398 &count) != KERN_SUCCESS) { | 398 &count) != KERN_SUCCESS) { |
399 return false; | 399 return false; |
400 } | 400 } |
| 401 DCHECK_EQ(HOST_VM_INFO64_COUNT, count); |
401 | 402 |
402 meminfo->free = static_cast<int>( | 403 meminfo->free = static_cast<int>( |
403 (vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE / 1024); | 404 (vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE / 1024); |
| 405 meminfo->speculative = |
| 406 static_cast<int>(vm_info.speculative_count * PAGE_SIZE / 1024); |
| 407 meminfo->file_backed = |
| 408 static_cast<int>(vm_info.external_page_count * PAGE_SIZE / 1024); |
| 409 meminfo->purgeable = |
| 410 static_cast<int>(vm_info.purgeable_count * PAGE_SIZE / 1024); |
404 | 411 |
405 return true; | 412 return true; |
406 } | 413 } |
407 | 414 |
408 } // namespace base | 415 } // namespace base |
OLD | NEW |