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 14 matching lines...) Expand all Loading... | |
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 "core/timing/PerformanceBase.h" | 32 #include "core/timing/PerformanceBase.h" |
33 | 33 |
34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
35 #include "core/dom/DocumentTiming.h" | |
36 #include "core/dom/Element.h" | |
35 #include "core/events/Event.h" | 37 #include "core/events/Event.h" |
38 #include "core/frame/LocalFrame.h" | |
36 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
40 #include "core/loader/DocumentLoadTiming.h" | |
41 #include "core/loader/DocumentLoader.h" | |
37 #include "core/timing/PerformanceLongTaskTiming.h" | 42 #include "core/timing/PerformanceLongTaskTiming.h" |
43 #include "core/timing/PerformanceNavigationTiming.h" | |
38 #include "core/timing/PerformanceObserver.h" | 44 #include "core/timing/PerformanceObserver.h" |
39 #include "core/timing/PerformanceResourceTiming.h" | 45 #include "core/timing/PerformanceResourceTiming.h" |
40 #include "core/timing/PerformanceUserTiming.h" | 46 #include "core/timing/PerformanceUserTiming.h" |
41 #include "platform/network/ResourceTimingInfo.h" | 47 #include "platform/network/ResourceTimingInfo.h" |
42 #include "platform/weborigin/SecurityOrigin.h" | 48 #include "platform/weborigin/SecurityOrigin.h" |
43 #include "wtf/CurrentTime.h" | 49 #include "wtf/CurrentTime.h" |
44 #include <algorithm> | 50 #include <algorithm> |
45 | 51 |
46 namespace blink { | 52 namespace blink { |
47 | 53 |
48 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; | 54 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; |
49 | 55 |
50 static const size_t defaultResourceTimingBufferSize = 150; | 56 static const size_t defaultResourceTimingBufferSize = 150; |
51 static const size_t defaultFrameTimingBufferSize = 150; | 57 static const size_t defaultFrameTimingBufferSize = 150; |
52 | 58 |
panicker
2016/11/02 20:12:37
probably needs a buffer size?
(only have 1 entry)
sunjian
2016/11/04 01:12:38
Since it's only one element, probably don't need a
| |
53 PerformanceBase::PerformanceBase(double timeOrigin) | 59 PerformanceBase::PerformanceBase(double timeOrigin) |
54 : m_frameTimingBufferSize(defaultFrameTimingBufferSize), | 60 : m_frameTimingBufferSize(defaultFrameTimingBufferSize), |
55 m_resourceTimingBufferSize(defaultResourceTimingBufferSize), | 61 m_resourceTimingBufferSize(defaultResourceTimingBufferSize), |
56 m_userTiming(nullptr), | 62 m_userTiming(nullptr), |
57 m_timeOrigin(timeOrigin), | 63 m_timeOrigin(timeOrigin), |
58 m_observerFilterOptions(PerformanceEntry::Invalid), | 64 m_observerFilterOptions(PerformanceEntry::Invalid), |
59 m_deliverObservationsTimer( | 65 m_deliverObservationsTimer( |
60 this, | 66 this, |
61 &PerformanceBase::deliverObservationsTimerFired) {} | 67 &PerformanceBase::deliverObservationsTimerFired) {} |
62 | 68 |
63 PerformanceBase::~PerformanceBase() {} | 69 PerformanceBase::~PerformanceBase() {} |
64 | 70 |
65 const AtomicString& PerformanceBase::interfaceName() const { | 71 const AtomicString& PerformanceBase::interfaceName() const { |
66 return EventTargetNames::Performance; | 72 return EventTargetNames::Performance; |
67 } | 73 } |
68 | 74 |
69 PerformanceTiming* PerformanceBase::timing() const { | 75 PerformanceTiming* PerformanceBase::timing() const { |
70 return nullptr; | 76 return nullptr; |
71 } | 77 } |
72 | 78 |
73 PerformanceEntryVector PerformanceBase::getEntries() const { | 79 PerformanceEntryVector PerformanceBase::getEntries() const { |
74 PerformanceEntryVector entries; | 80 PerformanceEntryVector entries; |
75 | 81 |
76 entries.appendVector(m_resourceTimingBuffer); | 82 entries.appendVector(m_resourceTimingBuffer); |
83 entries.appendVector(m_navigationTimingBuffer); | |
77 entries.appendVector(m_frameTimingBuffer); | 84 entries.appendVector(m_frameTimingBuffer); |
78 | 85 |
79 if (m_userTiming) { | 86 if (m_userTiming) { |
80 entries.appendVector(m_userTiming->getMarks()); | 87 entries.appendVector(m_userTiming->getMarks()); |
81 entries.appendVector(m_userTiming->getMeasures()); | 88 entries.appendVector(m_userTiming->getMeasures()); |
82 } | 89 } |
83 | 90 |
84 std::sort(entries.begin(), entries.end(), | 91 std::sort(entries.begin(), entries.end(), |
85 PerformanceEntry::startTimeCompareLessThan); | 92 PerformanceEntry::startTimeCompareLessThan); |
86 return entries; | 93 return entries; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 | 168 |
162 std::sort(entries.begin(), entries.end(), | 169 std::sort(entries.begin(), entries.end(), |
163 PerformanceEntry::startTimeCompareLessThan); | 170 PerformanceEntry::startTimeCompareLessThan); |
164 return entries; | 171 return entries; |
165 } | 172 } |
166 | 173 |
167 void PerformanceBase::clearResourceTimings() { | 174 void PerformanceBase::clearResourceTimings() { |
168 m_resourceTimingBuffer.clear(); | 175 m_resourceTimingBuffer.clear(); |
169 } | 176 } |
170 | 177 |
178 void PerformanceBase::clearNavigationTimings() { | |
179 m_navigationTimingBuffer.clear(); | |
180 } | |
181 | |
171 void PerformanceBase::setResourceTimingBufferSize(unsigned size) { | 182 void PerformanceBase::setResourceTimingBufferSize(unsigned size) { |
172 m_resourceTimingBufferSize = size; | 183 m_resourceTimingBufferSize = size; |
173 if (isResourceTimingBufferFull()) { | 184 if (isResourceTimingBufferFull()) { |
174 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); | 185 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); |
175 dispatchEvent( | 186 dispatchEvent( |
176 Event::create(EventTypeNames::webkitresourcetimingbufferfull)); | 187 Event::create(EventTypeNames::webkitresourcetimingbufferfull)); |
177 } | 188 } |
178 } | 189 } |
179 | 190 |
180 void PerformanceBase::clearFrameTimings() { | 191 void PerformanceBase::clearFrameTimings() { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); | 296 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); |
286 | 297 |
287 PerformanceEntry* entry = PerformanceResourceTiming::create( | 298 PerformanceEntry* entry = PerformanceResourceTiming::create( |
288 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, | 299 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, |
289 allowRedirectDetails); | 300 allowRedirectDetails); |
290 notifyObserversOfEntry(*entry); | 301 notifyObserversOfEntry(*entry); |
291 if (!isResourceTimingBufferFull()) | 302 if (!isResourceTimingBufferFull()) |
292 addResourceTimingBuffer(*entry); | 303 addResourceTimingBuffer(*entry); |
293 } | 304 } |
294 | 305 |
306 const DocumentLoader* PerformanceBase::documentLoader(LocalFrame* frame) { | |
307 if (!frame) | |
308 return nullptr; | |
309 return frame->loader().documentLoader(); | |
310 } | |
311 | |
312 const DocumentLoadTiming* PerformanceBase::documentLoadTiming( | |
313 LocalFrame* frame) { | |
314 const DocumentLoader* loader = documentLoader(frame); | |
315 if (!loader) | |
316 return nullptr; | |
317 return &loader->timing(); | |
318 } | |
319 | |
320 const DocumentTiming* PerformanceBase::documentTiming(LocalFrame* frame) { | |
321 if (!frame) | |
322 return nullptr; | |
323 | |
324 Document* document = frame->document(); | |
325 if (!document) | |
326 return nullptr; | |
327 | |
328 return &document->timing(); | |
329 } | |
330 | |
331 AtomicString PerformanceBase::getNavigationType(LocalFrame* frame) { | |
332 if (!frame) | |
333 return "navigate"; | |
334 | |
335 DocumentLoader* documentLoader = frame->loader().documentLoader(); | |
336 if (!documentLoader) | |
337 return "navigate"; | |
338 | |
339 switch (documentLoader->getNavigationType()) { | |
340 case NavigationTypeReload: | |
341 return "reload"; | |
342 case NavigationTypeBackForward: | |
343 return "back_forward"; | |
344 default: | |
345 return "navigate"; | |
346 } | |
347 } | |
348 | |
349 void PerformanceBase::addNavigationTiming(LocalFrame* frame) { | |
panicker
2016/11/02 20:12:37
Add a check for the runtimeflag:
if (!RuntimeEnabl
sunjian
2016/11/04 01:12:38
Done.
| |
350 DCHECK(!frame); | |
351 if (!frame) | |
352 return; | |
353 const DocumentLoader* documentLoader = PerformanceBase::documentLoader(frame); | |
354 DCHECK(!documentLoader); | |
355 if (!documentLoader) | |
panicker
2016/11/02 20:12:37
replace DCHECK with ASSERT and remove this if
sunjian
2016/11/04 01:12:38
Done.
| |
356 return; | |
357 const DocumentLoadTiming* documentLoadTiming = | |
358 PerformanceBase::documentLoadTiming(frame); | |
359 const DocumentTiming* documentTiming = PerformanceBase::documentTiming(frame); | |
360 DCHECK(!documentLoadTiming); | |
361 DCHECK(!documentTiming); | |
362 if (!documentTiming || !documentLoadTiming) | |
panicker
2016/11/02 20:12:37
(same comment)
sunjian
2016/11/04 01:12:38
Done.
| |
363 return; | |
364 | |
365 ResourceResponse finalResponse = documentLoader->response(); | |
366 | |
367 // Right now NavigationType doesn't seem to have a Prerender type yet | |
panicker
2016/11/02 20:12:37
Prefix with:
// TODO(sunjian): Right now ....
sunjian
2016/11/04 01:12:39
Done.
| |
368 // Need to look into this | |
369 AtomicString type = getNavigationType(frame); | |
370 | |
371 ResourceLoadTiming* resourceLoadTiming = finalResponse.resourceLoadTiming(); | |
372 double lastRedirectEndTime = documentLoadTiming->redirectEnd(); | |
373 double finishTime = documentLoadTiming->loadEventEnd(); | |
374 // TODO(sunjian) for now just use encodedDataLength as transferSize, but will | |
panicker
2016/11/02 20:12:37
for now just set it to 0
sunjian
2016/11/04 01:12:39
Done.
| |
375 // have to come | |
376 // back and fix it. | |
377 unsigned long long transferSize = finalResponse.encodedDataLength(); | |
378 unsigned long long encodedBodyLength = finalResponse.encodedBodyLength(); | |
379 unsigned long long decodedBodyLength = finalResponse.decodedBodyLength(); | |
380 bool didReuseConnection = finalResponse.connectionReused(); | |
381 | |
382 PerformanceEntry* entry = PerformanceNavigationTiming::create( | |
383 timeOrigin(), documentLoadTiming->unloadEventStart(), | |
384 documentLoadTiming->unloadEventEnd(), | |
385 documentLoadTiming->loadEventStart(), documentLoadTiming->loadEventEnd(), | |
386 documentLoadTiming->redirectCount(), documentTiming->domInteractive(), | |
387 documentTiming->domContentLoadedEventStart(), | |
388 documentTiming->domContentLoadedEventEnd(), documentTiming->domComplete(), | |
389 type, documentLoadTiming->redirectStart(), | |
390 documentLoadTiming->redirectEnd(), documentLoadTiming->fetchStart(), | |
391 documentLoadTiming->responseEnd(), | |
392 documentLoadTiming->hasCrossOriginRedirect(), | |
393 documentLoadTiming->hasSameOriginAsPreviousDocument(), resourceLoadTiming, | |
394 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength, | |
395 decodedBodyLength, didReuseConnection); | |
396 notifyObserversOfEntry(*entry); | |
397 m_navigationTimingBuffer.append(entry); | |
panicker
2016/11/02 20:12:37
assert that there's at most 1 entry in buffer?
sunjian
2016/11/04 01:12:38
Done.
| |
398 } | |
399 | |
295 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) { | 400 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) { |
296 m_resourceTimingBuffer.append(&entry); | 401 m_resourceTimingBuffer.append(&entry); |
297 | 402 |
298 if (isResourceTimingBufferFull()) { | 403 if (isResourceTimingBufferFull()) { |
299 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); | 404 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); |
300 dispatchEvent( | 405 dispatchEvent( |
301 Event::create(EventTypeNames::webkitresourcetimingbufferfull)); | 406 Event::create(EventTypeNames::webkitresourcetimingbufferfull)); |
302 } | 407 } |
303 } | 408 } |
304 | 409 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 return monotonicTimeToDOMHighResTimeStamp(monotonicTime) * 1000; | 562 return monotonicTimeToDOMHighResTimeStamp(monotonicTime) * 1000; |
458 } | 563 } |
459 | 564 |
460 DOMHighResTimeStamp PerformanceBase::now() const { | 565 DOMHighResTimeStamp PerformanceBase::now() const { |
461 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime()); | 566 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime()); |
462 } | 567 } |
463 | 568 |
464 DEFINE_TRACE(PerformanceBase) { | 569 DEFINE_TRACE(PerformanceBase) { |
465 visitor->trace(m_frameTimingBuffer); | 570 visitor->trace(m_frameTimingBuffer); |
466 visitor->trace(m_resourceTimingBuffer); | 571 visitor->trace(m_resourceTimingBuffer); |
572 visitor->trace(m_navigationTimingBuffer); | |
467 visitor->trace(m_userTiming); | 573 visitor->trace(m_userTiming); |
468 visitor->trace(m_observers); | 574 visitor->trace(m_observers); |
469 visitor->trace(m_activeObservers); | 575 visitor->trace(m_activeObservers); |
470 visitor->trace(m_suspendedObservers); | 576 visitor->trace(m_suspendedObservers); |
471 EventTargetWithInlineData::trace(visitor); | 577 EventTargetWithInlineData::trace(visitor); |
472 } | 578 } |
473 | 579 |
474 } // namespace blink | 580 } // namespace blink |
OLD | NEW |