1 /*
2 * Copyright (C) 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 * 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.
12 *
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.
24 */
25
26 #include "config.h"
27 #include "WebKitDLL.h"
28 #include "WebCoreStatistics.h"
29
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
37 using namespace JSC;
38 using namespace WebCore;
39
40 // WebCoreStatistics ---------------------------------------------------------------------------
41
WebCoreStatistics()42 WebCoreStatistics::WebCoreStatistics()
43 : m_refCount(0)
44 {
45 gClassCount++;
46 gClassNameCount.add("WebCoreStatistics");
47 }
48
~WebCoreStatistics()49 WebCoreStatistics::~WebCoreStatistics()
50 {
51 gClassCount--;
52 gClassNameCount.remove("WebCoreStatistics");
53 }
54
createInstance()55 WebCoreStatistics* WebCoreStatistics::createInstance()
56 {
57 WebCoreStatistics* instance = new WebCoreStatistics();
58 instance->AddRef();
59 return instance;
60 }
61
62 // IUnknown -------------------------------------------------------------------
63
QueryInterface(REFIID riid,void ** ppvObject)64 HRESULT STDMETHODCALLTYPE WebCoreStatistics::QueryInterface(REFIID riid, void** ppvObject)
65 {
66 *ppvObject = 0;
67 if (IsEqualGUID(riid, IID_IUnknown))
68 *ppvObject = static_cast<WebCoreStatistics*>(this);
69 else if (IsEqualGUID(riid, IID_IWebCoreStatistics))
70 *ppvObject = static_cast<WebCoreStatistics*>(this);
71 else
72 return E_NOINTERFACE;
73
74 AddRef();
75 return S_OK;
76 }
77
AddRef(void)78 ULONG STDMETHODCALLTYPE WebCoreStatistics::AddRef(void)
79 {
80 return ++m_refCount;
81 }
82
Release(void)83 ULONG STDMETHODCALLTYPE WebCoreStatistics::Release(void)
84 {
85 ULONG newRef = --m_refCount;
86 if (!newRef)
87 delete(this);
88
89 return newRef;
90 }
91
92 // IWebCoreStatistics ------------------------------------------------------------------------------
93
javaScriptObjectsCount(UINT * count)94 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptObjectsCount(
95 /* [retval][out] */ UINT* count)
96 {
97 if (!count)
98 return E_POINTER;
99
100 JSLock lock(SilenceAssertionsOnly);
101 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.objectCount();
102 return S_OK;
103 }
104
javaScriptGlobalObjectsCount(UINT * count)105 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptGlobalObjectsCount(
106 /* [retval][out] */ UINT* count)
107 {
108 if (!count)
109 return E_POINTER;
110
111 JSLock lock(SilenceAssertionsOnly);
112 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.globalObjectCount();
113 return S_OK;
114 }
115
javaScriptProtectedObjectsCount(UINT * count)116 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptProtectedObjectsCount(
117 /* [retval][out] */ UINT* count)
118 {
119 if (!count)
120 return E_POINTER;
121
122 JSLock lock(SilenceAssertionsOnly);
123 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.protectedObjectCount();
124 return S_OK;
125 }
126
javaScriptProtectedGlobalObjectsCount(UINT * count)127 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptProtectedGlobalObjectsCount(
128 /* [retval][out] */ UINT* count)
129 {
130 if (!count)
131 return E_POINTER;
132
133 JSLock lock(SilenceAssertionsOnly);
134 *count = (UINT)JSDOMWindow::commonJSGlobalData()->heap.protectedGlobalObjectCount();
135 return S_OK;
136 }
137
javaScriptProtectedObjectTypeCounts(IPropertyBag2 ** typeNamesAndCounts)138 HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptProtectedObjectTypeCounts(
139 /* [retval][out] */ IPropertyBag2** typeNamesAndCounts)
140 {
141 JSLock lock(SilenceAssertionsOnly);
142 OwnPtr<HashCountedSet<const char*> > jsObjectTypeNames(JSDOMWindow::commonJSGlobalData()->heap.protectedObjectTypeCounts());
143 typedef HashCountedSet<const char*>::const_iterator Iterator;
144 Iterator end = jsObjectTypeNames->end();
145 HashMap<String, int> typeCountMap;
146 for (Iterator current = jsObjectTypeNames->begin(); current != end; ++current)
147 typeCountMap.set(current->first, current->second);
148
149 COMPtr<IPropertyBag2> results(AdoptCOM, COMPropertyBag<int>::createInstance(typeCountMap));
150 results.copyRefTo(typeNamesAndCounts);
151 return S_OK;
152 }
153
iconPageURLMappingCount(UINT * count)154 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconPageURLMappingCount(
155 /* [retval][out] */ UINT* count)
156 {
157 if (!count)
158 return E_POINTER;
159 *count = (UINT) iconDatabase()->pageURLMappingCount();
160 return S_OK;
161 }
162
iconRetainedPageURLCount(UINT * count)163 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconRetainedPageURLCount(
164 /* [retval][out] */ UINT *count)
165 {
166 if (!count)
167 return E_POINTER;
168 *count = (UINT) iconDatabase()->retainedPageURLCount();
169 return S_OK;
170 }
171
iconRecordCount(UINT * count)172 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconRecordCount(
173 /* [retval][out] */ UINT *count)
174 {
175 if (!count)
176 return E_POINTER;
177 *count = (UINT) iconDatabase()->iconRecordCount();
178 return S_OK;
179 }
180
iconsWithDataCount(UINT * count)181 HRESULT STDMETHODCALLTYPE WebCoreStatistics::iconsWithDataCount(
182 /* [retval][out] */ UINT *count)
183 {
184 if (!count)
185 return E_POINTER;
186 *count = (UINT) iconDatabase()->iconRecordCountWithData();
187 return S_OK;
188 }
189
cachedFontDataCount(UINT * count)190 HRESULT STDMETHODCALLTYPE WebCoreStatistics::cachedFontDataCount(
191 /* [retval][out] */ UINT *count)
192 {
193 if (!count)
194 return E_POINTER;
195 *count = (UINT) fontCache()->fontDataCount();
196 return S_OK;
197 }
198
cachedFontDataInactiveCount(UINT * count)199 HRESULT STDMETHODCALLTYPE WebCoreStatistics::cachedFontDataInactiveCount(
200 /* [retval][out] */ UINT *count)
201 {
202 if (!count)
203 return E_POINTER;
204 *count = (UINT) fontCache()->inactiveFontDataCount();
205 return S_OK;
206 }
207
purgeInactiveFontData(void)208 HRESULT STDMETHODCALLTYPE WebCoreStatistics::purgeInactiveFontData(void)
209 {
210 fontCache()->purgeInactiveFontData();
211 return S_OK;
212 }
213
glyphPageCount(UINT * count)214 HRESULT STDMETHODCALLTYPE WebCoreStatistics::glyphPageCount(
215 /* [retval][out] */ UINT *count)
216 {
217 if (!count)
218 return E_POINTER;
219 *count = (UINT) GlyphPageTreeNode::treeGlyphPageCount();
220 return S_OK;
221 }
222