]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOKitDebug.cpp
xnu-792.6.70.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 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
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 *
37839358
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,
37839358
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
91447636
A
29#include <sys/sysctl.h>
30
1c79356b
A
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
1c79356b 40#ifdef IOKITDEBUG
91447636
A
41#define DEBUG_INIT_VALUE IOKITDEBUG
42#else
43#define DEBUG_INIT_VALUE 0
1c79356b 44#endif
91447636
A
45
46SInt64 gIOKitDebug = DEBUG_INIT_VALUE;
47SYSCTL_QUAD(_debug, OID_AUTO, iokit, CTLFLAG_RW, &gIOKitDebug, "boot_arg io");
48
1c79356b
A
49
50int debug_malloc_size;
51int debug_iomalloc_size;
91447636 52vm_size_t debug_iomallocpageable_size;
1c79356b
A
53int debug_container_malloc_size;
54// int debug_ivars_size; // in OSObject.cpp
55
91447636
A
56extern "C" {
57
58
1c79356b
A
59void 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())) {
0b4e3aa0 78 sprintf( format + 1, "%ds", 2 * next->getDepth( plane ));
1c79356b 79 IOLog( format, "");
0b4e3aa0
A
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());
1c79356b 84 if( (service = OSDynamicCast(IOService, next)))
0b4e3aa0
A
85 IOLog(", busy %ld", service->getBusyState());
86 IOLog( ">\n");
87 IOSleep(250);
1c79356b
A
88 }
89 iter->release();
90}
91
55e303ae
A
92void dbugprintf(char *fmt, ...);
93void db_dumpiojunk( const IORegistryPlane * plane );
94
95void 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
116void 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
1c79356b
A
147void 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
170OSDefineMetaClassAndStructors(IOKitDiagnostics, OSObject)
171
172/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
173
174OSObject * 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
187void 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
201bool 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" );
91447636 213 updateOffset( dict, debug_iomallocpageable_size, "Pageable allocation" );
1c79356b 214
55e303ae 215 OSMetaClass::serializeClassDictionary(dict);
1c79356b
A
216
217 ok = dict->serialize( s );
218
219 dict->release();
220
221 return( ok );
222}
223
224/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */