2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30 #include <sys/sysctl.h>
32 #include <IOKit/IOKitDebug.h>
33 #include <IOKit/IOLib.h>
34 #include <IOKit/assert.h>
35 #include <IOKit/IODeviceTreeSupport.h>
36 #include <IOKit/IOService.h>
38 #include <libkern/c++/OSContainers.h>
39 #include <libkern/c++/OSCPPDebug.h>
42 #define DEBUG_INIT_VALUE IOKITDEBUG
44 #define DEBUG_INIT_VALUE 0
47 SInt64 gIOKitDebug
= DEBUG_INIT_VALUE
;
48 SYSCTL_QUAD(_debug
, OID_AUTO
, iokit
, CTLFLAG_RW
, &gIOKitDebug
, "boot_arg io");
51 int debug_malloc_size
;
52 int debug_iomalloc_size
;
53 vm_size_t debug_iomallocpageable_size
;
54 int debug_container_malloc_size
;
55 // int debug_ivars_size; // in OSObject.cpp
60 void IOPrintPlane( const IORegistryPlane
* plane
)
62 IORegistryEntry
* next
;
63 IORegistryIterator
* iter
;
65 char format
[] = "%xxxs";
68 iter
= IORegistryIterator::iterateOver( plane
);
70 all
= iter
->iterateAll();
72 IOLog("Count %d\n", all
->getCount() );
78 while( (next
= iter
->getNextObjectRecursive())) {
79 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
81 IOLog( "\033[33m%s", next
->getName( plane
));
82 if( (next
->getLocation( plane
)))
83 IOLog("@%s", next
->getLocation( plane
));
84 IOLog("\033[0m <class %s", next
->getMetaClass()->getClassName());
85 if( (service
= OSDynamicCast(IOService
, next
)))
86 IOLog(", busy %ld", service
->getBusyState());
93 void dbugprintf(char *fmt
, ...);
94 void db_dumpiojunk( const IORegistryPlane
* plane
);
96 void db_piokjunk(void) {
98 dbugprintf("\nDT plane:\n");
99 db_dumpiojunk( gIODTPlane
);
100 dbugprintf("\n\nService plane:\n");
101 db_dumpiojunk( gIOServicePlane
);
103 "ivar kalloc() 0x%08x\n"
105 "containers kalloc() 0x%08x\n"
106 "IOMalloc() 0x%08x\n"
107 "----------------------------------------\n",
110 debug_container_malloc_size
,
117 void db_dumpiojunk( const IORegistryPlane
* plane
)
119 IORegistryEntry
* next
;
120 IORegistryIterator
* iter
;
122 char format
[] = "%xxxs";
125 iter
= IORegistryIterator::iterateOver( plane
);
127 all
= iter
->iterateAll();
129 dbugprintf("Count %d\n", all
->getCount() );
131 } else dbugprintf("Empty\n");
134 while( (next
= iter
->getNextObjectRecursive())) {
135 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
136 dbugprintf( format
, "");
137 dbugprintf( "%s", next
->getName( plane
));
138 if( (next
->getLocation( plane
)))
139 dbugprintf("@%s", next
->getLocation( plane
));
140 dbugprintf(" <class %s", next
->getMetaClass()->getClassName());
141 if( (service
= OSDynamicCast(IOService
, next
)))
142 dbugprintf(", busy %ld", service
->getBusyState());
148 void IOPrintMemory( void )
151 // OSMetaClass::printInstanceCounts();
154 "ivar kalloc() 0x%08x\n"
156 "containers kalloc() 0x%08x\n"
157 "IOMalloc() 0x%08x\n"
158 "----------------------------------------\n",
161 debug_container_malloc_size
,
168 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
170 #define super OSObject
171 OSDefineMetaClassAndStructors(IOKitDiagnostics
, OSObject
)
173 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
175 OSObject
* IOKitDiagnostics::diagnostics( void )
177 IOKitDiagnostics
* diags
;
179 diags
= new IOKitDiagnostics
;
180 if( diags
&& !diags
->init()) {
188 void IOKitDiagnostics::updateOffset( OSDictionary
* dict
,
189 UInt32 value
, const char * name
)
193 off
= OSNumber::withNumber( value
, 32 );
197 dict
->setObject( name
, off
);
202 bool IOKitDiagnostics::serialize(OSSerialize
*s
) const
207 dict
= OSDictionary::withCapacity( 5 );
211 updateOffset( dict
, debug_ivars_size
, "Instance allocation" );
212 updateOffset( dict
, debug_container_malloc_size
, "Container allocation" );
213 updateOffset( dict
, debug_iomalloc_size
, "IOMalloc allocation" );
214 updateOffset( dict
, debug_iomallocpageable_size
, "Pageable allocation" );
216 OSMetaClass::serializeClassDictionary(dict
);
218 ok
= dict
->serialize( s
);
225 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */