Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: Source/core/timing/PerformanceUserTiming.cpp

Issue 1198863006: First version of PerformanceObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Sync with latest spec draft (DOMString -> PerformanceEntryType and new PerformanceObserver -> windo… Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return map; 74 return map;
75 } 75 }
76 76
77 } // namespace anonymous 77 } // namespace anonymous
78 78
79 UserTiming::UserTiming(PerformanceBase* performance) 79 UserTiming::UserTiming(PerformanceBase* performance)
80 : m_performance(performance) 80 : m_performance(performance)
81 { 81 {
82 } 82 }
83 83
84 static void insertPerformanceEntry(PerformanceEntryMap& performanceEntryMap, Per formanceEntry* entry) 84 static void insertPerformanceEntry(PerformanceEntryMap& performanceEntryMap, New PerformanceEntryCallback callback, PerformanceEntry* entry)
85 { 85 {
86 (*callback)(entry);
esprehn 2015/07/18 22:24:17 This is very unusual for blink code, can you retur
86 PerformanceEntryMap::iterator it = performanceEntryMap.find(entry->name()); 87 PerformanceEntryMap::iterator it = performanceEntryMap.find(entry->name());
87 if (it != performanceEntryMap.end()) 88 if (it != performanceEntryMap.end())
88 it->value.append(entry); 89 it->value.append(entry);
89 else { 90 else {
90 PerformanceEntryVector vector(1); 91 PerformanceEntryVector vector(1);
91 vector[0] = entry; 92 vector[0] = entry;
92 performanceEntryMap.set(entry->name(), vector); 93 performanceEntryMap.set(entry->name(), vector);
93 } 94 }
94 } 95 }
95 96
96 static void clearPeformanceEntries(PerformanceEntryMap& performanceEntryMap, con st String& name) 97 static void clearPeformanceEntries(PerformanceEntryMap& performanceEntryMap, con st String& name)
97 { 98 {
98 if (name.isNull()) { 99 if (name.isNull()) {
99 performanceEntryMap.clear(); 100 performanceEntryMap.clear();
100 return; 101 return;
101 } 102 }
102 103
103 if (performanceEntryMap.contains(name)) 104 if (performanceEntryMap.contains(name))
104 performanceEntryMap.remove(name); 105 performanceEntryMap.remove(name);
105 } 106 }
106 107
107 void UserTiming::mark(const String& markName, ExceptionState& exceptionState) 108 void UserTiming::mark(const String& markName, NewPerformanceEntryCallback callba ck, ExceptionState& exceptionState)
108 { 109 {
109 if (restrictedKeyMap().contains(markName)) { 110 if (restrictedKeyMap().contains(markName)) {
110 exceptionState.throwDOMException(SyntaxError, "'" + markName + "' is par t of the PerformanceTiming interface, and cannot be used as a mark name."); 111 exceptionState.throwDOMException(SyntaxError, "'" + markName + "' is par t of the PerformanceTiming interface, and cannot be used as a mark name.");
111 return; 112 return;
112 } 113 }
113 114
114 TRACE_EVENT_COPY_MARK("blink.user_timing", markName.utf8().data()); 115 TRACE_EVENT_COPY_MARK("blink.user_timing", markName.utf8().data());
115 double startTime = m_performance->now(); 116 double startTime = m_performance->now();
116 insertPerformanceEntry(m_marksMap, PerformanceMark::create(markName, startTi me)); 117 insertPerformanceEntry(m_marksMap, callback, PerformanceMark::create(markNam e, startTime));
117 Platform::current()->histogramCustomCounts("PLT.UserTiming_Mark", static_cas t<int>(startTime), 0, 600000, 100); 118 Platform::current()->histogramCustomCounts("PLT.UserTiming_Mark", static_cas t<int>(startTime), 0, 600000, 100);
118 } 119 }
119 120
120 void UserTiming::clearMarks(const String& markName) 121 void UserTiming::clearMarks(const String& markName)
121 { 122 {
122 clearPeformanceEntries(m_marksMap, markName); 123 clearPeformanceEntries(m_marksMap, markName);
123 } 124 }
124 125
125 double UserTiming::findExistingMarkStartTime(const String& markName, ExceptionSt ate& exceptionState) 126 double UserTiming::findExistingMarkStartTime(const String& markName, ExceptionSt ate& exceptionState)
126 { 127 {
127 if (m_marksMap.contains(markName)) 128 if (m_marksMap.contains(markName))
128 return m_marksMap.get(markName).last()->startTime(); 129 return m_marksMap.get(markName).last()->startTime();
129 130
130 if (restrictedKeyMap().contains(markName) && m_performance->timing()) { 131 if (restrictedKeyMap().contains(markName) && m_performance->timing()) {
131 double value = static_cast<double>((m_performance->timing()->*(restricte dKeyMap().get(markName)))()); 132 double value = static_cast<double>((m_performance->timing()->*(restricte dKeyMap().get(markName)))());
132 if (!value) { 133 if (!value) {
133 exceptionState.throwDOMException(InvalidAccessError, "'" + markName + "' is empty: either the event hasn't happened yet, or it would provide cross-o rigin timing information."); 134 exceptionState.throwDOMException(InvalidAccessError, "'" + markName + "' is empty: either the event hasn't happened yet, or it would provide cross-o rigin timing information.");
134 return 0.0; 135 return 0.0;
135 } 136 }
136 return value - m_performance->timing()->navigationStart(); 137 return value - m_performance->timing()->navigationStart();
137 } 138 }
138 139
139 exceptionState.throwDOMException(SyntaxError, "The mark '" + markName + "' d oes not exist."); 140 exceptionState.throwDOMException(SyntaxError, "The mark '" + markName + "' d oes not exist.");
140 return 0.0; 141 return 0.0;
141 } 142 }
142 143
143 void UserTiming::measure(const String& measureName, const String& startMark, con st String& endMark, ExceptionState& exceptionState) 144 void UserTiming::measure(const String& measureName, const String& startMark, con st String& endMark, NewPerformanceEntryCallback callback, ExceptionState& except ionState)
144 { 145 {
145 double startTime = 0.0; 146 double startTime = 0.0;
146 double endTime = 0.0; 147 double endTime = 0.0;
147 148
148 if (startMark.isNull()) 149 if (startMark.isNull())
149 endTime = m_performance->now(); 150 endTime = m_performance->now();
150 else if (endMark.isNull()) { 151 else if (endMark.isNull()) {
151 endTime = m_performance->now(); 152 endTime = m_performance->now();
152 startTime = findExistingMarkStartTime(startMark, exceptionState); 153 startTime = findExistingMarkStartTime(startMark, exceptionState);
153 if (exceptionState.hadException()) 154 if (exceptionState.hadException())
154 return; 155 return;
155 } else { 156 } else {
156 endTime = findExistingMarkStartTime(endMark, exceptionState); 157 endTime = findExistingMarkStartTime(endMark, exceptionState);
157 if (exceptionState.hadException()) 158 if (exceptionState.hadException())
158 return; 159 return;
159 startTime = findExistingMarkStartTime(startMark, exceptionState); 160 startTime = findExistingMarkStartTime(startMark, exceptionState);
160 if (exceptionState.hadException()) 161 if (exceptionState.hadException())
161 return; 162 return;
162 } 163 }
163 164
164 // User timing events are stored as integer milliseconds from the start of 165 // User timing events are stored as integer milliseconds from the start of
165 // navigation, whereas trace events accept double seconds based off of 166 // navigation, whereas trace events accept double seconds based off of
166 // CurrentTime::monotonicallyIncreasingTime(). 167 // CurrentTime::monotonicallyIncreasingTime().
167 double startTimeMonotonic = m_performance->timeOrigin() + startTime / 1000.0 ; 168 double startTimeMonotonic = m_performance->timeOrigin() + startTime / 1000.0 ;
168 double endTimeMonotonic = m_performance->timeOrigin() + endTime / 1000.0; 169 double endTimeMonotonic = m_performance->timeOrigin() + endTime / 1000.0;
169 170
170 TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0("blink.user_timing", m easureName.utf8().data(), WTF::StringHash::hash(measureName), startTimeMonotonic ); 171 TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0("blink.user_timing", m easureName.utf8().data(), WTF::StringHash::hash(measureName), startTimeMonotonic );
171 TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0("blink.user_timing", mea sureName.utf8().data(), WTF::StringHash::hash(measureName), endTimeMonotonic); 172 TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0("blink.user_timing", mea sureName.utf8().data(), WTF::StringHash::hash(measureName), endTimeMonotonic);
172 173
173 insertPerformanceEntry(m_measuresMap, PerformanceMeasure::create(measureName , startTime, endTime)); 174 insertPerformanceEntry(m_measuresMap, callback, PerformanceMeasure::create(m easureName, startTime, endTime));
174 if (endTime >= startTime) 175 if (endTime >= startTime)
175 Platform::current()->histogramCustomCounts("PLT.UserTiming_MeasureDurati on", static_cast<int>(endTime - startTime), 0, 600000, 100); 176 Platform::current()->histogramCustomCounts("PLT.UserTiming_MeasureDurati on", static_cast<int>(endTime - startTime), 0, 600000, 100);
176 } 177 }
177 178
178 void UserTiming::clearMeasures(const String& measureName) 179 void UserTiming::clearMeasures(const String& measureName)
179 { 180 {
180 clearPeformanceEntries(m_measuresMap, measureName); 181 clearPeformanceEntries(m_measuresMap, measureName);
181 } 182 }
182 183
183 static PerformanceEntryVector convertToEntrySequence(const PerformanceEntryMap& performanceEntryMap) 184 static PerformanceEntryVector convertToEntrySequence(const PerformanceEntryMap& performanceEntryMap)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 223 }
223 224
224 DEFINE_TRACE(UserTiming) 225 DEFINE_TRACE(UserTiming)
225 { 226 {
226 visitor->trace(m_performance); 227 visitor->trace(m_performance);
227 visitor->trace(m_marksMap); 228 visitor->trace(m_marksMap);
228 visitor->trace(m_measuresMap); 229 visitor->trace(m_measuresMap);
229 } 230 }
230 231
231 } // namespace blink 232 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698