1 /* 2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * The contents of this file constitute Original Code as defined in and 7 * are subject to the Apple Public Source License Version 1.1 (the 8 * "License"). You may not use this file except in compliance with the 9 * License. Please obtain a copy of the License at 10 * http://www.apple.com/publicsource and read it before using this file. 11 * 12 * This Original Code and all software distributed under the License are 13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 * License for the specific language governing rights and limitations 18 * under the License. 19 * 20 * @APPLE_LICENSE_HEADER_END@ 21 */ 22 /* 23 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. 24 * 25 * HISTORY 26 * 27 */ 28 29 #include <IOKit/IOKitDebug.h> 30 #include <IOKit/IOLib.h> 31 #include <IOKit/assert.h> 32 #include <IOKit/IODeviceTreeSupport.h> 33 #include <IOKit/IOService.h> 34 35 #include <libkern/c++/OSContainers.h> 36 #include <libkern/c++/OSCPPDebug.h> 37 38 extern "C" { 39 40 SInt64 gIOKitDebug 41 #ifdef IOKITDEBUG 42 = IOKITDEBUG 43 #endif 44 ; 45 46 int debug_malloc_size; 47 int debug_iomalloc_size; 48 int debug_container_malloc_size; 49 // int debug_ivars_size; // in OSObject.cpp 50 51 void IOPrintPlane( const IORegistryPlane * plane ) 52 { 53 IORegistryEntry * next; 54 IORegistryIterator * iter; 55 OSOrderedSet * all; 56 char format[] = "%xxxs"; 57 IOService * service; 58 59 iter = IORegistryIterator::iterateOver( plane ); 60 assert( iter ); 61 all = iter->iterateAll(); 62 if( all) { 63 IOLog("Count %d\n", all->getCount() ); 64 all->release(); 65 } else 66 IOLog("Empty\n"); 67 68 iter->reset(); 69 while( (next = iter->getNextObjectRecursive())) { 70 sprintf( format + 1, "%ds", 2 * next->getDepth( plane )); 71 IOLog( format, ""); 72 IOLog( "\033[33m%s", next->getName( plane )); 73 if( (next->getLocation( plane ))) 74 IOLog("@%s", next->getLocation( plane )); 75 IOLog("\033[0m <class %s", next->getMetaClass()->getClassName()); 76 if( (service = OSDynamicCast(IOService, next))) 77 IOLog(", busy %ld", service->getBusyState()); 78 IOLog( ">\n"); 79 IOSleep(250); 80 } 81 iter->release(); 82 } 83 84 void IOPrintMemory( void ) 85 { 86 87 // OSMetaClass::printInstanceCounts(); 88 89 IOLog("\n" 90 "ivar kalloc() 0x%08x\n" 91 "malloc() 0x%08x\n" 92 "containers kalloc() 0x%08x\n" 93 "IOMalloc() 0x%08x\n" 94 "----------------------------------------\n", 95 debug_ivars_size, 96 debug_malloc_size, 97 debug_container_malloc_size, 98 debug_iomalloc_size 99 ); 100 } 101 102 } /* extern "C" */ 103 104 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 105 106 #define super OSObject 107 OSDefineMetaClassAndStructors(IOKitDiagnostics, OSObject) 108 109 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 110 111 OSObject * IOKitDiagnostics::diagnostics( void ) 112 { 113 IOKitDiagnostics * diags; 114 115 diags = new IOKitDiagnostics; 116 if( diags && !diags->init()) { 117 diags->release(); 118 diags = 0; 119 } 120 121 return( diags ); 122 } 123 124 void IOKitDiagnostics::updateOffset( OSDictionary * dict, 125 UInt32 value, const char * name ) 126 { 127 OSNumber * off; 128 129 off = OSNumber::withNumber( value, 32 ); 130 if( !off) 131 return; 132 133 dict->setObject( name, off ); 134 off->release(); 135 } 136 137 138 bool IOKitDiagnostics::serialize(OSSerialize *s) const 139 { 140 OSDictionary * dict; 141 bool ok; 142 143 dict = OSDictionary::withCapacity( 5 ); 144 if( !dict) 145 return( false ); 146 147 updateOffset( dict, debug_ivars_size, "Instance allocation" ); 148 updateOffset( dict, debug_container_malloc_size, "Container allocation" ); 149 updateOffset( dict, debug_iomalloc_size, "IOMalloc allocation" ); 150 151 dict->setObject( "Classes", OSMetaClass::getClassDictionary() ); 152 153 ok = dict->serialize( s ); 154 155 dict->release(); 156 157 return( ok ); 158 } 159 160 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 161