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

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: addressed 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 #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 typedef AsyncCallStackTracker::AsyncCallTraceIterator AsyncCallTraceIterator;
42
43 #if DUMP_ASYNC_CALLS_TRACKER_STATS
44 namespace {
45 unsigned totalAsyncCallStacks = 0;
46 }
47 #endif
48
49 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack()
50 {
51 #if DUMP_ASYNC_CALLS_TRACKER_STATS
52 dataLogF("AsyncCallStack::AsyncCallStack() %u\n", ++totalAsyncCallStacks);
53 #endif
54 }
55
56 AsyncCallStackTracker::AsyncCallStack::~AsyncCallStack()
57 {
58 #if DUMP_ASYNC_CALLS_TRACKER_STATS
59 dataLogF("AsyncCallStack::~AsyncCallStack() %u\n", --totalAsyncCallStacks);
60 #endif
61 }
62
63 bool AsyncCallTraceIterator::hasNext() const
64 {
65 return !m_callStacks.isEmpty() && !m_callStacks.first()->m_callFrames.hasNoV alue();
66 }
67
68 ScriptValue AsyncCallTraceIterator::next()
69 {
70 ASSERT(hasNext());
71 return m_callStacks.takeFirst()->m_callFrames;
72 }
73
74 AsyncCallStackTracker::AsyncCallStackTracker()
75 : m_maxAsyncCallStackDepth(DUMP_ASYNC_CALLS_TRACKER_STATS ? 4 : 0)
76 {
77 }
78
79 void AsyncCallStackTracker::setAsyncCallStackDepth(int depth)
80 {
81 if (depth <= 0) {
82 m_maxAsyncCallStackDepth = 0;
83 clear();
84 } else {
85 m_maxAsyncCallStackDepth = depth;
86 }
87 }
88
89 AsyncCallTraceIterator AsyncCallStackTracker::currentAsyncCallStack()
90 {
91 return m_currentAsyncCallTrace ? AsyncCallTraceIterator(*m_currentAsyncCallT race) : AsyncCallTraceIterator();
92 }
93
94 void AsyncCallStackTracker::didInstallTimer(int timerId, bool singleShot)
95 {
96 if (!isEnabled())
97 return;
98 ASSERT(timerId > 0);
99 m_timerCallTraces.set(timerId, createAsyncCallTrace());
100 if (!singleShot)
101 m_intervalTimerIds.add(timerId);
102 }
103
104 void AsyncCallStackTracker::didRemoveTimer(int timerId)
105 {
106 if (!isEnabled() || timerId <= 0)
107 return;
108 m_intervalTimerIds.remove(timerId);
109 m_timerCallTraces.remove(timerId);
110 }
111
112 void AsyncCallStackTracker::willFireTimer(int timerId)
113 {
114 if (!isEnabled())
115 return;
116 ASSERT(timerId > 0);
117 ASSERT(!m_currentAsyncCallTrace);
118 if (m_intervalTimerIds.contains(timerId))
119 m_currentAsyncCallTrace = m_timerCallTraces.get(timerId);
120 else
121 m_currentAsyncCallTrace = m_timerCallTraces.take(timerId);
122 }
123
124 void AsyncCallStackTracker::didRequestAnimationFrame(int callbackId)
125 {
126 if (!isEnabled())
127 return;
128 ASSERT(callbackId > 0);
129 m_animationFrameCallTraces.set(callbackId, createAsyncCallTrace());
130 }
131
132 void AsyncCallStackTracker::didCancelAnimationFrame(int callbackId)
133 {
134 if (!isEnabled() || callbackId <= 0)
135 return;
136 m_animationFrameCallTraces.remove(callbackId);
137 }
138
139 void AsyncCallStackTracker::willFireAnimationFrame(int callbackId)
140 {
141 if (!isEnabled())
142 return;
143 ASSERT(callbackId > 0);
144 ASSERT(!m_currentAsyncCallTrace);
145 m_currentAsyncCallTrace = m_animationFrameCallTraces.take(callbackId);
146 }
147
148 void AsyncCallStackTracker::didAsyncCall()
149 {
150 m_currentAsyncCallTrace = 0;
151 }
152
153 void AsyncCallStackTracker::didRequestAsyncCallFrames(ScriptValue callFrames)
154 {
155 if (!isEnabled())
156 return;
157 ASSERT(m_requestedAsyncCallStack);
158 if (!m_requestedAsyncCallStack)
159 return;
160 m_requestedAsyncCallStack->m_callFrames = callFrames;
161 // FIXME: clean up if callFrames has no value.
162 m_requestedAsyncCallStack = 0;
163 }
164
165 PassRefPtr<AsyncCallStackTracker::AsyncCallTrace> AsyncCallStackTracker::createA syncCallTrace()
166 {
167 ASSERT(isEnabled());
168 ASSERT(!m_requestedAsyncCallStack);
169 RefPtr<AsyncCallTrace> trace = adoptRef(m_currentAsyncCallTrace ? new AsyncC allStackTracker::AsyncCallTrace(*m_currentAsyncCallTrace) : new AsyncCallStackTr acker::AsyncCallTrace());
170 ensureMaxAsyncCallTraceDepth(trace.get(), m_maxAsyncCallStackDepth - 1);
171 m_requestedAsyncCallStack = adoptRef(new AsyncCallStackTracker::AsyncCallSta ck());
172 trace->m_callStacks.prepend(m_requestedAsyncCallStack);
173 return trace.release();
174 }
175
176 void AsyncCallStackTracker::ensureMaxAsyncCallTraceDepth(AsyncCallTrace* trace, unsigned maxDepth)
177 {
178 while (trace->m_callStacks.size() > maxDepth)
yurys 2013/12/03 13:41:08 Isn't it just 'if'?
aandrey 2013/12/04 12:45:47 The max depth limit can be changed at any time via
179 trace->m_callStacks.removeLast();
180 }
181
182 void AsyncCallStackTracker::clear()
183 {
184 m_requestedAsyncCallStack = 0;
185 m_currentAsyncCallTrace = 0;
186 m_intervalTimerIds.clear();
187 m_timerCallTraces.clear();
188 m_animationFrameCallTraces.clear();
189 }
190
191 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698