2 * Copyright (c) 1998-2011 Apple 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 #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 SInt64 gIOKitTrace
= 0x3B;
48 UInt64 gIOInterruptThresholdNS
= 0;
50 SYSCTL_QUAD(_debug
, OID_AUTO
, iokit
, CTLFLAG_RW
| CTLFLAG_LOCKED
, &gIOKitDebug
, "boot_arg io");
51 SYSCTL_QUAD(_debug
, OID_AUTO
, iotrace
, CTLFLAG_RW
| CTLFLAG_LOCKED
, &gIOKitTrace
, "trace io");
52 SYSCTL_QUAD(_debug
, OID_AUTO
, iointthreshold
, CTLFLAG_RW
| CTLFLAG_LOCKED
, &gIOInterruptThresholdNS
, "io interrupt threshold");
55 int debug_malloc_size
;
56 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 #define DEBG(fmt, args...) { kprintf(fmt, ## args); }
67 #define DEBG(fmt, args...) { IOLog(fmt, ## args); }
70 void IOPrintPlane( const IORegistryPlane
* plane
)
72 IORegistryEntry
* next
;
73 IORegistryIterator
* iter
;
75 char format
[] = "%xxxs";
78 iter
= IORegistryIterator::iterateOver( plane
);
80 all
= iter
->iterateAll();
82 DEBG("Count %d\n", all
->getCount() );
88 while( (next
= iter
->getNextObjectRecursive())) {
89 snprintf(format
+ 1, sizeof(format
) - 1, "%ds", 2 * next
->getDepth( plane
));
91 DEBG( "\033[33m%s", next
->getName( plane
));
92 if( (next
->getLocation( plane
)))
93 DEBG("@%s", next
->getLocation( plane
));
94 DEBG("\033[0m <class %s", next
->getMetaClass()->getClassName());
95 if( (service
= OSDynamicCast(IOService
, next
)))
96 DEBG(", busy %ld", (long) service
->getBusyState());
103 void dbugprintf(char *fmt
, ...);
104 void db_dumpiojunk( const IORegistryPlane
* plane
);
106 void db_piokjunk(void) {
108 dbugprintf("\nDT plane:\n");
109 db_dumpiojunk( gIODTPlane
);
110 dbugprintf("\n\nService plane:\n");
111 db_dumpiojunk( gIOServicePlane
);
113 "ivar kalloc() 0x%08x\n"
115 "containers kalloc() 0x%08x\n"
116 "IOMalloc() 0x%08x\n"
117 "----------------------------------------\n",
120 debug_container_malloc_size
,
127 void db_dumpiojunk( const IORegistryPlane
* plane
)
129 IORegistryEntry
* next
;
130 IORegistryIterator
* iter
;
132 char format
[] = "%xxxs";
135 iter
= IORegistryIterator::iterateOver( plane
);
137 all
= iter
->iterateAll();
139 dbugprintf("Count %d\n", all
->getCount() );
141 } else dbugprintf("Empty\n");
144 while( (next
= iter
->getNextObjectRecursive())) {
145 snprintf(format
+ 1, sizeof(format
) - 1, "%ds", 2 * next
->getDepth( plane
));
146 dbugprintf( format
, "");
147 dbugprintf( "%s", next
->getName( plane
));
148 if( (next
->getLocation( plane
)))
149 dbugprintf("@%s", next
->getLocation( plane
));
150 dbugprintf(" <class %s", next
->getMetaClass()->getClassName());
151 if( (service
= OSDynamicCast(IOService
, next
)))
152 dbugprintf(", busy %ld", service
->getBusyState());
158 void IOPrintMemory( void )
161 // OSMetaClass::printInstanceCounts();
164 "ivar kalloc() 0x%08x\n"
166 "containers kalloc() 0x%08x\n"
167 "IOMalloc() 0x%08x\n"
168 "----------------------------------------\n",
171 debug_container_malloc_size
,
178 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
180 #define super OSObject
181 OSDefineMetaClassAndStructors(IOKitDiagnostics
, OSObject
)
183 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
185 OSObject
* IOKitDiagnostics::diagnostics( void )
187 IOKitDiagnostics
* diags
;
189 diags
= new IOKitDiagnostics
;
190 if( diags
&& !diags
->init()) {
198 void IOKitDiagnostics::updateOffset( OSDictionary
* dict
,
199 UInt32 value
, const char * name
)
203 off
= OSNumber::withNumber( value
, 32 );
207 dict
->setObject( name
, off
);
211 bool IOKitDiagnostics::serialize(OSSerialize
*s
) const
216 dict
= OSDictionary::withCapacity( 5 );
220 updateOffset( dict
, debug_ivars_size
, "Instance allocation" );
221 updateOffset( dict
, debug_container_malloc_size
, "Container allocation" );
222 updateOffset( dict
, debug_iomalloc_size
, "IOMalloc allocation" );
223 updateOffset( dict
, debug_iomallocpageable_size
, "Pageable allocation" );
225 OSMetaClass::serializeClassDictionary(dict
);
227 ok
= dict
->serialize( s
);
234 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */