Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: base/process/process_metrics_mac.cc

Issue 2845793002: [Merge to 3071] Add the UMA metric Memory.Gpu.PhysicalFootprint.MacOS (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_metrics.h ('k') | chrome/browser/memory_details.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <stdint.h> 11 #include <stdint.h>
12 #include <sys/sysctl.h> 12 #include <sys/sysctl.h>
13 13
14 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/mac/mac_util.h"
16 #include "base/mac/mach_logging.h" 17 #include "base/mac/mach_logging.h"
17 #include "base/mac/scoped_mach_port.h" 18 #include "base/mac/scoped_mach_port.h"
18 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
19 #include "base/numerics/safe_conversions.h" 20 #include "base/numerics/safe_conversions.h"
20 #include "base/numerics/safe_math.h" 21 #include "base/numerics/safe_math.h"
21 #include "base/sys_info.h" 22 #include "base/sys_info.h"
22 23
23 namespace base { 24 namespace base {
24 25
25 namespace { 26 namespace {
26 27
28 #if !defined(MAC_OS_X_VERSION_10_11) || \
29 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
30 // The |phys_footprint| field was introduced in 10.11.
31 struct ChromeTaskVMInfo {
32 mach_vm_size_t virtual_size;
33 integer_t region_count;
34 integer_t page_size;
35 mach_vm_size_t resident_size;
36 mach_vm_size_t resident_size_peak;
37 mach_vm_size_t device;
38 mach_vm_size_t device_peak;
39 mach_vm_size_t internal;
40 mach_vm_size_t internal_peak;
41 mach_vm_size_t external;
42 mach_vm_size_t external_peak;
43 mach_vm_size_t reusable;
44 mach_vm_size_t reusable_peak;
45 mach_vm_size_t purgeable_volatile_pmap;
46 mach_vm_size_t purgeable_volatile_resident;
47 mach_vm_size_t purgeable_volatile_virtual;
48 mach_vm_size_t compressed;
49 mach_vm_size_t compressed_peak;
50 mach_vm_size_t compressed_lifetime;
51 mach_vm_size_t phys_footprint;
52 };
53 mach_msg_type_number_t ChromeTaskVMInfoCount =
54 sizeof(ChromeTaskVMInfo) / sizeof(natural_t);
55 #else
56 using ChromeTaskVMInfo = task_vm_info;
57 mach_msg_type_number_t ChromeTaskVMInfoCount = TASK_VM_INFO_REV1_COUNT;
58 #endif // MAC_OS_X_VERSION_10_11
59
27 bool GetTaskInfo(mach_port_t task, task_basic_info_64* task_info_data) { 60 bool GetTaskInfo(mach_port_t task, task_basic_info_64* task_info_data) {
28 if (task == MACH_PORT_NULL) 61 if (task == MACH_PORT_NULL)
29 return false; 62 return false;
30 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; 63 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
31 kern_return_t kr = task_info(task, 64 kern_return_t kr = task_info(task,
32 TASK_BASIC_INFO_64, 65 TASK_BASIC_INFO_64,
33 reinterpret_cast<task_info_t>(task_info_data), 66 reinterpret_cast<task_info_t>(task_info_data),
34 &count); 67 &count);
35 // Most likely cause for failure: |task| is a zombie. 68 // Most likely cause for failure: |task| is a zombie.
36 return kr == KERN_SUCCESS; 69 return kr == KERN_SUCCESS;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 usage->mapped = 0; 281 usage->mapped = 0;
249 usage->image = 0; 282 usage->image = 0;
250 283
251 ws_usage->priv = task_info_data.resident_size / 1024; 284 ws_usage->priv = task_info_data.resident_size / 1024;
252 ws_usage->shareable = 0; 285 ws_usage->shareable = 0;
253 ws_usage->shared = 0; 286 ws_usage->shared = 0;
254 287
255 return true; 288 return true;
256 } 289 }
257 290
291 size_t ProcessMetrics::GetPhysicalFootprint() const {
292 if (mac::IsAtMostOS10_10())
293 return 0;
294
295 ChromeTaskVMInfo task_vm_info;
296 mach_msg_type_number_t count = ChromeTaskVMInfoCount;
297 kern_return_t result =
298 task_info(TaskForPid(process_), TASK_VM_INFO,
299 reinterpret_cast<task_info_t>(&task_vm_info), &count);
300 if (result != KERN_SUCCESS)
301 return 0;
302 return task_vm_info.phys_footprint;
303 }
304
258 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \ 305 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \
259 (r)->tv_sec = (a)->seconds; \ 306 (r)->tv_sec = (a)->seconds; \
260 (r)->tv_usec = (a)->microseconds; \ 307 (r)->tv_usec = (a)->microseconds; \
261 } while (0) 308 } while (0)
262 309
263 double ProcessMetrics::GetCPUUsage() { 310 double ProcessMetrics::GetCPUUsage() {
264 mach_port_t task = TaskForPid(process_); 311 mach_port_t task = TaskForPid(process_);
265 if (task == MACH_PORT_NULL) 312 if (task == MACH_PORT_NULL)
266 return 0; 313 return 0;
267 314
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 task, address, size, VM_REGION_BASIC_INFO_64, 496 task, address, size, VM_REGION_BASIC_INFO_64,
450 reinterpret_cast<vm_region_info_t>(info), &info_count, &object_name); 497 reinterpret_cast<vm_region_info_t>(info), &info_count, &object_name);
451 // The kernel always returns a null object for VM_REGION_BASIC_INFO_64, but 498 // The kernel always returns a null object for VM_REGION_BASIC_INFO_64, but
452 // balance it with a deallocate in case this ever changes. See 10.9.2 499 // balance it with a deallocate in case this ever changes. See 10.9.2
453 // xnu-2422.90.20/osfmk/vm/vm_map.c vm_map_region. 500 // xnu-2422.90.20/osfmk/vm/vm_map.c vm_map_region.
454 mach_port_deallocate(task, object_name); 501 mach_port_deallocate(task, object_name);
455 return ParseOutputFromMachVMRegion(kr); 502 return ParseOutputFromMachVMRegion(kr);
456 } 503 }
457 504
458 } // namespace base 505 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_metrics.h ('k') | chrome/browser/memory_details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698