]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOKitDebug.cpp
xnu-2050.48.11.tar.gz
[apple/xnu.git] / iokit / Kernel / IOKitDebug.cpp
CommitLineData
1c79356b 1/*
6d2010ae 2 * Copyright (c) 1998-2010 Apple 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 27 */
1c79356b 28
91447636
A
29#include <sys/sysctl.h>
30
6d2010ae
A
31#include <libkern/c++/OSContainers.h>
32#include <libkern/c++/OSCPPDebug.h>
33
1c79356b
A
34#include <IOKit/IOKitDebug.h>
35#include <IOKit/IOLib.h>
36#include <IOKit/assert.h>
37#include <IOKit/IODeviceTreeSupport.h>
38#include <IOKit/IOService.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;
6d2010ae 47SInt64 gIOKitTrace = 0;
060df5ea
A
48
49SYSCTL_QUAD(_debug, OID_AUTO, iokit, CTLFLAG_RW | CTLFLAG_LOCKED, &gIOKitDebug, "boot_arg io");
50SYSCTL_QUAD(_debug, OID_AUTO, iotrace, CTLFLAG_RW | CTLFLAG_LOCKED, &gIOKitTrace, "trace io");
91447636 51
1c79356b
A
52
53int debug_malloc_size;
54int debug_iomalloc_size;
2d21ac55 55
91447636 56vm_size_t debug_iomallocpageable_size;
1c79356b
A
57int debug_container_malloc_size;
58// int debug_ivars_size; // in OSObject.cpp
59
91447636
A
60extern "C" {
61
b0d623f7
A
62#if 0
63#define DEBG(fmt, args...) { kprintf(fmt, ## args); }
64#else
65#define DEBG(fmt, args...) { IOLog(fmt, ## args); }
66#endif
91447636 67
1c79356b
A
68void IOPrintPlane( const IORegistryPlane * plane )
69{
70 IORegistryEntry * next;
71 IORegistryIterator * iter;
72 OSOrderedSet * all;
73 char format[] = "%xxxs";
74 IOService * service;
75
76 iter = IORegistryIterator::iterateOver( plane );
77 assert( iter );
78 all = iter->iterateAll();
79 if( all) {
b0d623f7 80 DEBG("Count %d\n", all->getCount() );
1c79356b
A
81 all->release();
82 } else
b0d623f7 83 DEBG("Empty\n");
1c79356b
A
84
85 iter->reset();
86 while( (next = iter->getNextObjectRecursive())) {
2d21ac55 87 snprintf(format + 1, sizeof(format) - 1, "%ds", 2 * next->getDepth( plane ));
b0d623f7
A
88 DEBG( format, "");
89 DEBG( "\033[33m%s", next->getName( plane ));
0b4e3aa0 90 if( (next->getLocation( plane )))
b0d623f7
A
91 DEBG("@%s", next->getLocation( plane ));
92 DEBG("\033[0m <class %s", next->getMetaClass()->getClassName());
1c79356b 93 if( (service = OSDynamicCast(IOService, next)))
b0d623f7
A
94 DEBG(", busy %ld", (long) service->getBusyState());
95 DEBG( ">\n");
96// IOSleep(250);
1c79356b
A
97 }
98 iter->release();
99}
100
316670eb
A
101void db_piokjunk(void)
102{
55e303ae
A
103}
104
316670eb 105void db_dumpiojunk( const IORegistryPlane * plane __unused )
55e303ae 106{
55e303ae
A
107}
108
1c79356b
A
109void IOPrintMemory( void )
110{
111
112// OSMetaClass::printInstanceCounts();
113
114 IOLog("\n"
115 "ivar kalloc() 0x%08x\n"
116 "malloc() 0x%08x\n"
117 "containers kalloc() 0x%08x\n"
118 "IOMalloc() 0x%08x\n"
119 "----------------------------------------\n",
120 debug_ivars_size,
121 debug_malloc_size,
122 debug_container_malloc_size,
123 debug_iomalloc_size
124 );
125}
126
127} /* extern "C" */
128
129/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
130
131#define super OSObject
132OSDefineMetaClassAndStructors(IOKitDiagnostics, OSObject)
133
134/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
135
136OSObject * IOKitDiagnostics::diagnostics( void )
137{
138 IOKitDiagnostics * diags;
139
140 diags = new IOKitDiagnostics;
141 if( diags && !diags->init()) {
142 diags->release();
143 diags = 0;
144 }
145
146 return( diags );
147}
148
149void IOKitDiagnostics::updateOffset( OSDictionary * dict,
150 UInt32 value, const char * name )
151{
152 OSNumber * off;
153
154 off = OSNumber::withNumber( value, 32 );
155 if( !off)
156 return;
157
158 dict->setObject( name, off );
159 off->release();
160}
161
1c79356b
A
162bool IOKitDiagnostics::serialize(OSSerialize *s) const
163{
164 OSDictionary * dict;
165 bool ok;
166
167 dict = OSDictionary::withCapacity( 5 );
168 if( !dict)
169 return( false );
170
171 updateOffset( dict, debug_ivars_size, "Instance allocation" );
172 updateOffset( dict, debug_container_malloc_size, "Container allocation" );
173 updateOffset( dict, debug_iomalloc_size, "IOMalloc allocation" );
91447636 174 updateOffset( dict, debug_iomallocpageable_size, "Pageable allocation" );
1c79356b 175
55e303ae 176 OSMetaClass::serializeClassDictionary(dict);
1c79356b
A
177
178 ok = dict->serialize( s );
179
180 dict->release();
181
182 return( ok );
183}
184
185/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */