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 24 matching lines...) Expand all Loading... |
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/WorkerGlobalScope.h" | 37 #include "core/workers/WorkerGlobalScope.h" |
38 #include "platform/Histogram.h" | 38 #include "platform/Histogram.h" |
39 #include "platform/TraceEvent.h" | 39 #include "platform/TraceEvent.h" |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 static int totalPagesMeasuredCSSSampleId() { return 1; } | 43 static int totalPagesMeasuredCSSSampleId() { return 1; } |
44 | 44 |
45 int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id) | 45 int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID cssPrope
rtyID) |
46 { | 46 { |
47 CSSPropertyID cssPropertyID = static_cast<CSSPropertyID>(id); | |
48 | |
49 switch (cssPropertyID) { | 47 switch (cssPropertyID) { |
50 // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId. | 48 // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId. |
51 case CSSPropertyColor: return 2; | 49 case CSSPropertyColor: return 2; |
52 case CSSPropertyDirection: return 3; | 50 case CSSPropertyDirection: return 3; |
53 case CSSPropertyDisplay: return 4; | 51 case CSSPropertyDisplay: return 4; |
54 case CSSPropertyFont: return 5; | 52 case CSSPropertyFont: return 5; |
55 case CSSPropertyFontFamily: return 6; | 53 case CSSPropertyFontFamily: return 6; |
56 case CSSPropertyFontSize: return 7; | 54 case CSSPropertyFontSize: return 7; |
57 case CSSPropertyFontStyle: return 8; | 55 case CSSPropertyFontStyle: return 8; |
58 case CSSPropertyFontVariant: return 9; | 56 case CSSPropertyFontVariant: return 9; |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 void UseCounter::unmuteForInspector() | 596 void UseCounter::unmuteForInspector() |
599 { | 597 { |
600 m_muteCount--; | 598 m_muteCount--; |
601 } | 599 } |
602 | 600 |
603 void UseCounter::recordMeasurement(Feature feature) | 601 void UseCounter::recordMeasurement(Feature feature) |
604 { | 602 { |
605 if (m_muteCount) | 603 if (m_muteCount) |
606 return; | 604 return; |
607 | 605 |
608 if (!m_countBits.hasRecordedMeasurement(feature)) { | 606 DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scal
ing factor. |
| 607 DCHECK(feature < NumberOfFeatures); |
| 608 |
| 609 if (!m_featureBits.quickGet(feature)) { |
609 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "FeatureF
irstUsed", "feature", feature); | 610 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "FeatureF
irstUsed", "feature", feature); |
| 611 m_featureBits.quickSet(feature); |
610 } | 612 } |
611 m_countBits.recordMeasurement(feature); | 613 } |
| 614 |
| 615 bool UseCounter::hasRecordedMeasurement(Feature feature) const |
| 616 { |
| 617 if (m_muteCount) |
| 618 return false; |
| 619 |
| 620 DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scal
ing factor. |
| 621 DCHECK(feature < NumberOfFeatures); |
| 622 |
| 623 return m_featureBits.quickGet(feature); |
612 } | 624 } |
613 | 625 |
614 UseCounter::UseCounter() | 626 UseCounter::UseCounter() |
615 : m_muteCount(0) | 627 : m_muteCount(0) |
| 628 , m_featureBits(NumberOfFeatures) |
| 629 , m_CSSFeatureBits(lastUnresolvedCSSProperty + 1) |
616 { | 630 { |
617 m_CSSFeatureBits.ensureSize(lastUnresolvedCSSProperty + 1); | |
618 m_CSSFeatureBits.clearAll(); | |
619 } | 631 } |
620 | 632 |
621 UseCounter::~UseCounter() | 633 UseCounter::~UseCounter() |
622 { | 634 { |
623 // We always log PageDestruction so that we have a scale for the rest of the
features. | 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 |
624 featureObserverHistogram().count(PageDestruction); | 637 featureObserverHistogram().count(PageDestruction); |
625 | 638 |
626 updateMeasurements(); | 639 updateMeasurements(); |
627 } | 640 } |
628 | 641 |
629 void UseCounter::CountBits::updateMeasurements() | 642 void UseCounter::updateMeasurements() |
630 { | 643 { |
631 EnumerationHistogram& featureHistogram = featureObserverHistogram(); | 644 EnumerationHistogram& featureHistogram = featureObserverHistogram(); |
632 for (unsigned i = 0; i < NumberOfFeatures; ++i) { | 645 featureHistogram.count(PageVisits); |
633 if (m_bits.quickGet(i)) | 646 for (size_t i = 0; i < NumberOfFeatures; ++i) { |
| 647 if (m_featureBits.quickGet(i)) |
634 featureHistogram.count(i); | 648 featureHistogram.count(i); |
635 } | 649 } |
636 // Clearing count bits is timing sensitive. | 650 // Clearing count bits is timing sensitive. |
637 m_bits.clearAll(); | 651 m_featureBits.clearAll(); |
638 } | |
639 | |
640 void UseCounter::updateMeasurements() | |
641 { | |
642 featureObserverHistogram().count(PageVisits); | |
643 m_countBits.updateMeasurements(); | |
644 | 652 |
645 // FIXME: Sometimes this function is called more than once per page. The fol
lowing | 653 // FIXME: Sometimes this function is called more than once per page. The fol
lowing |
646 // bool guards against incrementing the page count when there are no
CSS | 654 // bool guards against incrementing the page count when there are no
CSS |
647 // bits set. https://crbug.com/236262. | 655 // bits set. https://crbug.com/236262. |
648 DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore.
FeatureObserver.CSSProperties", maximumCSSSampleId())); | 656 DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore.
FeatureObserver.CSSProperties", maximumCSSSampleId())); |
649 bool needsPagesMeasuredUpdate = false; | 657 bool needsPagesMeasuredUpdate = false; |
650 for (int i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) { | 658 for (size_t i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) { |
651 if (m_CSSFeatureBits.quickGet(i)) { | 659 if (m_CSSFeatureBits.quickGet(i)) { |
652 int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(i); | 660 int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(static_c
ast<CSSPropertyID>(i)); |
653 cssPropertiesHistogram.count(cssSampleId); | 661 cssPropertiesHistogram.count(cssSampleId); |
654 needsPagesMeasuredUpdate = true; | 662 needsPagesMeasuredUpdate = true; |
655 } | 663 } |
656 } | 664 } |
657 | 665 |
658 if (needsPagesMeasuredUpdate) | 666 if (needsPagesMeasuredUpdate) |
659 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | 667 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
660 | 668 |
661 m_CSSFeatureBits.clearAll(); | 669 m_CSSFeatureBits.clearAll(); |
662 } | 670 } |
663 | 671 |
664 void UseCounter::didCommitLoad() | 672 void UseCounter::didCommitLoad() |
665 { | 673 { |
| 674 // 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 |
| 676 // their UseCounter to the containing Page. |
666 updateMeasurements(); | 677 updateMeasurements(); |
667 } | 678 } |
668 | 679 |
669 void UseCounter::count(const Frame* frame, Feature feature) | 680 void UseCounter::count(const Frame* frame, Feature feature) |
670 { | 681 { |
671 if (!frame) | 682 if (!frame) |
672 return; | 683 return; |
673 FrameHost* host = frame->host(); | 684 FrameHost* host = frame->host(); |
674 if (!host) | 685 if (!host) |
675 return; | 686 return; |
(...skipping 15 matching lines...) Expand all Loading... |
691 if (!host) | 702 if (!host) |
692 return false; | 703 return false; |
693 return host->useCounter().hasRecordedMeasurement(feature); | 704 return host->useCounter().hasRecordedMeasurement(feature); |
694 } | 705 } |
695 | 706 |
696 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) | 707 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) |
697 { | 708 { |
698 return m_CSSFeatureBits.quickGet(unresolvedProperty); | 709 return m_CSSFeatureBits.quickGet(unresolvedProperty); |
699 } | 710 } |
700 | 711 |
701 | |
702 bool UseCounter::isCounted(Document& document, const String& string) | 712 bool UseCounter::isCounted(Document& document, const String& string) |
703 { | 713 { |
704 Frame* frame = document.frame(); | 714 Frame* frame = document.frame(); |
705 if (!frame) | 715 if (!frame) |
706 return false; | 716 return false; |
707 FrameHost* host = frame->host(); | 717 FrameHost* host = frame->host(); |
708 if (!host) | 718 if (!host) |
709 return false; | 719 return false; |
710 | 720 |
711 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(string); | 721 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(string); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 | 759 |
750 void UseCounter::countCrossOriginIframe(const Document& document, Feature featur
e) | 760 void UseCounter::countCrossOriginIframe(const Document& document, Feature featur
e) |
751 { | 761 { |
752 LocalFrame* frame = document.frame(); | 762 LocalFrame* frame = document.frame(); |
753 if (frame && frame->isCrossOriginSubframe()) | 763 if (frame && frame->isCrossOriginSubframe()) |
754 count(frame, feature); | 764 count(frame, feature); |
755 } | 765 } |
756 | 766 |
757 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID feature) | 767 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID feature) |
758 { | 768 { |
759 ASSERT(feature >= firstCSSProperty); | 769 DCHECK(feature >= firstCSSProperty); |
760 ASSERT(feature <= lastUnresolvedCSSProperty); | 770 DCHECK(feature <= lastUnresolvedCSSProperty); |
761 | 771 |
762 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) | 772 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) |
763 return; | 773 return; |
764 | 774 |
765 if (!m_CSSFeatureBits.quickGet(feature)) { | 775 if (!m_CSSFeatureBits.quickGet(feature)) { |
766 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "CSSFeatu
reFirstUsed", "feature", feature); | 776 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), "CSSFeatu
reFirstUsed", "feature", feature); |
| 777 m_CSSFeatureBits.quickSet(feature); |
767 } | 778 } |
768 m_CSSFeatureBits.quickSet(feature); | |
769 } | 779 } |
770 | 780 |
771 void UseCounter::count(Feature feature) | 781 void UseCounter::count(Feature feature) |
772 { | 782 { |
773 ASSERT(Deprecation::deprecationMessage(feature).isEmpty()); | 783 DCHECK(Deprecation::deprecationMessage(feature).isEmpty()); |
774 recordMeasurement(feature); | 784 recordMeasurement(feature); |
775 } | 785 } |
776 | 786 |
777 UseCounter* UseCounter::getFrom(const Document* document) | 787 UseCounter* UseCounter::getFrom(const Document* document) |
778 { | 788 { |
779 if (document && document->frameHost()) | 789 if (document && document->frameHost()) |
780 return &document->frameHost()->useCounter(); | 790 return &document->frameHost()->useCounter(); |
781 return 0; | 791 return 0; |
782 } | 792 } |
783 | 793 |
784 UseCounter* UseCounter::getFrom(const CSSStyleSheet* sheet) | 794 UseCounter* UseCounter::getFrom(const CSSStyleSheet* sheet) |
785 { | 795 { |
786 if (sheet) | 796 if (sheet) |
787 return getFrom(sheet->contents()); | 797 return getFrom(sheet->contents()); |
788 return 0; | 798 return 0; |
789 } | 799 } |
790 | 800 |
791 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) | 801 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) |
792 { | 802 { |
793 // FIXME: We may want to handle stylesheets that have multiple owners | 803 // FIXME: We may want to handle stylesheets that have multiple owners |
794 // https://crbug.com/242125 | 804 // https://crbug.com/242125 |
795 if (sheetContents && sheetContents->hasSingleOwnerNode()) | 805 if (sheetContents && sheetContents->hasSingleOwnerNode()) |
796 return getFrom(sheetContents->singleOwnerDocument()); | 806 return getFrom(sheetContents->singleOwnerDocument()); |
797 return 0; | 807 return 0; |
798 } | 808 } |
799 | 809 |
800 } // namespace blink | 810 } // namespace blink |
OLD | NEW |