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

Unified Diff: base/mach_ipc_mac.mm

Issue 9193024: [Mac] Add a perf test that counts the number of Mach ports in the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/mach_ipc_mac.h ('k') | chrome/browser/automation/testing_automation_provider.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mach_ipc_mac.mm
diff --git a/base/mach_ipc_mac.mm b/base/mach_ipc_mac.mm
index b6dedd2b89190b7cea5dba167105c77db155e818..61ea4e333e78e3f58f29d572a1c8284cdeda331a 100644
--- a/base/mach_ipc_mac.mm
+++ b/base/mach_ipc_mac.mm
@@ -5,6 +5,7 @@
#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
« no previous file with comments | « base/mach_ipc_mac.h ('k') | chrome/browser/automation/testing_automation_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698