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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 usage->image = 0; | 281 usage->image = 0; |
282 | 282 |
283 ws_usage->priv = task_info_data.resident_size / 1024; | 283 ws_usage->priv = task_info_data.resident_size / 1024; |
284 ws_usage->shareable = 0; | 284 ws_usage->shareable = 0; |
285 ws_usage->shared = 0; | 285 ws_usage->shared = 0; |
286 | 286 |
287 return true; | 287 return true; |
288 } | 288 } |
289 | 289 |
290 size_t ProcessMetrics::GetPhysicalFootprint() const { | 290 size_t ProcessMetrics::GetPhysicalFootprint() const { |
291 if (mac::IsAtMostOS10_10()) | 291 if (mac::IsAtMostOS10_11()) |
292 return 0; | 292 return 0; |
293 | 293 |
294 ChromeTaskVMInfo task_vm_info; | 294 ChromeTaskVMInfo task_vm_info; |
295 mach_msg_type_number_t count = ChromeTaskVMInfoCount; | 295 mach_msg_type_number_t count = ChromeTaskVMInfoCount; |
296 kern_return_t result = | 296 kern_return_t result = |
297 task_info(TaskForPid(process_), TASK_VM_INFO, | 297 task_info(TaskForPid(process_), TASK_VM_INFO, |
298 reinterpret_cast<task_info_t>(&task_vm_info), &count); | 298 reinterpret_cast<task_info_t>(&task_vm_info), &count); |
Mark Mentovai
2017/04/24 23:57:21
Note that you can also get rid of the OS version c
erikchen
2017/04/25 00:19:05
I'd like to avoid a syscall when I know the result
| |
299 if (result != KERN_SUCCESS) | 299 if (result != KERN_SUCCESS) |
300 return 0; | 300 return 0; |
301 return task_vm_info.phys_footprint; | 301 return task_vm_info.phys_footprint; |
302 } | 302 } |
303 | 303 |
304 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \ | 304 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \ |
305 (r)->tv_sec = (a)->seconds; \ | 305 (r)->tv_sec = (a)->seconds; \ |
306 (r)->tv_usec = (a)->microseconds; \ | 306 (r)->tv_usec = (a)->microseconds; \ |
307 } while (0) | 307 } while (0) |
308 | 308 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 task, address, size, VM_REGION_BASIC_INFO_64, | 495 task, address, size, VM_REGION_BASIC_INFO_64, |
496 reinterpret_cast<vm_region_info_t>(info), &info_count, &object_name); | 496 reinterpret_cast<vm_region_info_t>(info), &info_count, &object_name); |
497 // The kernel always returns a null object for VM_REGION_BASIC_INFO_64, but | 497 // The kernel always returns a null object for VM_REGION_BASIC_INFO_64, but |
498 // balance it with a deallocate in case this ever changes. See 10.9.2 | 498 // balance it with a deallocate in case this ever changes. See 10.9.2 |
499 // xnu-2422.90.20/osfmk/vm/vm_map.c vm_map_region. | 499 // xnu-2422.90.20/osfmk/vm/vm_map.c vm_map_region. |
500 mach_port_deallocate(task, object_name); | 500 mach_port_deallocate(task, object_name); |
501 return ParseOutputFromMachVMRegion(kr); | 501 return ParseOutputFromMachVMRegion(kr); |
502 } | 502 } |
503 | 503 |
504 } // namespace base | 504 } // namespace base |
OLD | NEW |