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

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: 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
Index: base/mach_ipc_mac.mm
diff --git a/base/mach_ipc_mac.mm b/base/mach_ipc_mac.mm
index b6dedd2b89190b7cea5dba167105c77db155e818..e89cf286c23a4d6e723bac0e167bfaea5de1eae8 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(task_port,
Mark Mentovai 2012/01/23 21:12:30 346 and 349 should use mach_task_self.
Robert Sesek 2012/01/23 21:58:41 Done.
+ reinterpret_cast<vm_address_t>(names),
+ names_count * sizeof(mach_port_name_array_t));
+ kr = vm_deallocate(task_port,
+ reinterpret_cast<vm_address_t>(types),
+ types_count * sizeof(mach_port_type_array_t));
+
+ return kr;
+}
+
+} // namespace mac
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698