OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Google 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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef MemoryInstrumentationImpl_h | |
32 #define MemoryInstrumentationImpl_h | |
33 | |
34 | |
35 #include <wtf/Forward.h> | |
36 #include <wtf/HashMap.h> | |
37 #include <wtf/HashSet.h> | |
38 #include <wtf/MemoryInstrumentation.h> | |
39 #include <wtf/Vector.h> | |
40 #include <wtf/text/StringHash.h> | |
41 | |
42 using WTF::MemoryObjectType; | |
43 using WTF::MemberType; | |
44 | |
45 namespace WebCore { | |
46 | |
47 class HeapGraphSerializer; | |
48 | |
49 typedef HashSet<const void*> VisitedObjects; | |
50 typedef HashMap<String, size_t> TypeNameToSizeMap; | |
51 | |
52 class MemoryInstrumentationClientImpl : public WTF::MemoryInstrumentationClient
{ | |
53 public: | |
54 typedef HashMap<const void*, size_t> ObjectToSizeMap; | |
55 | |
56 explicit MemoryInstrumentationClientImpl(HeapGraphSerializer* serializer) | |
57 : m_totalCountedObjects(0) | |
58 , m_totalObjectsNotInAllocatedSet(0) | |
59 , m_graphSerializer(serializer) | |
60 { } | |
61 | |
62 size_t totalSize(MemoryObjectType objectType) const | |
63 { | |
64 TypeToSizeMap::const_iterator i = m_totalSizes.find(objectType); | |
65 return i == m_totalSizes.end() ? 0 : i->value; | |
66 } | |
67 | |
68 size_t reportedSizeForAllTypes() const | |
69 { | |
70 size_t size = 0; | |
71 for (TypeToSizeMap::const_iterator i = m_totalSizes.begin(); i != m_tota
lSizes.end(); ++i) | |
72 size += i->value; | |
73 return size; | |
74 } | |
75 | |
76 TypeNameToSizeMap sizesMap() const; | |
77 VisitedObjects& allocatedObjects() { return m_allocatedObjects; } | |
78 const ObjectToSizeMap& countedObjects() { return m_countedObjects; } | |
79 | |
80 bool checkInstrumentedObjects() const { return !m_allocatedObjects.isEmpty()
; } | |
81 size_t visitedObjects() const { return m_visitedObjects.size(); } | |
82 size_t totalCountedObjects() const { return m_totalCountedObjects; } | |
83 size_t totalObjectsNotInAllocatedSet() const { return m_totalObjectsNotInAll
ocatedSet; } | |
84 | |
85 virtual void countObjectSize(const void*, MemoryObjectType, size_t) OVERRIDE
; | |
86 virtual bool visited(const void*) OVERRIDE; | |
87 virtual bool checkCountedObject(const void*) OVERRIDE; | |
88 virtual void reportNode(const MemoryObjectInfo&) OVERRIDE; | |
89 virtual void reportEdge(const void*, const char*, MemberType) OVERRIDE; | |
90 virtual void reportLeaf(const MemoryObjectInfo&, const char*) OVERRIDE; | |
91 virtual void reportBaseAddress(const void*, const void*) OVERRIDE; | |
92 virtual int registerString(const char*) OVERRIDE; | |
93 | |
94 void reportMemoryUsage(MemoryObjectInfo*) const; | |
95 | |
96 private: | |
97 typedef HashMap<MemoryObjectType, size_t> TypeToSizeMap; | |
98 TypeToSizeMap m_totalSizes; | |
99 VisitedObjects m_visitedObjects; | |
100 VisitedObjects m_allocatedObjects; | |
101 ObjectToSizeMap m_countedObjects; | |
102 size_t m_totalCountedObjects; | |
103 size_t m_totalObjectsNotInAllocatedSet; | |
104 HeapGraphSerializer* m_graphSerializer; | |
105 }; | |
106 | |
107 class MemoryInstrumentationImpl : public WTF::MemoryInstrumentation { | |
108 public: | |
109 explicit MemoryInstrumentationImpl(WTF::MemoryInstrumentationClient* client) | |
110 : MemoryInstrumentation(client) | |
111 { | |
112 } | |
113 | |
114 size_t selfSize() const; | |
115 | |
116 void reportMemoryUsage(MemoryObjectInfo*) const; | |
117 | |
118 private: | |
119 virtual void deferObject(PassOwnPtr<WrapperBase>) OVERRIDE; | |
120 virtual void processDeferredObjects() OVERRIDE; | |
121 | |
122 Vector<OwnPtr<WrapperBase> > m_deferredObjects; | |
123 }; | |
124 | |
125 } // namespace WebCore | |
126 | |
127 #endif // !defined(MemoryInstrumentationImpl_h) | |
128 | |
OLD | NEW |