Chromium Code Reviews| 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 namespace WebCore { | |
| 35 | |
| 36 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack(AsyncCallStack* next) | |
| 37 : m_callFrames(ScriptValue()) | |
| 38 , m_next(next) | |
| 39 , m_pathCount(0) | |
| 40 { | |
| 41 } | |
| 42 | |
| 43 AsyncCallStackTracker::AsyncCallStackIterator::AsyncCallStackIterator(AsyncCallS tack* head, AsyncCallStack* tail) | |
| 44 : m_head(head) | |
| 45 , m_tail(tail) | |
| 46 { | |
| 47 } | |
| 48 | |
| 49 bool AsyncCallStackTracker::AsyncCallStackIterator::hasNext() const | |
| 50 { | |
| 51 return m_head && m_head != m_tail && !m_head->m_callFrames.hasNoValue(); | |
| 52 } | |
| 53 | |
| 54 ScriptValue AsyncCallStackTracker::AsyncCallStackIterator::next() | |
| 55 { | |
| 56 ASSERT(hasNext()); | |
| 57 ScriptValue result = m_head->m_callFrames; | |
| 58 m_head = m_head->m_next; | |
| 59 if (m_head == m_tail) | |
| 60 m_head = m_tail = 0; | |
| 61 return result; | |
| 62 } | |
| 63 | |
| 64 AsyncCallStackTracker::AsyncCallStackTracker() | |
| 65 : m_maxAsyncCallStackDepth(0) | |
| 66 , m_currentAsyncCallStackDelta(0) | |
| 67 { | |
| 68 } | |
| 69 | |
| 70 void AsyncCallStackTracker::setAsyncCallStackDepth(int depth) | |
| 71 { | |
| 72 if (depth <= 0) { | |
| 73 m_maxAsyncCallStackDepth = 0; | |
| 74 clear(); | |
| 75 } else { | |
| 76 m_maxAsyncCallStackDepth = depth; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 AsyncCallStackTracker::AsyncCallStackIterator AsyncCallStackTracker::currentAsyn cCallStack() | |
| 81 { | |
| 82 RefPtr<AsyncCallStack> head = m_currentAsyncCallStack; | |
| 83 RefPtr<AsyncCallStack> tail = m_currentAsyncCallStack; | |
| 84 for (int i = 0; tail && i < m_maxAsyncCallStackDepth; ++i) | |
| 85 tail = tail->m_next; | |
| 86 return AsyncCallStackTracker::AsyncCallStackIterator(head.get(), tail.get()) ; | |
| 87 } | |
| 88 | |
| 89 void AsyncCallStackTracker::didInstallTimer(int timerId, bool singleShot) | |
| 90 { | |
| 91 if (!isEnabled()) | |
| 92 return; | |
| 93 ASSERT(timerId > 0); | |
| 94 m_timerCallStacks.add(timerId, requestAsyncCallStack()); | |
| 95 if (!singleShot) | |
| 96 m_intervalTimerIds.add(timerId); | |
| 97 } | |
| 98 | |
| 99 void AsyncCallStackTracker::didRemoveTimer(int timerId) | |
| 100 { | |
| 101 if (!isEnabled() || timerId <= 0) | |
| 102 return; | |
| 103 m_intervalTimerIds.remove(timerId); | |
| 104 modifyPathCount(m_timerCallStacks.take(timerId), -1); | |
| 105 } | |
| 106 | |
| 107 void AsyncCallStackTracker::willFireTimer(int timerId) | |
| 108 { | |
| 109 if (!isEnabled()) | |
| 110 return; | |
| 111 ASSERT(timerId > 0); | |
| 112 ASSERT(!m_currentAsyncCallStack); | |
| 113 if (m_intervalTimerIds.contains(timerId)) | |
| 114 setCurrentAsyncCallStack(m_timerCallStacks.get(timerId), 0); | |
| 115 else | |
| 116 setCurrentAsyncCallStack(m_timerCallStacks.take(timerId), -1); | |
| 117 } | |
| 118 | |
| 119 void AsyncCallStackTracker::didRequestAnimationFrame(int callbackId) | |
| 120 { | |
| 121 if (!isEnabled()) | |
| 122 return; | |
| 123 ASSERT(callbackId > 0); | |
| 124 m_animationFrameCallStacks.add(callbackId, requestAsyncCallStack()); | |
| 125 } | |
| 126 | |
| 127 void AsyncCallStackTracker::didCancelAnimationFrame(int callbackId) | |
| 128 { | |
| 129 if (!isEnabled() || callbackId <= 0) | |
| 130 return; | |
| 131 modifyPathCount(m_animationFrameCallStacks.take(callbackId), -1); | |
| 132 } | |
| 133 | |
| 134 void AsyncCallStackTracker::willFireAnimationFrame(int callbackId) | |
| 135 { | |
| 136 if (!isEnabled()) | |
| 137 return; | |
| 138 ASSERT(callbackId > 0); | |
| 139 ASSERT(!m_currentAsyncCallStack); | |
| 140 setCurrentAsyncCallStack(m_animationFrameCallStacks.take(callbackId), -1); | |
| 141 } | |
| 142 | |
| 143 void AsyncCallStackTracker::didAsyncCall() | |
| 144 { | |
| 145 if (!isEnabled()) | |
| 146 return; | |
| 147 setCurrentAsyncCallStack(0, 0); | |
| 148 } | |
| 149 | |
| 150 void AsyncCallStackTracker::didRequestAsyncCallFrames(ScriptValue callFrames) | |
| 151 { | |
| 152 if (!isEnabled()) | |
| 153 return; | |
| 154 ASSERT(m_requestedAsyncCallStack); | |
| 155 if (!m_requestedAsyncCallStack) | |
| 156 return; | |
| 157 m_requestedAsyncCallStack->m_callFrames = callFrames; | |
| 158 m_requestedAsyncCallStack = 0; | |
| 159 } | |
| 160 | |
| 161 AsyncCallStackTracker::AsyncCallStack* AsyncCallStackTracker::requestAsyncCallSt ack() | |
| 162 { | |
| 163 ASSERT(isEnabled()); | |
| 164 ASSERT(!m_requestedAsyncCallStack); | |
| 165 m_requestedAsyncCallStack = adoptRef(new AsyncCallStackTracker::AsyncCallSta ck(m_currentAsyncCallStack.get())); | |
| 166 modifyPathCount(m_requestedAsyncCallStack, 1); | |
| 167 return m_requestedAsyncCallStack.get(); | |
| 168 } | |
| 169 | |
| 170 void AsyncCallStackTracker::setCurrentAsyncCallStack(PassRefPtr<AsyncCallStack> callStack, int delta) | |
| 171 { | |
| 172 if (m_currentAsyncCallStack) | |
| 173 modifyPathCount(m_currentAsyncCallStack.release(), m_currentAsyncCallSta ckDelta); | |
| 174 m_currentAsyncCallStack = callStack; | |
| 175 m_currentAsyncCallStackDelta = delta; | |
| 176 } | |
| 177 | |
| 178 void AsyncCallStackTracker::modifyPathCount(PassRefPtr<AsyncCallStack> head, int delta) | |
| 179 { | |
| 180 if (!head || !delta) | |
| 181 return; | |
| 182 if (head == m_currentAsyncCallStack) { | |
| 183 // Defer modifying the path count. | |
|
yurys
2013/11/28 09:18:16
Why do you need to defer here, can't we simply che
| |
| 184 m_currentAsyncCallStackDelta += delta; | |
| 185 return; | |
| 186 } | |
| 187 int depth = 0; | |
| 188 RefPtr<AsyncCallStack> current = head; | |
| 189 while (current && depth < m_maxAsyncCallStackDepth) { | |
| 190 ++depth; | |
| 191 current->m_pathCount += delta; | |
| 192 if (current->m_pathCount <= 0) { | |
|
yurys
2013/11/28 09:18:16
If m_pathCount == 0 we should dispose of current,
| |
| 193 ASSERT(!current->m_pathCount); | |
| 194 current = current->m_next.release(); | |
| 195 } else { | |
| 196 current = current->m_next; | |
| 197 } | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 void AsyncCallStackTracker::clear() | |
| 202 { | |
| 203 m_currentAsyncCallStackDelta = 0; | |
| 204 m_currentAsyncCallStack = 0; | |
| 205 m_requestedAsyncCallStack = 0; | |
| 206 m_intervalTimerIds.clear(); | |
| 207 m_timerCallStacks.clear(); | |
| 208 m_animationFrameCallStacks.clear(); | |
| 209 } | |
| 210 | |
| 211 } // namespace WebCore | |
| OLD | NEW |