| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/inspector/V8AsyncCallTracker.h" | 6 #include "core/inspector/V8AsyncCallTracker.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/V8PerContextData.h" | 8 #include "bindings/core/v8/V8PerContextData.h" |
| 9 #include "core/inspector/AsyncCallChainMap.h" | 9 #include "core/inspector/AsyncOperationMap.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "wtf/HashMap.h" | 11 #include "wtf/HashMap.h" |
| 12 #include "wtf/text/StringBuilder.h" | 12 #include "wtf/text/StringBuilder.h" |
| 13 #include "wtf/text/StringHash.h" | 13 #include "wtf/text/StringHash.h" |
| 14 #include "wtf/text/WTFString.h" | 14 #include "wtf/text/WTFString.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; | 20 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; |
| 21 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; | 21 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; |
| 22 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; | 22 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; |
| 23 | 23 |
| 24 } | 24 } |
| 25 | 25 |
| 26 class V8AsyncCallTracker::V8ContextAsyncCallChains final : public NoBaseWillBeGa
rbageCollectedFinalized<V8AsyncCallTracker::V8ContextAsyncCallChains> { | 26 class V8AsyncCallTracker::V8ContextAsyncOperations final : public NoBaseWillBeGa
rbageCollectedFinalized<V8AsyncCallTracker::V8ContextAsyncOperations> { |
| 27 WTF_MAKE_NONCOPYABLE(V8ContextAsyncCallChains); | 27 WTF_MAKE_NONCOPYABLE(V8ContextAsyncOperations); |
| 28 public: | 28 public: |
| 29 explicit V8ContextAsyncCallChains(InspectorDebuggerAgent* debuggerAgent) | 29 explicit V8ContextAsyncOperations(InspectorDebuggerAgent* debuggerAgent) |
| 30 : m_v8AsyncCallChains(debuggerAgent) | 30 : m_v8AsyncOperations(debuggerAgent) |
| 31 { | 31 { |
| 32 } | 32 } |
| 33 | 33 |
| 34 ~V8ContextAsyncCallChains() | 34 ~V8ContextAsyncOperations() |
| 35 { | 35 { |
| 36 ASSERT(m_v8AsyncCallChains.hasBeenDisposed()); | 36 ASSERT(m_v8AsyncOperations.hasBeenDisposed()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void dispose() | 39 void dispose() |
| 40 { | 40 { |
| 41 // FIXME: get rid of the dispose method and this class altogether once A
syncCallChainMap is always allocated on C++ heap. | 41 // FIXME: get rid of the dispose method and this class altogether once A
syncOperationMap is always allocated on C++ heap. |
| 42 m_v8AsyncCallChains.dispose(); | 42 m_v8AsyncOperations.dispose(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void trace(Visitor* visitor) | 45 void trace(Visitor* visitor) |
| 46 { | 46 { |
| 47 #if ENABLE(OILPAN) | 47 #if ENABLE(OILPAN) |
| 48 visitor->trace(m_v8AsyncCallChains); | 48 visitor->trace(m_v8AsyncOperations); |
| 49 #endif | 49 #endif |
| 50 } | 50 } |
| 51 | 51 |
| 52 AsyncCallChainMap<String> m_v8AsyncCallChains; | 52 AsyncOperationMap<String> m_v8AsyncOperations; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 static String makeV8AsyncTaskUniqueId(const String& eventName, int id) | 55 static String makeV8AsyncTaskUniqueId(const String& eventName, int id) |
| 56 { | 56 { |
| 57 StringBuilder builder; | 57 StringBuilder builder; |
| 58 builder.append(eventName); | 58 builder.append(eventName); |
| 59 builder.append(" -> "); | 59 builder.append(" -> "); |
| 60 builder.appendNumber(id); | 60 builder.appendNumber(id); |
| 61 return builder.toString(); | 61 return builder.toString(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 V8AsyncCallTracker::V8AsyncCallTracker(InspectorDebuggerAgent* debuggerAgent) :
m_debuggerAgent(debuggerAgent) | 64 V8AsyncCallTracker::V8AsyncCallTracker(InspectorDebuggerAgent* debuggerAgent) :
m_debuggerAgent(debuggerAgent) |
| 65 { | 65 { |
| 66 } | 66 } |
| 67 | 67 |
| 68 V8AsyncCallTracker::~V8AsyncCallTracker() | 68 V8AsyncCallTracker::~V8AsyncCallTracker() |
| 69 { | 69 { |
| 70 ASSERT(m_contextAsyncCallChainMap.isEmpty()); | 70 ASSERT(m_contextAsyncOperationMap.isEmpty()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void V8AsyncCallTracker::trace(Visitor* visitor) | 73 void V8AsyncCallTracker::trace(Visitor* visitor) |
| 74 { | 74 { |
| 75 #if ENABLE(OILPAN) | 75 #if ENABLE(OILPAN) |
| 76 visitor->trace(m_contextAsyncCallChainMap); | 76 visitor->trace(m_contextAsyncOperationMap); |
| 77 visitor->trace(m_debuggerAgent); | 77 visitor->trace(m_debuggerAgent); |
| 78 #endif | 78 #endif |
| 79 InspectorDebuggerAgent::AsyncCallTrackingListener::trace(visitor); | 79 InspectorDebuggerAgent::AsyncCallTrackingListener::trace(visitor); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void V8AsyncCallTracker::asyncCallTrackingStateChanged(bool) | 82 void V8AsyncCallTracker::asyncCallTrackingStateChanged(bool) |
| 83 { | 83 { |
| 84 } | 84 } |
| 85 | 85 |
| 86 void V8AsyncCallTracker::resetAsyncCallChains() | 86 void V8AsyncCallTracker::resetAsyncOperations() |
| 87 { | 87 { |
| 88 for (auto& it : m_contextAsyncCallChainMap) { | 88 for (auto& it : m_contextAsyncOperationMap) { |
| 89 it.key->removeObserver(this); | 89 it.key->removeObserver(this); |
| 90 it.value->dispose(); | 90 it.value->dispose(); |
| 91 } | 91 } |
| 92 m_contextAsyncCallChainMap.clear(); | 92 m_contextAsyncOperationMap.clear(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void V8AsyncCallTracker::willDisposeScriptState(ScriptState* state) | 95 void V8AsyncCallTracker::willDisposeScriptState(ScriptState* state) |
| 96 { | 96 { |
| 97 m_contextAsyncCallChainMap.remove(state); | 97 m_contextAsyncOperationMap.remove(state); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(ScriptState* state, const St
ring& eventType, const String& eventName, int id) | 100 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(ScriptState* state, const St
ring& eventType, const String& eventName, int id) |
| 101 { | 101 { |
| 102 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 102 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 103 if (eventType == v8AsyncTaskEventEnqueue) | 103 if (eventType == v8AsyncTaskEventEnqueue) |
| 104 didEnqueueV8AsyncTask(state, eventName, id); | 104 didEnqueueV8AsyncTask(state, eventName, id); |
| 105 else if (eventType == v8AsyncTaskEventWillHandle) | 105 else if (eventType == v8AsyncTaskEventWillHandle) |
| 106 willHandleV8AsyncTask(state, eventName, id); | 106 willHandleV8AsyncTask(state, eventName, id); |
| 107 else if (eventType == v8AsyncTaskEventDidHandle) | 107 else if (eventType == v8AsyncTaskEventDidHandle) |
| 108 m_debuggerAgent->traceAsyncCallbackCompleted(); | 108 m_debuggerAgent->traceAsyncCallbackCompleted(); |
| 109 else | 109 else |
| 110 ASSERT_NOT_REACHED(); | 110 ASSERT_NOT_REACHED(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void V8AsyncCallTracker::didEnqueueV8AsyncTask(ScriptState* state, const String&
eventName, int id) | 113 void V8AsyncCallTracker::didEnqueueV8AsyncTask(ScriptState* state, const String&
eventName, int id) |
| 114 { | 114 { |
| 115 ASSERT(state); | 115 ASSERT(state); |
| 116 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 116 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 117 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName); | 117 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName); |
| 118 if (!operationId) | 118 if (!operationId) |
| 119 return; | 119 return; |
| 120 V8ContextAsyncCallChains* contextCallChains = m_contextAsyncCallChainMap.get
(state); | 120 V8ContextAsyncOperations* contextCallChains = m_contextAsyncOperationMap.get
(state); |
| 121 if (!contextCallChains) | 121 if (!contextCallChains) |
| 122 contextCallChains = m_contextAsyncCallChainMap.set(state, adoptPtrWillBe
Noop(new V8ContextAsyncCallChains(m_debuggerAgent))).storedValue->value.get(); | 122 contextCallChains = m_contextAsyncOperationMap.set(state, adoptPtrWillBe
Noop(new V8ContextAsyncOperations(m_debuggerAgent))).storedValue->value.get(); |
| 123 contextCallChains->m_v8AsyncCallChains.set(makeV8AsyncTaskUniqueId(eventName
, id), operationId); | 123 contextCallChains->m_v8AsyncOperations.set(makeV8AsyncTaskUniqueId(eventName
, id), operationId); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void V8AsyncCallTracker::willHandleV8AsyncTask(ScriptState* state, const String&
eventName, int id) | 126 void V8AsyncCallTracker::willHandleV8AsyncTask(ScriptState* state, const String&
eventName, int id) |
| 127 { | 127 { |
| 128 ASSERT(state); | 128 ASSERT(state); |
| 129 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 129 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 130 if (V8ContextAsyncCallChains* contextCallChains = m_contextAsyncCallChainMap
.get(state)) { | 130 if (V8ContextAsyncOperations* contextCallChains = m_contextAsyncOperationMap
.get(state)) { |
| 131 String taskId = makeV8AsyncTaskUniqueId(eventName, id); | 131 String taskId = makeV8AsyncTaskUniqueId(eventName, id); |
| 132 m_debuggerAgent->traceAsyncCallbackStarting(state->isolate(), contextCal
lChains->m_v8AsyncCallChains.get(taskId)); | 132 m_debuggerAgent->traceAsyncCallbackStarting(contextCallChains->m_v8Async
Operations.get(taskId)); |
| 133 contextCallChains->m_v8AsyncCallChains.remove(taskId); | 133 contextCallChains->m_v8AsyncOperations.remove(taskId); |
| 134 } else { | 134 } else { |
| 135 m_debuggerAgent->traceAsyncCallbackStarting(state->isolate(), InspectorD
ebuggerAgent::unknownAsyncOperationId); | 135 m_debuggerAgent->traceAsyncCallbackStarting(InspectorDebuggerAgent::unkn
ownAsyncOperationId); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace blink | 139 } // namespace blink |
| OLD | NEW |