OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Intel Inc. All rights reserved. | 2 * Copyright (C) 2012 Intel Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/timing/PerformanceUserTiming.h" | 27 #include "core/timing/PerformanceUserTiming.h" |
28 | 28 |
29 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
31 #include "core/timing/Performance.h" | 31 #include "core/timing/PerformanceBase.h" |
32 #include "core/timing/PerformanceMark.h" | 32 #include "core/timing/PerformanceMark.h" |
33 #include "core/timing/PerformanceMeasure.h" | 33 #include "core/timing/PerformanceMeasure.h" |
34 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
35 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
36 #include "wtf/text/StringHash.h" | 36 #include "wtf/text/StringHash.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 using RestrictedKeyMap = HashMap<String, NavigationTimingFunction>; | 42 using RestrictedKeyMap = HashMap<String, NavigationTimingFunction>; |
43 static RestrictedKeyMap restrictedKeyMap() | 43 |
| 44 RestrictedKeyMap* createRestrictedKeyMap() |
44 { | 45 { |
45 DEFINE_STATIC_LOCAL(RestrictedKeyMap, map, ()); | 46 RestrictedKeyMap* map = new RestrictedKeyMap(); |
46 if (map.isEmpty()) { | 47 map->add("navigationStart", &PerformanceTiming::navigationStart); |
47 map.add("navigationStart", &PerformanceTiming::navigationStart); | 48 map->add("unloadEventStart", &PerformanceTiming::unloadEventStart); |
48 map.add("unloadEventStart", &PerformanceTiming::unloadEventStart); | 49 map->add("unloadEventEnd", &PerformanceTiming::unloadEventEnd); |
49 map.add("unloadEventEnd", &PerformanceTiming::unloadEventEnd); | 50 map->add("redirectStart", &PerformanceTiming::redirectStart); |
50 map.add("redirectStart", &PerformanceTiming::redirectStart); | 51 map->add("redirectEnd", &PerformanceTiming::redirectEnd); |
51 map.add("redirectEnd", &PerformanceTiming::redirectEnd); | 52 map->add("fetchStart", &PerformanceTiming::fetchStart); |
52 map.add("fetchStart", &PerformanceTiming::fetchStart); | 53 map->add("domainLookupStart", &PerformanceTiming::domainLookupStart); |
53 map.add("domainLookupStart", &PerformanceTiming::domainLookupStart); | 54 map->add("domainLookupEnd", &PerformanceTiming::domainLookupEnd); |
54 map.add("domainLookupEnd", &PerformanceTiming::domainLookupEnd); | 55 map->add("connectStart", &PerformanceTiming::connectStart); |
55 map.add("connectStart", &PerformanceTiming::connectStart); | 56 map->add("connectEnd", &PerformanceTiming::connectEnd); |
56 map.add("connectEnd", &PerformanceTiming::connectEnd); | 57 map->add("secureConnectionStart", &PerformanceTiming::secureConnectionStart)
; |
57 map.add("secureConnectionStart", &PerformanceTiming::secureConnectionSta
rt); | 58 map->add("requestStart", &PerformanceTiming::requestStart); |
58 map.add("requestStart", &PerformanceTiming::requestStart); | 59 map->add("responseStart", &PerformanceTiming::responseStart); |
59 map.add("responseStart", &PerformanceTiming::responseStart); | 60 map->add("responseEnd", &PerformanceTiming::responseEnd); |
60 map.add("responseEnd", &PerformanceTiming::responseEnd); | 61 map->add("domLoading", &PerformanceTiming::domLoading); |
61 map.add("domLoading", &PerformanceTiming::domLoading); | 62 map->add("domInteractive", &PerformanceTiming::domInteractive); |
62 map.add("domInteractive", &PerformanceTiming::domInteractive); | 63 map->add("domContentLoadedEventStart", &PerformanceTiming::domContentLoadedE
ventStart); |
63 map.add("domContentLoadedEventStart", &PerformanceTiming::domContentLoad
edEventStart); | 64 map->add("domContentLoadedEventEnd", &PerformanceTiming::domContentLoadedEve
ntEnd); |
64 map.add("domContentLoadedEventEnd", &PerformanceTiming::domContentLoaded
EventEnd); | 65 map->add("domComplete", &PerformanceTiming::domComplete); |
65 map.add("domComplete", &PerformanceTiming::domComplete); | 66 map->add("loadEventStart", &PerformanceTiming::loadEventStart); |
66 map.add("loadEventStart", &PerformanceTiming::loadEventStart); | 67 map->add("loadEventEnd", &PerformanceTiming::loadEventEnd); |
67 map.add("loadEventEnd", &PerformanceTiming::loadEventEnd); | 68 return map; |
68 } | 69 } |
| 70 |
| 71 const RestrictedKeyMap& restrictedKeyMap() |
| 72 { |
| 73 AtomicallyInitializedStaticReference(RestrictedKeyMap, map, createRestricted
KeyMap()); |
69 return map; | 74 return map; |
70 } | 75 } |
71 | 76 |
72 } // namespace anonymous | 77 } // namespace anonymous |
73 | 78 |
74 UserTiming::UserTiming(Performance* performance) | 79 UserTiming::UserTiming(PerformanceBase* performance) |
75 : m_performance(performance) | 80 : m_performance(performance) |
76 { | 81 { |
77 } | 82 } |
78 | 83 |
79 static void insertPerformanceEntry(PerformanceEntryMap& performanceEntryMap, Per
formanceEntry* entry) | 84 static void insertPerformanceEntry(PerformanceEntryMap& performanceEntryMap, Per
formanceEntry* entry) |
80 { | 85 { |
81 PerformanceEntryMap::iterator it = performanceEntryMap.find(entry->name()); | 86 PerformanceEntryMap::iterator it = performanceEntryMap.find(entry->name()); |
82 if (it != performanceEntryMap.end()) | 87 if (it != performanceEntryMap.end()) |
83 it->value.append(entry); | 88 it->value.append(entry); |
84 else { | 89 else { |
(...skipping 30 matching lines...) Expand all Loading... |
115 void UserTiming::clearMarks(const String& markName) | 120 void UserTiming::clearMarks(const String& markName) |
116 { | 121 { |
117 clearPeformanceEntries(m_marksMap, markName); | 122 clearPeformanceEntries(m_marksMap, markName); |
118 } | 123 } |
119 | 124 |
120 double UserTiming::findExistingMarkStartTime(const String& markName, ExceptionSt
ate& exceptionState) | 125 double UserTiming::findExistingMarkStartTime(const String& markName, ExceptionSt
ate& exceptionState) |
121 { | 126 { |
122 if (m_marksMap.contains(markName)) | 127 if (m_marksMap.contains(markName)) |
123 return m_marksMap.get(markName).last()->startTime(); | 128 return m_marksMap.get(markName).last()->startTime(); |
124 | 129 |
125 if (restrictedKeyMap().contains(markName)) { | 130 if (restrictedKeyMap().contains(markName) && m_performance->timing()) { |
126 double value = static_cast<double>((m_performance->timing()->*(restricte
dKeyMap().get(markName)))()); | 131 double value = static_cast<double>((m_performance->timing()->*(restricte
dKeyMap().get(markName)))()); |
127 if (!value) { | 132 if (!value) { |
128 exceptionState.throwDOMException(InvalidAccessError, "'" + markName
+ "' is empty: either the event hasn't happened yet, or it would provide cross-o
rigin timing information."); | 133 exceptionState.throwDOMException(InvalidAccessError, "'" + markName
+ "' is empty: either the event hasn't happened yet, or it would provide cross-o
rigin timing information."); |
129 return 0.0; | 134 return 0.0; |
130 } | 135 } |
131 return value - m_performance->timing()->navigationStart(); | 136 return value - m_performance->timing()->navigationStart(); |
132 } | 137 } |
133 | 138 |
134 exceptionState.throwDOMException(SyntaxError, "The mark '" + markName + "' d
oes not exist."); | 139 exceptionState.throwDOMException(SyntaxError, "The mark '" + markName + "' d
oes not exist."); |
135 return 0.0; | 140 return 0.0; |
(...skipping 16 matching lines...) Expand all Loading... |
152 if (exceptionState.hadException()) | 157 if (exceptionState.hadException()) |
153 return; | 158 return; |
154 startTime = findExistingMarkStartTime(startMark, exceptionState); | 159 startTime = findExistingMarkStartTime(startMark, exceptionState); |
155 if (exceptionState.hadException()) | 160 if (exceptionState.hadException()) |
156 return; | 161 return; |
157 } | 162 } |
158 | 163 |
159 // User timing events are stored as integer milliseconds from the start of | 164 // User timing events are stored as integer milliseconds from the start of |
160 // navigation, whereas trace events accept double seconds based off of | 165 // navigation, whereas trace events accept double seconds based off of |
161 // CurrentTime::monotonicallyIncreasingTime(). | 166 // CurrentTime::monotonicallyIncreasingTime(). |
162 double startTimeMonotonic = m_performance->timing()->integerMillisecondsToMo
notonicTime(startTime + m_performance->timing()->navigationStart()); | 167 double startTimeMonotonic = m_performance->timeOrigin() + startTime / 1000.0
; |
163 double endTimeMonotonic = m_performance->timing()->integerMillisecondsToMono
tonicTime(endTime + m_performance->timing()->navigationStart()); | 168 double endTimeMonotonic = m_performance->timeOrigin() + endTime / 1000.0; |
164 | 169 |
165 TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0("blink.user_timing", m
easureName.utf8().data(), WTF::StringHash::hash(measureName), startTimeMonotonic
); | 170 TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0("blink.user_timing", m
easureName.utf8().data(), WTF::StringHash::hash(measureName), startTimeMonotonic
); |
166 TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0("blink.user_timing", mea
sureName.utf8().data(), WTF::StringHash::hash(measureName), endTimeMonotonic); | 171 TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0("blink.user_timing", mea
sureName.utf8().data(), WTF::StringHash::hash(measureName), endTimeMonotonic); |
167 | 172 |
168 insertPerformanceEntry(m_measuresMap, PerformanceMeasure::create(measureName
, startTime, endTime)); | 173 insertPerformanceEntry(m_measuresMap, PerformanceMeasure::create(measureName
, startTime, endTime)); |
169 if (endTime >= startTime) | 174 if (endTime >= startTime) |
170 Platform::current()->histogramCustomCounts("PLT.UserTiming_MeasureDurati
on", static_cast<int>(endTime - startTime), 0, 600000, 100); | 175 Platform::current()->histogramCustomCounts("PLT.UserTiming_MeasureDurati
on", static_cast<int>(endTime - startTime), 0, 600000, 100); |
171 } | 176 } |
172 | 177 |
173 void UserTiming::clearMeasures(const String& measureName) | 178 void UserTiming::clearMeasures(const String& measureName) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 222 } |
218 | 223 |
219 DEFINE_TRACE(UserTiming) | 224 DEFINE_TRACE(UserTiming) |
220 { | 225 { |
221 visitor->trace(m_performance); | 226 visitor->trace(m_performance); |
222 visitor->trace(m_marksMap); | 227 visitor->trace(m_marksMap); |
223 visitor->trace(m_measuresMap); | 228 visitor->trace(m_measuresMap); |
224 } | 229 } |
225 | 230 |
226 } // namespace blink | 231 } // namespace blink |
OLD | NEW |