2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebKitDLL.h"
28 #include "WebCoreStatistics.h"
30 #include "COMPropertyBag.h"
31 #include <JavaScriptCore/JSLock.h>
32 #include <WebCore/FontCache.h>
33 #include <WebCore/GlyphPageTreeNode.h>
34 #include <WebCore/IconDatabase.h>
35 #include <WebCore/JSDOMWindow.h>
36 #include <WebCore/SharedBuffer.h>
39 using namespace WebCore;
41 // WebCoreStatistics ---------------------------------------------------------------------------
43 WebCoreStatistics::WebCoreStatistics()
47 gClassNameCount.add("WebCoreStatistics");
50 WebCoreStatistics::~WebCoreStatistics()
53 gClassNameCount.remove("WebCoreStatistics");
56 WebCoreStatistics* WebCoreStatistics::createInstance()
58 WebCoreStatistics* instance = new WebCoreStatistics();
63 // IUnknown -------------------------------------------------------------------
65 HRESULT STDMETHODCALLTYPE WebCoreStatistics::QueryInterface(REFIID riid, void** ppvObject)
68 if (IsEqualGUID(riid, IID_IUnknown))
69 *ppvObject = static_cast<WebCoreStatistics*>(this);
70 else if (IsEqualGUID(riid, IID_IWebCoreStatistics))
71 *ppvObject = static_cast<WebCoreStatistics*>(this);
79 ULONG STDMETHODCALLTYPE WebCoreStatistics::AddRef(void)
84 ULONG STDMETHODCALLTYPE WebCoreStatistics::Release(void)
86 ULONG newRef = --m_refCount;
93 // IWebCoreStatistics ------------------------------------------------------------------------------
95 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptObjectsCount(
96 /* [retval][out] */ UINT* count)
101 JSLockHolder lock(JSDOMWindow::commonJSGlobalData());
102 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.objectCount();
106 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptGlobalObjectsCount(
107 /* [retval][out] */ UINT* count)
112 JSLockHolder lock(JSDOMWindow::commonJSGlobalData());
113 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.globalObjectCount();
117 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptProtectedObjectsCount(
118 /* [retval][out] */ UINT* count)
123 JSLockHolder lock(JSDOMWindow::commonJSGlobalData());
124 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.protectedObjectCount();
128 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptProtectedGlobalObjectsCount(
129 /* [retval][out] */ UINT* count)
134 JSLockHolder lock(JSDOMWindow::commonJSGlobalData());
135 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.protectedGlobalObjectCount();
139 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptProtectedObjectTypeCounts(
140 /* [retval][out] */ IPropertyBag2** typeNamesAndCounts)
142 JSLockHolder lock(JSDOMWindow::commonJSGlobalData());
143 OwnPtr<TypeCountSet> jsObjectTypeNames(JSDOMWindow::commonJSGlobalData()->heap.protectedObjectTypeCounts());
144 typedef TypeCountSet::const_iterator Iterator;
145 Iterator end = jsObjectTypeNames->end();
146 HashMap<String, int> typeCountMap;
147 for (Iterator current = jsObjectTypeNames->begin(); current != end; ++current)
148 typeCountMap.set(current->first, current->second);
150 COMPtr<IPropertyBag2> results(AdoptCOM, COMPropertyBag<int>::createInstance(typeCountMap));
151 results.copyRefTo(typeNamesAndCounts);
155 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconPageURLMappingCount(
156 /* [retval][out] */ UINT* count)
160 *count = (UINT) iconDatabase().pageURLMappingCount();
164 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconRetainedPageURLCount(
165 /* [retval][out] */ UINT *count)
169 *count = (UINT) iconDatabase().retainedPageURLCount();
173 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconRecordCount(
174 /* [retval][out] */ UINT *count)
178 *count = (UINT) iconDatabase().iconRecordCount();
182 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconsWithDataCount(
183 /* [retval][out] */ UINT *count)
187 *count = (UINT) iconDatabase().iconRecordCountWithData();
191 HRESULT STDMETHODCALLTYPE WebCoreStatistics::cachedFontDataCount(
192 /* [retval][out] */ UINT *count)
196 *count = (UINT) fontCache()->fontDataCount();
200 HRESULT STDMETHODCALLTYPE WebCoreStatistics::cachedFontDataInactiveCount(
201 /* [retval][out] */ UINT *count)
205 *count = (UINT) fontCache()->inactiveFontDataCount();
209 HRESULT STDMETHODCALLTYPE WebCoreStatistics::purgeInactiveFontData(void)
211 fontCache()->purgeInactiveFontData();
215 HRESULT STDMETHODCALLTYPE WebCoreStatistics::glyphPageCount(
216 /* [retval][out] */ UINT *count)
220 *count = (UINT) GlyphPageTreeNode::treeGlyphPageCount();