diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-28 00:51:42 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-28 00:51:42 +0000 |
commit | 23c6c2b0988fee9b5d0c9eb3565b41cfd1afb940 (patch) | |
tree | ab5076f8c9b869383cf55686f1b7268d048488e9 /base | |
parent | c66f58a78b49eaa7856f2b6459fd57e1b792eb8d (diff) | |
download | chromium_src-23c6c2b0988fee9b5d0c9eb3565b41cfd1afb940.zip chromium_src-23c6c2b0988fee9b5d0c9eb3565b41cfd1afb940.tar.gz chromium_src-23c6c2b0988fee9b5d0c9eb3565b41cfd1afb940.tar.bz2 |
[Mac] Add a perf test that counts the number of Mach ports in the browser.
BUG=105513
TEST=This is one.
Review URL: http://codereview.chromium.org/9193024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119541 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/mach_ipc_mac.h | 15 | ||||
-rw-r--r-- | base/mach_ipc_mac.mm | 35 |
2 files changed, 48 insertions, 2 deletions
diff --git a/base/mach_ipc_mac.h b/base/mach_ipc_mac.h index 7d39101..d0898a3 100644 --- a/base/mach_ipc_mac.h +++ b/base/mach_ipc_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -309,6 +309,19 @@ class BASE_EXPORT MachPortSender { DISALLOW_COPY_AND_ASSIGN(MachPortSender); }; +//============================================================================== +// Static utility functions. + +namespace mac { + +// Returns the number of Mach ports to which the given task has a right. +// Note that unless the calling task has send rights to the passed task port, +// this will fail unless the calling task is running as root. +kern_return_t BASE_EXPORT GetNumberOfMachPorts(mach_port_t task_port, + int* port_count); + +} // namespace mac + } // namespace base #endif // BASE_MACH_IPC_MAC_H_ diff --git a/base/mach_ipc_mac.mm b/base/mach_ipc_mac.mm index b6dedd2..3d45dd7 100644 --- a/base/mach_ipc_mac.mm +++ b/base/mach_ipc_mac.mm @@ -1,10 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/mach_ipc_mac.h" #import <Foundation/Foundation.h> +#include <mach/vm_map.h> #include <stdio.h> #include "base/logging.h" @@ -322,4 +323,36 @@ kern_return_t MachPortSender::SendMessage(MachSendMessage &message, return result; } +//============================================================================== + +namespace mac { + +kern_return_t GetNumberOfMachPorts(mach_port_t task_port, int* num_ports) { + mach_port_name_array_t names; + mach_msg_type_number_t names_count; + mach_port_type_array_t types; + mach_msg_type_number_t types_count; + + // A friendlier interface would allow NULL buffers to only get the counts. + kern_return_t kr = mach_port_names(task_port, &names, &names_count, + &types, &types_count); + if (kr != KERN_SUCCESS) + return kr; + + // The documentation states this is an invariant. + DCHECK_EQ(names_count, types_count); + *num_ports = names_count; + + kr = vm_deallocate(mach_task_self(), + reinterpret_cast<vm_address_t>(names), + names_count * sizeof(mach_port_name_array_t)); + kr = vm_deallocate(mach_task_self(), + reinterpret_cast<vm_address_t>(types), + types_count * sizeof(mach_port_type_array_t)); + + return kr; +} + +} // namespace mac + } // namespace base |