]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOKitDebug.cpp
6676cd6325d7e2aaab2bf31e43ff6b8af33f5962
[apple/xnu.git] / iokit / Kernel / IOKitDebug.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
25 *
26 * HISTORY
27 *
28 */
29
30 #include <sys/sysctl.h>
31
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>
37
38 #include <libkern/c++/OSContainers.h>
39 #include <libkern/c++/OSCPPDebug.h>
40
41 #ifdef IOKITDEBUG
42 #define DEBUG_INIT_VALUE IOKITDEBUG
43 #else
44 #define DEBUG_INIT_VALUE 0
45 #endif
46
47 SInt64 gIOKitDebug = DEBUG_INIT_VALUE;
48 SYSCTL_QUAD(_debug, OID_AUTO, iokit, CTLFLAG_RW, &gIOKitDebug, "boot_arg io");
49
50
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
56
57 extern "C" {
58
59
60 void IOPrintPlane( const IORegistryPlane * plane )
61 {
62 IORegistryEntry * next;
63 IORegistryIterator * iter;
64 OSOrderedSet * all;
65 char format[] = "%xxxs";
66 IOService * service;
67
68 iter = IORegistryIterator::iterateOver( plane );
69 assert( iter );
70 all = iter->iterateAll();
71 if( all) {
72 IOLog("Count %d\n", all->getCount() );
73 all->release();
74 } else
75 IOLog("Empty\n");
76
77 iter->reset();
78 while( (next = iter->getNextObjectRecursive())) {
79 sprintf( format + 1, "%ds", 2 * next->getDepth( plane ));
80 IOLog( format, "");
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());
87 IOLog( ">\n");
88 IOSleep(250);
89 }
90 iter->release();
91 }
92
93 void dbugprintf(char *fmt, ...);
94 void db_dumpiojunk( const IORegistryPlane * plane );
95
96 void db_piokjunk(void) {
97
98 dbugprintf("\nDT plane:\n");
99 db_dumpiojunk( gIODTPlane );
100 dbugprintf("\n\nService plane:\n");
101 db_dumpiojunk( gIOServicePlane );
102 dbugprintf("\n\n"
103 "ivar kalloc() 0x%08x\n"
104 "malloc() 0x%08x\n"
105 "containers kalloc() 0x%08x\n"
106 "IOMalloc() 0x%08x\n"
107 "----------------------------------------\n",
108 debug_ivars_size,
109 debug_malloc_size,
110 debug_container_malloc_size,
111 debug_iomalloc_size
112 );
113
114 }
115
116
117 void db_dumpiojunk( const IORegistryPlane * plane )
118 {
119 IORegistryEntry * next;
120 IORegistryIterator * iter;
121 OSOrderedSet * all;
122 char format[] = "%xxxs";
123 IOService * service;
124
125 iter = IORegistryIterator::iterateOver( plane );
126
127 all = iter->iterateAll();
128 if( all) {
129 dbugprintf("Count %d\n", all->getCount() );
130 all->release();
131 } else dbugprintf("Empty\n");
132
133 iter->reset();
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());
143 dbugprintf( ">\n");
144 }
145 iter->release();
146 }
147
148 void IOPrintMemory( void )
149 {
150
151 // OSMetaClass::printInstanceCounts();
152
153 IOLog("\n"
154 "ivar kalloc() 0x%08x\n"
155 "malloc() 0x%08x\n"
156 "containers kalloc() 0x%08x\n"
157 "IOMalloc() 0x%08x\n"
158 "----------------------------------------\n",
159 debug_ivars_size,
160 debug_malloc_size,
161 debug_container_malloc_size,
162 debug_iomalloc_size
163 );
164 }
165
166 } /* extern "C" */
167
168 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
169
170 #define super OSObject
171 OSDefineMetaClassAndStructors(IOKitDiagnostics, OSObject)
172
173 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
174
175 OSObject * IOKitDiagnostics::diagnostics( void )
176 {
177 IOKitDiagnostics * diags;
178
179 diags = new IOKitDiagnostics;
180 if( diags && !diags->init()) {
181 diags->release();
182 diags = 0;
183 }
184
185 return( diags );
186 }
187
188 void IOKitDiagnostics::updateOffset( OSDictionary * dict,
189 UInt32 value, const char * name )
190 {
191 OSNumber * off;
192
193 off = OSNumber::withNumber( value, 32 );
194 if( !off)
195 return;
196
197 dict->setObject( name, off );
198 off->release();
199 }
200
201
202 bool IOKitDiagnostics::serialize(OSSerialize *s) const
203 {
204 OSDictionary * dict;
205 bool ok;
206
207 dict = OSDictionary::withCapacity( 5 );
208 if( !dict)
209 return( false );
210
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" );
215
216 OSMetaClass::serializeClassDictionary(dict);
217
218 ok = dict->serialize( s );
219
220 dict->release();
221
222 return( ok );
223 }
224
225 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */