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