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

Side by Side Diff: third_party/WebKit/Source/core/frame/UseCounter.cpp

Issue 2290733002: Add new UseCounter metric (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Overhaul tests Created 4 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
OLDNEW
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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 return 0; 575 return 0;
576 } 576 }
577 577
578 ASSERT_NOT_REACHED(); 578 ASSERT_NOT_REACHED();
579 return 0; 579 return 0;
580 } 580 }
581 581
582 // Make sure update_use_counter_css.py was run which updates histograms.xml. 582 // Make sure update_use_counter_css.py was run which updates histograms.xml.
583 static int maximumCSSSampleId() { return 539; } 583 static int maximumCSSSampleId() { return 539; }
584 584
585 static EnumerationHistogram& featureObserverHistogram() 585 static EnumerationHistogram& useCounterHistogram()
dtapuska 2016/09/09 18:30:19 shouldn't these statics really be in an anonymous
Rick Byers 2016/09/09 19:31:37 I don't think our coding style says to prefer one
586 { 586 {
587 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserv er", UseCounter::NumberOfFeatures)); 587 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.UseCounter.Fe atures", UseCounter::NumberOfFeatures));
588 return histogram; 588 return histogram;
dtapuska 2016/09/09 18:30:19 Perhaps we should use temporary names because we h
Rick Byers 2016/09/09 19:31:36 Done.
589 } 589 }
590 590
591 static EnumerationHistogram& CSSUseCounterHistogram()
592 {
593 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.UseCounter.CS SProperties", maximumCSSSampleId()));
594 return histogram;
595 }
596
597 UseCounter::UseCounter()
598 : m_muteCount(0)
599 , m_featuresRecorded(NumberOfFeatures)
600 , m_CSSRecorded(lastUnresolvedCSSProperty + 1)
601 {
602 }
603
591 void UseCounter::muteForInspector() 604 void UseCounter::muteForInspector()
592 { 605 {
593 m_muteCount++; 606 m_muteCount++;
594 } 607 }
595 608
596 void UseCounter::unmuteForInspector() 609 void UseCounter::unmuteForInspector()
597 { 610 {
598 m_muteCount--; 611 m_muteCount--;
599 } 612 }
600 613
601 void UseCounter::recordMeasurement(Feature feature) 614 void UseCounter::recordMeasurement(Feature feature)
602 { 615 {
603 if (m_muteCount) 616 if (m_muteCount)
604 return; 617 return;
605 618
606 DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scal ing factor. 619 DCHECK(feature != OBSOLETE_PageDestruction && feature != PageVisits); // Pag eDestruction is reserved as a scaling factor.
607 DCHECK(feature < NumberOfFeatures); 620 DCHECK(feature < NumberOfFeatures);
608 621
609 if (!m_featureBits.quickGet(feature)) { 622 if (!m_featuresRecorded.quickGet(feature)) {
623 // Note that HTTPArchive tooling looks specifically for this event - see https://github.com/HTTPArchive/httparchive/issues/59
610 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "FeatureF irstUsed", "feature", feature); 624 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "FeatureF irstUsed", "feature", feature);
611 m_featureBits.quickSet(feature); 625 useCounterHistogram().count(feature);
626 m_featuresRecorded.quickSet(feature);
612 } 627 }
628 m_legacyCounter.countFeature(feature);
dtapuska 2016/09/09 18:30:19 Can this not go up into the conditional?
Rick Byers 2016/09/09 19:31:37 No, the legacy counter has it's own set of recorde
613 } 629 }
614 630
615 bool UseCounter::hasRecordedMeasurement(Feature feature) const 631 bool UseCounter::hasRecordedMeasurement(Feature feature) const
616 { 632 {
617 if (m_muteCount) 633 if (m_muteCount)
618 return false; 634 return false;
619 635
620 DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scal ing factor. 636 DCHECK(feature != OBSOLETE_PageDestruction && feature != PageVisits); // Pag eDestruction is reserved as a scaling factor.
621 DCHECK(feature < NumberOfFeatures); 637 DCHECK(feature < NumberOfFeatures);
622 638
623 return m_featureBits.quickGet(feature); 639 return m_featuresRecorded.quickGet(feature);
624 }
625
626 UseCounter::UseCounter()
627 : m_muteCount(0)
628 , m_featureBits(NumberOfFeatures)
629 , m_CSSFeatureBits(lastUnresolvedCSSProperty + 1)
630 {
631 }
632
633 UseCounter::~UseCounter()
634 {
635 // We always log PageDestruction so that we have a scale for the rest of the features.
636 // TODO(rbyers): This is flawed due to renderer fast shutdown - crbug.com/59 7963
637 featureObserverHistogram().count(PageDestruction);
638
639 updateMeasurements();
640 }
641
642 void UseCounter::updateMeasurements()
643 {
644 EnumerationHistogram& featureHistogram = featureObserverHistogram();
645 featureHistogram.count(PageVisits);
646 for (size_t i = 0; i < NumberOfFeatures; ++i) {
647 if (m_featureBits.quickGet(i))
648 featureHistogram.count(i);
649 }
650 // Clearing count bits is timing sensitive.
651 m_featureBits.clearAll();
652
653 // FIXME: Sometimes this function is called more than once per page. The fol lowing
654 // bool guards against incrementing the page count when there are no CSS
655 // bits set. https://crbug.com/236262.
656 DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore. FeatureObserver.CSSProperties", maximumCSSSampleId()));
657 bool needsPagesMeasuredUpdate = false;
658 for (size_t i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) {
659 if (m_CSSFeatureBits.quickGet(i)) {
660 int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(static_c ast<CSSPropertyID>(i));
661 cssPropertiesHistogram.count(cssSampleId);
662 needsPagesMeasuredUpdate = true;
663 }
664 }
665
666 if (needsPagesMeasuredUpdate)
667 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId());
668
669 m_CSSFeatureBits.clearAll();
670 } 640 }
671 641
672 void UseCounter::didCommitLoad() 642 void UseCounter::didCommitLoad()
673 { 643 {
674 // TODO(rbyers): This gets invoked more than expected. crbug.com/236262 644 // TODO(rbyers): This gets invoked more than expected. crbug.com/236262
675 // Eg. every SVGImage has it's own Page instance, they should probably all b e delegating 645 // Eg. every SVGImage has it's own Page instance, they should probably all b e delegating
676 // their UseCounter to the containing Page. 646 // their UseCounter to the containing Page.
677 updateMeasurements(); 647 m_legacyCounter.updateMeasurements();
648
649 // TODO: When exactly do we want to do this?
650 m_featuresRecorded.clearAll();
651 useCounterHistogram().count(PageVisits);
652 m_CSSRecorded.clearAll();
653 CSSUseCounterHistogram().count(totalPagesMeasuredCSSSampleId());
678 } 654 }
679 655
680 void UseCounter::count(const Frame* frame, Feature feature) 656 void UseCounter::count(const Frame* frame, Feature feature)
681 { 657 {
682 if (!frame) 658 if (!frame)
683 return; 659 return;
684 FrameHost* host = frame->host(); 660 FrameHost* host = frame->host();
685 if (!host) 661 if (!host)
686 return; 662 return;
687 663
(...skipping 11 matching lines...) Expand all
699 if (!frame) 675 if (!frame)
700 return false; 676 return false;
701 FrameHost* host = frame->host(); 677 FrameHost* host = frame->host();
702 if (!host) 678 if (!host)
703 return false; 679 return false;
704 return host->useCounter().hasRecordedMeasurement(feature); 680 return host->useCounter().hasRecordedMeasurement(feature);
705 } 681 }
706 682
707 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) 683 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty)
708 { 684 {
709 return m_CSSFeatureBits.quickGet(unresolvedProperty); 685 return m_CSSRecorded.quickGet(unresolvedProperty);
710 } 686 }
711 687
712 bool UseCounter::isCounted(Document& document, const String& string) 688 bool UseCounter::isCounted(Document& document, const String& string)
713 { 689 {
714 Frame* frame = document.frame(); 690 Frame* frame = document.frame();
715 if (!frame) 691 if (!frame)
716 return false; 692 return false;
717 FrameHost* host = frame->host(); 693 FrameHost* host = frame->host();
718 if (!host) 694 if (!host)
719 return false; 695 return false;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 UseCounter::count(context, feature); 733 UseCounter::count(context, feature);
758 } 734 }
759 735
760 void UseCounter::countCrossOriginIframe(const Document& document, Feature featur e) 736 void UseCounter::countCrossOriginIframe(const Document& document, Feature featur e)
761 { 737 {
762 LocalFrame* frame = document.frame(); 738 LocalFrame* frame = document.frame();
763 if (frame && frame->isCrossOriginSubframe()) 739 if (frame && frame->isCrossOriginSubframe())
764 count(frame, feature); 740 count(frame, feature);
765 } 741 }
766 742
767 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID feature) 743 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID property)
768 { 744 {
769 DCHECK(feature >= firstCSSProperty); 745 DCHECK(property >= firstCSSProperty);
770 DCHECK(feature <= lastUnresolvedCSSProperty); 746 DCHECK(property <= lastUnresolvedCSSProperty);
771 747
772 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) 748 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount)
773 return; 749 return;
774 750
775 if (!m_CSSFeatureBits.quickGet(feature)) { 751 if (!m_CSSRecorded.quickGet(property)) {
776 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "CSSFeatu reFirstUsed", "feature", feature); 752 // Note that HTTPArchive tooling looks specifically for this event - see https://github.com/HTTPArchive/httparchive/issues/59
777 m_CSSFeatureBits.quickSet(feature); 753 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "CSSFeatu reFirstUsed", "feature", property);
754 CSSUseCounterHistogram().count(mapCSSPropertyIdToCSSSampleIdForHistogram (property));
755 m_CSSRecorded.quickSet(property);
778 } 756 }
757 m_legacyCounter.countCSS(property);
dtapuska 2016/09/09 18:30:19 likewise why isn't this inside the else?
Rick Byers 2016/09/09 19:31:36 I added some comments to the declarations to make
779 } 758 }
780 759
781 void UseCounter::count(Feature feature) 760 void UseCounter::count(Feature feature)
782 { 761 {
783 DCHECK(Deprecation::deprecationMessage(feature).isEmpty()); 762 DCHECK(Deprecation::deprecationMessage(feature).isEmpty());
784 recordMeasurement(feature); 763 recordMeasurement(feature);
785 } 764 }
786 765
787 UseCounter* UseCounter::getFrom(const Document* document) 766 UseCounter* UseCounter::getFrom(const Document* document)
788 { 767 {
(...skipping 11 matching lines...) Expand all
800 779
801 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) 780 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents)
802 { 781 {
803 // FIXME: We may want to handle stylesheets that have multiple owners 782 // FIXME: We may want to handle stylesheets that have multiple owners
804 // https://crbug.com/242125 783 // https://crbug.com/242125
805 if (sheetContents && sheetContents->hasSingleOwnerNode()) 784 if (sheetContents && sheetContents->hasSingleOwnerNode())
806 return getFrom(sheetContents->singleOwnerDocument()); 785 return getFrom(sheetContents->singleOwnerDocument());
807 return 0; 786 return 0;
808 } 787 }
809 788
789 /*
790 *
791 * LEGACY metrics support - WebCore.FeatureObserver is to be superceded by WebCo re.UseCounter
792 *
793 */
794
795 static EnumerationHistogram& featureObserverHistogram()
796 {
797 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserv er", UseCounter::NumberOfFeatures));
798 return histogram;
799 }
800
801 UseCounter::LegacyCounter::LegacyCounter()
802 : m_featureBits(NumberOfFeatures)
803 , m_CSSBits(lastUnresolvedCSSProperty + 1)
804 {
805 }
806
807 UseCounter::LegacyCounter::~LegacyCounter()
808 {
809 // PageDestruction was intended to be used as a scale, but it's broken (due to fast shutdown).
810 // See https://crbug.com/597963.
811 featureObserverHistogram().count(OBSOLETE_PageDestruction);
812 updateMeasurements();
813 }
814
815 void UseCounter::LegacyCounter::countFeature(Feature feature)
816 {
817 m_featureBits.quickSet(feature);
818 }
819
820 void UseCounter::LegacyCounter::countCSS(CSSPropertyID property)
821 {
822 m_CSSBits.quickSet(property);
823 }
824
825 void UseCounter::LegacyCounter::updateMeasurements()
826 {
827 EnumerationHistogram& featureHistogram = featureObserverHistogram();
828 featureHistogram.count(PageVisits);
829 for (size_t i = 0; i < NumberOfFeatures; ++i) {
830 if (m_featureBits.quickGet(i))
831 featureHistogram.count(i);
832 }
833 // Clearing count bits is timing sensitive.
834 m_featureBits.clearAll();
835
836 // FIXME: Sometimes this function is called more than once per page. The fol lowing
837 // bool guards against incrementing the page count when there are no CSS
838 // bits set. https://crbug.com/236262.
839 DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore. FeatureObserver.CSSProperties", maximumCSSSampleId()));
840 bool needsPagesMeasuredUpdate = false;
841 for (size_t i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) {
842 if (m_CSSBits.quickGet(i)) {
843 int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(static_c ast<CSSPropertyID>(i));
844 cssPropertiesHistogram.count(cssSampleId);
845 needsPagesMeasuredUpdate = true;
846 }
847 }
848
849 if (needsPagesMeasuredUpdate)
850 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId());
851
852 m_CSSBits.clearAll();
853 }
854
855
810 } // namespace blink 856 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698