]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOKitDebug.cpp
54e70a468c9a57da2b7e650342c03e48624f94fe
[apple/xnu.git] / iokit / Kernel / IOKitDebug.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27 *
28 * HISTORY
29 *
30 */
31
32 #include <IOKit/IOKitDebug.h>
33 #include <IOKit/IOLib.h>
34 #include <IOKit/assert.h>
35 #include <IOKit/IODeviceTreeSupport.h>
36 #include <IOKit/IOService.h>
37
38 #include <libkern/c++/OSContainers.h>
39 #include <libkern/c++/OSCPPDebug.h>
40
41 extern "C" {
42
43 SInt64 gIOKitDebug
44 #ifdef IOKITDEBUG
45 = IOKITDEBUG
46 #endif
47 ;
48
49 int debug_malloc_size;
50 int debug_iomalloc_size;
51 int debug_container_malloc_size;
52 // int debug_ivars_size; // in OSObject.cpp
53
54 void IOPrintPlane( const IORegistryPlane * plane )
55 {
56 IORegistryEntry * next;
57 IORegistryIterator * iter;
58 OSOrderedSet * all;
59 char format[] = "%xxxs";
60 IOService * service;
61
62 iter = IORegistryIterator::iterateOver( plane );
63 assert( iter );
64 all = iter->iterateAll();
65 if( all) {
66 IOLog("Count %d\n", all->getCount() );
67 all->release();
68 } else
69 IOLog("Empty\n");
70
71 iter->reset();
72 while( (next = iter->getNextObjectRecursive())) {
73 sprintf( format + 1, "%ds", 2 * next->getDepth( plane ));
74 IOLog( format, "");
75 IOLog( "\033[33m%s", next->getName( plane ));
76 if( (next->getLocation( plane )))
77 IOLog("@%s", next->getLocation( plane ));
78 IOLog("\033[0m <class %s", next->getMetaClass()->getClassName());
79 if( (service = OSDynamicCast(IOService, next)))
80 IOLog(", busy %ld", service->getBusyState());
81 IOLog( ">\n");
82 IOSleep(250);
83 }
84 iter->release();
85 }
86
87 void IOPrintMemory( void )
88 {
89
90 // OSMetaClass::printInstanceCounts();
91
92 IOLog("\n"
93 "ivar kalloc() 0x%08x\n"
94 "malloc() 0x%08x\n"
95 "containers kalloc() 0x%08x\n"
96 "IOMalloc() 0x%08x\n"
97 "----------------------------------------\n",
98 debug_ivars_size,
99 debug_malloc_size,
100 debug_container_malloc_size,
101 debug_iomalloc_size
102 );
103 }
104
105 } /* extern "C" */
106
107 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
108
109 #define super OSObject
110 OSDefineMetaClassAndStructors(IOKitDiagnostics, OSObject)
111
112 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
113
114 OSObject * IOKitDiagnostics::diagnostics( void )
115 {
116 IOKitDiagnostics * diags;
117
118 diags = new IOKitDiagnostics;
119 if( diags && !diags->init()) {
120 diags->release();
121 diags = 0;
122 }
123
124 return( diags );
125 }
126
127 void IOKitDiagnostics::updateOffset( OSDictionary * dict,
128 UInt32 value, const char * name )
129 {
130 OSNumber * off;
131
132 off = OSNumber::withNumber( value, 32 );
133 if( !off)
134 return;
135
136 dict->setObject( name, off );
137 off->release();
138 }
139
140
141 bool IOKitDiagnostics::serialize(OSSerialize *s) const
142 {
143 OSDictionary * dict;
144 bool ok;
145
146 dict = OSDictionary::withCapacity( 5 );
147 if( !dict)
148 return( false );
149
150 updateOffset( dict, debug_ivars_size, "Instance allocation" );
151 updateOffset( dict, debug_container_malloc_size, "Container allocation" );
152 updateOffset( dict, debug_iomalloc_size, "IOMalloc allocation" );
153
154 dict->setObject( "Classes", OSMetaClass::getClassDictionary() );
155
156 ok = dict->serialize( s );
157
158 dict->release();
159
160 return( ok );
161 }
162
163 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */