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