2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
35 #include <sys/sysctl.h>
37 #include <IOKit/IOKitDebug.h>
38 #include <IOKit/IOLib.h>
39 #include <IOKit/assert.h>
40 #include <IOKit/IODeviceTreeSupport.h>
41 #include <IOKit/IOService.h>
43 #include <libkern/c++/OSContainers.h>
44 #include <libkern/c++/OSCPPDebug.h>
47 #define DEBUG_INIT_VALUE IOKITDEBUG
49 #define DEBUG_INIT_VALUE 0
52 SInt64 gIOKitDebug
= DEBUG_INIT_VALUE
;
53 SYSCTL_QUAD(_debug
, OID_AUTO
, iokit
, CTLFLAG_RW
, &gIOKitDebug
, "boot_arg io");
56 int debug_malloc_size
;
57 int debug_iomalloc_size
;
58 vm_size_t debug_iomallocpageable_size
;
59 int debug_container_malloc_size
;
60 // int debug_ivars_size; // in OSObject.cpp
65 void IOPrintPlane( const IORegistryPlane
* plane
)
67 IORegistryEntry
* next
;
68 IORegistryIterator
* iter
;
70 char format
[] = "%xxxs";
73 iter
= IORegistryIterator::iterateOver( plane
);
75 all
= iter
->iterateAll();
77 IOLog("Count %d\n", all
->getCount() );
83 while( (next
= iter
->getNextObjectRecursive())) {
84 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
86 IOLog( "\033[33m%s", next
->getName( plane
));
87 if( (next
->getLocation( plane
)))
88 IOLog("@%s", next
->getLocation( plane
));
89 IOLog("\033[0m <class %s", next
->getMetaClass()->getClassName());
90 if( (service
= OSDynamicCast(IOService
, next
)))
91 IOLog(", busy %ld", service
->getBusyState());
98 void dbugprintf(char *fmt
, ...);
99 void db_dumpiojunk( const IORegistryPlane
* plane
);
101 void db_piokjunk(void) {
103 dbugprintf("\nDT plane:\n");
104 db_dumpiojunk( gIODTPlane
);
105 dbugprintf("\n\nService plane:\n");
106 db_dumpiojunk( gIOServicePlane
);
108 "ivar kalloc() 0x%08x\n"
110 "containers kalloc() 0x%08x\n"
111 "IOMalloc() 0x%08x\n"
112 "----------------------------------------\n",
115 debug_container_malloc_size
,
122 void db_dumpiojunk( const IORegistryPlane
* plane
)
124 IORegistryEntry
* next
;
125 IORegistryIterator
* iter
;
127 char format
[] = "%xxxs";
130 iter
= IORegistryIterator::iterateOver( plane
);
132 all
= iter
->iterateAll();
134 dbugprintf("Count %d\n", all
->getCount() );
136 } else dbugprintf("Empty\n");
139 while( (next
= iter
->getNextObjectRecursive())) {
140 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
141 dbugprintf( format
, "");
142 dbugprintf( "%s", next
->getName( plane
));
143 if( (next
->getLocation( plane
)))
144 dbugprintf("@%s", next
->getLocation( plane
));
145 dbugprintf(" <class %s", next
->getMetaClass()->getClassName());
146 if( (service
= OSDynamicCast(IOService
, next
)))
147 dbugprintf(", busy %ld", service
->getBusyState());
153 void IOPrintMemory( void )
156 // OSMetaClass::printInstanceCounts();
159 "ivar kalloc() 0x%08x\n"
161 "containers kalloc() 0x%08x\n"
162 "IOMalloc() 0x%08x\n"
163 "----------------------------------------\n",
166 debug_container_malloc_size
,
173 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
175 #define super OSObject
176 OSDefineMetaClassAndStructors(IOKitDiagnostics
, OSObject
)
178 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
180 OSObject
* IOKitDiagnostics::diagnostics( void )
182 IOKitDiagnostics
* diags
;
184 diags
= new IOKitDiagnostics
;
185 if( diags
&& !diags
->init()) {
193 void IOKitDiagnostics::updateOffset( OSDictionary
* dict
,
194 UInt32 value
, const char * name
)
198 off
= OSNumber::withNumber( value
, 32 );
202 dict
->setObject( name
, off
);
207 bool IOKitDiagnostics::serialize(OSSerialize
*s
) const
212 dict
= OSDictionary::withCapacity( 5 );
216 updateOffset( dict
, debug_ivars_size
, "Instance allocation" );
217 updateOffset( dict
, debug_container_malloc_size
, "Container allocation" );
218 updateOffset( dict
, debug_iomalloc_size
, "IOMalloc allocation" );
219 updateOffset( dict
, debug_iomallocpageable_size
, "Pageable allocation" );
221 OSMetaClass::serializeClassDictionary(dict
);
223 ok
= dict
->serialize( s
);
230 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */