Chromium Code Reviews| Index: third_party/WebKit/Source/core/frame/UseCounter.cpp |
| diff --git a/third_party/WebKit/Source/core/frame/UseCounter.cpp b/third_party/WebKit/Source/core/frame/UseCounter.cpp |
| index f7795822618707a81251a9c02d3516ced8d92409..820dd15885b577e0aeb8d155bfb7d58a3cc21c0a 100644 |
| --- a/third_party/WebKit/Source/core/frame/UseCounter.cpp |
| +++ b/third_party/WebKit/Source/core/frame/UseCounter.cpp |
| @@ -43,10 +43,8 @@ static int totalPagesMeasuredCSSSampleId() { return 1; } |
| int UseCounter::m_muteCount = 0; |
| -int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id) |
| +int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID cssPropertyID) |
| { |
| - CSSPropertyID cssPropertyID = static_cast<CSSPropertyID>(id); |
| - |
| switch (cssPropertyID) { |
| // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId. |
| case CSSPropertyColor: return 2; |
| @@ -580,12 +578,17 @@ int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id) |
| return 0; |
| } |
| - |
| static int maximumCSSSampleId() { return 535; } |
| -static EnumerationHistogram& featureObserverHistogram() |
| +static EnumerationHistogram& useCounterHistogram() |
| { |
| - DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserver", UseCounter::NumberOfFeatures)); |
| + DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.UseCounter", UseCounter::NumberOfFeatures)); |
| + return histogram; |
| +} |
| + |
| +static EnumerationHistogram& CSSUseCounterHistogram() |
| +{ |
| + DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.UseCounter.CSSProperties", maximumCSSSampleId())); |
| return histogram; |
| } |
| @@ -599,60 +602,6 @@ void UseCounter::unmuteForInspector() |
| UseCounter::m_muteCount--; |
| } |
| -UseCounter::UseCounter() |
| -{ |
| - m_CSSFeatureBits.ensureSize(lastUnresolvedCSSProperty + 1); |
| - m_CSSFeatureBits.clearAll(); |
| -} |
| - |
| -UseCounter::~UseCounter() |
| -{ |
| - // We always log PageDestruction so that we have a scale for the rest of the features. |
| - featureObserverHistogram().count(PageDestruction); |
| - |
| - updateMeasurements(); |
| -} |
| - |
| -void UseCounter::CountBits::updateMeasurements() |
| -{ |
| - EnumerationHistogram& featureHistogram = featureObserverHistogram(); |
| - for (unsigned i = 0; i < NumberOfFeatures; ++i) { |
| - if (m_bits.quickGet(i)) |
| - featureHistogram.count(i); |
| - } |
| - // Clearing count bits is timing sensitive. |
| - m_bits.clearAll(); |
| -} |
| - |
| -void UseCounter::updateMeasurements() |
| -{ |
| - featureObserverHistogram().count(PageVisits); |
| - m_countBits.updateMeasurements(); |
| - |
| - // FIXME: Sometimes this function is called more than once per page. The following |
| - // bool guards against incrementing the page count when there are no CSS |
| - // bits set. https://crbug.com/236262. |
| - DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore.FeatureObserver.CSSProperties", maximumCSSSampleId())); |
| - bool needsPagesMeasuredUpdate = false; |
| - for (int i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) { |
| - if (m_CSSFeatureBits.quickGet(i)) { |
| - int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(i); |
| - cssPropertiesHistogram.count(cssSampleId); |
| - needsPagesMeasuredUpdate = true; |
| - } |
| - } |
| - |
| - if (needsPagesMeasuredUpdate) |
| - cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
| - |
| - m_CSSFeatureBits.clearAll(); |
| -} |
| - |
| -void UseCounter::didCommitLoad() |
| -{ |
| - updateMeasurements(); |
| -} |
| - |
| void UseCounter::count(const Frame* frame, Feature feature) |
| { |
| if (!frame) |
| @@ -683,9 +632,29 @@ bool UseCounter::isCounted(Document& document, Feature feature) |
| bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) |
| { |
| - return m_CSSFeatureBits.quickGet(unresolvedProperty); |
| + return m_CSSFeaturesReported.quickGet(unresolvedProperty); |
| } |
| +void UseCounter::didCommitLoad() |
| +{ |
| + m_featuresReported.clearAll(); |
| + useCounterHistogram().count(PageVisits); |
|
dtapuska
2016/05/31 01:10:51
Are you explicitly counting here even though muted
|
| + |
| + m_CSSFeaturesReported.clearAll(); |
| + CSSUseCounterHistogram().count(totalPagesMeasuredCSSSampleId()); |
| +} |
| + |
| +void UseCounter::recordMeasurement(Feature feature) |
| +{ |
| + if (UseCounter::m_muteCount) |
| + return; |
| + |
| + if (!m_featuresReported.quickGet(feature)) { |
| + m_featuresReported.quickSet(feature); |
| + useCounterHistogram().count(feature); |
| + } |
| + m_legacyCounter.recordMeasurement(feature); |
| +} |
| bool UseCounter::isCounted(Document& document, const String& string) |
| { |
| @@ -750,7 +719,11 @@ void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID feature) |
| if (!isUseCounterEnabledForMode(cssParserMode)) |
| return; |
| - m_CSSFeatureBits.quickSet(feature); |
| + if (!m_CSSFeaturesReported.quickGet(feature)) { |
| + m_CSSFeaturesReported.quickSet(feature); |
| + CSSUseCounterHistogram().count(mapCSSPropertyIdToCSSSampleIdForHistogram(feature)); |
| + } |
| + m_legacyCounter.countCSS(feature); |
| } |
| void UseCounter::count(Feature feature) |
| @@ -782,4 +755,83 @@ UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) |
| return 0; |
| } |
| +/* |
| + * |
| + * LEGACY metrics support - WebCore.FeatureObserver is to be superceded by WebCore.UseCounter |
| + * |
| + */ |
| + |
| +static EnumerationHistogram& featureObserverHistogram() |
| +{ |
| + DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserver", UseCounter::NumberOfFeatures)); |
| + return histogram; |
| +} |
| + |
| +UseCounter::LegacyCounter::LegacyCounter() |
| + : m_countBits(NumberOfFeatures) |
| + , m_CSSFeatureBits(lastUnresolvedCSSProperty + 1) |
| +{ |
| +} |
| + |
| +UseCounter::LegacyCounter::~LegacyCounter() |
| +{ |
| + // We always log PageDestruction so that we have a scale for the rest of the features. |
| + featureObserverHistogram().count(PageDestruction); |
| + updateMeasurements(); |
| +} |
| + |
| +void UseCounter::LegacyCounter::recordMeasurement(Feature feature) |
| +{ |
| + DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scaling factor. |
| + DCHECK(feature < NumberOfFeatures); |
| + |
| + m_countBits.quickSet(feature); |
| +} |
| + |
| +void UseCounter::LegacyCounter::updateMeasurements() |
| +{ |
| + EnumerationHistogram& featureHistogram = featureObserverHistogram(); |
| + featureHistogram.count(PageVisits); |
| + for (unsigned i = 0; i < NumberOfFeatures; ++i) { |
| + if (m_countBits.quickGet(i)) |
| + featureHistogram.count(i); |
| + } |
| + // Clearing count bits is timing sensitive. |
| + m_countBits.clearAll(); |
| + |
| + // FIXME: Sometimes this function is called more than once per page. The following |
| + // bool guards against incrementing the page count when there are no CSS |
| + // bits set. https://crbug.com/236262. |
| + DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore.FeatureObserver.CSSProperties", maximumCSSSampleId())); |
| + bool needsPagesMeasuredUpdate = false; |
| + for (int i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) { |
| + if (m_CSSFeatureBits.quickGet(i)) { |
| + int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(static_cast<CSSPropertyID>(i)); |
| + cssPropertiesHistogram.count(cssSampleId); |
| + needsPagesMeasuredUpdate = true; |
| + } |
| + } |
| + |
| + if (needsPagesMeasuredUpdate) |
| + cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
| + |
| + m_CSSFeatureBits.clearAll(); |
| +} |
| + |
| +bool UseCounter::LegacyCounter::hasRecordedMeasurement(Feature feature) const |
| +{ |
| + if (UseCounter::m_muteCount) |
| + return false; |
| + DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scaling factor. |
| + DCHECK(feature < NumberOfFeatures); |
| + |
| + return m_countBits.quickGet(feature); |
| +} |
| + |
| +void UseCounter::LegacyCounter::countCSS(CSSPropertyID feature) |
| +{ |
| + m_CSSFeatureBits.quickSet(feature); |
| +} |
| + |
| + |
| } // namespace blink |