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

Unified Diff: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp

Issue 1857713004: DevTools: simplify the async instrumentation harness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp
diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp
index 41b8c3fe3f337ba3d75a1f2e948b4c83e65f07e9..bf784567f8322d96a7dd2e7623cd50d0d5e02b22 100644
--- a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp
+++ b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp
@@ -13,7 +13,6 @@
#include "platform/v8_inspector/JavaScriptCallFrame.h"
#include "platform/v8_inspector/RemoteObjectId.h"
#include "platform/v8_inspector/ScriptBreakpoint.h"
-#include "platform/v8_inspector/V8AsyncCallTracker.h"
#include "platform/v8_inspector/V8Regex.h"
#include "platform/v8_inspector/V8RuntimeAgentImpl.h"
#include "platform/v8_inspector/V8StackTraceImpl.h"
@@ -35,6 +34,12 @@ using blink::protocol::Runtime::ScriptId;
using blink::protocol::Runtime::StackTrace;
using blink::protocol::Runtime::RemoteObject;
+namespace {
+static const char v8AsyncTaskEventEnqueue[] = "enqueue";
+static const char v8AsyncTaskEventWillHandle[] = "willHandle";
+static const char v8AsyncTaskEventDidHandle[] = "didHandle";
+}
+
namespace blink {
namespace DebuggerAgentState {
@@ -56,8 +61,6 @@ static const int maxSkipStepFrameCount = 128;
const char V8DebuggerAgent::backtraceObjectGroup[] = "backtrace";
-const int V8DebuggerAgent::unknownAsyncOperationId = 0;
-
static String16 breakpointIdSuffix(V8DebuggerAgentImpl::BreakpointSource source)
{
switch (source) {
@@ -159,6 +162,14 @@ PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(V8RuntimeAgent* runtimeAgent
return adoptPtr(new V8DebuggerAgentImpl(runtimeAgentImpl->getInjectedScriptManager(), runtimeAgentImpl->debugger(), runtimeAgentImpl->contextGroupId()));
}
+void V8DebuggerAgent::asyncTaskStarted(void* task)
dgozman 2016/04/05 01:09:49 Remove.
+{
+}
+
+void V8DebuggerAgent::asyncTaskFinished(void* task)
+{
+}
+
V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptManager, V8DebuggerImpl* debugger, int contextGroupId)
: m_injectedScriptManager(injectedScriptManager)
, m_debugger(debugger)
@@ -177,18 +188,10 @@ V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptMa
, m_recursionLevelForStepOut(0)
, m_recursionLevelForStepFrame(0)
, m_skipAllPauses(false)
- , m_lastAsyncOperationId(0)
, m_maxAsyncCallStackDepth(0)
- , m_currentAsyncCallChain(nullptr)
- , m_nestedAsyncCallCount(0)
- , m_currentAsyncOperationId(unknownAsyncOperationId)
- , m_pendingTraceAsyncOperationCompleted(false)
{
ASSERT(contextGroupId);
m_injectedScriptManager->injectedScriptHost()->setDebuggerAgent(this);
-
- // FIXME: remove once InjectedScriptManager moves to v8.
- m_v8AsyncCallTracker = V8AsyncCallTracker::create(this);
clearBreakDetails();
}
@@ -263,11 +266,10 @@ void V8DebuggerAgentImpl::internalSetAsyncCallStackDepth(int depth)
{
if (depth <= 0) {
m_maxAsyncCallStackDepth = 0;
- resetAsyncCallTracker();
+ resetAsyncCallStacks();
} else {
m_maxAsyncCallStackDepth = depth;
}
- m_v8AsyncCallTracker->asyncCallTrackingStateChanged(m_maxAsyncCallStackDepth);
}
void V8DebuggerAgentImpl::setInspectorState(protocol::DictionaryValue* state)
@@ -845,13 +847,22 @@ void V8DebuggerAgentImpl::cancelPauseOnNextStatement()
bool V8DebuggerAgentImpl::v8AsyncTaskEventsEnabled() const
{
- return trackingAsyncCalls();
+ return m_maxAsyncCallStackDepth;
}
void V8DebuggerAgentImpl::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> context, const String16& eventType, const String16& eventName, int id)
{
+ ASSERT(m_maxAsyncCallStackDepth);
+ void* ptr = reinterpret_cast<void*> (id * 2 + 1);
ASSERT(trackingAsyncCalls());
- m_v8AsyncCallTracker->didReceiveV8AsyncTaskEvent(context, eventType, eventName, id);
+ if (eventType == v8AsyncTaskEventEnqueue)
+ scheduleAsyncTask(eventName, ptr, false);
+ else if (eventType == v8AsyncTaskEventWillHandle)
+ asyncTaskStarted(ptr);
+ else if (eventType == v8AsyncTaskEventDidHandle)
+ asyncTaskFinished(ptr);
+ else
+ ASSERT_NOT_REACHED();
}
void V8DebuggerAgentImpl::pause(ErrorString* errorString)
@@ -1047,98 +1058,39 @@ void V8DebuggerAgentImpl::setAsyncCallStackDepth(ErrorString* errorString, int d
internalSetAsyncCallStackDepth(depth);
}
-int V8DebuggerAgentImpl::traceAsyncOperationStarting(const String16& description)
+void V8DebuggerAgentImpl::scheduleAsyncTask(const String16& taskName, void* task, bool recurring)
{
v8::HandleScope scope(m_isolate);
- OwnPtr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, V8StackTrace::maxCallStackSizeToCapture, description);
-
- do {
- ++m_lastAsyncOperationId;
- if (m_lastAsyncOperationId <= 0)
- m_lastAsyncOperationId = 1;
- } while (m_asyncOperations.contains(m_lastAsyncOperationId));
-
+ OwnPtr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, V8StackTrace::maxCallStackSizeToCapture, taskName);
if (chain)
- m_asyncOperations.set(m_lastAsyncOperationId, chain.release());
-
- return m_lastAsyncOperationId;
-}
-
-void V8DebuggerAgentImpl::traceAsyncCallbackStarting(int operationId)
-{
- ASSERT(operationId > 0 || operationId == unknownAsyncOperationId);
- V8StackTraceImpl* chain = operationId > 0 ? m_asyncOperations.get(operationId) : nullptr;
- // FIXME: extract recursion check into a delegate.
- bool hasRecursionLevel = m_debugger->client()->hasRecursionLevel();
- if (chain && !hasRecursionLevel) {
- // There can be still an old m_currentAsyncCallChain set if we start running Microtasks
- // right after executing a JS callback but before the corresponding traceAsyncCallbackCompleted().
- // In this case just call traceAsyncCallbackCompleted() now, and the subsequent ones will be ignored.
- //
- // The nested levels count may be greater than 1, for example, when events are guarded via custom
- // traceAsync* calls, like in window.postMessage(). In this case there will be a willHandleEvent
- // instrumentation with unknownAsyncOperationId bumping up the nested levels count.
- if (m_currentAsyncCallChain) {
- ASSERT(m_nestedAsyncCallCount >= 1);
- m_nestedAsyncCallCount = 1;
- traceAsyncCallbackCompleted();
- }
-
- // Current AsyncCallChain corresponds to the bottommost JS call frame.
- ASSERT(!m_currentAsyncCallChain);
- m_currentAsyncCallChain = chain->clone();
- m_currentAsyncOperationId = operationId;
- m_pendingTraceAsyncOperationCompleted = false;
- m_nestedAsyncCallCount = 1;
- } else {
- if (m_currentAsyncCallChain)
- ++m_nestedAsyncCallCount;
- }
+ m_asyncTaskStacks.set(task, chain.release());
}
-void V8DebuggerAgentImpl::traceAsyncCallbackCompleted()
+void V8DebuggerAgentImpl::cancelAsyncTask(void* task)
{
- if (!m_nestedAsyncCallCount)
- return;
- ASSERT(m_currentAsyncCallChain);
- --m_nestedAsyncCallCount;
- if (!m_nestedAsyncCallCount)
- clearCurrentAsyncOperation();
+ m_asyncTaskStacks.remove(task);
}
-void V8DebuggerAgentImpl::traceAsyncOperationCompleted(int operationId)
+void V8DebuggerAgentImpl::cancelAllAsyncTasks()
{
- ASSERT(operationId > 0 || operationId == unknownAsyncOperationId);
- if (operationId > 0) {
- if (m_currentAsyncOperationId == operationId) {
- if (m_pendingTraceAsyncOperationCompleted) {
- m_pendingTraceAsyncOperationCompleted = false;
- } else {
- // Delay traceAsyncOperationCompleted() until the last async callback (being currently executed) is done.
- m_pendingTraceAsyncOperationCompleted = true;
- return;
- }
- }
- m_asyncOperations.remove(operationId);
- }
+ m_asyncTaskStacks.clear();
}
-void V8DebuggerAgentImpl::clearCurrentAsyncOperation()
+void V8DebuggerAgentImpl::asyncTaskStarted(void* task)
{
- if (m_pendingTraceAsyncOperationCompleted && m_currentAsyncOperationId != unknownAsyncOperationId)
- traceAsyncOperationCompleted(m_currentAsyncOperationId);
+ m_currentTasks.append(task);
+}
- m_currentAsyncOperationId = unknownAsyncOperationId;
- m_pendingTraceAsyncOperationCompleted = false;
- m_nestedAsyncCallCount = 0;
- m_currentAsyncCallChain.clear();
+void V8DebuggerAgentImpl::asyncTaskFinished(void* task)
+{
+ ASSERT(m_currentTasks.size() && m_currentTasks.last() == task);
+ m_currentTasks.removeLast();
+ m_asyncTaskStacks.remove(task);
}
-void V8DebuggerAgentImpl::resetAsyncCallTracker()
+void V8DebuggerAgentImpl::resetAsyncCallStacks()
{
- clearCurrentAsyncOperation();
- m_v8AsyncCallTracker->resetAsyncOperations();
- m_asyncOperations.clear();
+ m_asyncTaskStacks.clear();
}
void V8DebuggerAgentImpl::setBlackboxedRanges(ErrorString* error, const String16& scriptId, PassOwnPtr<protocol::Array<protocol::Debugger::ScriptPosition>> inPositions)
@@ -1291,15 +1243,17 @@ PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(ErrorString*
PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace()
{
- if (m_pausedContext.IsEmpty() || !trackingAsyncCalls() || !m_currentAsyncCallChain)
+ if (m_pausedContext.IsEmpty() || !m_maxAsyncCallStackDepth || !m_currentTasks.size())
return nullptr;
- return m_currentAsyncCallChain->buildInspectorObjectForTail(this);
+ return m_asyncTaskStacks.get(m_currentTasks.last())->buildInspectorObjectForTail(this);
}
V8StackTraceImpl* V8DebuggerAgentImpl::currentAsyncCallChain()
{
- return trackingAsyncCalls() ? m_currentAsyncCallChain.get() : nullptr;
+ if (!m_currentTasks.size())
+ return nullptr;
+ return m_asyncTaskStacks.get(m_currentTasks.last());
}
void V8DebuggerAgentImpl::didParseSource(const V8DebuggerParsedScript& parsedScript)
@@ -1508,7 +1462,7 @@ void V8DebuggerAgentImpl::reset()
m_scripts.clear();
m_blackboxedPositions.clear();
m_breakpointIdToDebuggerBreakpointIds.clear();
- resetAsyncCallTracker();
+ resetAsyncCallStacks();
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698