WebCoreStatistics.cpp 6.7 KB

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