OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef HeapGraphSerializer_h | 31 #ifndef HeapGraphSerializer_h |
32 #define HeapGraphSerializer_h | 32 #define HeapGraphSerializer_h |
33 | 33 |
34 | 34 |
35 #include "InspectorFrontend.h" | 35 #include "InspectorFrontend.h" |
36 #include <wtf/Forward.h> | 36 #include <wtf/Forward.h> |
37 #include <wtf/HashMap.h> | 37 #include <wtf/HashMap.h> |
38 #include <wtf/MemoryInstrumentation.h> | |
39 #include <wtf/Noncopyable.h> | 38 #include <wtf/Noncopyable.h> |
40 #include <wtf/Vector.h> | 39 #include <wtf/Vector.h> |
41 #include <wtf/text/StringHash.h> | 40 #include <wtf/text/StringHash.h> |
42 | 41 |
43 namespace WebCore { | 42 namespace WebCore { |
44 | 43 |
45 class HeapGraphSerializer { | 44 class HeapGraphSerializer { |
46 WTF_MAKE_NONCOPYABLE(HeapGraphSerializer); | 45 WTF_MAKE_NONCOPYABLE(HeapGraphSerializer); |
47 public: | 46 public: |
48 | 47 |
49 class Client { | 48 class Client { |
50 public: | 49 public: |
51 virtual ~Client() { } | 50 virtual ~Client() { } |
52 virtual void addNativeSnapshotChunk(PassRefPtr<TypeBuilder::Memory::Heap
SnapshotChunk>) = 0; | 51 virtual void addNativeSnapshotChunk(PassRefPtr<TypeBuilder::Memory::Heap
SnapshotChunk>) = 0; |
53 }; | 52 }; |
54 | 53 |
55 explicit HeapGraphSerializer(Client*); | 54 explicit HeapGraphSerializer(Client*); |
56 ~HeapGraphSerializer(); | 55 ~HeapGraphSerializer(); |
57 void reportNode(const WTF::MemoryObjectInfo&); | |
58 void reportEdge(const void*, const char*, WTF::MemberType); | |
59 void reportLeaf(const WTF::MemoryObjectInfo&, const char*); | |
60 void reportBaseAddress(const void*, const void*); | 56 void reportBaseAddress(const void*, const void*); |
61 int registerString(const char*); | 57 int registerString(const char*); |
62 | 58 |
63 PassRefPtr<InspectorObject> finish(); | 59 PassRefPtr<InspectorObject> finish(); |
64 | 60 |
65 void reportMemoryUsage(MemoryObjectInfo*) const; | |
66 | |
67 private: | 61 private: |
68 void pushUpdateIfNeeded(); | 62 void pushUpdateIfNeeded(); |
69 void pushUpdate(); | 63 void pushUpdate(); |
70 | 64 |
71 int toNodeId(const void*); | 65 int toNodeId(const void*); |
72 | 66 |
73 void addRootNode(); | 67 void addRootNode(); |
74 int registerTypeString(const char*); | 68 int registerTypeString(const char*); |
75 | 69 |
76 void reportEdgeImpl(const int toNodeId, const char* name, int memberType); | 70 void reportEdgeImpl(const int toNodeId, const char* name, int memberType); |
77 int reportNodeImpl(const WTF::MemoryObjectInfo&, int edgesCount); | |
78 | 71 |
79 Client* m_client; | 72 Client* m_client; |
80 | 73 |
81 typedef HashMap<String, int> StringMap; | 74 typedef HashMap<String, int> StringMap; |
82 StringMap m_stringToIndex; | 75 StringMap m_stringToIndex; |
83 typedef TypeBuilder::Array<String> Strings; | 76 typedef TypeBuilder::Array<String> Strings; |
84 RefPtr<Strings> m_strings; | 77 RefPtr<Strings> m_strings; |
85 | 78 |
86 typedef TypeBuilder::Array<int> Edges; | 79 typedef TypeBuilder::Array<int> Edges; |
87 RefPtr<Edges> m_edges; | 80 RefPtr<Edges> m_edges; |
88 int m_nodeEdgesCount; | 81 int m_nodeEdgesCount; |
89 static const size_t s_edgeFieldsCount = 3; | 82 static const size_t s_edgeFieldsCount = 3; |
90 | 83 |
91 typedef TypeBuilder::Array<int> Nodes; | 84 typedef TypeBuilder::Array<int> Nodes; |
92 RefPtr<Nodes> m_nodes; | 85 RefPtr<Nodes> m_nodes; |
93 static const size_t s_nodeFieldsCount = 5; | 86 static const size_t s_nodeFieldsCount = 5; |
94 | 87 |
95 typedef TypeBuilder::Array<int> BaseToRealNodeIdMap; | 88 typedef TypeBuilder::Array<int> BaseToRealNodeIdMap; |
96 RefPtr<BaseToRealNodeIdMap> m_baseToRealNodeIdMap; | 89 RefPtr<BaseToRealNodeIdMap> m_baseToRealNodeIdMap; |
97 static const size_t s_idMapEntryFieldCount = 2; | 90 static const size_t s_idMapEntryFieldCount = 2; |
98 | 91 |
99 typedef HashMap<const void*, int> Address2NodeId; | 92 typedef HashMap<const void*, int> Address2NodeId; |
100 Address2NodeId m_address2NodeIdMap; | 93 Address2NodeId m_address2NodeIdMap; |
101 | 94 |
102 Vector<const void*> m_roots; | 95 Vector<const void*> m_roots; |
103 RefPtr<InspectorObject> m_typeStrings; | 96 RefPtr<InspectorObject> m_typeStrings; |
104 | 97 |
105 size_t m_edgeTypes[WTF::LastMemberTypeEntry]; | |
106 int m_unknownClassNameId; | 98 int m_unknownClassNameId; |
107 int m_leafCount; | 99 int m_leafCount; |
108 | 100 |
109 static const int s_firstNodeId = 1; | 101 static const int s_firstNodeId = 1; |
110 }; | 102 }; |
111 | 103 |
112 } // namespace WebCore | 104 } // namespace WebCore |
113 | 105 |
114 #endif // !defined(HeapGraphSerializer_h) | 106 #endif // !defined(HeapGraphSerializer_h) |
OLD | NEW |