• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#import "WebCoreStatistics.h"
30
31#import "WebCache.h"
32#import "WebFrameInternal.h"
33#import <runtime/JSLock.h>
34#import <WebCore/Console.h>
35#import <WebCore/FontCache.h>
36#import <WebCore/Frame.h>
37#import <WebCore/GCController.h>
38#import <WebCore/GlyphPageTreeNode.h>
39#import <WebCore/IconDatabase.h>
40#import <WebCore/JSDOMWindow.h>
41#import <WebCore/PageCache.h>
42#import <WebCore/RenderTreeAsText.h>
43#import <WebCore/RenderView.h>
44
45using namespace JSC;
46using namespace WebCore;
47
48@implementation WebCoreStatistics
49
50+ (NSArray *)statistics
51{
52    return [WebCache statistics];
53}
54
55+ (size_t)javaScriptObjectsCount
56{
57    JSLock lock(SilenceAssertionsOnly);
58    return JSDOMWindow::commonJSGlobalData()->heap.objectCount();
59}
60
61+ (size_t)javaScriptGlobalObjectsCount
62{
63    JSLock lock(SilenceAssertionsOnly);
64    return JSDOMWindow::commonJSGlobalData()->heap.globalObjectCount();
65}
66
67+ (size_t)javaScriptProtectedObjectsCount
68{
69    JSLock lock(SilenceAssertionsOnly);
70    return JSDOMWindow::commonJSGlobalData()->heap.protectedObjectCount();
71}
72
73+ (size_t)javaScriptProtectedGlobalObjectsCount
74{
75    JSLock lock(SilenceAssertionsOnly);
76    return JSDOMWindow::commonJSGlobalData()->heap.protectedGlobalObjectCount();
77}
78
79+ (NSCountedSet *)javaScriptProtectedObjectTypeCounts
80{
81    JSLock lock(SilenceAssertionsOnly);
82
83    NSCountedSet *result = [NSCountedSet set];
84
85    OwnPtr<HashCountedSet<const char*> > counts(JSDOMWindow::commonJSGlobalData()->heap.protectedObjectTypeCounts());
86    HashCountedSet<const char*>::iterator end = counts->end();
87    for (HashCountedSet<const char*>::iterator it = counts->begin(); it != end; ++it)
88        for (unsigned i = 0; i < it->second; ++i)
89            [result addObject:[NSString stringWithUTF8String:it->first]];
90
91    return result;
92}
93
94+ (void)garbageCollectJavaScriptObjects
95{
96    gcController().garbageCollectNow();
97}
98
99+ (void)garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging:(BOOL)waitUntilDone
100{
101    gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
102}
103
104+ (size_t)iconPageURLMappingCount
105{
106    return iconDatabase()->pageURLMappingCount();
107}
108
109+ (size_t)iconRetainedPageURLCount
110{
111    return iconDatabase()->retainedPageURLCount();
112}
113
114+ (size_t)iconRecordCount
115{
116    return iconDatabase()->iconRecordCount();
117}
118
119+ (size_t)iconsWithDataCount
120{
121    return iconDatabase()->iconRecordCountWithData();
122}
123
124+ (size_t)cachedFontDataCount
125{
126    return fontCache()->fontDataCount();
127}
128
129+ (size_t)cachedFontDataInactiveCount
130{
131    return fontCache()->inactiveFontDataCount();
132}
133
134+ (void)purgeInactiveFontData
135{
136    fontCache()->purgeInactiveFontData();
137}
138
139+ (size_t)glyphPageCount
140{
141    return GlyphPageTreeNode::treeGlyphPageCount();
142}
143
144+ (BOOL)shouldPrintExceptions
145{
146    JSLock lock(SilenceAssertionsOnly);
147    return Console::shouldPrintExceptions();
148}
149
150+ (void)setShouldPrintExceptions:(BOOL)print
151{
152    JSLock lock(SilenceAssertionsOnly);
153    Console::setShouldPrintExceptions(print);
154}
155
156+ (void)emptyCache
157{
158    [WebCache empty];
159}
160
161+ (void)setCacheDisabled:(BOOL)disabled
162{
163    [WebCache setDisabled:disabled];
164}
165
166+ (void)startIgnoringWebCoreNodeLeaks
167{
168    WebCore::Node::startIgnoringLeaks();
169}
170
171+ (void)stopIgnoringWebCoreNodeLeaks
172{
173    WebCore::Node::stopIgnoringLeaks();
174}
175
176+ (NSDictionary *)memoryStatistics
177{
178    WTF::FastMallocStatistics fastMallocStatistics = WTF::fastMallocStatistics();
179    JSLock lock(SilenceAssertionsOnly);
180    Heap::Statistics jsHeapStatistics = JSDOMWindow::commonJSGlobalData()->heap.statistics();
181    return [NSDictionary dictionaryWithObjectsAndKeys:
182                [NSNumber numberWithInt:fastMallocStatistics.heapSize], @"FastMallocHeapSize",
183                [NSNumber numberWithInt:fastMallocStatistics.freeSizeInHeap], @"FastMallocFreeSizeInHeap",
184                [NSNumber numberWithInt:fastMallocStatistics.freeSizeInCaches], @"FastMallocFreeSizeInCaches",
185                [NSNumber numberWithInt:fastMallocStatistics.returnedSize], @"FastMallocReturnedSize",
186                [NSNumber numberWithInt:jsHeapStatistics.size], @"JavaScriptHeapSize",
187                [NSNumber numberWithInt:jsHeapStatistics.free], @"JavaScriptFreeSize",
188            nil];
189}
190
191+ (void)returnFreeMemoryToSystem
192{
193    WTF::releaseFastMallocFreeMemory();
194}
195
196+ (int)cachedPageCount
197{
198    return pageCache()->pageCount();
199}
200
201+ (int)cachedFrameCount
202{
203    return pageCache()->frameCount();
204}
205
206+ (int)autoreleasedPageCount
207{
208    return pageCache()->autoreleasedPageCount();
209}
210
211// Deprecated
212+ (size_t)javaScriptNoGCAllowedObjectsCount
213{
214    return 0;
215}
216
217+ (size_t)javaScriptReferencedObjectsCount
218{
219    JSLock lock(SilenceAssertionsOnly);
220    return JSDOMWindow::commonJSGlobalData()->heap.protectedObjectCount();
221}
222
223+ (NSSet *)javaScriptRootObjectClasses
224{
225    return [self javaScriptRootObjectTypeCounts];
226}
227
228+ (size_t)javaScriptInterpretersCount
229{
230    return [self javaScriptProtectedGlobalObjectsCount];
231}
232
233+ (NSCountedSet *)javaScriptRootObjectTypeCounts
234{
235    return [self javaScriptProtectedObjectTypeCounts];
236}
237
238@end
239
240@implementation WebFrame (WebKitDebug)
241
242- (NSString *)renderTreeAsExternalRepresentation
243{
244    return externalRepresentation(_private->coreFrame->contentRenderer());
245}
246
247@end
248