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

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: Code review comments Created 5 years, 3 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
« no previous file with comments | « Source/core/timing/PerformanceUserTiming.h ('k') | Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 const RestrictedKeyMap& restrictedKeyMap() 71 const RestrictedKeyMap& restrictedKeyMap()
72 { 72 {
73 AtomicallyInitializedStaticReference(RestrictedKeyMap, map, createRestricted KeyMap()); 73 AtomicallyInitializedStaticReference(RestrictedKeyMap, map, createRestricted KeyMap());
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, Per formanceEntry& entry)
85 { 85 {
86 PerformanceEntryMap::iterator it = performanceEntryMap.find(entry->name()); 86 PerformanceEntryMap::iterator it = performanceEntryMap.find(entry.name());
87 if (it != performanceEntryMap.end()) { 87 if (it != performanceEntryMap.end()) {
88 it->value.append(entry); 88 it->value.append(&entry);
89 } else { 89 } else {
90 PerformanceEntryVector vector(1); 90 PerformanceEntryVector vector(1);
91 vector[0] = entry; 91 vector[0] = Member<PerformanceEntry>(entry);
92 performanceEntryMap.set(entry->name(), vector); 92 performanceEntryMap.set(entry.name(), vector);
93 } 93 }
94 } 94 }
95 95
96 static void clearPeformanceEntries(PerformanceEntryMap& performanceEntryMap, con st String& name) 96 static void clearPeformanceEntries(PerformanceEntryMap& performanceEntryMap, con st String& name)
97 { 97 {
98 if (name.isNull()) { 98 if (name.isNull()) {
99 performanceEntryMap.clear(); 99 performanceEntryMap.clear();
100 return; 100 return;
101 } 101 }
102 102
103 if (performanceEntryMap.contains(name)) 103 if (performanceEntryMap.contains(name))
104 performanceEntryMap.remove(name); 104 performanceEntryMap.remove(name);
105 } 105 }
106 106
107 void UserTiming::mark(const String& markName, ExceptionState& exceptionState) 107 PerformanceEntry* UserTiming::mark(const String& markName, ExceptionState& excep tionState)
108 { 108 {
109 if (restrictedKeyMap().contains(markName)) { 109 if (restrictedKeyMap().contains(markName)) {
110 exceptionState.throwDOMException(SyntaxError, "'" + markName + "' is par t of the PerformanceTiming interface, and cannot be used as a mark name."); 110 exceptionState.throwDOMException(SyntaxError, "'" + markName + "' is par t of the PerformanceTiming interface, and cannot be used as a mark name.");
111 return; 111 return nullptr;
112 } 112 }
113 113
114 TRACE_EVENT_COPY_MARK("blink.user_timing", markName.utf8().data()); 114 TRACE_EVENT_COPY_MARK("blink.user_timing", markName.utf8().data());
115 double startTime = m_performance->now(); 115 double startTime = m_performance->now();
116 insertPerformanceEntry(m_marksMap, PerformanceMark::create(markName, startTi me)); 116 PerformanceEntry* entry = PerformanceMark::create(markName, startTime);
117 insertPerformanceEntry(m_marksMap, *entry);
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);
119 return entry;
118 } 120 }
119 121
120 void UserTiming::clearMarks(const String& markName) 122 void UserTiming::clearMarks(const String& markName)
121 { 123 {
122 clearPeformanceEntries(m_marksMap, markName); 124 clearPeformanceEntries(m_marksMap, markName);
123 } 125 }
124 126
125 double UserTiming::findExistingMarkStartTime(const String& markName, ExceptionSt ate& exceptionState) 127 double UserTiming::findExistingMarkStartTime(const String& markName, ExceptionSt ate& exceptionState)
126 { 128 {
127 if (m_marksMap.contains(markName)) 129 if (m_marksMap.contains(markName))
128 return m_marksMap.get(markName).last()->startTime(); 130 return m_marksMap.get(markName).last()->startTime();
129 131
130 if (restrictedKeyMap().contains(markName) && m_performance->timing()) { 132 if (restrictedKeyMap().contains(markName) && m_performance->timing()) {
131 double value = static_cast<double>((m_performance->timing()->*(restricte dKeyMap().get(markName)))()); 133 double value = static_cast<double>((m_performance->timing()->*(restricte dKeyMap().get(markName)))());
132 if (!value) { 134 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."); 135 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; 136 return 0.0;
135 } 137 }
136 return value - m_performance->timing()->navigationStart(); 138 return value - m_performance->timing()->navigationStart();
137 } 139 }
138 140
139 exceptionState.throwDOMException(SyntaxError, "The mark '" + markName + "' d oes not exist."); 141 exceptionState.throwDOMException(SyntaxError, "The mark '" + markName + "' d oes not exist.");
140 return 0.0; 142 return 0.0;
141 } 143 }
142 144
143 void UserTiming::measure(const String& measureName, const String& startMark, con st String& endMark, ExceptionState& exceptionState) 145 PerformanceEntry* UserTiming::measure(const String& measureName, const String& s tartMark, const String& endMark, ExceptionState& exceptionState)
144 { 146 {
145 double startTime = 0.0; 147 double startTime = 0.0;
146 double endTime = 0.0; 148 double endTime = 0.0;
147 149
148 if (startMark.isNull()) { 150 if (startMark.isNull()) {
149 endTime = m_performance->now(); 151 endTime = m_performance->now();
150 } else if (endMark.isNull()) { 152 } else if (endMark.isNull()) {
151 endTime = m_performance->now(); 153 endTime = m_performance->now();
152 startTime = findExistingMarkStartTime(startMark, exceptionState); 154 startTime = findExistingMarkStartTime(startMark, exceptionState);
153 if (exceptionState.hadException()) 155 if (exceptionState.hadException())
154 return; 156 return nullptr;
155 } else { 157 } else {
156 endTime = findExistingMarkStartTime(endMark, exceptionState); 158 endTime = findExistingMarkStartTime(endMark, exceptionState);
157 if (exceptionState.hadException()) 159 if (exceptionState.hadException())
158 return; 160 return nullptr;
159 startTime = findExistingMarkStartTime(startMark, exceptionState); 161 startTime = findExistingMarkStartTime(startMark, exceptionState);
160 if (exceptionState.hadException()) 162 if (exceptionState.hadException())
161 return; 163 return nullptr;
162 } 164 }
163 165
164 // User timing events are stored as integer milliseconds from the start of 166 // User timing events are stored as integer milliseconds from the start of
165 // navigation, whereas trace events accept double seconds based off of 167 // navigation, whereas trace events accept double seconds based off of
166 // CurrentTime::monotonicallyIncreasingTime(). 168 // CurrentTime::monotonicallyIncreasingTime().
167 double startTimeMonotonic = m_performance->timeOrigin() + startTime / 1000.0 ; 169 double startTimeMonotonic = m_performance->timeOrigin() + startTime / 1000.0 ;
168 double endTimeMonotonic = m_performance->timeOrigin() + endTime / 1000.0; 170 double endTimeMonotonic = m_performance->timeOrigin() + endTime / 1000.0;
169 171
170 TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0("blink.user_timing", m easureName.utf8().data(), WTF::StringHash::hash(measureName), startTimeMonotonic ); 172 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); 173 TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0("blink.user_timing", mea sureName.utf8().data(), WTF::StringHash::hash(measureName), endTimeMonotonic);
172 174
173 insertPerformanceEntry(m_measuresMap, PerformanceMeasure::create(measureName , startTime, endTime)); 175 PerformanceEntry* entry = PerformanceMeasure::create(measureName, startTime, endTime);
176 insertPerformanceEntry(m_measuresMap, *entry);
174 if (endTime >= startTime) 177 if (endTime >= startTime)
175 Platform::current()->histogramCustomCounts("PLT.UserTiming_MeasureDurati on", static_cast<int>(endTime - startTime), 0, 600000, 100); 178 Platform::current()->histogramCustomCounts("PLT.UserTiming_MeasureDurati on", static_cast<int>(endTime - startTime), 0, 600000, 100);
179 return entry;
176 } 180 }
177 181
178 void UserTiming::clearMeasures(const String& measureName) 182 void UserTiming::clearMeasures(const String& measureName)
179 { 183 {
180 clearPeformanceEntries(m_measuresMap, measureName); 184 clearPeformanceEntries(m_measuresMap, measureName);
181 } 185 }
182 186
183 static PerformanceEntryVector convertToEntrySequence(const PerformanceEntryMap& performanceEntryMap) 187 static PerformanceEntryVector convertToEntrySequence(const PerformanceEntryMap& performanceEntryMap)
184 { 188 {
185 PerformanceEntryVector entries; 189 PerformanceEntryVector entries;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 226 }
223 227
224 DEFINE_TRACE(UserTiming) 228 DEFINE_TRACE(UserTiming)
225 { 229 {
226 visitor->trace(m_performance); 230 visitor->trace(m_performance);
227 visitor->trace(m_marksMap); 231 visitor->trace(m_marksMap);
228 visitor->trace(m_measuresMap); 232 visitor->trace(m_measuresMap);
229 } 233 }
230 234
231 } // namespace blink 235 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/timing/PerformanceUserTiming.h ('k') | Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698