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

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

Issue 2832933003: Add the UMA metric Memory.Gpu.PhysicalFootprint.MacOS (Closed)
Patch Set: clean up 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/sys_info.h" 21 #include "base/sys_info.h"
21 22
22 namespace base { 23 namespace base {
23 24
24 namespace { 25 namespace {
25 26
27 #if !defined(MAC_OS_X_VERSION_10_11) || \
28 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11
Mark Mentovai 2017/04/21 03:30:00 Whether task_vm_info is available and correct is a
erikchen 2017/04/21 17:35:32 Thanks, I seem to have a penchant for mixing the t
29 // The |phys_footprint| field was introduced in 10.11.
30 struct ChromeTaskVMInfo {
31 mach_vm_size_t virtual_size;
32 integer_t region_count;
33 integer_t page_size;
34 mach_vm_size_t resident_size;
35 mach_vm_size_t resident_size_peak;
36 mach_vm_size_t device;
37 mach_vm_size_t device_peak;
38 mach_vm_size_t internal;
39 mach_vm_size_t internal_peak;
40 mach_vm_size_t external;
41 mach_vm_size_t external_peak;
42 mach_vm_size_t reusable;
43 mach_vm_size_t reusable_peak;
44 mach_vm_size_t purgeable_volatile_pmap;
45 mach_vm_size_t purgeable_volatile_resident;
46 mach_vm_size_t purgeable_volatile_virtual;
47 mach_vm_size_t compressed;
48 mach_vm_size_t compressed_peak;
49 mach_vm_size_t compressed_lifetime;
50 mach_vm_size_t phys_footprint;
51 };
52 mach_msg_type_number_t ChromeTaskVMInfoCount =
53 sizeof(ChromeTaskVMInfo) / sizeof(natural_t);
54 #else
55 using ChromeTaskVMInfo = task_vm_info;
56 mach_msg_type_number_t ChromeTaskVMInfoCount = TASK_VM_INFO_REV1_COUNT;
zino 2017/04/23 20:35:45 Hi This line is breaking build on 11.x. I'm not s
57 #endif // MAC_OS_X_VERSION_10_11
58
26 bool GetTaskInfo(mach_port_t task, task_basic_info_64* task_info_data) { 59 bool GetTaskInfo(mach_port_t task, task_basic_info_64* task_info_data) {
27 if (task == MACH_PORT_NULL) 60 if (task == MACH_PORT_NULL)
28 return false; 61 return false;
29 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; 62 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
30 kern_return_t kr = task_info(task, 63 kern_return_t kr = task_info(task,
31 TASK_BASIC_INFO_64, 64 TASK_BASIC_INFO_64,
32 reinterpret_cast<task_info_t>(task_info_data), 65 reinterpret_cast<task_info_t>(task_info_data),
33 &count); 66 &count);
34 // Most likely cause for failure: |task| is a zombie. 67 // Most likely cause for failure: |task| is a zombie.
35 return kr == KERN_SUCCESS; 68 return kr == KERN_SUCCESS;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 usage->mapped = 0; 316 usage->mapped = 0;
284 usage->image = 0; 317 usage->image = 0;
285 318
286 ws_usage->priv = task_info_data.resident_size / 1024; 319 ws_usage->priv = task_info_data.resident_size / 1024;
287 ws_usage->shareable = 0; 320 ws_usage->shareable = 0;
288 ws_usage->shared = 0; 321 ws_usage->shared = 0;
289 322
290 return true; 323 return true;
291 } 324 }
292 325
326 size_t ProcessMetrics::GetPhysicalFootprint() const {
327 if (mac::IsAtMostOS10_10())
328 return 0;
329
330 ChromeTaskVMInfo task_vm_info;
331 mach_msg_type_number_t count = ChromeTaskVMInfoCount;
332 kern_return_t result =
333 task_info(TaskForPid(process_), TASK_VM_INFO,
334 reinterpret_cast<task_info_t>(&task_vm_info), &count);
335 if (result != KERN_SUCCESS)
336 return 0;
337 return task_vm_info.phys_footprint;
338 }
339
293 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \ 340 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \
294 (r)->tv_sec = (a)->seconds; \ 341 (r)->tv_sec = (a)->seconds; \
295 (r)->tv_usec = (a)->microseconds; \ 342 (r)->tv_usec = (a)->microseconds; \
296 } while (0) 343 } while (0)
297 344
298 double ProcessMetrics::GetCPUUsage() { 345 double ProcessMetrics::GetCPUUsage() {
299 mach_port_t task = TaskForPid(process_); 346 mach_port_t task = TaskForPid(process_);
300 if (task == MACH_PORT_NULL) 347 if (task == MACH_PORT_NULL)
301 return 0; 348 return 0;
302 349
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.speculative_count); 497 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.speculative_count);
451 meminfo->file_backed = 498 meminfo->file_backed =
452 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.external_page_count); 499 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.external_page_count);
453 meminfo->purgeable = 500 meminfo->purgeable =
454 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.purgeable_count); 501 saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.purgeable_count);
455 502
456 return true; 503 return true;
457 } 504 }
458 505
459 } // namespace base 506 } // 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