]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOKitDebug.cpp
xnu-792.12.6.tar.gz
[apple/xnu.git] / iokit / Kernel / IOKitDebug.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
32 *
33 * HISTORY
34 *
35 */
36
37 #include <sys/sysctl.h>
38
39 #include <IOKit/IOKitDebug.h>
40 #include <IOKit/IOLib.h>
41 #include <IOKit/assert.h>
42 #include <IOKit/IODeviceTreeSupport.h>
43 #include <IOKit/IOService.h>
44
45 #include <libkern/c++/OSContainers.h>
46 #include <libkern/c++/OSCPPDebug.h>
47
48 #ifdef IOKITDEBUG
49 #define DEBUG_INIT_VALUE IOKITDEBUG
50 #else
51 #define DEBUG_INIT_VALUE 0
52 #endif
53
54 SInt64 gIOKitDebug = DEBUG_INIT_VALUE;
55 SYSCTL_QUAD(_debug, OID_AUTO, iokit, CTLFLAG_RW, &gIOKitDebug, "boot_arg io");
56
57
58 int debug_malloc_size;
59 int debug_iomalloc_size;
60 vm_size_t debug_iomallocpageable_size;
61 int debug_container_malloc_size;
62 // int debug_ivars_size; // in OSObject.cpp
63
64 extern "C" {
65
66
67 void IOPrintPlane( const IORegistryPlane * plane )
68 {
69 IORegistryEntry * next;
70 IORegistryIterator * iter;
71 OSOrderedSet * all;
72 char format[] = "%xxxs";
73 IOService * service;
74
75 iter = IORegistryIterator::iterateOver( plane );
76 assert( iter );
77 all = iter->iterateAll();
78 if( all) {
79 IOLog("Count %d\n", all->getCount() );
80 all->release();
81 } else
82 IOLog("Empty\n");
83
84 iter->reset();
85 while( (next = iter->getNextObjectRecursive())) {
86 sprintf( format + 1, "%ds", 2 * next->getDepth( plane ));
87 IOLog( format, "");
88 IOLog( "\033[33m%s", next->getName( plane ));
89 if( (next->getLocation( plane )))
90 IOLog("@%s", next->getLocation( plane ));
91 IOLog("\033[0m <class %s", next->getMetaClass()->getClassName());
92 if( (service = OSDynamicCast(IOService, next)))
93 IOLog(", busy %ld", service->getBusyState());
94 IOLog( ">\n");
95 IOSleep(250);
96 }
97 iter->release();
98 }
99
100 void dbugprintf(char *fmt, ...);
101 void db_dumpiojunk( const IORegistryPlane * plane );
102
103 void db_piokjunk(void) {
104
105 dbugprintf("\nDT plane:\n");
106 db_dumpiojunk( gIODTPlane );
107 dbugprintf("\n\nService plane:\n");
108 db_dumpiojunk( gIOServicePlane );
109 dbugprintf("\n\n"
110 "ivar kalloc() 0x%08x\n"
111 "malloc() 0x%08x\n"
112 "containers kalloc() 0x%08x\n"
113 "IOMalloc() 0x%08x\n"
114 "----------------------------------------\n",
115 debug_ivars_size,
116 debug_malloc_size,
117 debug_container_malloc_size,
118 debug_iomalloc_size
119 );
120
121 }
122
123
124 void db_dumpiojunk( const IORegistryPlane * plane )
125 {
126 IORegistryEntry * next;
127 IORegistryIterator * iter;
128 OSOrderedSet * all;
129 char format[] = "%xxxs";
130 IOService * service;
131
132 iter = IORegistryIterator::iterateOver( plane );
133
134 all = iter->iterateAll();
135 if( all) {
136 dbugprintf("Count %d\n", all->getCount() );
137 all->release();
138 } else dbugprintf("Empty\n");
139
140 iter->reset();
141 while( (next = iter->getNextObjectRecursive())) {
142 sprintf( format + 1, "%ds", 2 * next->getDepth( plane ));
143 dbugprintf( format, "");
144 dbugprintf( "%s", next->getName( plane ));
145 if( (next->getLocation( plane )))
146 dbugprintf("@%s", next->getLocation( plane ));
147 dbugprintf(" <class %s", next->getMetaClass()->getClassName());
148 if( (service = OSDynamicCast(IOService, next)))
149 dbugprintf(", busy %ld", service->getBusyState());
150 dbugprintf( ">\n");
151 }
152 iter->release();
153 }
154
155 void IOPrintMemory( void )
156 {
157
158 // OSMetaClass::printInstanceCounts();
159
160 IOLog("\n"
161 "ivar kalloc() 0x%08x\n"
162 "malloc() 0x%08x\n"
163 "containers kalloc() 0x%08x\n"
164 "IOMalloc() 0x%08x\n"
165 "----------------------------------------\n",
166 debug_ivars_size,
167 debug_malloc_size,
168 debug_container_malloc_size,
169 debug_iomalloc_size
170 );
171 }
172
173 } /* extern "C" */
174
175 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
176
177 #define super OSObject
178 OSDefineMetaClassAndStructors(IOKitDiagnostics, OSObject)
179
180 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
181
182 OSObject * IOKitDiagnostics::diagnostics( void )
183 {
184 IOKitDiagnostics * diags;
185
186 diags = new IOKitDiagnostics;
187 if( diags && !diags->init()) {
188 diags->release();
189 diags = 0;
190 }
191
192 return( diags );
193 }
194
195 void IOKitDiagnostics::updateOffset( OSDictionary * dict,
196 UInt32 value, const char * name )
197 {
198 OSNumber * off;
199
200 off = OSNumber::withNumber( value, 32 );
201 if( !off)
202 return;
203
204 dict->setObject( name, off );
205 off->release();
206 }
207
208
209 bool IOKitDiagnostics::serialize(OSSerialize *s) const
210 {
211 OSDictionary * dict;
212 bool ok;
213
214 dict = OSDictionary::withCapacity( 5 );
215 if( !dict)
216 return( false );
217
218 updateOffset( dict, debug_ivars_size, "Instance allocation" );
219 updateOffset( dict, debug_container_malloc_size, "Container allocation" );
220 updateOffset( dict, debug_iomalloc_size, "IOMalloc allocation" );
221 updateOffset( dict, debug_iomallocpageable_size, "Pageable allocation" );
222
223 OSMetaClass::serializeClassDictionary(dict);
224
225 ok = dict->serialize( s );
226
227 dict->release();
228
229 return( ok );
230 }
231
232 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */