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

Side by Side Diff: Source/core/inspector/AsyncCallTracker.cpp

Issue 1198863006: First version of PerformanceObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: use WeakCallback Created 5 years, 4 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 #include "core/inspector/AsyncCallTracker.h" 32 #include "core/inspector/AsyncCallTracker.h"
33 33
34 #include "core/dom/ContextLifecycleObserver.h" 34 #include "core/dom/ContextLifecycleObserver.h"
35 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
36 #include "core/dom/ExecutionContextTask.h" 36 #include "core/dom/ExecutionContextTask.h"
37 #include "core/events/Event.h" 37 #include "core/events/Event.h"
38 #include "core/events/EventTarget.h" 38 #include "core/events/EventTarget.h"
39 #include "core/inspector/AsyncOperationMap.h" 39 #include "core/inspector/AsyncOperationMap.h"
40 #include "core/inspector/InspectorDebuggerAgent.h" 40 #include "core/inspector/InspectorDebuggerAgent.h"
41 #include "core/timing/PerformanceObserver.h"
41 #include "core/xmlhttprequest/XMLHttpRequest.h" 42 #include "core/xmlhttprequest/XMLHttpRequest.h"
42 #include "core/xmlhttprequest/XMLHttpRequestUpload.h" 43 #include "core/xmlhttprequest/XMLHttpRequestUpload.h"
43 #include "platform/ScriptForbiddenScope.h" 44 #include "platform/ScriptForbiddenScope.h"
44 #include "wtf/MainThread.h" 45 #include "wtf/MainThread.h"
45 #include "wtf/text/StringBuilder.h" 46 #include "wtf/text/StringBuilder.h"
46 #include "wtf/text/StringHash.h" 47 #include "wtf/text/StringHash.h"
47 48
48 namespace { 49 namespace {
49 50
50 static const char setTimeoutName[] = "setTimeout"; 51 static const char setTimeoutName[] = "setTimeout";
51 static const char setIntervalName[] = "setInterval"; 52 static const char setIntervalName[] = "setInterval";
52 static const char requestAnimationFrameName[] = "requestAnimationFrame"; 53 static const char requestAnimationFrameName[] = "requestAnimationFrame";
53 static const char xhrSendName[] = "XMLHttpRequest.send"; 54 static const char xhrSendName[] = "XMLHttpRequest.send";
54 static const char enqueueMutationRecordName[] = "Mutation"; 55 static const char enqueueMutationRecordName[] = "Mutation";
56 static const char enqueuePerformanceObservationsName[] = "PerformanceObservation ";
55 57
56 } 58 }
57 59
58 namespace blink { 60 namespace blink {
59 61
60 class AsyncCallTracker::ExecutionContextData final : public NoBaseWillBeGarbageC ollectedFinalized<ExecutionContextData>, public ContextLifecycleObserver { 62 class AsyncCallTracker::ExecutionContextData final : public NoBaseWillBeGarbageC ollectedFinalized<ExecutionContextData>, public ContextLifecycleObserver {
61 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AsyncCallTracker::ExecutionContextData ); 63 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AsyncCallTracker::ExecutionContextData );
62 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(AsyncCallTracker::ExecutionContextDa ta); 64 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(AsyncCallTracker::ExecutionContextDa ta);
63 public: 65 public:
64 ExecutionContextData(AsyncCallTracker* tracker, ExecutionContext* executionC ontext) 66 ExecutionContextData(AsyncCallTracker* tracker, ExecutionContext* executionC ontext)
65 : ContextLifecycleObserver(executionContext) 67 : ContextLifecycleObserver(executionContext)
66 , m_tracker(tracker) 68 , m_tracker(tracker)
67 , m_timerCallChains(tracker->m_debuggerAgent) 69 , m_timerCallChains(tracker->m_debuggerAgent)
68 , m_animationFrameCallChains(tracker->m_debuggerAgent) 70 , m_animationFrameCallChains(tracker->m_debuggerAgent)
69 , m_eventCallChains(tracker->m_debuggerAgent) 71 , m_eventCallChains(tracker->m_debuggerAgent)
70 , m_xhrCallChains(tracker->m_debuggerAgent) 72 , m_xhrCallChains(tracker->m_debuggerAgent)
71 , m_mutationObserverCallChains(tracker->m_debuggerAgent) 73 , m_mutationObserverCallChains(tracker->m_debuggerAgent)
74 , m_performanceObserverCallChains(tracker->m_debuggerAgent)
72 , m_executionContextTaskCallChains(tracker->m_debuggerAgent) 75 , m_executionContextTaskCallChains(tracker->m_debuggerAgent)
73 , m_asyncOperations(tracker->m_debuggerAgent) 76 , m_asyncOperations(tracker->m_debuggerAgent)
74 { 77 {
75 } 78 }
76 79
77 void contextDestroyed() override 80 void contextDestroyed() override
78 { 81 {
79 ASSERT(executionContext()); 82 ASSERT(executionContext());
80 OwnPtrWillBeRawPtr<ExecutionContextData> self = m_tracker->m_executionCo ntextDataMap.take(executionContext()); 83 OwnPtrWillBeRawPtr<ExecutionContextData> self = m_tracker->m_executionCo ntextDataMap.take(executionContext());
81 ASSERT_UNUSED(self, self == this); 84 ASSERT_UNUSED(self, self == this);
(...skipping 12 matching lines...) Expand all
94 visitor->trace(m_tracker); 97 visitor->trace(m_tracker);
95 #if ENABLE(OILPAN) 98 #if ENABLE(OILPAN)
96 visitor->trace(m_timerCallChains); 99 visitor->trace(m_timerCallChains);
97 visitor->trace(m_animationFrameCallChains); 100 visitor->trace(m_animationFrameCallChains);
98 visitor->trace(m_eventCallChains); 101 visitor->trace(m_eventCallChains);
99 visitor->trace(m_xhrCallChains); 102 visitor->trace(m_xhrCallChains);
100 visitor->trace(m_mutationObserverCallChains); 103 visitor->trace(m_mutationObserverCallChains);
101 visitor->trace(m_executionContextTaskCallChains); 104 visitor->trace(m_executionContextTaskCallChains);
102 visitor->trace(m_asyncOperations); 105 visitor->trace(m_asyncOperations);
103 #endif 106 #endif
107 visitor->trace(m_performanceObserverCallChains);
104 ContextLifecycleObserver::trace(visitor); 108 ContextLifecycleObserver::trace(visitor);
105 } 109 }
106 110
107 RawPtrWillBeMember<AsyncCallTracker> m_tracker; 111 RawPtrWillBeMember<AsyncCallTracker> m_tracker;
108 HashSet<int> m_intervalTimerIds; 112 HashSet<int> m_intervalTimerIds;
109 AsyncOperationMap<int> m_timerCallChains; 113 AsyncOperationMap<int> m_timerCallChains;
110 AsyncOperationMap<int> m_animationFrameCallChains; 114 AsyncOperationMap<int> m_animationFrameCallChains;
111 AsyncOperationMap<RawPtrWillBeMember<Event> > m_eventCallChains; 115 AsyncOperationMap<RawPtrWillBeMember<Event> > m_eventCallChains;
112 AsyncOperationMap<RawPtrWillBeMember<EventTarget> > m_xhrCallChains; 116 AsyncOperationMap<RawPtrWillBeMember<EventTarget> > m_xhrCallChains;
113 AsyncOperationMap<RawPtrWillBeMember<MutationObserver> > m_mutationObserverC allChains; 117 AsyncOperationMap<RawPtrWillBeMember<MutationObserver> > m_mutationObserverC allChains;
118 AsyncOperationMap<Member<PerformanceObserver>, HeapHashMap<Member<Performanc eObserver>, int>> m_performanceObserverCallChains;
114 AsyncOperationMap<ExecutionContextTask*> m_executionContextTaskCallChains; 119 AsyncOperationMap<ExecutionContextTask*> m_executionContextTaskCallChains;
115 AsyncOperationMap<int> m_asyncOperations; 120 AsyncOperationMap<int> m_asyncOperations;
116 121
117 private: 122 private:
118 void disposeCallChains() 123 void disposeCallChains()
119 { 124 {
120 m_timerCallChains.dispose(); 125 m_timerCallChains.dispose();
121 m_animationFrameCallChains.dispose(); 126 m_animationFrameCallChains.dispose();
122 m_eventCallChains.dispose(); 127 m_eventCallChains.dispose();
123 m_xhrCallChains.dispose(); 128 m_xhrCallChains.dispose();
124 m_mutationObserverCallChains.dispose(); 129 m_mutationObserverCallChains.dispose();
130 m_performanceObserverCallChains.dispose();
125 m_executionContextTaskCallChains.dispose(); 131 m_executionContextTaskCallChains.dispose();
126 m_asyncOperations.dispose(); 132 m_asyncOperations.dispose();
127 } 133 }
128 }; 134 };
129 135
130 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) 136 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget)
131 { 137 {
132 const AtomicString& interfaceName = eventTarget->interfaceName(); 138 const AtomicString& interfaceName = eventTarget->interfaceName();
133 if (interfaceName == EventTargetNames::XMLHttpRequest) 139 if (interfaceName == EventTargetNames::XMLHttpRequest)
134 return static_cast<XMLHttpRequest*>(eventTarget); 140 return static_cast<XMLHttpRequest*>(eventTarget);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 ASSERT(context); 332 ASSERT(context);
327 ASSERT(m_debuggerAgent->trackingAsyncCalls()); 333 ASSERT(m_debuggerAgent->trackingAsyncCalls());
328 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { 334 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) {
329 willFireAsyncCall(data->m_mutationObserverCallChains.get(observer)); 335 willFireAsyncCall(data->m_mutationObserverCallChains.get(observer));
330 data->m_mutationObserverCallChains.remove(observer); 336 data->m_mutationObserverCallChains.remove(observer);
331 } else { 337 } else {
332 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId); 338 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId);
333 } 339 }
334 } 340 }
335 341
342 void AsyncCallTracker::didEnqueuePerformanceObserverEntries(ExecutionContext* co ntext, PerformanceObserver* observer)
343 {
344 ASSERT(context);
345 ASSERT(m_debuggerAgent->trackingAsyncCalls());
346 ExecutionContextData* data = createContextDataIfNeeded(context);
347 if (data->m_performanceObserverCallChains.contains(observer))
348 return;
349 int operationId = m_debuggerAgent->traceAsyncOperationStarting(enqueuePerfor manceObservationsName);
350 data->m_performanceObserverCallChains.set(observer, operationId);
351 }
352
353 void AsyncCallTracker::didClearAllPerformanceObservations(ExecutionContext* cont ext, PerformanceObserver* observer)
354 {
355 ASSERT(context);
356 ASSERT(m_debuggerAgent->trackingAsyncCalls());
357 if (ExecutionContextData* data = m_executionContextDataMap.get(context))
358 data->m_performanceObserverCallChains.remove(observer);
359 }
360
361 void AsyncCallTracker::willDeliverPerformanceObservations(ExecutionContext* cont ext, PerformanceObserver* observer)
362 {
363 ASSERT(context);
364 ASSERT(m_debuggerAgent->trackingAsyncCalls());
365 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) {
366 willFireAsyncCall(data->m_performanceObserverCallChains.get(observer));
367 data->m_performanceObserverCallChains.remove(observer);
368 } else {
369 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId);
370 }
371 }
372
336 void AsyncCallTracker::didPostExecutionContextTask(ExecutionContext* context, Ex ecutionContextTask* task) 373 void AsyncCallTracker::didPostExecutionContextTask(ExecutionContext* context, Ex ecutionContextTask* task)
337 { 374 {
338 ASSERT(context); 375 ASSERT(context);
339 ASSERT(m_debuggerAgent->trackingAsyncCalls()); 376 ASSERT(m_debuggerAgent->trackingAsyncCalls());
340 if (task->taskNameForInstrumentation().isEmpty()) 377 if (task->taskNameForInstrumentation().isEmpty())
341 return; 378 return;
342 int operationId = m_debuggerAgent->traceAsyncOperationStarting(task->taskNam eForInstrumentation()); 379 int operationId = m_debuggerAgent->traceAsyncOperationStarting(task->taskNam eForInstrumentation());
343 ExecutionContextData* data = createContextDataIfNeeded(context); 380 ExecutionContextData* data = createContextDataIfNeeded(context);
344 data->m_executionContextTaskCallChains.set(task, operationId); 381 data->m_executionContextTaskCallChains.set(task, operationId);
345 } 382 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 { 470 {
434 #if ENABLE(OILPAN) 471 #if ENABLE(OILPAN)
435 visitor->trace(m_executionContextDataMap); 472 visitor->trace(m_executionContextDataMap);
436 visitor->trace(m_debuggerAgent); 473 visitor->trace(m_debuggerAgent);
437 visitor->trace(m_instrumentingAgents); 474 visitor->trace(m_instrumentingAgents);
438 #endif 475 #endif
439 InspectorDebuggerAgent::AsyncCallTrackingListener::trace(visitor); 476 InspectorDebuggerAgent::AsyncCallTrackingListener::trace(visitor);
440 } 477 }
441 478
442 } // namespace blink 479 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698