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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/mach_ipc_mac.h" 5 #include "base/mach_ipc_mac.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 #include <mach/vm_map.h>
8 9
9 #include <stdio.h> 10 #include <stdio.h>
10 #include "base/logging.h" 11 #include "base/logging.h"
11 12
12 namespace base { 13 namespace base {
13 14
14 // static 15 // static
15 const size_t MachMessage::kEmptyMessageSize = sizeof(mach_msg_header_t) + 16 const size_t MachMessage::kEmptyMessageSize = sizeof(mach_msg_header_t) +
16 sizeof(mach_msg_body_t) + sizeof(MessageDataPacket); 17 sizeof(mach_msg_body_t) + sizeof(MessageDataPacket);
17 18
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 MACH_SEND_MSG | MACH_SEND_TIMEOUT, 316 MACH_SEND_MSG | MACH_SEND_TIMEOUT,
316 message.Head()->msgh_size, 317 message.Head()->msgh_size,
317 0, 318 0,
318 MACH_PORT_NULL, 319 MACH_PORT_NULL,
319 timeout, // timeout in ms 320 timeout, // timeout in ms
320 MACH_PORT_NULL); 321 MACH_PORT_NULL);
321 322
322 return result; 323 return result;
323 } 324 }
324 325
326 //==============================================================================
327
328 namespace mac {
329
330 kern_return_t GetNumberOfMachPorts(mach_port_t task_port, int* num_ports) {
331 mach_port_name_array_t names;
332 mach_msg_type_number_t names_count;
333 mach_port_type_array_t types;
334 mach_msg_type_number_t types_count;
335
336 // A friendlier interface would allow NULL buffers to only get the counts.
337 kern_return_t kr = mach_port_names(task_port, &names, &names_count,
338 &types, &types_count);
339 if (kr != KERN_SUCCESS)
340 return kr;
341
342 // The documentation states this is an invariant.
343 DCHECK_EQ(names_count, types_count);
344 *num_ports = names_count;
345
346 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.
347 reinterpret_cast<vm_address_t>(names),
348 names_count * sizeof(mach_port_name_array_t));
349 kr = vm_deallocate(task_port,
350 reinterpret_cast<vm_address_t>(types),
351 types_count * sizeof(mach_port_type_array_t));
352
353 return kr;
354 }
355
356 } // namespace mac
357
325 } // namespace base 358 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698