OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2013 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 "core/inspector/AsyncCallStackTracker.h" | |
33 | |
34 #define DUMP_ASYNC_CALLS_TRACKER_STATS 0 | |
35 #if DUMP_ASYNC_CALLS_TRACKER_STATS | |
36 #include "wtf/DataLog.h" | |
37 #endif | |
38 | |
39 namespace WebCore { | |
40 | |
41 #if DUMP_ASYNC_CALLS_TRACKER_STATS | |
42 namespace { | |
43 unsigned totalAsyncCallStacks = 0; | |
44 } | |
45 #endif | |
46 | |
47 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack(const ScriptValue& callFra mes) | |
48 : m_callFrames(callFrames) | |
49 { | |
50 #if DUMP_ASYNC_CALLS_TRACKER_STATS | |
51 dataLogF("AsyncCallStack::AsyncCallStack() %u\n", ++totalAsyncCallStacks); | |
yurys
2013/12/04 15:25:52
What's the point in this dataLogF, why not printf?
aandrey
2013/12/04 15:57:26
it's the same essentially. plus there is a way to
yurys
2013/12/05 11:37:48
Then printf should be preferred, I don't see dataL
aandrey
2013/12/05 13:03:40
Done.
| |
52 #endif | |
53 } | |
54 | |
55 AsyncCallStackTracker::AsyncCallStack::~AsyncCallStack() | |
56 { | |
57 #if DUMP_ASYNC_CALLS_TRACKER_STATS | |
58 dataLogF("AsyncCallStack::~AsyncCallStack() %u\n", --totalAsyncCallStacks); | |
59 #endif | |
60 } | |
61 | |
62 AsyncCallStackTracker::AsyncCallStackTracker() | |
63 : m_maxAsyncCallStackDepth(DUMP_ASYNC_CALLS_TRACKER_STATS ? 4 : 0) | |
64 { | |
65 } | |
66 | |
67 void AsyncCallStackTracker::setAsyncCallStackDepth(int depth) | |
68 { | |
69 if (depth <= 0) { | |
70 m_maxAsyncCallStackDepth = 0; | |
71 clear(); | |
72 } else { | |
73 m_maxAsyncCallStackDepth = depth; | |
74 } | |
75 } | |
76 | |
77 const AsyncCallStackTracker::AsyncCallChain* AsyncCallStackTracker::currentAsync CallChain() const | |
78 { | |
79 if (m_currentAsyncCallChain) | |
80 ensureMaxAsyncCallChainDepth(m_currentAsyncCallChain.get(), m_maxAsyncCa llStackDepth); | |
81 return m_currentAsyncCallChain.get(); | |
82 } | |
83 | |
84 void AsyncCallStackTracker::didInstallTimer(int timerId, bool singleShot, Script Value callFrames) | |
85 { | |
86 if (!isEnabled() || !validateCallFrames(callFrames)) | |
yurys
2013/12/04 15:25:52
ASSERT(isEnabled()) as you already check it on the
aandrey
2013/12/04 15:57:26
Done.
| |
87 return; | |
88 ASSERT(timerId > 0); | |
89 m_timerCallChains.set(timerId, createAsyncCallChain(callFrames)); | |
90 if (!singleShot) | |
91 m_intervalTimerIds.add(timerId); | |
92 } | |
93 | |
94 void AsyncCallStackTracker::didRemoveTimer(int timerId) | |
95 { | |
96 if (!isEnabled() || timerId <= 0) | |
yurys
2013/12/04 15:25:52
How can timerId be <= 0 ? Maybe ASSERT as in didIn
aandrey
2013/12/04 15:57:26
Easy:
window.clearTimeout(-5);
But we do want t
yurys
2013/12/05 11:37:48
Got it, thanks for explaining.
| |
97 return; | |
98 m_intervalTimerIds.remove(timerId); | |
99 m_timerCallChains.remove(timerId); | |
100 } | |
101 | |
102 void AsyncCallStackTracker::willFireTimer(int timerId) | |
103 { | |
104 if (!isEnabled()) | |
105 return; | |
106 ASSERT(timerId > 0); | |
107 ASSERT(!m_currentAsyncCallChain); | |
108 if (m_intervalTimerIds.contains(timerId)) | |
109 m_currentAsyncCallChain = m_timerCallChains.get(timerId); | |
110 else | |
111 m_currentAsyncCallChain = m_timerCallChains.take(timerId); | |
112 } | |
113 | |
114 void AsyncCallStackTracker::didRequestAnimationFrame(int callbackId, ScriptValue callFrames) | |
115 { | |
116 if (!isEnabled() || !validateCallFrames(callFrames)) | |
117 return; | |
118 ASSERT(callbackId > 0); | |
119 m_animationFrameCallChains.set(callbackId, createAsyncCallChain(callFrames)) ; | |
120 } | |
121 | |
122 void AsyncCallStackTracker::didCancelAnimationFrame(int callbackId) | |
123 { | |
124 if (!isEnabled() || callbackId <= 0) | |
125 return; | |
126 m_animationFrameCallChains.remove(callbackId); | |
127 } | |
128 | |
129 void AsyncCallStackTracker::willFireAnimationFrame(int callbackId) | |
130 { | |
131 if (!isEnabled()) | |
132 return; | |
133 ASSERT(callbackId > 0); | |
134 ASSERT(!m_currentAsyncCallChain); | |
135 m_currentAsyncCallChain = m_animationFrameCallChains.take(callbackId); | |
136 } | |
137 | |
138 void AsyncCallStackTracker::didFireAsyncCall() | |
139 { | |
140 m_currentAsyncCallChain = 0; | |
141 } | |
142 | |
143 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA syncCallChain(ScriptValue& callFrames) | |
144 { | |
145 ASSERT(isEnabled()); | |
146 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr acker::AsyncCallChain()); | |
147 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); | |
148 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta ck(callFrames))); | |
149 return chain.release(); | |
150 } | |
151 | |
152 void AsyncCallStackTracker::ensureMaxAsyncCallChainDepth(AsyncCallChain* chain, unsigned maxDepth) | |
153 { | |
154 while (chain->m_callStacks.size() > maxDepth) | |
155 chain->m_callStacks.removeLast(); | |
156 } | |
157 | |
158 bool AsyncCallStackTracker::validateCallFrames(ScriptValue& callFrames) | |
159 { | |
160 return !callFrames.hasNoValue() && callFrames.isObject(); | |
161 } | |
162 | |
163 void AsyncCallStackTracker::clear() | |
164 { | |
165 m_currentAsyncCallChain = 0; | |
166 m_intervalTimerIds.clear(); | |
167 m_timerCallChains.clear(); | |
168 m_animationFrameCallChains.clear(); | |
169 } | |
170 | |
171 } // namespace WebCore | |
OLD | NEW |