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