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

Side by Side Diff: src/inspector/v8-stack-trace-impl.cc

Issue 2648873002: [inspector] added creation frame for async call chains for promises (Closed)
Patch Set: removed redundant async call chains Created 3 years, 10 months 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/inspector/v8-stack-trace-impl.h" 5 #include "src/inspector/v8-stack-trace-impl.h"
6 6
7 #include "src/inspector/string-util.h" 7 #include "src/inspector/string-util.h"
8 #include "src/inspector/v8-debugger-agent-impl.h" 8 #include "src/inspector/v8-debugger-agent-impl.h"
9 #include "src/inspector/v8-debugger.h" 9 #include "src/inspector/v8-debugger.h"
10 #include "src/inspector/v8-inspector-impl.h" 10 #include "src/inspector/v8-inspector-impl.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Do not accidentally append async call chain from another group. This should 134 // Do not accidentally append async call chain from another group. This should
135 // not 135 // not
136 // happen if we have proper instrumentation, but let's double-check to be 136 // happen if we have proper instrumentation, but let's double-check to be
137 // safe. 137 // safe.
138 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId && 138 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId &&
139 asyncCallChain->m_contextGroupId != contextGroupId) { 139 asyncCallChain->m_contextGroupId != contextGroupId) {
140 asyncCallChain = nullptr; 140 asyncCallChain = nullptr;
141 maxAsyncCallChainDepth = 1; 141 maxAsyncCallChainDepth = 1;
142 } 142 }
143 143
144 // Only the top stack in the chain may be empty, so ensure that second stack 144 // Only the top stack in the chain may be empty and doesn't contain creation
145 // is non-empty (it's the top of appended chain). 145 // stack , so ensure that second stack is non-empty (it's the top of appended
146 if (asyncCallChain && asyncCallChain->isEmpty()) 146 // chain).
147 if (asyncCallChain && asyncCallChain->isEmpty() &&
148 !asyncCallChain->m_creation) {
147 asyncCallChain = asyncCallChain->m_parent.get(); 149 asyncCallChain = asyncCallChain->m_parent.get();
150 }
151
152 // When async call chain is empty but doesn't contain useful schedule stack
153 // and
154 // parent async call chain contains creationg stack but doesn't synchronous we
155 // can merge them together.
156 // e.g. Promise ThenableJob.
157 if (asyncCallChain && asyncCallChain->isEmpty() && asyncCallChain->m_parent) {
158 if (asyncCallChain->m_creation && asyncCallChain->isEmpty() &&
159 !asyncCallChain->m_parent->m_creation) {
160 asyncCallChain->m_parent->m_creation =
161 std::move(asyncCallChain->m_creation);
162 asyncCallChain = asyncCallChain->m_parent.get();
163 }
164 }
148 165
149 if (stackTrace.IsEmpty() && !asyncCallChain) return nullptr; 166 if (stackTrace.IsEmpty() && !asyncCallChain) return nullptr;
150 167
151 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl( 168 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl(
152 contextGroupId, description, frames, 169 contextGroupId, description, frames,
153 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr)); 170 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr, nullptr));
154 171
155 // Crop to not exceed maxAsyncCallChainDepth. 172 // Crop to not exceed maxAsyncCallChainDepth.
156 V8StackTraceImpl* deepest = result.get(); 173 V8StackTraceImpl* deepest = result.get();
157 while (deepest && maxAsyncCallChainDepth) { 174 while (deepest && maxAsyncCallChainDepth) {
158 deepest = deepest->m_parent.get(); 175 deepest = deepest->m_parent.get();
159 maxAsyncCallChainDepth--; 176 maxAsyncCallChainDepth--;
160 } 177 }
161 if (deepest) deepest->m_parent.reset(); 178 if (deepest) deepest->m_parent.reset();
162 179
163 return result; 180 return result;
(...skipping 11 matching lines...) Expand all
175 isolate, static_cast<int>(maxStackSize), stackTraceOptions); 192 isolate, static_cast<int>(maxStackSize), stackTraceOptions);
176 } 193 }
177 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, 194 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace,
178 maxStackSize, description); 195 maxStackSize, description);
179 } 196 }
180 197
181 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { 198 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() {
182 std::vector<Frame> framesCopy(m_frames); 199 std::vector<Frame> framesCopy(m_frames);
183 return std::unique_ptr<V8StackTraceImpl>( 200 return std::unique_ptr<V8StackTraceImpl>(
184 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, 201 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy,
185 m_parent ? m_parent->cloneImpl() : nullptr)); 202 m_parent ? m_parent->cloneImpl() : nullptr,
203 m_creation ? m_creation->cloneImpl() : nullptr));
186 } 204 }
187 205
188 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { 206 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() {
189 std::vector<Frame> frames; 207 std::vector<Frame> frames;
190 for (size_t i = 0; i < m_frames.size(); i++) 208 for (size_t i = 0; i < m_frames.size(); i++)
191 frames.push_back(m_frames.at(i).clone()); 209 frames.push_back(m_frames.at(i).clone());
192 return std::unique_ptr<V8StackTraceImpl>( 210 return std::unique_ptr<V8StackTraceImpl>(new V8StackTraceImpl(
193 new V8StackTraceImpl(m_contextGroupId, m_description, frames, nullptr)); 211 m_contextGroupId, m_description, frames, nullptr, nullptr));
194 } 212 }
195 213
196 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId, 214 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId,
197 const String16& description, 215 const String16& description,
198 std::vector<Frame>& frames, 216 std::vector<Frame>& frames,
199 std::unique_ptr<V8StackTraceImpl> parent) 217 std::unique_ptr<V8StackTraceImpl> parent,
218 std::unique_ptr<V8StackTraceImpl> creation)
200 : m_contextGroupId(contextGroupId), 219 : m_contextGroupId(contextGroupId),
201 m_description(description), 220 m_description(description),
202 m_parent(std::move(parent)) { 221 m_parent(std::move(parent)),
222 m_creation(std::move(creation)) {
203 m_frames.swap(frames); 223 m_frames.swap(frames);
204 } 224 }
205 225
206 V8StackTraceImpl::~V8StackTraceImpl() {} 226 V8StackTraceImpl::~V8StackTraceImpl() {}
207 227
208 StringView V8StackTraceImpl::topSourceURL() const { 228 StringView V8StackTraceImpl::topSourceURL() const {
209 DCHECK(m_frames.size()); 229 DCHECK(m_frames.size());
210 return toStringView(m_frames[0].m_scriptName); 230 return toStringView(m_frames[0].m_scriptName);
211 } 231 }
212 232
(...skipping 23 matching lines...) Expand all
236 protocol::Array<protocol::Runtime::CallFrame>::create(); 256 protocol::Array<protocol::Runtime::CallFrame>::create();
237 for (size_t i = 0; i < m_frames.size(); i++) 257 for (size_t i = 0; i < m_frames.size(); i++)
238 frames->addItem(m_frames.at(i).buildInspectorObject()); 258 frames->addItem(m_frames.at(i).buildInspectorObject());
239 259
240 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = 260 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace =
241 protocol::Runtime::StackTrace::create() 261 protocol::Runtime::StackTrace::create()
242 .setCallFrames(std::move(frames)) 262 .setCallFrames(std::move(frames))
243 .build(); 263 .build();
244 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); 264 if (!m_description.isEmpty()) stackTrace->setDescription(m_description);
245 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); 265 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl());
266 if (m_creation && m_creation->m_frames.size()) {
267 stackTrace->setPromiseCreationFrame(
268 m_creation->m_frames[0].buildInspectorObject());
269 }
246 return stackTrace; 270 return stackTrace;
247 } 271 }
248 272
249 std::unique_ptr<protocol::Runtime::StackTrace> 273 std::unique_ptr<protocol::Runtime::StackTrace>
250 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { 274 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const {
251 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); 275 v8::HandleScope handleScope(v8::Isolate::GetCurrent());
252 // Next call collapses possible empty stack and ensures 276 // Next call collapses possible empty stack and ensures
253 // maxAsyncCallChainDepth. 277 // maxAsyncCallChainDepth.
254 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( 278 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create(
255 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), 279 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(),
(...skipping 20 matching lines...) Expand all
276 stackTrace.append(String16::fromInteger(frame.lineNumber())); 300 stackTrace.append(String16::fromInteger(frame.lineNumber()));
277 stackTrace.append(':'); 301 stackTrace.append(':');
278 stackTrace.append(String16::fromInteger(frame.columnNumber())); 302 stackTrace.append(String16::fromInteger(frame.columnNumber()));
279 stackTrace.append(')'); 303 stackTrace.append(')');
280 } 304 }
281 String16 string = stackTrace.toString(); 305 String16 string = stackTrace.toString();
282 return StringBufferImpl::adopt(string); 306 return StringBufferImpl::adopt(string);
283 } 307 }
284 308
285 } // namespace v8_inspector 309 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698