| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google, Inc. All rights reserved. | 2 * Copyright (C) 2012 Google, 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 19 matching lines...) Expand all Loading... |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/ExecutionContext.h" | 31 #include "core/dom/ExecutionContext.h" |
| 32 #include "core/frame/Deprecation.h" | 32 #include "core/frame/Deprecation.h" |
| 33 #include "core/frame/FrameConsole.h" | 33 #include "core/frame/FrameConsole.h" |
| 34 #include "core/frame/FrameHost.h" | 34 #include "core/frame/FrameHost.h" |
| 35 #include "core/frame/LocalFrame.h" | 35 #include "core/frame/LocalFrame.h" |
| 36 #include "core/inspector/ConsoleMessage.h" | 36 #include "core/inspector/ConsoleMessage.h" |
| 37 #include "core/workers/WorkerOrWorkletGlobalScope.h" | 37 #include "core/workers/WorkerOrWorkletGlobalScope.h" |
| 38 #include "platform/Histogram.h" | 38 #include "platform/Histogram.h" |
| 39 #include "platform/instrumentation/tracing/TraceEvent.h" | 39 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 40 #include "platform/weborigin/SchemeRegistry.h" |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 int totalPagesMeasuredCSSSampleId() { | 44 int totalPagesMeasuredCSSSampleId() { |
| 44 return 1; | 45 return 1; |
| 45 } | 46 } |
| 46 | 47 |
| 47 // Make sure update_use_counter_css.py was run which updates histograms.xml. | 48 // Make sure update_use_counter_css.py was run which updates histograms.xml. |
| 48 constexpr int kMaximumCSSSampleId = 549; | 49 constexpr int kMaximumCSSSampleId = 549; |
| 49 | 50 |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 ASSERT_NOT_REACHED(); | 1077 ASSERT_NOT_REACHED(); |
| 1077 return 0; | 1078 return 0; |
| 1078 } | 1079 } |
| 1079 | 1080 |
| 1080 ASSERT_NOT_REACHED(); | 1081 ASSERT_NOT_REACHED(); |
| 1081 return 0; | 1082 return 0; |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 UseCounter::UseCounter(Context context) | 1085 UseCounter::UseCounter(Context context) |
| 1085 : m_muteCount(0), | 1086 : m_muteCount(0), |
| 1087 m_disableReporting(false), |
| 1086 m_context(context), | 1088 m_context(context), |
| 1087 m_featuresRecorded(NumberOfFeatures), | 1089 m_featuresRecorded(NumberOfFeatures), |
| 1088 m_CSSRecorded(lastUnresolvedCSSProperty + 1) {} | 1090 m_CSSRecorded(lastUnresolvedCSSProperty + 1) {} |
| 1089 | 1091 |
| 1090 void UseCounter::muteForInspector() { | 1092 void UseCounter::muteForInspector() { |
| 1091 m_muteCount++; | 1093 m_muteCount++; |
| 1092 } | 1094 } |
| 1093 | 1095 |
| 1094 void UseCounter::unmuteForInspector() { | 1096 void UseCounter::unmuteForInspector() { |
| 1095 m_muteCount--; | 1097 m_muteCount--; |
| 1096 } | 1098 } |
| 1097 | 1099 |
| 1098 void UseCounter::recordMeasurement(Feature feature) { | 1100 void UseCounter::recordMeasurement(Feature feature) { |
| 1099 if (m_muteCount) | 1101 if (m_muteCount) |
| 1100 return; | 1102 return; |
| 1101 | 1103 |
| 1102 DCHECK(feature != OBSOLETE_PageDestruction && | 1104 DCHECK(feature != OBSOLETE_PageDestruction && |
| 1103 feature != | 1105 feature != |
| 1104 PageVisits); // PageDestruction is reserved as a scaling factor. | 1106 PageVisits); // PageDestruction is reserved as a scaling factor. |
| 1105 DCHECK(feature < NumberOfFeatures); | 1107 DCHECK(feature < NumberOfFeatures); |
| 1106 | 1108 |
| 1107 if (!m_featuresRecorded.quickGet(feature)) { | 1109 if (!m_featuresRecorded.quickGet(feature)) { |
| 1108 // Note that HTTPArchive tooling looks specifically for this event - see | 1110 // Note that HTTPArchive tooling looks specifically for this event - see |
| 1109 // https://github.com/HTTPArchive/httparchive/issues/59 | 1111 // https://github.com/HTTPArchive/httparchive/issues/59 |
| 1110 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), | 1112 if (!m_disableReporting) { |
| 1111 "FeatureFirstUsed", "feature", feature); | 1113 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
| 1112 featuresHistogram().count(feature); | 1114 "FeatureFirstUsed", "feature", feature); |
| 1115 featuresHistogram().count(feature); |
| 1116 } |
| 1113 m_featuresRecorded.quickSet(feature); | 1117 m_featuresRecorded.quickSet(feature); |
| 1114 } | 1118 } |
| 1115 m_legacyCounter.countFeature(feature); | 1119 m_legacyCounter.countFeature(feature); |
| 1116 } | 1120 } |
| 1117 | 1121 |
| 1118 bool UseCounter::hasRecordedMeasurement(Feature feature) const { | 1122 bool UseCounter::hasRecordedMeasurement(Feature feature) const { |
| 1119 if (m_muteCount) | 1123 if (m_muteCount) |
| 1120 return false; | 1124 return false; |
| 1121 | 1125 |
| 1122 DCHECK(feature != OBSOLETE_PageDestruction && | 1126 DCHECK(feature != OBSOLETE_PageDestruction && |
| 1123 feature != | 1127 feature != |
| 1124 PageVisits); // PageDestruction is reserved as a scaling factor. | 1128 PageVisits); // PageDestruction is reserved as a scaling factor. |
| 1125 DCHECK(feature < NumberOfFeatures); | 1129 DCHECK(feature < NumberOfFeatures); |
| 1126 | 1130 |
| 1127 return m_featuresRecorded.quickGet(feature); | 1131 return m_featuresRecorded.quickGet(feature); |
| 1128 } | 1132 } |
| 1129 | 1133 |
| 1130 void UseCounter::didCommitLoad() { | 1134 void UseCounter::didCommitLoad(KURL url) { |
| 1131 m_legacyCounter.updateMeasurements(); | 1135 m_legacyCounter.updateMeasurements(); |
| 1132 | 1136 |
| 1133 // TODO: Is didCommitLoad really the right time to do this? crbug.com/608040 | 1137 // Reset state from previous load. |
| 1138 m_disableReporting = false; |
| 1139 |
| 1140 // Use the protocol of the document being loaded into the main frame to |
| 1141 // decide whether this page is interesting from a metrics perspective. |
| 1142 // Note that SVGImage cases always have an about:blank URL |
| 1143 if (m_context == DefaultContext && |
| 1144 !SchemeRegistry::shouldTrackUsageMetricsForScheme(url.protocol())) { |
| 1145 m_disableReporting = true; |
| 1146 } |
| 1147 |
| 1134 m_featuresRecorded.clearAll(); | 1148 m_featuresRecorded.clearAll(); |
| 1135 featuresHistogram().count(PageVisits); | |
| 1136 m_CSSRecorded.clearAll(); | 1149 m_CSSRecorded.clearAll(); |
| 1137 cssHistogram().count(totalPagesMeasuredCSSSampleId()); | 1150 if (!m_disableReporting && !m_muteCount) { |
| 1151 featuresHistogram().count(PageVisits); |
| 1152 cssHistogram().count(totalPagesMeasuredCSSSampleId()); |
| 1153 } |
| 1138 } | 1154 } |
| 1139 | 1155 |
| 1140 void UseCounter::count(const Frame* frame, Feature feature) { | 1156 void UseCounter::count(const Frame* frame, Feature feature) { |
| 1141 if (!frame) | 1157 if (!frame) |
| 1142 return; | 1158 return; |
| 1143 FrameHost* host = frame->host(); | 1159 FrameHost* host = frame->host(); |
| 1144 if (!host) | 1160 if (!host) |
| 1145 return; | 1161 return; |
| 1146 | 1162 |
| 1147 host->useCounter().count(feature); | 1163 host->useCounter().count(feature); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID property) { | 1216 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID property) { |
| 1201 DCHECK(isCSSPropertyIDWithName(property)); | 1217 DCHECK(isCSSPropertyIDWithName(property)); |
| 1202 | 1218 |
| 1203 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) | 1219 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) |
| 1204 return; | 1220 return; |
| 1205 | 1221 |
| 1206 if (!m_CSSRecorded.quickGet(property)) { | 1222 if (!m_CSSRecorded.quickGet(property)) { |
| 1207 // Note that HTTPArchive tooling looks specifically for this event - see | 1223 // Note that HTTPArchive tooling looks specifically for this event - see |
| 1208 // https://github.com/HTTPArchive/httparchive/issues/59 | 1224 // https://github.com/HTTPArchive/httparchive/issues/59 |
| 1209 int sampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(property); | 1225 int sampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(property); |
| 1210 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), | 1226 if (!m_disableReporting) { |
| 1211 "CSSFirstUsed", "feature", sampleId); | 1227 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
| 1212 cssHistogram().count(sampleId); | 1228 "CSSFirstUsed", "feature", sampleId); |
| 1229 cssHistogram().count(sampleId); |
| 1230 } |
| 1213 m_CSSRecorded.quickSet(property); | 1231 m_CSSRecorded.quickSet(property); |
| 1214 } | 1232 } |
| 1215 m_legacyCounter.countCSS(property); | 1233 m_legacyCounter.countCSS(property); |
| 1216 } | 1234 } |
| 1217 | 1235 |
| 1218 void UseCounter::count(Feature feature) { | 1236 void UseCounter::count(Feature feature) { |
| 1219 DCHECK(Deprecation::deprecationMessage(feature).isEmpty()); | 1237 DCHECK(Deprecation::deprecationMessage(feature).isEmpty()); |
| 1220 recordMeasurement(feature); | 1238 recordMeasurement(feature); |
| 1221 } | 1239 } |
| 1222 | 1240 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1234 | 1252 |
| 1235 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) { | 1253 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) { |
| 1236 // FIXME: We may want to handle stylesheets that have multiple owners | 1254 // FIXME: We may want to handle stylesheets that have multiple owners |
| 1237 // https://crbug.com/242125 | 1255 // https://crbug.com/242125 |
| 1238 if (sheetContents && sheetContents->hasSingleOwnerNode()) | 1256 if (sheetContents && sheetContents->hasSingleOwnerNode()) |
| 1239 return getFrom(sheetContents->singleOwnerDocument()); | 1257 return getFrom(sheetContents->singleOwnerDocument()); |
| 1240 return 0; | 1258 return 0; |
| 1241 } | 1259 } |
| 1242 | 1260 |
| 1243 EnumerationHistogram& UseCounter::featuresHistogram() const { | 1261 EnumerationHistogram& UseCounter::featuresHistogram() const { |
| 1244 // TODO(rbyers): Fix the SVG case. crbug.com/236262 | 1262 // Every SVGImage has it's own Page instance, and multiple web pages can |
| 1245 // Eg. every SVGImage has it's own Page instance, they should probably all be | 1263 // share the usage of a single SVGImage. Ideally perhaps we'd delegate |
| 1246 // delegating their UseCounter to the containing Page. For now just use a | 1264 // metrics from an SVGImage to one of the Page's it's displayed in, but |
| 1247 // separate histogram. | 1265 // that's tricky (SVGImage is intentionally isolated, and the Page that |
| 1266 // created it may not even exist anymore). |
| 1267 // So instead we just use a dedicated histogram for the SVG case. |
| 1248 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, | 1268 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, |
| 1249 ("WebCore.UseCounter_TEST.Features", | 1269 ("WebCore.UseCounter_TEST.Features", |
| 1250 blink::UseCounter::NumberOfFeatures)); | 1270 blink::UseCounter::NumberOfFeatures)); |
| 1251 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svgHistogram, | 1271 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svgHistogram, |
| 1252 ("WebCore.UseCounter_TEST.SVGImage.Features", | 1272 ("WebCore.UseCounter_TEST.SVGImage.Features", |
| 1253 blink::UseCounter::NumberOfFeatures)); | 1273 blink::UseCounter::NumberOfFeatures)); |
| 1254 | 1274 |
| 1255 return m_context == SVGImageContext ? svgHistogram : histogram; | 1275 return m_context == SVGImageContext ? svgHistogram : histogram; |
| 1256 } | 1276 } |
| 1257 | 1277 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 } | 1345 } |
| 1326 } | 1346 } |
| 1327 | 1347 |
| 1328 if (needsPagesMeasuredUpdate) | 1348 if (needsPagesMeasuredUpdate) |
| 1329 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | 1349 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
| 1330 | 1350 |
| 1331 m_CSSBits.clearAll(); | 1351 m_CSSBits.clearAll(); |
| 1332 } | 1352 } |
| 1333 | 1353 |
| 1334 } // namespace blink | 1354 } // namespace blink |
| OLD | NEW |