WebCoreStatistics.cpp revision 81bc750723a18f21cd17d1b173cd2a4dda9cea6e
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 37using namespace JSC; 38using namespace WebCore; 39 40// WebCoreStatistics --------------------------------------------------------------------------- 41 42WebCoreStatistics::WebCoreStatistics() 43: m_refCount(0) 44{ 45 gClassCount++; 46 gClassNameCount.add("WebCoreStatistics"); 47} 48 49WebCoreStatistics::~WebCoreStatistics() 50{ 51 gClassCount--; 52 gClassNameCount.remove("WebCoreStatistics"); 53} 54 55WebCoreStatistics* WebCoreStatistics::createInstance() 56{ 57 WebCoreStatistics* instance = new WebCoreStatistics(); 58 instance->AddRef(); 59 return instance; 60} 61 62// IUnknown ------------------------------------------------------------------- 63 64HRESULT 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 78ULONG STDMETHODCALLTYPE WebCoreStatistics::AddRef(void) 79{ 80 return ++m_refCount; 81} 82 83ULONG 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 94HRESULT 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 105HRESULT 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 116HRESULT 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 127HRESULT 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 138HRESULT STDMETHODCALLTYPE WebCoreStatistics::javaScriptProtectedObjectTypeCounts( 139 /* [retval][out] */ IPropertyBag2** typeNamesAndCounts) 140{ 141 JSLock lock(SilenceAssertionsOnly); 142 OwnPtr<TypeCountSet> jsObjectTypeNames(JSDOMWindow::commonJSGlobalData()->heap.protectedObjectTypeCounts()); 143 typedef TypeCountSet::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 154HRESULT 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 163HRESULT 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 172HRESULT 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 181HRESULT 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 190HRESULT 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 199HRESULT 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 208HRESULT STDMETHODCALLTYPE WebCoreStatistics::purgeInactiveFontData(void) 209{ 210 fontCache()->purgeInactiveFontData(); 211 return S_OK; 212} 213 214HRESULT 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