Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Side by Side Diff: Source/core/inspector/AsyncCallStackTracker.cpp

Issue 74063002: DevTools: Support asynchronous call stacks on backend. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed test flakiness Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #ifdef DEBUG_ASYNC_CALLS_DEBUGGER_SUPPORT
37 namespace {
38 unsigned totalAsyncCallStacks = 0;
39 }
40 #endif
41
42 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack(const ScriptValue& callFra mes)
43 : m_callFrames(callFrames)
44 {
45 #ifdef DEBUG_ASYNC_CALLS_DEBUGGER_SUPPORT
46 fprintf(stderr, "AsyncCallStack::AsyncCallStack() %u\n", ++totalAsyncCallSta cks);
47 #endif
48 }
49
50 AsyncCallStackTracker::AsyncCallStack::~AsyncCallStack()
51 {
52 #ifdef DEBUG_ASYNC_CALLS_DEBUGGER_SUPPORT
53 fprintf(stderr, "AsyncCallStack::~AsyncCallStack() %u\n", --totalAsyncCallSt acks);
54 #endif
55 }
56
57 AsyncCallStackTracker::AsyncCallStackTracker()
58 : m_maxAsyncCallStackDepth(0)
59 {
60 #ifdef DEBUG_ASYNC_CALLS_DEBUGGER_SUPPORT
61 m_maxAsyncCallStackDepth = 4;
62 #endif
63 }
64
65 void AsyncCallStackTracker::setAsyncCallStackDepth(int depth)
66 {
67 if (depth <= 0) {
68 m_maxAsyncCallStackDepth = 0;
69 clear();
70 } else {
71 m_maxAsyncCallStackDepth = depth;
72 }
73 }
74
75 const AsyncCallStackTracker::AsyncCallChain* AsyncCallStackTracker::currentAsync CallChain() const
76 {
77 if (m_currentAsyncCallChain)
78 ensureMaxAsyncCallChainDepth(m_currentAsyncCallChain.get(), m_maxAsyncCa llStackDepth);
79 return m_currentAsyncCallChain.get();
80 }
81
82 void AsyncCallStackTracker::didInstallTimer(int timerId, bool singleShot, const ScriptValue& callFrames)
83 {
84 ASSERT(isEnabled());
85 if (!validateCallFrames(callFrames))
86 return;
87 ASSERT(timerId > 0);
88 m_timerCallChains.set(timerId, createAsyncCallChain(callFrames));
89 if (!singleShot)
90 m_intervalTimerIds.add(timerId);
91 }
92
93 void AsyncCallStackTracker::didRemoveTimer(int timerId)
94 {
95 if (!isEnabled() || timerId <= 0)
96 return;
97 m_intervalTimerIds.remove(timerId);
98 m_timerCallChains.remove(timerId);
99 }
100
101 void AsyncCallStackTracker::willFireTimer(int timerId)
102 {
103 if (!isEnabled())
104 return;
105 ASSERT(timerId > 0);
106 ASSERT(!m_currentAsyncCallChain);
107 if (m_intervalTimerIds.contains(timerId))
108 m_currentAsyncCallChain = m_timerCallChains.get(timerId);
109 else
110 m_currentAsyncCallChain = m_timerCallChains.take(timerId);
111 }
112
113 void AsyncCallStackTracker::didRequestAnimationFrame(int callbackId, const Scrip tValue& callFrames)
114 {
115 ASSERT(isEnabled());
116 if (!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(const 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(const 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
OLDNEW
« no previous file with comments | « Source/core/inspector/AsyncCallStackTracker.h ('k') | Source/core/inspector/InspectorDebuggerAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698