| 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 27 matching lines...) Expand all Loading... |
| 38 #include "platform/Histogram.h" | 38 #include "platform/Histogram.h" |
| 39 #include "platform/TraceEvent.h" | 39 #include "platform/TraceEvent.h" |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 int totalPagesMeasuredCSSSampleId() { return 1; } | 43 int totalPagesMeasuredCSSSampleId() { return 1; } |
| 44 | 44 |
| 45 // Make sure update_use_counter_css.py was run which updates histograms.xml. | 45 // Make sure update_use_counter_css.py was run which updates histograms.xml. |
| 46 int maximumCSSSampleId() { return 539; } | 46 int maximumCSSSampleId() { return 539; } |
| 47 | 47 |
| 48 blink::EnumerationHistogram& useCounterHistogram() | |
| 49 { | |
| 50 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, ("WebCore.UseCou
nter_TEST.Features", blink::UseCounter::NumberOfFeatures)); | |
| 51 return histogram; | |
| 52 } | |
| 53 | |
| 54 blink::EnumerationHistogram& CSSUseCounterHistogram() | |
| 55 { | |
| 56 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, ("WebCore.UseCou
nter_TEST.CSSProperties", maximumCSSSampleId())); | |
| 57 return histogram; | |
| 58 } | |
| 59 | |
| 60 } // namespace | 48 } // namespace |
| 61 | 49 |
| 62 namespace blink { | 50 namespace blink { |
| 63 | 51 |
| 64 int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID cssPrope
rtyID) | 52 int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID cssPrope
rtyID) |
| 65 { | 53 { |
| 66 switch (cssPropertyID) { | 54 switch (cssPropertyID) { |
| 67 // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId. | 55 // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId. |
| 68 case CSSPropertyColor: return 2; | 56 case CSSPropertyColor: return 2; |
| 69 case CSSPropertyDirection: return 3; | 57 case CSSPropertyDirection: return 3; |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 579 |
| 592 case CSSPropertyInvalid: | 580 case CSSPropertyInvalid: |
| 593 ASSERT_NOT_REACHED(); | 581 ASSERT_NOT_REACHED(); |
| 594 return 0; | 582 return 0; |
| 595 } | 583 } |
| 596 | 584 |
| 597 ASSERT_NOT_REACHED(); | 585 ASSERT_NOT_REACHED(); |
| 598 return 0; | 586 return 0; |
| 599 } | 587 } |
| 600 | 588 |
| 601 UseCounter::UseCounter() | 589 UseCounter::UseCounter(Context context) |
| 602 : m_muteCount(0) | 590 : m_muteCount(0) |
| 591 , m_context(context) |
| 603 , m_featuresRecorded(NumberOfFeatures) | 592 , m_featuresRecorded(NumberOfFeatures) |
| 604 , m_CSSRecorded(lastUnresolvedCSSProperty + 1) | 593 , m_CSSRecorded(lastUnresolvedCSSProperty + 1) |
| 605 { | 594 { |
| 606 } | 595 } |
| 607 | 596 |
| 608 void UseCounter::muteForInspector() | 597 void UseCounter::muteForInspector() |
| 609 { | 598 { |
| 610 m_muteCount++; | 599 m_muteCount++; |
| 611 } | 600 } |
| 612 | 601 |
| 613 void UseCounter::unmuteForInspector() | 602 void UseCounter::unmuteForInspector() |
| 614 { | 603 { |
| 615 m_muteCount--; | 604 m_muteCount--; |
| 616 } | 605 } |
| 617 | 606 |
| 618 void UseCounter::recordMeasurement(Feature feature) | 607 void UseCounter::recordMeasurement(Feature feature) |
| 619 { | 608 { |
| 620 if (m_muteCount) | 609 if (m_muteCount) |
| 621 return; | 610 return; |
| 622 | 611 |
| 623 DCHECK(feature != OBSOLETE_PageDestruction && feature != PageVisits); // Pag
eDestruction is reserved as a scaling factor. | 612 DCHECK(feature != OBSOLETE_PageDestruction && feature != PageVisits); // Pag
eDestruction is reserved as a scaling factor. |
| 624 DCHECK(feature < NumberOfFeatures); | 613 DCHECK(feature < NumberOfFeatures); |
| 625 | 614 |
| 626 if (!m_featuresRecorded.quickGet(feature)) { | 615 if (!m_featuresRecorded.quickGet(feature)) { |
| 627 // Note that HTTPArchive tooling looks specifically for this event - see
https://github.com/HTTPArchive/httparchive/issues/59 | 616 // Note that HTTPArchive tooling looks specifically for this event - see
https://github.com/HTTPArchive/httparchive/issues/59 |
| 628 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "FeatureF
irstUsed", "feature", feature); | 617 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "FeatureF
irstUsed", "feature", feature); |
| 629 useCounterHistogram().count(feature); | 618 featuresHistogram().count(feature); |
| 630 m_featuresRecorded.quickSet(feature); | 619 m_featuresRecorded.quickSet(feature); |
| 631 } | 620 } |
| 632 m_legacyCounter.countFeature(feature); | 621 m_legacyCounter.countFeature(feature); |
| 633 } | 622 } |
| 634 | 623 |
| 635 bool UseCounter::hasRecordedMeasurement(Feature feature) const | 624 bool UseCounter::hasRecordedMeasurement(Feature feature) const |
| 636 { | 625 { |
| 637 if (m_muteCount) | 626 if (m_muteCount) |
| 638 return false; | 627 return false; |
| 639 | 628 |
| 640 DCHECK(feature != OBSOLETE_PageDestruction && feature != PageVisits); // Pag
eDestruction is reserved as a scaling factor. | 629 DCHECK(feature != OBSOLETE_PageDestruction && feature != PageVisits); // Pag
eDestruction is reserved as a scaling factor. |
| 641 DCHECK(feature < NumberOfFeatures); | 630 DCHECK(feature < NumberOfFeatures); |
| 642 | 631 |
| 643 return m_featuresRecorded.quickGet(feature); | 632 return m_featuresRecorded.quickGet(feature); |
| 644 } | 633 } |
| 645 | 634 |
| 646 void UseCounter::didCommitLoad() | 635 void UseCounter::didCommitLoad() |
| 647 { | 636 { |
| 648 // TODO(rbyers): This gets invoked more than expected. crbug.com/236262 | |
| 649 // Eg. every SVGImage has it's own Page instance, they should probably all b
e delegating | |
| 650 // their UseCounter to the containing Page. | |
| 651 m_legacyCounter.updateMeasurements(); | 637 m_legacyCounter.updateMeasurements(); |
| 652 | 638 |
| 653 // TODO: Is didCommitLoad really the right time to do this? crbug.com/60804
0 | 639 // TODO: Is didCommitLoad really the right time to do this? crbug.com/60804
0 |
| 654 m_featuresRecorded.clearAll(); | 640 m_featuresRecorded.clearAll(); |
| 655 useCounterHistogram().count(PageVisits); | 641 featuresHistogram().count(PageVisits); |
| 656 m_CSSRecorded.clearAll(); | 642 m_CSSRecorded.clearAll(); |
| 657 CSSUseCounterHistogram().count(totalPagesMeasuredCSSSampleId()); | 643 cssHistogram().count(totalPagesMeasuredCSSSampleId()); |
| 658 } | 644 } |
| 659 | 645 |
| 660 void UseCounter::count(const Frame* frame, Feature feature) | 646 void UseCounter::count(const Frame* frame, Feature feature) |
| 661 { | 647 { |
| 662 if (!frame) | 648 if (!frame) |
| 663 return; | 649 return; |
| 664 FrameHost* host = frame->host(); | 650 FrameHost* host = frame->host(); |
| 665 if (!host) | 651 if (!host) |
| 666 return; | 652 return; |
| 667 | 653 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 { | 734 { |
| 749 DCHECK(property >= firstCSSProperty); | 735 DCHECK(property >= firstCSSProperty); |
| 750 DCHECK(property <= lastUnresolvedCSSProperty); | 736 DCHECK(property <= lastUnresolvedCSSProperty); |
| 751 | 737 |
| 752 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) | 738 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) |
| 753 return; | 739 return; |
| 754 | 740 |
| 755 if (!m_CSSRecorded.quickGet(property)) { | 741 if (!m_CSSRecorded.quickGet(property)) { |
| 756 // Note that HTTPArchive tooling looks specifically for this event - see
https://github.com/HTTPArchive/httparchive/issues/59 | 742 // Note that HTTPArchive tooling looks specifically for this event - see
https://github.com/HTTPArchive/httparchive/issues/59 |
| 757 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "CSSFeatu
reFirstUsed", "feature", property); | 743 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "CSSFeatu
reFirstUsed", "feature", property); |
| 758 CSSUseCounterHistogram().count(mapCSSPropertyIdToCSSSampleIdForHistogram
(property)); | 744 cssHistogram().count(mapCSSPropertyIdToCSSSampleIdForHistogram(property)
); |
| 759 m_CSSRecorded.quickSet(property); | 745 m_CSSRecorded.quickSet(property); |
| 760 } | 746 } |
| 761 m_legacyCounter.countCSS(property); | 747 m_legacyCounter.countCSS(property); |
| 762 } | 748 } |
| 763 | 749 |
| 764 void UseCounter::count(Feature feature) | 750 void UseCounter::count(Feature feature) |
| 765 { | 751 { |
| 766 DCHECK(Deprecation::deprecationMessage(feature).isEmpty()); | 752 DCHECK(Deprecation::deprecationMessage(feature).isEmpty()); |
| 767 recordMeasurement(feature); | 753 recordMeasurement(feature); |
| 768 } | 754 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 783 | 769 |
| 784 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) | 770 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) |
| 785 { | 771 { |
| 786 // FIXME: We may want to handle stylesheets that have multiple owners | 772 // FIXME: We may want to handle stylesheets that have multiple owners |
| 787 // https://crbug.com/242125 | 773 // https://crbug.com/242125 |
| 788 if (sheetContents && sheetContents->hasSingleOwnerNode()) | 774 if (sheetContents && sheetContents->hasSingleOwnerNode()) |
| 789 return getFrom(sheetContents->singleOwnerDocument()); | 775 return getFrom(sheetContents->singleOwnerDocument()); |
| 790 return 0; | 776 return 0; |
| 791 } | 777 } |
| 792 | 778 |
| 779 EnumerationHistogram& UseCounter::featuresHistogram() const |
| 780 { |
| 781 // TODO(rbyers): Fix the SVG case. crbug.com/236262 |
| 782 // Eg. every SVGImage has it's own Page instance, they should probably all b
e delegating |
| 783 // their UseCounter to the containing Page. For now just use a separate his
togram. |
| 784 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, ("WebCore.UseCou
nter_TEST.Features", blink::UseCounter::NumberOfFeatures)); |
| 785 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svgHistogram, ("WebCore.Use
Counter_TEST.SVGImage.Features", blink::UseCounter::NumberOfFeatures)); |
| 786 |
| 787 return m_context == SVGImageContext ? svgHistogram : histogram; |
| 788 } |
| 789 |
| 790 EnumerationHistogram& UseCounter::cssHistogram() const |
| 791 { |
| 792 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, ("WebCore.UseCou
nter_TEST.CSSProperties", maximumCSSSampleId())); |
| 793 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svgHistogram, ("WebCore.Use
Counter_TEST.SVGImage.CSSProperties", maximumCSSSampleId())); |
| 794 |
| 795 return m_context == SVGImageContext ? svgHistogram : histogram; |
| 796 } |
| 797 |
| 793 /* | 798 /* |
| 794 * | 799 * |
| 795 * LEGACY metrics support - WebCore.FeatureObserver is to be superceded by WebCo
re.UseCounter | 800 * LEGACY metrics support - WebCore.FeatureObserver is to be superceded by WebCo
re.UseCounter |
| 796 * | 801 * |
| 797 */ | 802 */ |
| 798 | 803 |
| 799 static EnumerationHistogram& featureObserverHistogram() | 804 static EnumerationHistogram& featureObserverHistogram() |
| 800 { | 805 { |
| 801 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserv
er", UseCounter::NumberOfFeatures)); | 806 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserv
er", UseCounter::NumberOfFeatures)); |
| 802 return histogram; | 807 return histogram; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 } | 855 } |
| 851 } | 856 } |
| 852 | 857 |
| 853 if (needsPagesMeasuredUpdate) | 858 if (needsPagesMeasuredUpdate) |
| 854 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | 859 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
| 855 | 860 |
| 856 m_CSSBits.clearAll(); | 861 m_CSSBits.clearAll(); |
| 857 } | 862 } |
| 858 | 863 |
| 859 } // namespace blink | 864 } // namespace blink |
| OLD | NEW |