2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
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>
49 int debug_malloc_size
;
50 int debug_iomalloc_size
;
51 int debug_container_malloc_size
;
52 // int debug_ivars_size; // in OSObject.cpp
54 void IOPrintPlane( const IORegistryPlane
* plane
)
56 IORegistryEntry
* next
;
57 IORegistryIterator
* iter
;
59 char format
[] = "%xxxs";
62 iter
= IORegistryIterator::iterateOver( plane
);
64 all
= iter
->iterateAll();
66 IOLog("Count %d\n", all
->getCount() );
72 while( (next
= iter
->getNextObjectRecursive())) {
73 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
75 IOLog( "\033[33m%s", next
->getName( plane
));
76 if( (next
->getLocation( plane
)))
77 IOLog("@%s", next
->getLocation( plane
));
78 IOLog("\033[0m <class %s", next
->getMetaClass()->getClassName());
79 if( (service
= OSDynamicCast(IOService
, next
)))
80 IOLog(", busy %ld", service
->getBusyState());
87 void dbugprintf(char *fmt
, ...);
88 void db_dumpiojunk( const IORegistryPlane
* plane
);
90 void db_piokjunk(void) {
92 dbugprintf("\nDT plane:\n");
93 db_dumpiojunk( gIODTPlane
);
94 dbugprintf("\n\nService plane:\n");
95 db_dumpiojunk( gIOServicePlane
);
97 "ivar kalloc() 0x%08x\n"
99 "containers kalloc() 0x%08x\n"
100 "IOMalloc() 0x%08x\n"
101 "----------------------------------------\n",
104 debug_container_malloc_size
,
111 void db_dumpiojunk( const IORegistryPlane
* plane
)
113 IORegistryEntry
* next
;
114 IORegistryIterator
* iter
;
116 char format
[] = "%xxxs";
119 iter
= IORegistryIterator::iterateOver( plane
);
121 all
= iter
->iterateAll();
123 dbugprintf("Count %d\n", all
->getCount() );
125 } else dbugprintf("Empty\n");
128 while( (next
= iter
->getNextObjectRecursive())) {
129 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
130 dbugprintf( format
, "");
131 dbugprintf( "%s", next
->getName( plane
));
132 if( (next
->getLocation( plane
)))
133 dbugprintf("@%s", next
->getLocation( plane
));
134 dbugprintf(" <class %s", next
->getMetaClass()->getClassName());
135 if( (service
= OSDynamicCast(IOService
, next
)))
136 dbugprintf(", busy %ld", service
->getBusyState());
142 void IOPrintMemory( void )
145 // OSMetaClass::printInstanceCounts();
148 "ivar kalloc() 0x%08x\n"
150 "containers kalloc() 0x%08x\n"
151 "IOMalloc() 0x%08x\n"
152 "----------------------------------------\n",
155 debug_container_malloc_size
,
162 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
164 #define super OSObject
165 OSDefineMetaClassAndStructors(IOKitDiagnostics
, OSObject
)
167 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
169 OSObject
* IOKitDiagnostics::diagnostics( void )
171 IOKitDiagnostics
* diags
;
173 diags
= new IOKitDiagnostics
;
174 if( diags
&& !diags
->init()) {
182 void IOKitDiagnostics::updateOffset( OSDictionary
* dict
,
183 UInt32 value
, const char * name
)
187 off
= OSNumber::withNumber( value
, 32 );
191 dict
->setObject( name
, off
);
196 bool IOKitDiagnostics::serialize(OSSerialize
*s
) const
201 dict
= OSDictionary::withCapacity( 5 );
205 updateOffset( dict
, debug_ivars_size
, "Instance allocation" );
206 updateOffset( dict
, debug_container_malloc_size
, "Container allocation" );
207 updateOffset( dict
, debug_iomalloc_size
, "IOMalloc allocation" );
209 OSMetaClass::serializeClassDictionary(dict
);
211 ok
= dict
->serialize( s
);
218 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */