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 18 matching lines...) Expand all Loading... |
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/Performance.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" | 37 #include "core/frame/LocalFrame.h" |
38 #include "core/loader/DocumentLoader.h" | 38 #include "core/loader/DocumentLoader.h" |
39 #include "core/timing/ResourceTimingInfo.h" | 39 #include "core/timing/PerformanceCompositeTiming.h" |
| 40 #include "core/timing/PerformanceRenderTiming.h" |
40 #include "core/timing/PerformanceResourceTiming.h" | 41 #include "core/timing/PerformanceResourceTiming.h" |
41 #include "core/timing/PerformanceUserTiming.h" | 42 #include "core/timing/PerformanceUserTiming.h" |
| 43 #include "core/timing/ResourceTimingInfo.h" |
42 #include "platform/weborigin/SecurityOrigin.h" | 44 #include "platform/weborigin/SecurityOrigin.h" |
43 #include "wtf/CurrentTime.h" | 45 #include "wtf/CurrentTime.h" |
44 | 46 |
45 namespace blink { | 47 namespace blink { |
46 | 48 |
47 static const size_t defaultResourceTimingBufferSize = 150; | 49 static const size_t defaultResourceTimingBufferSize = 150; |
| 50 static const size_t defaultFrameTimingBufferSize = 150; |
48 | 51 |
49 Performance::Performance(LocalFrame* frame) | 52 Performance::Performance(LocalFrame* frame) |
50 : DOMWindowProperty(frame) | 53 : DOMWindowProperty(frame) |
| 54 , m_frameTimingBufferSize(defaultFrameTimingBufferSize) |
51 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) | 55 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) |
52 , m_referenceTime(frame && frame->host() ? frame->document()->loader()->timi
ng().referenceMonotonicTime() : 0.0) | 56 , m_referenceTime(frame && frame->host() ? frame->document()->loader()->timi
ng().referenceMonotonicTime() : 0.0) |
53 , m_userTiming(nullptr) | 57 , m_userTiming(nullptr) |
54 { | 58 { |
55 } | 59 } |
56 | 60 |
57 Performance::~Performance() | 61 Performance::~Performance() |
58 { | 62 { |
59 } | 63 } |
60 | 64 |
(...skipping 29 matching lines...) Expand all Loading... |
90 | 94 |
91 return m_timing.get(); | 95 return m_timing.get(); |
92 } | 96 } |
93 | 97 |
94 PerformanceEntryVector Performance::getEntries() const | 98 PerformanceEntryVector Performance::getEntries() const |
95 { | 99 { |
96 PerformanceEntryVector entries; | 100 PerformanceEntryVector entries; |
97 | 101 |
98 entries.appendVector(m_resourceTimingBuffer); | 102 entries.appendVector(m_resourceTimingBuffer); |
99 | 103 |
| 104 entries.appendVector(m_frameTimingBuffer); |
| 105 |
100 if (m_userTiming) { | 106 if (m_userTiming) { |
101 entries.appendVector(m_userTiming->getMarks()); | 107 entries.appendVector(m_userTiming->getMarks()); |
102 entries.appendVector(m_userTiming->getMeasures()); | 108 entries.appendVector(m_userTiming->getMeasures()); |
103 } | 109 } |
104 | 110 |
105 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 111 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
106 return entries; | 112 return entries; |
107 } | 113 } |
108 | 114 |
109 PerformanceEntryVector Performance::getEntriesByType(const String& entryType) | 115 PerformanceEntryVector Performance::getEntriesByType(const String& entryType) |
110 { | 116 { |
111 PerformanceEntryVector entries; | 117 PerformanceEntryVector entries; |
112 | 118 |
113 if (equalIgnoringCase(entryType, "resource")) { | 119 if (equalIgnoringCase(entryType, "resource")) { |
114 for (const auto& resource : m_resourceTimingBuffer) | 120 for (const auto& resource : m_resourceTimingBuffer) |
115 entries.append(resource); | 121 entries.append(resource); |
116 } | 122 } |
117 | 123 |
| 124 if (equalIgnoringCase(entryType, "composite") |
| 125 || equalIgnoringCase(entryType, "render")) { |
| 126 for (const auto& frame : m_frameTimingBuffer) { |
| 127 if (equalIgnoringCase(entryType, frame->entryType())) { |
| 128 entries.append(frame); |
| 129 } |
| 130 } |
| 131 } |
| 132 |
118 if (m_userTiming) { | 133 if (m_userTiming) { |
119 if (equalIgnoringCase(entryType, "mark")) | 134 if (equalIgnoringCase(entryType, "mark")) |
120 entries.appendVector(m_userTiming->getMarks()); | 135 entries.appendVector(m_userTiming->getMarks()); |
121 else if (equalIgnoringCase(entryType, "measure")) | 136 else if (equalIgnoringCase(entryType, "measure")) |
122 entries.appendVector(m_userTiming->getMeasures()); | 137 entries.appendVector(m_userTiming->getMeasures()); |
123 } | 138 } |
124 | 139 |
125 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 140 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
126 return entries; | 141 return entries; |
127 } | 142 } |
128 | 143 |
129 PerformanceEntryVector Performance::getEntriesByName(const String& name, const S
tring& entryType) | 144 PerformanceEntryVector Performance::getEntriesByName(const String& name, const S
tring& entryType) |
130 { | 145 { |
131 PerformanceEntryVector entries; | 146 PerformanceEntryVector entries; |
132 | 147 |
133 if (entryType.isNull() || equalIgnoringCase(entryType, "resource")) { | 148 if (entryType.isNull() || equalIgnoringCase(entryType, "resource")) { |
134 for (const auto& resource : m_resourceTimingBuffer) { | 149 for (const auto& resource : m_resourceTimingBuffer) { |
135 if (resource->name() == name) | 150 if (resource->name() == name) |
136 entries.append(resource); | 151 entries.append(resource); |
137 } | 152 } |
138 } | 153 } |
139 | 154 |
| 155 if (entryType.isNull() || equalIgnoringCase(entryType, "composite") |
| 156 || equalIgnoringCase(entryType, "render")) { |
| 157 for (const auto& frame : m_frameTimingBuffer) { |
| 158 if (frame->name() == name && (entryType.isNull() |
| 159 || equalIgnoringCase(entryType, frame->entryType()))) { |
| 160 entries.append(frame); |
| 161 } |
| 162 } |
| 163 } |
| 164 |
140 if (m_userTiming) { | 165 if (m_userTiming) { |
141 if (entryType.isNull() || equalIgnoringCase(entryType, "mark")) | 166 if (entryType.isNull() || equalIgnoringCase(entryType, "mark")) |
142 entries.appendVector(m_userTiming->getMarks(name)); | 167 entries.appendVector(m_userTiming->getMarks(name)); |
143 if (entryType.isNull() || equalIgnoringCase(entryType, "measure")) | 168 if (entryType.isNull() || equalIgnoringCase(entryType, "measure")) |
144 entries.appendVector(m_userTiming->getMeasures(name)); | 169 entries.appendVector(m_userTiming->getMeasures(name)); |
145 } | 170 } |
146 | 171 |
147 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 172 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
148 return entries; | 173 return entries; |
149 } | 174 } |
150 | 175 |
151 void Performance::webkitClearResourceTimings() | 176 void Performance::webkitClearResourceTimings() |
152 { | 177 { |
153 m_resourceTimingBuffer.clear(); | 178 m_resourceTimingBuffer.clear(); |
154 } | 179 } |
155 | 180 |
156 void Performance::webkitSetResourceTimingBufferSize(unsigned size) | 181 void Performance::webkitSetResourceTimingBufferSize(unsigned size) |
157 { | 182 { |
158 m_resourceTimingBufferSize = size; | 183 m_resourceTimingBufferSize = size; |
159 if (isResourceTimingBufferFull()) | 184 if (isResourceTimingBufferFull()) |
160 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); | 185 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); |
161 } | 186 } |
162 | 187 |
| 188 void Performance::webkitClearFrameTimings() |
| 189 { |
| 190 m_frameTimingBuffer.clear(); |
| 191 } |
| 192 |
| 193 void Performance::webkitSetFrameTimingBufferSize(unsigned size) |
| 194 { |
| 195 m_frameTimingBufferSize = size; |
| 196 if (isFrameTimingBufferFull()) |
| 197 dispatchEvent(Event::create(EventTypeNames::webkitframetimingbufferfull)
); |
| 198 } |
| 199 |
163 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r
equestingDocument, const AtomicString& originalTimingAllowOrigin) | 200 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r
equestingDocument, const AtomicString& originalTimingAllowOrigin) |
164 { | 201 { |
165 AtomicallyInitializedStaticReference(AtomicString, timingAllowOrigin, new At
omicString("timing-allow-origin")); | 202 AtomicallyInitializedStaticReference(AtomicString, timingAllowOrigin, new At
omicString("timing-allow-origin")); |
166 | 203 |
167 RefPtr<SecurityOrigin> resourceOrigin = SecurityOrigin::create(response.url(
)); | 204 RefPtr<SecurityOrigin> resourceOrigin = SecurityOrigin::create(response.url(
)); |
168 if (resourceOrigin->isSameSchemeHostPort(requestingDocument->securityOrigin(
))) | 205 if (resourceOrigin->isSameSchemeHostPort(requestingDocument->securityOrigin(
))) |
169 return true; | 206 return true; |
170 | 207 |
171 const AtomicString& timingAllowOriginString = originalTimingAllowOrigin.isEm
pty() ? response.httpHeaderField(timingAllowOrigin) : originalTimingAllowOrigin; | 208 const AtomicString& timingAllowOriginString = originalTimingAllowOrigin.isEm
pty() ? response.httpHeaderField(timingAllowOrigin) : originalTimingAllowOrigin; |
172 if (timingAllowOriginString.isEmpty() || equalIgnoringCase(timingAllowOrigin
String, "null")) | 209 if (timingAllowOriginString.isEmpty() || equalIgnoringCase(timingAllowOrigin
String, "null")) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 275 |
239 if (isResourceTimingBufferFull()) | 276 if (isResourceTimingBufferFull()) |
240 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); | 277 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); |
241 } | 278 } |
242 | 279 |
243 bool Performance::isResourceTimingBufferFull() | 280 bool Performance::isResourceTimingBufferFull() |
244 { | 281 { |
245 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; | 282 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; |
246 } | 283 } |
247 | 284 |
| 285 void Performance::addRenderTiming(Document* initiatorDocument, unsigned sourceFr
ame, double startTime) |
| 286 { |
| 287 if (isFrameTimingBufferFull()) |
| 288 return; |
| 289 |
| 290 RefPtrWillBeRawPtr<PerformanceEntry> entry = PerformanceRenderTiming::create
(initiatorDocument, sourceFrame, startTime); |
| 291 addFrameTimingBuffer(entry); |
| 292 } |
| 293 |
| 294 void Performance::addCompositeTiming(Document* initiatorDocument, unsigned sourc
eFrame, double startTime) |
| 295 { |
| 296 if (isFrameTimingBufferFull()) |
| 297 return; |
| 298 |
| 299 RefPtrWillBeRawPtr<PerformanceEntry> entry = PerformanceCompositeTiming::cre
ate(initiatorDocument, sourceFrame, startTime); |
| 300 addFrameTimingBuffer(entry); |
| 301 } |
| 302 |
| 303 void Performance::addFrameTimingBuffer(PassRefPtrWillBeRawPtr<PerformanceEntry>
entry) |
| 304 { |
| 305 m_frameTimingBuffer.append(entry); |
| 306 |
| 307 if (isFrameTimingBufferFull()) |
| 308 dispatchEvent(Event::create(EventTypeNames::webkitframetimingbufferfull)
); |
| 309 } |
| 310 |
| 311 bool Performance::isFrameTimingBufferFull() |
| 312 { |
| 313 return m_frameTimingBuffer.size() >= m_frameTimingBufferSize; |
| 314 } |
| 315 |
248 void Performance::mark(const String& markName, ExceptionState& exceptionState) | 316 void Performance::mark(const String& markName, ExceptionState& exceptionState) |
249 { | 317 { |
250 if (!m_userTiming) | 318 if (!m_userTiming) |
251 m_userTiming = UserTiming::create(this); | 319 m_userTiming = UserTiming::create(this); |
252 m_userTiming->mark(markName, exceptionState); | 320 m_userTiming->mark(markName, exceptionState); |
253 } | 321 } |
254 | 322 |
255 void Performance::clearMarks(const String& markName) | 323 void Performance::clearMarks(const String& markName) |
256 { | 324 { |
257 if (!m_userTiming) | 325 if (!m_userTiming) |
(...skipping 17 matching lines...) Expand all Loading... |
275 | 343 |
276 double Performance::now() const | 344 double Performance::now() const |
277 { | 345 { |
278 return 1000.0 * (monotonicallyIncreasingTime() - m_referenceTime); | 346 return 1000.0 * (monotonicallyIncreasingTime() - m_referenceTime); |
279 } | 347 } |
280 | 348 |
281 DEFINE_TRACE(Performance) | 349 DEFINE_TRACE(Performance) |
282 { | 350 { |
283 visitor->trace(m_navigation); | 351 visitor->trace(m_navigation); |
284 visitor->trace(m_timing); | 352 visitor->trace(m_timing); |
| 353 visitor->trace(m_frameTimingBuffer); |
285 visitor->trace(m_resourceTimingBuffer); | 354 visitor->trace(m_resourceTimingBuffer); |
286 visitor->trace(m_userTiming); | 355 visitor->trace(m_userTiming); |
287 EventTargetWithInlineData::trace(visitor); | 356 EventTargetWithInlineData::trace(visitor); |
288 DOMWindowProperty::trace(visitor); | 357 DOMWindowProperty::trace(visitor); |
289 } | 358 } |
290 | 359 |
291 } // namespace blink | 360 } // namespace blink |
OLD | NEW |