Commit f515bcb7 authored by tkent@chromium.org's avatar tkent@chromium.org

Add instance counters of Resource and AudioNode, and expose them via WebLeakDetector.

BUG=400588

Review URL: https://codereview.chromium.org/450183002

git-svn-id: svn://svn.chromium.org/blink/trunk@179845 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 45aebb53
...@@ -93,6 +93,7 @@ static inline bool shouldUpdateHeaderAfterRevalidation(const AtomicString& heade ...@@ -93,6 +93,7 @@ static inline bool shouldUpdateHeaderAfterRevalidation(const AtomicString& heade
} }
DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("Resource")); DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("Resource"));
unsigned Resource::s_instanceCount = 0;
Resource::Resource(const ResourceRequest& request, Type type) Resource::Resource(const ResourceRequest& request, Type type)
: m_resourceRequest(request) : m_resourceRequest(request)
...@@ -120,6 +121,7 @@ Resource::Resource(const ResourceRequest& request, Type type) ...@@ -120,6 +121,7 @@ Resource::Resource(const ResourceRequest& request, Type type)
, m_proxyResource(nullptr) , m_proxyResource(nullptr)
{ {
ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests careless updates of the enum. ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests careless updates of the enum.
++s_instanceCount;
#ifndef NDEBUG #ifndef NDEBUG
cachedResourceLeakCounter.increment(); cachedResourceLeakCounter.increment();
#endif #endif
...@@ -149,6 +151,7 @@ Resource::~Resource() ...@@ -149,6 +151,7 @@ Resource::~Resource()
#ifndef NDEBUG #ifndef NDEBUG
cachedResourceLeakCounter.decrement(); cachedResourceLeakCounter.decrement();
#endif #endif
--s_instanceCount;
} }
void Resource::dispose() void Resource::dispose()
......
...@@ -93,6 +93,7 @@ public: ...@@ -93,6 +93,7 @@ public:
#endif #endif
virtual void dispose(); virtual void dispose();
virtual void trace(Visitor*); virtual void trace(Visitor*);
static unsigned instanceCount() { return s_instanceCount; }
virtual void load(ResourceFetcher*, const ResourceLoaderOptions&); virtual void load(ResourceFetcher*, const ResourceLoaderOptions&);
...@@ -401,6 +402,8 @@ private: ...@@ -401,6 +402,8 @@ private:
// Ordered list of all redirects followed while fetching this resource. // Ordered list of all redirects followed while fetching this resource.
Vector<RedirectPair> m_redirectChain; Vector<RedirectPair> m_redirectChain;
static unsigned s_instanceCount;
}; };
#if !LOG_DISABLED #if !LOG_DISABLED
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
namespace blink { namespace blink {
unsigned AudioNode::s_instanceCount = 0;
AudioNode::AudioNode(AudioContext* context, float sampleRate) AudioNode::AudioNode(AudioContext* context, float sampleRate)
: m_isInitialized(false) : m_isInitialized(false)
, m_nodeType(NodeTypeUnknown) , m_nodeType(NodeTypeUnknown)
...@@ -70,10 +72,12 @@ AudioNode::AudioNode(AudioContext* context, float sampleRate) ...@@ -70,10 +72,12 @@ AudioNode::AudioNode(AudioContext* context, float sampleRate)
atexit(AudioNode::printNodeCounts); atexit(AudioNode::printNodeCounts);
} }
#endif #endif
++s_instanceCount;
} }
AudioNode::~AudioNode() AudioNode::~AudioNode()
{ {
--s_instanceCount;
#if DEBUG_AUDIONODE_REFERENCES #if DEBUG_AUDIONODE_REFERENCES
--s_nodeCount[nodeType()]; --s_nodeCount[nodeType()];
#if ENABLE(OILPAN) #if ENABLE(OILPAN)
......
...@@ -60,6 +60,7 @@ public: ...@@ -60,6 +60,7 @@ public:
// dispose() is called just before the destructor. This must be called in // dispose() is called just before the destructor. This must be called in
// the main thread, and while the graph lock is held. // the main thread, and while the graph lock is held.
virtual void dispose(); virtual void dispose();
static unsigned instanceCount() { return s_instanceCount; }
AudioContext* context() { return m_context.get(); } AudioContext* context() { return m_context.get(); }
const AudioContext* context() const { return m_context.get(); } const AudioContext* context() const { return m_context.get(); }
...@@ -231,6 +232,7 @@ private: ...@@ -231,6 +232,7 @@ private:
static bool s_isNodeCountInitialized; static bool s_isNodeCountInitialized;
static int s_nodeCount[NodeTypeEnd]; static int s_nodeCount[NodeTypeEnd];
#endif #endif
static unsigned s_instanceCount;
#if !ENABLE(OILPAN) #if !ENABLE(OILPAN)
virtual void refEventTarget() OVERRIDE FINAL { ref(); } virtual void refEventTarget() OVERRIDE FINAL { ref(); }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "core/fetch/ResourceFetcher.h" #include "core/fetch/ResourceFetcher.h"
#include "core/inspector/InspectorCounters.h" #include "core/inspector/InspectorCounters.h"
#include "core/rendering/RenderObject.h" #include "core/rendering/RenderObject.h"
#include "modules/webaudio/AudioNode.h"
#include "platform/Timer.h" #include "platform/Timer.h"
#include "public/web/WebDocument.h" #include "public/web/WebDocument.h"
#include "public/web/WebLocalFrame.h" #include "public/web/WebLocalFrame.h"
...@@ -129,9 +130,11 @@ void WebLeakDetectorImpl::delayedReport(Timer<WebLeakDetectorImpl>*) ...@@ -129,9 +130,11 @@ void WebLeakDetectorImpl::delayedReport(Timer<WebLeakDetectorImpl>*)
ASSERT(m_client); ASSERT(m_client);
WebLeakDetectorClient::Result result; WebLeakDetectorClient::Result result;
result.numberOfLiveAudioNodes = AudioNode::instanceCount();
result.numberOfLiveDocuments = InspectorCounters::counterValue(InspectorCounters::DocumentCounter); result.numberOfLiveDocuments = InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
result.numberOfLiveNodes = InspectorCounters::counterValue(InspectorCounters::NodeCounter); result.numberOfLiveNodes = InspectorCounters::counterValue(InspectorCounters::NodeCounter);
result.numberOfLiveRenderObjects = RenderObject::instanceCount(); result.numberOfLiveRenderObjects = RenderObject::instanceCount();
result.numberOfLiveResources = Resource::instanceCount();
m_client->onLeakDetectionComplete(result); m_client->onLeakDetectionComplete(result);
......
...@@ -39,9 +39,11 @@ namespace blink { ...@@ -39,9 +39,11 @@ namespace blink {
class WebLeakDetectorClient { class WebLeakDetectorClient {
public: public:
struct Result { struct Result {
unsigned numberOfLiveNodes; unsigned numberOfLiveAudioNodes;
unsigned numberOfLiveDocuments; unsigned numberOfLiveDocuments;
unsigned numberOfLiveNodes;
unsigned numberOfLiveRenderObjects; unsigned numberOfLiveRenderObjects;
unsigned numberOfLiveResources;
}; };
virtual void onLeakDetectionComplete(const Result&) = 0; virtual void onLeakDetectionComplete(const Result&) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment