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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8AsyncCallTracker.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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "platform/v8_inspector/V8AsyncCallTracker.h"
6
7 #include "platform/inspector_protocol/Collections.h"
8 #include "platform/inspector_protocol/String16.h"
9
10 namespace blink {
11
12 namespace {
13
14 static const char v8AsyncTaskEventEnqueue[] = "enqueue";
15 static const char v8AsyncTaskEventWillHandle[] = "willHandle";
16 static const char v8AsyncTaskEventDidHandle[] = "didHandle";
17
18 }
19
20 static String16 makeV8AsyncTaskUniqueId(const String16& eventName, int id)
21 {
22 String16Builder builder;
23 builder.append(eventName);
24 builder.append(" -> ");
25 builder.appendNumber(id);
26 return builder.toString();
27 }
28
29 V8AsyncCallTracker::V8AsyncCallTracker(V8DebuggerAgentImpl* debuggerAgent)
30 : m_debuggerAgent(debuggerAgent)
31 {
32 }
33
34 V8AsyncCallTracker::~V8AsyncCallTracker()
35 {
36 ASSERT(m_idToOperations.isEmpty());
37 }
38
39 void V8AsyncCallTracker::asyncCallTrackingStateChanged(bool)
40 {
41 }
42
43 void V8AsyncCallTracker::resetAsyncOperations()
44 {
45 for (auto& it : m_idToOperations)
46 completeOperations(it.second->map);
47 m_idToOperations.clear();
48 }
49
50 void V8AsyncCallTracker::contextDisposed(int contextId)
51 {
52 completeOperations(m_idToOperations.get(contextId)->map);
53 m_idToOperations.remove(contextId);
54 }
55
56 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> conte xt, const String16& eventType, const String16& eventName, int id)
57 {
58 ASSERT(m_debuggerAgent->trackingAsyncCalls());
59 if (eventType == v8AsyncTaskEventEnqueue)
60 didEnqueueV8AsyncTask(context, eventName, id);
61 else if (eventType == v8AsyncTaskEventWillHandle)
62 willHandleV8AsyncTask(context, eventName, id);
63 else if (eventType == v8AsyncTaskEventDidHandle)
64 m_debuggerAgent->traceAsyncCallbackCompleted();
65 else
66 ASSERT_NOT_REACHED();
67 }
68
69 void V8AsyncCallTracker::weakCallback(const v8::WeakCallbackInfo<Operations>& da ta)
70 {
71 data.GetParameter()->target->contextDisposed(data.GetParameter()->contextId) ;
72 }
73
74 void V8AsyncCallTracker::didEnqueueV8AsyncTask(v8::Local<v8::Context> context, c onst String16& eventName, int id)
75 {
76 ASSERT(!context.IsEmpty());
77 ASSERT(m_debuggerAgent->trackingAsyncCalls());
78 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName);
79 if (!operationId)
80 return;
81 int contextId = V8Debugger::contextId(context);
82 Operations* operations = m_idToOperations.get(contextId);
83 if (!operations) {
84 OwnPtr<Operations> newOperations = adoptPtr(new Operations());
85 newOperations->contextId = contextId;
86 newOperations->target = this;
87 newOperations->context.Reset(context->GetIsolate(), context);
88 operations = newOperations.get();
89 m_idToOperations.set(contextId, newOperations.release());
90 operations->context.SetWeak(operations, V8AsyncCallTracker::weakCallback , v8::WeakCallbackType::kParameter);
91 }
92 operations->map.set(makeV8AsyncTaskUniqueId(eventName, id), operationId);
93 }
94
95 void V8AsyncCallTracker::willHandleV8AsyncTask(v8::Local<v8::Context> context, c onst String16& eventName, int id)
96 {
97 ASSERT(!context.IsEmpty());
98 ASSERT(m_debuggerAgent->trackingAsyncCalls());
99 int contextId = V8Debugger::contextId(context);
100 if (Operations* operations = m_idToOperations.get(contextId)) {
101 String16 taskId = makeV8AsyncTaskUniqueId(eventName, id);
102 int operationId = operations->map.get(taskId);
103 m_debuggerAgent->traceAsyncCallbackStarting(operationId);
104 m_debuggerAgent->traceAsyncOperationCompleted(operationId);
105 operations->map.remove(taskId);
106 } else {
107 m_debuggerAgent->traceAsyncCallbackStarting(V8DebuggerAgentImpl::unknown AsyncOperationId);
108 }
109 }
110
111 void V8AsyncCallTracker::completeOperations(const protocol::HashMap<String16, in t>& contextCallChains)
112 {
113 for (const auto& it : contextCallChains)
114 m_debuggerAgent->traceAsyncOperationCompleted(*it.second);
115 }
116
117 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698