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

Side by Side Diff: third_party/WebKit/Source/core/timing/Performance.cpp

Issue 2484213003: Convert performance monitor to the subscription model. (Closed)
Patch Set: core export Created 4 years, 1 month 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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Inc. All rights reserved. 3 * Copyright (C) 2012 Intel Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 17 matching lines...) Expand all
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #include "core/timing/Performance.h" 32 #include "core/timing/Performance.h"
33 33
34 #include "bindings/core/v8/ScriptValue.h" 34 #include "bindings/core/v8/ScriptValue.h"
35 #include "bindings/core/v8/V8ObjectBuilder.h" 35 #include "bindings/core/v8/V8ObjectBuilder.h"
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
38 #include "core/frame/PerformanceMonitor.h" 38 #include "core/frame/UseCounter.h"
39 #include "core/loader/DocumentLoader.h" 39 #include "core/loader/DocumentLoader.h"
40 #include "core/origin_trials/OriginTrials.h" 40 #include "core/origin_trials/OriginTrials.h"
41 #include "core/timing/PerformanceTiming.h" 41 #include "core/timing/PerformanceTiming.h"
42 42
43 static const double kLongTaskThreshold = 0.05;
44
45 static const char kUnknownAttribution[] = "unknown";
46 static const char kAmbugiousAttribution[] = "multiple-contexts";
47 static const char kSameOriginAttribution[] = "same-origin";
48 static const char kAncestorAttribution[] = "cross-origin-ancestor";
49 static const char kDescendantAttribution[] = "cross-origin-descendant";
50 static const char kCrossOriginAttribution[] = "cross-origin-unreachable";
51
43 namespace blink { 52 namespace blink {
44 53
45 static double toTimeOrigin(LocalFrame* frame) { 54 static double toTimeOrigin(LocalFrame* frame) {
46 if (!frame) 55 if (!frame)
47 return 0.0; 56 return 0.0;
48 57
49 Document* document = frame->document(); 58 Document* document = frame->document();
50 if (!document) 59 if (!document)
51 return 0.0; 60 return 0.0;
52 61
53 DocumentLoader* loader = document->loader(); 62 DocumentLoader* loader = document->loader();
54 if (!loader) 63 if (!loader)
55 return 0.0; 64 return 0.0;
56 65
57 return loader->timing().referenceMonotonicTime(); 66 return loader->timing().referenceMonotonicTime();
58 } 67 }
59 68
60 Performance::Performance(LocalFrame* frame) 69 Performance::Performance(LocalFrame* frame)
61 : PerformanceBase(toTimeOrigin(frame)), DOMWindowProperty(frame) {} 70 : PerformanceBase(toTimeOrigin(frame)), DOMWindowProperty(frame) {}
62 71
63 Performance::~Performance() { 72 Performance::~Performance() {
64 if (frame()) 73 if (frame())
65 PerformanceMonitor::performanceObserverRemoved(this); 74 frame()->performanceMonitor()->unsubscribeAll(this);
66 } 75 }
67 76
68 void Performance::frameDestroyed() { 77 void Performance::frameDestroyed() {
69 PerformanceMonitor::performanceObserverRemoved(this); 78 frame()->performanceMonitor()->unsubscribeAll(this);
70 DOMWindowProperty::frameDestroyed(); 79 DOMWindowProperty::frameDestroyed();
71 } 80 }
72 81
73 ExecutionContext* Performance::getExecutionContext() const { 82 ExecutionContext* Performance::getExecutionContext() const {
74 if (!frame()) 83 if (!frame())
75 return nullptr; 84 return nullptr;
76 return frame()->document(); 85 return frame()->document();
77 } 86 }
78 87
79 MemoryInfo* Performance::memory() { 88 MemoryInfo* Performance::memory() {
(...skipping 12 matching lines...) Expand all
92 m_timing = PerformanceTiming::create(frame()); 101 m_timing = PerformanceTiming::create(frame());
93 102
94 return m_timing.get(); 103 return m_timing.get();
95 } 104 }
96 105
97 void Performance::updateLongTaskInstrumentation() { 106 void Performance::updateLongTaskInstrumentation() {
98 DCHECK(frame()); 107 DCHECK(frame());
99 if (!frame()->document() || 108 if (!frame()->document() ||
100 !OriginTrials::longTaskObserverEnabled(frame()->document())) 109 !OriginTrials::longTaskObserverEnabled(frame()->document()))
101 return; 110 return;
102 LocalFrame* localRoot = frame()->localFrameRoot();
103 DCHECK(localRoot);
104 111
105 if (hasObserverFor(PerformanceEntry::LongTask)) 112 if (hasObserverFor(PerformanceEntry::LongTask)) {
106 PerformanceMonitor::performanceObserverAdded(this); 113 UseCounter::count(frame()->localFrameRoot(), UseCounter::LongTaskObserver);
107 else 114 frame()->performanceMonitor()->subscribe(PerformanceMonitor::kLongTask,
108 PerformanceMonitor::performanceObserverRemoved(this); 115 kLongTaskThreshold, this);
116 } else {
117 frame()->performanceMonitor()->unsubscribeAll(this);
118 }
109 } 119 }
110 120
111 ScriptValue Performance::toJSONForBinding(ScriptState* scriptState) const { 121 ScriptValue Performance::toJSONForBinding(ScriptState* scriptState) const {
112 V8ObjectBuilder result(scriptState); 122 V8ObjectBuilder result(scriptState);
113 result.add("timing", timing()->toJSONForBinding(scriptState)); 123 result.add("timing", timing()->toJSONForBinding(scriptState));
114 result.add("navigation", navigation()->toJSONForBinding(scriptState)); 124 result.add("navigation", navigation()->toJSONForBinding(scriptState));
115 return result.scriptValue(); 125 return result.scriptValue();
116 } 126 }
117 127
118 DEFINE_TRACE(Performance) { 128 DEFINE_TRACE(Performance) {
119 visitor->trace(m_navigation); 129 visitor->trace(m_navigation);
120 visitor->trace(m_timing); 130 visitor->trace(m_timing);
121 DOMWindowProperty::trace(visitor); 131 DOMWindowProperty::trace(visitor);
122 PerformanceBase::trace(visitor); 132 PerformanceBase::trace(visitor);
133 PerformanceMonitor::Client::trace(visitor);
134 }
135
136 static bool canAccessOrigin(Frame* frame1, Frame* frame2) {
137 SecurityOrigin* securityOrigin1 =
138 frame1->securityContext()->getSecurityOrigin();
139 SecurityOrigin* securityOrigin2 =
140 frame2->securityContext()->getSecurityOrigin();
141 return securityOrigin1->canAccess(securityOrigin2);
142 }
143
144 /**
145 * Report sanitized name based on cross-origin policy.
146 * See detailed Security doc here: http://bit.ly/2duD3F7
147 */
148 // static
149 std::pair<String, DOMWindow*> Performance::sanitizedAttribution(
150 const HeapHashSet<Member<Frame>>& frames,
151 Frame* observerFrame) {
152 if (frames.size() == 0) {
153 // Unable to attribute as no script was involved.
154 return std::make_pair(kUnknownAttribution, nullptr);
155 }
156 if (frames.size() > 1) {
157 // Unable to attribute, multiple script execution contents were involved.
158 return std::make_pair(kAmbugiousAttribution, nullptr);
159 }
160 // Exactly one culprit location, attribute based on origin boundary.
161 DCHECK_EQ(1u, frames.size());
162 Frame* culpritFrame = *frames.begin();
163 DCHECK(culpritFrame);
164 if (canAccessOrigin(observerFrame, culpritFrame)) {
165 // From accessible frames or same origin, return culprit location URL.
166 return std::make_pair(kSameOriginAttribution, culpritFrame->domWindow());
167 }
168 // For cross-origin, if the culprit is the descendant or ancestor of
169 // observer then indicate the *closest* cross-origin frame between
170 // the observer and the culprit, in the corresponding direction.
171 if (culpritFrame->tree().isDescendantOf(observerFrame)) {
172 // If the culprit is a descendant of the observer, then walk up the tree
173 // from culprit to observer, and report the *last* cross-origin (from
174 // observer) frame. If no intermediate cross-origin frame is found, then
175 // report the culprit directly.
176 Frame* lastCrossOriginFrame = culpritFrame;
177 for (Frame* frame = culpritFrame; frame != observerFrame;
178 frame = frame->tree().parent()) {
179 if (!canAccessOrigin(observerFrame, frame)) {
180 lastCrossOriginFrame = frame;
181 }
182 }
183 return std::make_pair(kDescendantAttribution,
184 lastCrossOriginFrame->domWindow());
185 }
186 if (observerFrame->tree().isDescendantOf(culpritFrame)) {
187 return std::make_pair(kAncestorAttribution, nullptr);
188 }
189 return std::make_pair(kCrossOriginAttribution, nullptr);
190 }
191
192 void Performance::reportLongTask(
193 double startTime,
194 double endTime,
195 const HeapHashSet<Member<Frame>>& contextFrames) {
196 std::pair<String, DOMWindow*> attribution =
197 Performance::sanitizedAttribution(contextFrames, frame());
198 addLongTaskTiming(startTime, endTime, attribution.first, attribution.second);
123 } 199 }
124 200
125 } // namespace blink 201 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/timing/Performance.h ('k') | third_party/WebKit/Source/core/timing/PerformanceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698