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 #include "config.h" | |
32 #include "MemoryInstrumentationImpl.h" | |
33 | |
34 #include "HeapGraphSerializer.h" | |
35 #include "WebCoreMemoryInstrumentation.h" | |
36 #include <wtf/Assertions.h> | |
37 #include <wtf/MemoryInstrumentationHashMap.h> | |
38 #include <wtf/MemoryInstrumentationHashSet.h> | |
39 #include <wtf/MemoryInstrumentationVector.h> | |
40 #include <wtf/text/StringHash.h> | |
41 | |
42 namespace WebCore { | |
43 | |
44 TypeNameToSizeMap MemoryInstrumentationClientImpl::sizesMap() const | |
45 { | |
46 // TypeToSizeMap uses const char* as the key. | |
47 // Thus it could happen that we have two different keys with equal string. | |
48 TypeNameToSizeMap sizesMap; | |
49 for (TypeToSizeMap::const_iterator i = m_totalSizes.begin(); i != m_totalSiz
es.end(); ++i) { | |
50 String objectType(i->key); | |
51 TypeNameToSizeMap::AddResult result = sizesMap.add(objectType, i->value)
; | |
52 if (!result.isNewEntry) | |
53 result.iterator->value += i->value; | |
54 } | |
55 | |
56 return sizesMap; | |
57 } | |
58 | |
59 void MemoryInstrumentationClientImpl::countObjectSize(const void* object, Memory
ObjectType objectType, size_t size) | |
60 { | |
61 ASSERT(objectType); | |
62 | |
63 TypeToSizeMap::AddResult result = m_totalSizes.add(objectType, size); | |
64 if (!result.isNewEntry) | |
65 result.iterator->value += size; | |
66 ++m_totalCountedObjects; | |
67 | |
68 if (!checkInstrumentedObjects()) | |
69 return; | |
70 | |
71 if (object) | |
72 m_countedObjects.add(object, size); | |
73 } | |
74 | |
75 bool MemoryInstrumentationClientImpl::visited(const void* object) | |
76 { | |
77 return !m_visitedObjects.add(object).isNewEntry; | |
78 } | |
79 | |
80 bool MemoryInstrumentationClientImpl::checkCountedObject(const void* object) | |
81 { | |
82 if (!checkInstrumentedObjects()) | |
83 return true; | |
84 if (!m_allocatedObjects.contains(object)) { | |
85 ++m_totalObjectsNotInAllocatedSet; | |
86 return false; | |
87 } | |
88 return true; | |
89 } | |
90 | |
91 void MemoryInstrumentationClientImpl::reportNode(const MemoryObjectInfo& node) | |
92 { | |
93 if (m_graphSerializer) | |
94 m_graphSerializer->reportNode(node); | |
95 } | |
96 | |
97 void MemoryInstrumentationClientImpl::reportEdge(const void* target, const char*
name, MemberType memberType) | |
98 { | |
99 if (m_graphSerializer) | |
100 m_graphSerializer->reportEdge(target, name, memberType); | |
101 } | |
102 | |
103 void MemoryInstrumentationClientImpl::reportLeaf(const MemoryObjectInfo& target,
const char* edgeName) | |
104 { | |
105 if (m_graphSerializer) | |
106 m_graphSerializer->reportLeaf(target, edgeName); | |
107 } | |
108 | |
109 void MemoryInstrumentationClientImpl::reportBaseAddress(const void* base, const
void* real) | |
110 { | |
111 if (m_graphSerializer) | |
112 m_graphSerializer->reportBaseAddress(base, real); | |
113 } | |
114 | |
115 int MemoryInstrumentationClientImpl::registerString(const char* string) | |
116 { | |
117 if (m_graphSerializer) | |
118 return m_graphSerializer->registerString(string); | |
119 return -1; | |
120 } | |
121 | |
122 void MemoryInstrumentationClientImpl::reportMemoryUsage(MemoryObjectInfo* memory
ObjectInfo) const | |
123 { | |
124 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorMe
moryAgent); | |
125 info.addMember(m_totalSizes, "totalSizes"); | |
126 info.addMember(m_visitedObjects, "visitedObjects"); | |
127 info.addMember(m_allocatedObjects, "allocatedObjects"); | |
128 info.addMember(m_countedObjects, "countedObjects"); | |
129 info.addMember(m_graphSerializer, "graphSerializer"); | |
130 } | |
131 | |
132 void MemoryInstrumentationImpl::processDeferredObjects() | |
133 { | |
134 while (!m_deferredObjects.isEmpty()) { | |
135 OwnPtr<WrapperBase> pointer = m_deferredObjects.last().release(); | |
136 m_deferredObjects.removeLast(); | |
137 pointer->process(this); | |
138 } | |
139 } | |
140 | |
141 void MemoryInstrumentationImpl::deferObject(PassOwnPtr<WrapperBase> pointer) | |
142 { | |
143 m_deferredObjects.append(pointer); | |
144 } | |
145 | |
146 void MemoryInstrumentationImpl::reportMemoryUsage(MemoryObjectInfo* memoryObject
Info) const | |
147 { | |
148 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorMe
moryAgent); | |
149 info.addMember(m_deferredObjects, "deferredObjects"); | |
150 } | |
151 | |
152 | |
153 } // namespace WebCore | |
154 | |
OLD | NEW |