]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOKitDebug.cpp
xnu-792.21.3.tar.gz
[apple/xnu.git] / iokit / Kernel / IOKitDebug.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
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
52SInt64 gIOKitDebug = DEBUG_INIT_VALUE;
53SYSCTL_QUAD(_debug, OID_AUTO, iokit, CTLFLAG_RW, &gIOKitDebug, "boot_arg io");
54
1c79356b
A
55
56int debug_malloc_size;
57int debug_iomalloc_size;
91447636 58vm_size_t debug_iomallocpageable_size;
1c79356b
A
59int debug_container_malloc_size;
60// int debug_ivars_size; // in OSObject.cpp
61
91447636
A
62extern "C" {
63
64
1c79356b
A
65void IOPrintPlane( const IORegistryPlane * plane )
66{
67 IORegistryEntry * next;
68 IORegistryIterator * iter;
69 OSOrderedSet * all;
70 char format[] = "%xxxs";
71 IOService * service;
72
73 iter = IORegistryIterator::iterateOver( plane );
74 assert( iter );
75 all = iter->iterateAll();
76 if( all) {
77 IOLog("Count %d\n", all->getCount() );
78 all->release();
79 } else
80 IOLog("Empty\n");
81
82 iter->reset();
83 while( (next = iter->getNextObjectRecursive())) {
0b4e3aa0 84 sprintf( format + 1, "%ds", 2 * next->getDepth( plane ));
1c79356b 85 IOLog( format, "");
0b4e3aa0
A
86 IOLog( "\033[33m%s", next->getName( plane ));
87 if( (next->getLocation( plane )))
88 IOLog("@%s", next->getLocation( plane ));
89 IOLog("\033[0m <class %s", next->getMetaClass()->getClassName());
1c79356b 90 if( (service = OSDynamicCast(IOService, next)))
0b4e3aa0
A
91 IOLog(", busy %ld", service->getBusyState());
92 IOLog( ">\n");
93 IOSleep(250);
1c79356b
A
94 }
95 iter->release();
96}
97
55e303ae
A
98void dbugprintf(char *fmt, ...);
99void db_dumpiojunk( const IORegistryPlane * plane );
100
101void db_piokjunk(void) {
102
103 dbugprintf("\nDT plane:\n");
104 db_dumpiojunk( gIODTPlane );
105 dbugprintf("\n\nService plane:\n");
106 db_dumpiojunk( gIOServicePlane );
107 dbugprintf("\n\n"
108 "ivar kalloc() 0x%08x\n"
109 "malloc() 0x%08x\n"
110 "containers kalloc() 0x%08x\n"
111 "IOMalloc() 0x%08x\n"
112 "----------------------------------------\n",
113 debug_ivars_size,
114 debug_malloc_size,
115 debug_container_malloc_size,
116 debug_iomalloc_size
117 );
118
119}
120
121
122void db_dumpiojunk( const IORegistryPlane * plane )
123{
124 IORegistryEntry * next;
125 IORegistryIterator * iter;
126 OSOrderedSet * all;
127 char format[] = "%xxxs";
128 IOService * service;
129
130 iter = IORegistryIterator::iterateOver( plane );
131
132 all = iter->iterateAll();
133 if( all) {
134 dbugprintf("Count %d\n", all->getCount() );
135 all->release();
136 } else dbugprintf("Empty\n");
137
138 iter->reset();
139 while( (next = iter->getNextObjectRecursive())) {
140 sprintf( format + 1, "%ds", 2 * next->getDepth( plane ));
141 dbugprintf( format, "");
142 dbugprintf( "%s", next->getName( plane ));
143 if( (next->getLocation( plane )))
144 dbugprintf("@%s", next->getLocation( plane ));
145 dbugprintf(" <class %s", next->getMetaClass()->getClassName());
146 if( (service = OSDynamicCast(IOService, next)))
147 dbugprintf(", busy %ld", service->getBusyState());
148 dbugprintf( ">\n");
149 }
150 iter->release();
151}
152
1c79356b
A
153void IOPrintMemory( void )
154{
155
156// OSMetaClass::printInstanceCounts();
157
158 IOLog("\n"
159 "ivar kalloc() 0x%08x\n"
160 "malloc() 0x%08x\n"
161 "containers kalloc() 0x%08x\n"
162 "IOMalloc() 0x%08x\n"
163 "----------------------------------------\n",
164 debug_ivars_size,
165 debug_malloc_size,
166 debug_container_malloc_size,
167 debug_iomalloc_size
168 );
169}
170
171} /* extern "C" */
172
173/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
174
175#define super OSObject
176OSDefineMetaClassAndStructors(IOKitDiagnostics, OSObject)
177
178/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
179
180OSObject * IOKitDiagnostics::diagnostics( void )
181{
182 IOKitDiagnostics * diags;
183
184 diags = new IOKitDiagnostics;
185 if( diags && !diags->init()) {
186 diags->release();
187 diags = 0;
188 }
189
190 return( diags );
191}
192
193void IOKitDiagnostics::updateOffset( OSDictionary * dict,
194 UInt32 value, const char * name )
195{
196 OSNumber * off;
197
198 off = OSNumber::withNumber( value, 32 );
199 if( !off)
200 return;
201
202 dict->setObject( name, off );
203 off->release();
204}
205
206
207bool IOKitDiagnostics::serialize(OSSerialize *s) const
208{
209 OSDictionary * dict;
210 bool ok;
211
212 dict = OSDictionary::withCapacity( 5 );
213 if( !dict)
214 return( false );
215
216 updateOffset( dict, debug_ivars_size, "Instance allocation" );
217 updateOffset( dict, debug_container_malloc_size, "Container allocation" );
218 updateOffset( dict, debug_iomalloc_size, "IOMalloc allocation" );
91447636 219 updateOffset( dict, debug_iomallocpageable_size, "Pageable allocation" );
1c79356b 220
55e303ae 221 OSMetaClass::serializeClassDictionary(dict);
1c79356b
A
222
223 ok = dict->serialize( s );
224
225 dict->release();
226
227 return( ok );
228}
229
230/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */