2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
29 #include <sys/sysctl.h>
31 #include <IOKit/IOKitDebug.h>
32 #include <IOKit/IOLib.h>
33 #include <IOKit/assert.h>
34 #include <IOKit/IODeviceTreeSupport.h>
35 #include <IOKit/IOService.h>
37 #include <libkern/c++/OSContainers.h>
38 #include <libkern/c++/OSCPPDebug.h>
41 #define DEBUG_INIT_VALUE IOKITDEBUG
43 #define DEBUG_INIT_VALUE 0
46 SInt64 gIOKitDebug
= DEBUG_INIT_VALUE
;
47 SYSCTL_QUAD(_debug
, OID_AUTO
, iokit
, CTLFLAG_RW
, &gIOKitDebug
, "boot_arg io");
50 int debug_malloc_size
;
51 int debug_iomalloc_size
;
52 vm_size_t debug_iomallocpageable_size
;
53 int debug_container_malloc_size
;
54 // int debug_ivars_size; // in OSObject.cpp
59 void IOPrintPlane( const IORegistryPlane
* plane
)
61 IORegistryEntry
* next
;
62 IORegistryIterator
* iter
;
64 char format
[] = "%xxxs";
67 iter
= IORegistryIterator::iterateOver( plane
);
69 all
= iter
->iterateAll();
71 IOLog("Count %d\n", all
->getCount() );
77 while( (next
= iter
->getNextObjectRecursive())) {
78 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
80 IOLog( "\033[33m%s", next
->getName( plane
));
81 if( (next
->getLocation( plane
)))
82 IOLog("@%s", next
->getLocation( plane
));
83 IOLog("\033[0m <class %s", next
->getMetaClass()->getClassName());
84 if( (service
= OSDynamicCast(IOService
, next
)))
85 IOLog(", busy %ld", service
->getBusyState());
92 void dbugprintf(char *fmt
, ...);
93 void db_dumpiojunk( const IORegistryPlane
* plane
);
95 void db_piokjunk(void) {
97 dbugprintf("\nDT plane:\n");
98 db_dumpiojunk( gIODTPlane
);
99 dbugprintf("\n\nService plane:\n");
100 db_dumpiojunk( gIOServicePlane
);
102 "ivar kalloc() 0x%08x\n"
104 "containers kalloc() 0x%08x\n"
105 "IOMalloc() 0x%08x\n"
106 "----------------------------------------\n",
109 debug_container_malloc_size
,
116 void db_dumpiojunk( const IORegistryPlane
* plane
)
118 IORegistryEntry
* next
;
119 IORegistryIterator
* iter
;
121 char format
[] = "%xxxs";
124 iter
= IORegistryIterator::iterateOver( plane
);
126 all
= iter
->iterateAll();
128 dbugprintf("Count %d\n", all
->getCount() );
130 } else dbugprintf("Empty\n");
133 while( (next
= iter
->getNextObjectRecursive())) {
134 sprintf( format
+ 1, "%ds", 2 * next
->getDepth( plane
));
135 dbugprintf( format
, "");
136 dbugprintf( "%s", next
->getName( plane
));
137 if( (next
->getLocation( plane
)))
138 dbugprintf("@%s", next
->getLocation( plane
));
139 dbugprintf(" <class %s", next
->getMetaClass()->getClassName());
140 if( (service
= OSDynamicCast(IOService
, next
)))
141 dbugprintf(", busy %ld", service
->getBusyState());
147 void IOPrintMemory( void )
150 // OSMetaClass::printInstanceCounts();
153 "ivar kalloc() 0x%08x\n"
155 "containers kalloc() 0x%08x\n"
156 "IOMalloc() 0x%08x\n"
157 "----------------------------------------\n",
160 debug_container_malloc_size
,
167 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
169 #define super OSObject
170 OSDefineMetaClassAndStructors(IOKitDiagnostics
, OSObject
)
172 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
174 OSObject
* IOKitDiagnostics::diagnostics( void )
176 IOKitDiagnostics
* diags
;
178 diags
= new IOKitDiagnostics
;
179 if( diags
&& !diags
->init()) {
187 void IOKitDiagnostics::updateOffset( OSDictionary
* dict
,
188 UInt32 value
, const char * name
)
192 off
= OSNumber::withNumber( value
, 32 );
196 dict
->setObject( name
, off
);
201 bool IOKitDiagnostics::serialize(OSSerialize
*s
) const
206 dict
= OSDictionary::withCapacity( 5 );
210 updateOffset( dict
, debug_ivars_size
, "Instance allocation" );
211 updateOffset( dict
, debug_container_malloc_size
, "Container allocation" );
212 updateOffset( dict
, debug_iomalloc_size
, "IOMalloc allocation" );
213 updateOffset( dict
, debug_iomallocpageable_size
, "Pageable allocation" );
215 OSMetaClass::serializeClassDictionary(dict
);
217 ok
= dict
->serialize( s
);
224 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */