OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 "config.h" | 32 #include "config.h" |
33 #include "core/timing/Performance.h" | 33 #include "core/timing/PerformanceBase.h" |
34 | 34 |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/events/Event.h" | 36 #include "core/events/Event.h" |
37 #include "core/frame/LocalFrame.h" | |
38 #include "core/loader/DocumentLoader.h" | |
39 #include "core/timing/PerformanceCompositeTiming.h" | 37 #include "core/timing/PerformanceCompositeTiming.h" |
40 #include "core/timing/PerformanceRenderTiming.h" | 38 #include "core/timing/PerformanceRenderTiming.h" |
41 #include "core/timing/PerformanceResourceTiming.h" | 39 #include "core/timing/PerformanceResourceTiming.h" |
42 #include "core/timing/PerformanceTiming.h" | |
43 #include "core/timing/PerformanceUserTiming.h" | 40 #include "core/timing/PerformanceUserTiming.h" |
44 #include "core/timing/ResourceTimingInfo.h" | 41 #include "core/timing/ResourceTimingInfo.h" |
45 #include "platform/weborigin/SecurityOrigin.h" | 42 #include "platform/weborigin/SecurityOrigin.h" |
46 #include "wtf/CurrentTime.h" | 43 #include "wtf/CurrentTime.h" |
47 | 44 |
48 namespace blink { | 45 namespace blink { |
49 | 46 |
50 static const size_t defaultResourceTimingBufferSize = 150; | 47 static const size_t defaultResourceTimingBufferSize = 150; |
51 static const size_t defaultFrameTimingBufferSize = 150; | 48 static const size_t defaultFrameTimingBufferSize = 150; |
52 | 49 |
53 Performance::Performance(LocalFrame* frame) | 50 PerformanceBase::PerformanceBase(double timeOrigin) |
54 : DOMWindowProperty(frame) | 51 : m_frameTimingBufferSize(defaultFrameTimingBufferSize) |
55 , m_frameTimingBufferSize(defaultFrameTimingBufferSize) | |
56 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) | 52 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) |
57 , m_referenceTime(frame && frame->host() ? frame->document()->loader()->timi
ng().referenceMonotonicTime() : 0.0) | 53 , m_timeOrigin(timeOrigin) |
58 , m_userTiming(nullptr) | 54 , m_userTiming(nullptr) |
59 { | 55 { |
60 } | 56 } |
61 | 57 |
62 Performance::~Performance() | 58 PerformanceBase::~PerformanceBase() |
63 { | 59 { |
64 } | 60 } |
65 | 61 |
66 const AtomicString& Performance::interfaceName() const | 62 const AtomicString& PerformanceBase::interfaceName() const |
67 { | 63 { |
68 return EventTargetNames::Performance; | 64 return EventTargetNames::Performance; |
69 } | 65 } |
70 | 66 |
71 ExecutionContext* Performance::executionContext() const | 67 PerformanceTiming* PerformanceBase::timing() const |
72 { | 68 { |
73 if (!frame()) | 69 return nullptr; |
74 return nullptr; | |
75 return frame()->document(); | |
76 } | 70 } |
77 | 71 |
78 MemoryInfo* Performance::memory() | 72 PerformanceEntryVector PerformanceBase::getEntries() const |
79 { | |
80 if (!m_memoryInfo) | |
81 m_memoryInfo = MemoryInfo::create(); | |
82 return m_memoryInfo.get(); | |
83 } | |
84 | |
85 PerformanceNavigation* Performance::navigation() const | |
86 { | |
87 if (!m_navigation) | |
88 m_navigation = PerformanceNavigation::create(m_frame); | |
89 | |
90 return m_navigation.get(); | |
91 } | |
92 | |
93 PerformanceTiming* Performance::timing() const | |
94 { | |
95 if (!m_timing) | |
96 m_timing = PerformanceTiming::create(m_frame); | |
97 | |
98 return m_timing.get(); | |
99 } | |
100 | |
101 PerformanceEntryVector Performance::getEntries() const | |
102 { | 73 { |
103 PerformanceEntryVector entries; | 74 PerformanceEntryVector entries; |
104 | 75 |
105 entries.appendVector(m_resourceTimingBuffer); | 76 entries.appendVector(m_resourceTimingBuffer); |
106 entries.appendVector(m_frameTimingBuffer); | 77 entries.appendVector(m_frameTimingBuffer); |
107 | 78 |
108 if (m_userTiming) { | 79 if (m_userTiming) { |
109 entries.appendVector(m_userTiming->getMarks()); | 80 entries.appendVector(m_userTiming->getMarks()); |
110 entries.appendVector(m_userTiming->getMeasures()); | 81 entries.appendVector(m_userTiming->getMeasures()); |
111 } | 82 } |
112 | 83 |
113 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 84 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
114 return entries; | 85 return entries; |
115 } | 86 } |
116 | 87 |
117 PerformanceEntryVector Performance::getEntriesByType(const String& entryType) | 88 PerformanceEntryVector PerformanceBase::getEntriesByType(const String& entryType
) |
118 { | 89 { |
119 PerformanceEntryVector entries; | 90 PerformanceEntryVector entries; |
120 | 91 |
121 if (equalIgnoringCase(entryType, "resource")) { | 92 if (equalIgnoringCase(entryType, "resource")) { |
122 for (const auto& resource : m_resourceTimingBuffer) | 93 for (const auto& resource : m_resourceTimingBuffer) |
123 entries.append(resource); | 94 entries.append(resource); |
124 } | 95 } |
125 | 96 |
126 if (equalIgnoringCase(entryType, "composite") | 97 if (equalIgnoringCase(entryType, "composite") |
127 || equalIgnoringCase(entryType, "render")) { | 98 || equalIgnoringCase(entryType, "render")) { |
128 for (const auto& frame : m_frameTimingBuffer) { | 99 for (const auto& frame : m_frameTimingBuffer) { |
129 if (equalIgnoringCase(entryType, frame->entryType())) { | 100 if (equalIgnoringCase(entryType, frame->entryType())) { |
130 entries.append(frame); | 101 entries.append(frame); |
131 } | 102 } |
132 } | 103 } |
133 } | 104 } |
134 | 105 |
135 if (m_userTiming) { | 106 if (m_userTiming) { |
136 if (equalIgnoringCase(entryType, "mark")) | 107 if (equalIgnoringCase(entryType, "mark")) |
137 entries.appendVector(m_userTiming->getMarks()); | 108 entries.appendVector(m_userTiming->getMarks()); |
138 else if (equalIgnoringCase(entryType, "measure")) | 109 else if (equalIgnoringCase(entryType, "measure")) |
139 entries.appendVector(m_userTiming->getMeasures()); | 110 entries.appendVector(m_userTiming->getMeasures()); |
140 } | 111 } |
141 | 112 |
142 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 113 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
143 return entries; | 114 return entries; |
144 } | 115 } |
145 | 116 |
146 PerformanceEntryVector Performance::getEntriesByName(const String& name, const S
tring& entryType) | 117 PerformanceEntryVector PerformanceBase::getEntriesByName(const String& name, con
st String& entryType) |
147 { | 118 { |
148 PerformanceEntryVector entries; | 119 PerformanceEntryVector entries; |
149 | 120 |
150 if (entryType.isNull() || equalIgnoringCase(entryType, "resource")) { | 121 if (entryType.isNull() || equalIgnoringCase(entryType, "resource")) { |
151 for (const auto& resource : m_resourceTimingBuffer) { | 122 for (const auto& resource : m_resourceTimingBuffer) { |
152 if (resource->name() == name) | 123 if (resource->name() == name) |
153 entries.append(resource); | 124 entries.append(resource); |
154 } | 125 } |
155 } | 126 } |
156 | 127 |
(...skipping 11 matching lines...) Expand all Loading... |
168 if (entryType.isNull() || equalIgnoringCase(entryType, "mark")) | 139 if (entryType.isNull() || equalIgnoringCase(entryType, "mark")) |
169 entries.appendVector(m_userTiming->getMarks(name)); | 140 entries.appendVector(m_userTiming->getMarks(name)); |
170 if (entryType.isNull() || equalIgnoringCase(entryType, "measure")) | 141 if (entryType.isNull() || equalIgnoringCase(entryType, "measure")) |
171 entries.appendVector(m_userTiming->getMeasures(name)); | 142 entries.appendVector(m_userTiming->getMeasures(name)); |
172 } | 143 } |
173 | 144 |
174 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 145 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
175 return entries; | 146 return entries; |
176 } | 147 } |
177 | 148 |
178 void Performance::webkitClearResourceTimings() | 149 void PerformanceBase::webkitClearResourceTimings() |
179 { | 150 { |
180 m_resourceTimingBuffer.clear(); | 151 m_resourceTimingBuffer.clear(); |
181 } | 152 } |
182 | 153 |
183 void Performance::webkitSetResourceTimingBufferSize(unsigned size) | 154 void PerformanceBase::webkitSetResourceTimingBufferSize(unsigned size) |
184 { | 155 { |
185 m_resourceTimingBufferSize = size; | 156 m_resourceTimingBufferSize = size; |
186 if (isResourceTimingBufferFull()) | 157 if (isResourceTimingBufferFull()) |
187 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); | 158 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); |
188 } | 159 } |
189 | 160 |
190 void Performance::clearFrameTimings() | 161 void PerformanceBase::clearFrameTimings() |
191 { | 162 { |
192 m_frameTimingBuffer.clear(); | 163 m_frameTimingBuffer.clear(); |
193 } | 164 } |
194 | 165 |
195 void Performance::setFrameTimingBufferSize(unsigned size) | 166 void PerformanceBase::setFrameTimingBufferSize(unsigned size) |
196 { | 167 { |
197 m_frameTimingBufferSize = size; | 168 m_frameTimingBufferSize = size; |
198 if (isFrameTimingBufferFull()) | 169 if (isFrameTimingBufferFull()) |
199 dispatchEvent(Event::create(EventTypeNames::frametimingbufferfull)); | 170 dispatchEvent(Event::create(EventTypeNames::frametimingbufferfull)); |
200 } | 171 } |
201 | 172 |
202 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r
equestingDocument, const AtomicString& originalTimingAllowOrigin) | 173 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r
equestingDocument, const AtomicString& originalTimingAllowOrigin) |
203 { | 174 { |
204 AtomicallyInitializedStaticReference(AtomicString, timingAllowOrigin, new At
omicString("timing-allow-origin")); | 175 AtomicallyInitializedStaticReference(AtomicString, timingAllowOrigin, new At
omicString("timing-allow-origin")); |
205 | 176 |
(...skipping 25 matching lines...) Expand all Loading... |
231 return false; | 202 return false; |
232 | 203 |
233 for (const ResourceResponse& response : redirectChain) { | 204 for (const ResourceResponse& response : redirectChain) { |
234 if (!passesTimingAllowCheck(response, initiatorDocument, emptyAtom)) | 205 if (!passesTimingAllowCheck(response, initiatorDocument, emptyAtom)) |
235 return false; | 206 return false; |
236 } | 207 } |
237 | 208 |
238 return true; | 209 return true; |
239 } | 210 } |
240 | 211 |
241 void Performance::addResourceTiming(const ResourceTimingInfo& info, Document* in
itiatorDocument) | 212 void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info, Document
* initiatorDocument) |
242 { | 213 { |
243 if (isResourceTimingBufferFull()) | 214 if (isResourceTimingBufferFull()) |
244 return; | 215 return; |
245 | 216 |
246 const ResourceResponse& finalResponse = info.finalResponse(); | 217 const ResourceResponse& finalResponse = info.finalResponse(); |
247 bool allowTimingDetails = passesTimingAllowCheck(finalResponse, initiatorDoc
ument, info.originalTimingAllowOrigin()); | 218 bool allowTimingDetails = passesTimingAllowCheck(finalResponse, initiatorDoc
ument, info.originalTimingAllowOrigin()); |
248 double startTime = info.initialTime(); | 219 double startTime = info.initialTime(); |
249 | 220 |
250 if (info.redirectChain().isEmpty()) { | 221 if (info.redirectChain().isEmpty()) { |
251 PerformanceEntry* entry = PerformanceResourceTiming::create(info, initia
torDocument, startTime, allowTimingDetails); | 222 PerformanceEntry* entry = PerformanceResourceTiming::create(info, initia
torDocument, startTime, allowTimingDetails); |
(...skipping 12 matching lines...) Expand all Loading... |
264 } | 235 } |
265 | 236 |
266 ResourceLoadTiming* lastRedirectTiming = redirectChain.last().resourceLoadTi
ming(); | 237 ResourceLoadTiming* lastRedirectTiming = redirectChain.last().resourceLoadTi
ming(); |
267 ASSERT(lastRedirectTiming); | 238 ASSERT(lastRedirectTiming); |
268 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); | 239 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); |
269 | 240 |
270 PerformanceEntry* entry = PerformanceResourceTiming::create(info, initiatorD
ocument, startTime, lastRedirectEndTime, allowTimingDetails, allowRedirectDetail
s); | 241 PerformanceEntry* entry = PerformanceResourceTiming::create(info, initiatorD
ocument, startTime, lastRedirectEndTime, allowTimingDetails, allowRedirectDetail
s); |
271 addResourceTimingBuffer(entry); | 242 addResourceTimingBuffer(entry); |
272 } | 243 } |
273 | 244 |
274 void Performance::addResourceTimingBuffer(PerformanceEntry* entry) | 245 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry* entry) |
275 { | 246 { |
276 m_resourceTimingBuffer.append(entry); | 247 m_resourceTimingBuffer.append(entry); |
277 | 248 |
278 if (isResourceTimingBufferFull()) | 249 if (isResourceTimingBufferFull()) |
279 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); | 250 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); |
280 } | 251 } |
281 | 252 |
282 bool Performance::isResourceTimingBufferFull() | 253 bool PerformanceBase::isResourceTimingBufferFull() |
283 { | 254 { |
284 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; | 255 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; |
285 } | 256 } |
286 | 257 |
287 void Performance::addRenderTiming(Document* initiatorDocument, unsigned sourceFr
ame, double startTime, double finishTime) | 258 void PerformanceBase::addRenderTiming(Document* initiatorDocument, unsigned sour
ceFrame, double startTime, double finishTime) |
288 { | 259 { |
289 if (isFrameTimingBufferFull()) | 260 if (isFrameTimingBufferFull()) |
290 return; | 261 return; |
291 | 262 |
292 PerformanceEntry* entry = PerformanceRenderTiming::create(initiatorDocument,
sourceFrame, startTime, finishTime); | 263 PerformanceEntry* entry = PerformanceRenderTiming::create(initiatorDocument,
sourceFrame, startTime, finishTime); |
293 addFrameTimingBuffer(entry); | 264 addFrameTimingBuffer(entry); |
294 } | 265 } |
295 | 266 |
296 void Performance::addCompositeTiming(Document* initiatorDocument, unsigned sourc
eFrame, double startTime) | 267 void PerformanceBase::addCompositeTiming(Document* initiatorDocument, unsigned s
ourceFrame, double startTime) |
297 { | 268 { |
298 if (isFrameTimingBufferFull()) | 269 if (isFrameTimingBufferFull()) |
299 return; | 270 return; |
300 | 271 |
301 PerformanceEntry* entry = PerformanceCompositeTiming::create(initiatorDocume
nt, sourceFrame, startTime); | 272 PerformanceEntry* entry = PerformanceCompositeTiming::create(initiatorDocume
nt, sourceFrame, startTime); |
302 addFrameTimingBuffer(entry); | 273 addFrameTimingBuffer(entry); |
303 } | 274 } |
304 | 275 |
305 void Performance::addFrameTimingBuffer(PerformanceEntry* entry) | 276 void PerformanceBase::addFrameTimingBuffer(PerformanceEntry* entry) |
306 { | 277 { |
307 m_frameTimingBuffer.append(entry); | 278 m_frameTimingBuffer.append(entry); |
308 | 279 |
309 if (isFrameTimingBufferFull()) | 280 if (isFrameTimingBufferFull()) |
310 dispatchEvent(Event::create(EventTypeNames::frametimingbufferfull)); | 281 dispatchEvent(Event::create(EventTypeNames::frametimingbufferfull)); |
311 } | 282 } |
312 | 283 |
313 bool Performance::isFrameTimingBufferFull() | 284 bool PerformanceBase::isFrameTimingBufferFull() |
314 { | 285 { |
315 return m_frameTimingBuffer.size() >= m_frameTimingBufferSize; | 286 return m_frameTimingBuffer.size() >= m_frameTimingBufferSize; |
316 } | 287 } |
317 | 288 |
318 void Performance::mark(const String& markName, ExceptionState& exceptionState) | 289 void PerformanceBase::mark(const String& markName, ExceptionState& exceptionStat
e) |
319 { | 290 { |
320 if (!m_userTiming) | 291 if (!m_userTiming) |
321 m_userTiming = UserTiming::create(this); | 292 m_userTiming = UserTiming::create(this); |
322 m_userTiming->mark(markName, exceptionState); | 293 m_userTiming->mark(markName, exceptionState); |
323 } | 294 } |
324 | 295 |
325 void Performance::clearMarks(const String& markName) | 296 void PerformanceBase::clearMarks(const String& markName) |
326 { | 297 { |
327 if (!m_userTiming) | 298 if (!m_userTiming) |
328 m_userTiming = UserTiming::create(this); | 299 m_userTiming = UserTiming::create(this); |
329 m_userTiming->clearMarks(markName); | 300 m_userTiming->clearMarks(markName); |
330 } | 301 } |
331 | 302 |
332 void Performance::measure(const String& measureName, const String& startMark, co
nst String& endMark, ExceptionState& exceptionState) | 303 void PerformanceBase::measure(const String& measureName, const String& startMark
, const String& endMark, ExceptionState& exceptionState) |
333 { | 304 { |
334 if (!m_userTiming) | 305 if (!m_userTiming) |
335 m_userTiming = UserTiming::create(this); | 306 m_userTiming = UserTiming::create(this); |
336 m_userTiming->measure(measureName, startMark, endMark, exceptionState); | 307 m_userTiming->measure(measureName, startMark, endMark, exceptionState); |
337 } | 308 } |
338 | 309 |
339 void Performance::clearMeasures(const String& measureName) | 310 void PerformanceBase::clearMeasures(const String& measureName) |
340 { | 311 { |
341 if (!m_userTiming) | 312 if (!m_userTiming) |
342 m_userTiming = UserTiming::create(this); | 313 m_userTiming = UserTiming::create(this); |
343 m_userTiming->clearMeasures(measureName); | 314 m_userTiming->clearMeasures(measureName); |
344 } | 315 } |
345 | 316 |
346 double Performance::now() const | 317 double PerformanceBase::now() const |
347 { | 318 { |
348 return 1000.0 * (monotonicallyIncreasingTime() - m_referenceTime); | 319 return 1000.0 * (monotonicallyIncreasingTime() - m_timeOrigin); |
349 } | 320 } |
350 | 321 |
351 DEFINE_TRACE(Performance) | 322 DEFINE_TRACE(PerformanceBase) |
352 { | 323 { |
353 visitor->trace(m_navigation); | |
354 visitor->trace(m_timing); | |
355 visitor->trace(m_frameTimingBuffer); | 324 visitor->trace(m_frameTimingBuffer); |
356 visitor->trace(m_resourceTimingBuffer); | 325 visitor->trace(m_resourceTimingBuffer); |
357 visitor->trace(m_memoryInfo); | |
358 visitor->trace(m_userTiming); | 326 visitor->trace(m_userTiming); |
359 EventTargetWithInlineData::trace(visitor); | 327 EventTargetWithInlineData::trace(visitor); |
360 DOMWindowProperty::trace(visitor); | |
361 } | 328 } |
362 | 329 |
363 } // namespace blink | 330 } // namespace blink |
OLD | NEW |