1/* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24cc alloccount.c -o alloccount -Wall -framework IOKit 25 */ 26 27#include <assert.h> 28#include <CoreFoundation/CoreFoundation.h> 29#include <IOKit/IOKitLib.h> 30#include <IOKit/IOKitKeys.h> 31 32static void printNumber( CFDictionaryRef dict, CFStringRef name ) 33{ 34 CFNumberRef num; 35 SInt32 num32; 36 37 num = (CFNumberRef) CFDictionaryGetValue(dict, name); 38 if( num) { 39 assert( CFNumberGetTypeID() == CFGetTypeID(num) ); 40 CFNumberGetValue(num, kCFNumberSInt32Type, &num32); 41 printf("%22s = %08lx = %ld K\n", 42 CFStringGetCStringPtr(name, CFStringGetSystemEncoding()), 43 num32, num32 / 1024); 44 } 45} 46 47int main(int argc, char **argv) 48{ 49 mach_port_t masterPort; 50 io_registry_entry_t root; 51 CFDictionaryRef props; 52 kern_return_t status; 53 54 // Obtain the I/O Kit communication handle. 55 56 status = IOMasterPort(bootstrap_port, &masterPort); 57 assert(status == KERN_SUCCESS); 58 59 // Obtain the registry root entry. 60 61 root = IORegistryGetRootEntry(masterPort); 62 assert(root); 63 64 status = IORegistryEntryCreateCFProperties(root, 65 (CFTypeRef *) &props, 66 kCFAllocatorDefault, kNilOptions ); 67 assert( KERN_SUCCESS == status ); 68 assert( CFDictionaryGetTypeID() == CFGetTypeID(props)); 69 70 props = (CFDictionaryRef) 71 CFDictionaryGetValue( props, CFSTR(kIOKitDiagnosticsKey)); 72 assert( props ); 73 assert( CFDictionaryGetTypeID() == CFGetTypeID(props)); 74 75 printNumber(props, CFSTR("Instance allocation")); 76 printNumber(props, CFSTR("Container allocation")); 77 printNumber(props, CFSTR("IOMalloc allocation")); 78 79 CFRelease(props); 80 IOObjectRelease(root); 81 82 exit(0); 83} 84 85