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