2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
37 #include <sys/sysctl.h>
39 #include <IOKit/IOKitDebug.h>
40 #include <IOKit/IOLib.h>
41 #include <IOKit/assert.h>
42 #include <IOKit/IODeviceTreeSupport.h>
43 #include <IOKit/IOService.h>
45 #include <libkern/c++/OSContainers.h>
46 #include <libkern/c++/OSCPPDebug.h>
49 #define DEBUG_INIT_VALUE IOKITDEBUG
51 #define DEBUG_INIT_VALUE 0
54 SInt64 gIOKitDebug
= DEBUG_INIT_VALUE
;
55 SYSCTL_QUAD(_debug
, OID_AUTO
, iokit
, CTLFLAG_RW
, &gIOKitDebug
, "boot_arg io");
58 int debug_malloc_size
;
59 int debug_iomalloc_size
;
60 vm_size_t debug_iomallocpageable_size
;
61 int debug_container_malloc_size
;
62 // int debug_ivars_size; // in OSObject.cpp
67 void IOPrintPlane( const IORegistryPlane
* plane
)
69 IORegistryEntry
* next
;
70 IORegistryIterator
* iter
;
72 char format
[] = "%xxxs";
75 iter
= IORegistryIterator::iterateOver( plane
);
77 all
= iter
->iterateAll();
79 IOLog("Count %d\n", all
->getCount() );
85 while( (next
= iter
->getNextObjectRecursive())) {
86 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
88 IOLog( "\033[33m%s", next
->getName( plane
));
89 if( (next
->getLocation( plane
)))
90 IOLog("@%s", next
->getLocation( plane
));
91 IOLog("\033[0m <class %s", next
->getMetaClass()->getClassName());
92 if( (service
= OSDynamicCast(IOService
, next
)))
93 IOLog(", busy %ld", service
->getBusyState());
100 void dbugprintf(char *fmt
, ...);
101 void db_dumpiojunk( const IORegistryPlane
* plane
);
103 void db_piokjunk(void) {
105 dbugprintf("\nDT plane:\n");
106 db_dumpiojunk( gIODTPlane
);
107 dbugprintf("\n\nService plane:\n");
108 db_dumpiojunk( gIOServicePlane
);
110 "ivar kalloc() 0x%08x\n"
112 "containers kalloc() 0x%08x\n"
113 "IOMalloc() 0x%08x\n"
114 "----------------------------------------\n",
117 debug_container_malloc_size
,
124 void db_dumpiojunk( const IORegistryPlane
* plane
)
126 IORegistryEntry
* next
;
127 IORegistryIterator
* iter
;
129 char format
[] = "%xxxs";
132 iter
= IORegistryIterator::iterateOver( plane
);
134 all
= iter
->iterateAll();
136 dbugprintf("Count %d\n", all
->getCount() );
138 } else dbugprintf("Empty\n");
141 while( (next
= iter
->getNextObjectRecursive())) {
142 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
143 dbugprintf( format
, "");
144 dbugprintf( "%s", next
->getName( plane
));
145 if( (next
->getLocation( plane
)))
146 dbugprintf("@%s", next
->getLocation( plane
));
147 dbugprintf(" <class %s", next
->getMetaClass()->getClassName());
148 if( (service
= OSDynamicCast(IOService
, next
)))
149 dbugprintf(", busy %ld", service
->getBusyState());
155 void IOPrintMemory( void )
158 // OSMetaClass::printInstanceCounts();
161 "ivar kalloc() 0x%08x\n"
163 "containers kalloc() 0x%08x\n"
164 "IOMalloc() 0x%08x\n"
165 "----------------------------------------\n",
168 debug_container_malloc_size
,
175 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
177 #define super OSObject
178 OSDefineMetaClassAndStructors(IOKitDiagnostics
, OSObject
)
180 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
182 OSObject
* IOKitDiagnostics::diagnostics( void )
184 IOKitDiagnostics
* diags
;
186 diags
= new IOKitDiagnostics
;
187 if( diags
&& !diags
->init()) {
195 void IOKitDiagnostics::updateOffset( OSDictionary
* dict
,
196 UInt32 value
, const char * name
)
200 off
= OSNumber::withNumber( value
, 32 );
204 dict
->setObject( name
, off
);
209 bool IOKitDiagnostics::serialize(OSSerialize
*s
) const
214 dict
= OSDictionary::withCapacity( 5 );
218 updateOffset( dict
, debug_ivars_size
, "Instance allocation" );
219 updateOffset( dict
, debug_container_malloc_size
, "Container allocation" );
220 updateOffset( dict
, debug_iomalloc_size
, "IOMalloc allocation" );
221 updateOffset( dict
, debug_iomallocpageable_size
, "Pageable allocation" );
223 OSMetaClass::serializeClassDictionary(dict
);
225 ok
= dict
->serialize( s
);
232 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */