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