]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
81345200 | 2 | * Copyright (C) 2008, 2014 Apple Inc. All rights reserved. |
9dae56ea A |
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 | * | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
81345200 | 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
9dae56ea A |
14 | * its contributors may be used to endorse or promote products derived |
15 | * from this software without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #ifndef ProfileNode_h | |
30 | #define ProfileNode_h | |
31 | ||
32 | #include "CallIdentifier.h" | |
14957cd0 | 33 | #include <wtf/HashCountedSet.h> |
9dae56ea A |
34 | #include <wtf/RefCounted.h> |
35 | #include <wtf/RefPtr.h> | |
14957cd0 | 36 | #include <wtf/Vector.h> |
9dae56ea A |
37 | |
38 | namespace JSC { | |
39 | ||
14957cd0 | 40 | class ExecState; |
9dae56ea A |
41 | class ProfileNode; |
42 | ||
14957cd0 | 43 | typedef HashCountedSet<StringImpl*> FunctionCallHashCount; |
9dae56ea A |
44 | |
45 | class ProfileNode : public RefCounted<ProfileNode> { | |
46 | public: | |
14957cd0 | 47 | static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, const CallIdentifier& callIdentifier, ProfileNode* headNode, ProfileNode* parentNode) |
9dae56ea | 48 | { |
14957cd0 | 49 | return adoptRef(new ProfileNode(callerCallFrame, callIdentifier, headNode, parentNode)); |
9dae56ea | 50 | } |
81345200 | 51 | |
14957cd0 | 52 | static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, ProfileNode* headNode, ProfileNode* node) |
9dae56ea | 53 | { |
14957cd0 | 54 | return adoptRef(new ProfileNode(callerCallFrame, headNode, node)); |
9dae56ea A |
55 | } |
56 | ||
81345200 A |
57 | struct Call { |
58 | public: | |
59 | Call(double startTime, double totalTime = NAN) | |
60 | : m_startTime(startTime) | |
61 | , m_totalTime(totalTime) | |
62 | { | |
63 | } | |
64 | ||
65 | double startTime() const { return m_startTime; } | |
66 | void setStartTime(double time) { m_startTime = time; } | |
67 | ||
68 | double totalTime() const { return m_totalTime; } | |
69 | void setTotalTime(double time) { m_totalTime = time; } | |
70 | ||
71 | private: | |
72 | double m_startTime; | |
73 | double m_totalTime; | |
74 | }; | |
75 | ||
9dae56ea A |
76 | bool operator==(ProfileNode* node) { return m_callIdentifier == node->callIdentifier(); } |
77 | ||
14957cd0 | 78 | ProfileNode* willExecute(ExecState* callerCallFrame, const CallIdentifier&); |
9dae56ea A |
79 | ProfileNode* didExecute(); |
80 | ||
81 | void stopProfiling(); | |
82 | ||
83 | // CallIdentifier members | |
14957cd0 | 84 | ExecState* callerCallFrame() const { return m_callerCallFrame; } |
9dae56ea | 85 | const CallIdentifier& callIdentifier() const { return m_callIdentifier; } |
81345200 A |
86 | unsigned id() const { return m_callIdentifier.hash(); } |
87 | const String& functionName() const { return m_callIdentifier.functionName(); } | |
88 | const String& url() const { return m_callIdentifier.url(); } | |
89 | unsigned lineNumber() const { return m_callIdentifier.lineNumber(); } | |
90 | unsigned columnNumber() const { return m_callIdentifier.columnNumber(); } | |
9dae56ea A |
91 | |
92 | // Relationships | |
93 | ProfileNode* head() const { return m_head; } | |
94 | void setHead(ProfileNode* head) { m_head = head; } | |
81345200 | 95 | |
9dae56ea A |
96 | ProfileNode* parent() const { return m_parent; } |
97 | void setParent(ProfileNode* parent) { m_parent = parent; } | |
81345200 | 98 | |
9dae56ea A |
99 | ProfileNode* nextSibling() const { return m_nextSibling; } |
100 | void setNextSibling(ProfileNode* nextSibling) { m_nextSibling = nextSibling; } | |
101 | ||
102 | // Time members | |
81345200 A |
103 | double totalTime() const { return m_totalTime; } |
104 | void setTotalTime(double time) { m_totalTime = time; } | |
105 | ||
106 | double selfTime() const { return m_selfTime; } | |
107 | void setSelfTime(double time) { m_selfTime = time; } | |
108 | ||
109 | double totalPercent() const { return (m_totalTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; } | |
110 | double selfPercent() const { return (m_selfTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; } | |
111 | ||
112 | Vector<Call> calls() const { return m_calls; } | |
113 | Call& lastCall() { ASSERT(!m_calls.isEmpty()); return m_calls.last(); } | |
114 | size_t numberOfCalls() const { return m_calls.size(); } | |
9dae56ea A |
115 | |
116 | // Children members | |
81345200 | 117 | const Vector<RefPtr<ProfileNode>>& children() const { return m_children; } |
9dae56ea A |
118 | ProfileNode* firstChild() const { return m_children.size() ? m_children.first().get() : 0; } |
119 | ProfileNode* lastChild() const { return m_children.size() ? m_children.last().get() : 0; } | |
9dae56ea A |
120 | void removeChild(ProfileNode*); |
121 | void addChild(PassRefPtr<ProfileNode> prpChild); | |
122 | void insertNode(PassRefPtr<ProfileNode> prpNode); | |
123 | ||
9dae56ea | 124 | ProfileNode* traverseNextNodePostOrder() const; |
9dae56ea A |
125 | |
126 | #ifndef NDEBUG | |
127 | const char* c_str() const { return m_callIdentifier; } | |
128 | void debugPrintData(int indentLevel) const; | |
129 | double debugPrintDataSampleStyle(int indentLevel, FunctionCallHashCount&) const; | |
130 | #endif | |
131 | ||
132 | private: | |
81345200 A |
133 | typedef Vector<RefPtr<ProfileNode>>::const_iterator StackIterator; |
134 | ||
14957cd0 A |
135 | ProfileNode(ExecState* callerCallFrame, const CallIdentifier&, ProfileNode* headNode, ProfileNode* parentNode); |
136 | ProfileNode(ExecState* callerCallFrame, ProfileNode* headNode, ProfileNode* nodeToCopy); | |
9dae56ea A |
137 | |
138 | void startTimer(); | |
139 | void resetChildrensSiblings(); | |
81345200 | 140 | void endAndRecordCall(); |
9dae56ea | 141 | |
14957cd0 | 142 | ExecState* m_callerCallFrame; |
9dae56ea A |
143 | CallIdentifier m_callIdentifier; |
144 | ProfileNode* m_head; | |
145 | ProfileNode* m_parent; | |
146 | ProfileNode* m_nextSibling; | |
147 | ||
81345200 A |
148 | double m_totalTime; |
149 | double m_selfTime; | |
9dae56ea | 150 | |
81345200 A |
151 | Vector<Call, 1> m_calls; |
152 | Vector<RefPtr<ProfileNode>> m_children; | |
9dae56ea A |
153 | }; |
154 | ||
155 | } // namespace JSC | |
156 | ||
157 | #endif // ProfileNode_h |