Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 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 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 static int totalPagesMeasuredCSSSampleId() { return 1; } | 42 static int totalPagesMeasuredCSSSampleId() { return 1; } |
| 43 | 43 |
| 44 int UseCounter::m_muteCount = 0; | 44 int UseCounter::m_muteCount = 0; |
| 45 | 45 |
| 46 int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id) | 46 int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID cssPrope rtyID) |
| 47 { | 47 { |
| 48 CSSPropertyID cssPropertyID = static_cast<CSSPropertyID>(id); | |
| 49 | |
| 50 switch (cssPropertyID) { | 48 switch (cssPropertyID) { |
| 51 // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId. | 49 // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId. |
| 52 case CSSPropertyColor: return 2; | 50 case CSSPropertyColor: return 2; |
| 53 case CSSPropertyDirection: return 3; | 51 case CSSPropertyDirection: return 3; |
| 54 case CSSPropertyDisplay: return 4; | 52 case CSSPropertyDisplay: return 4; |
| 55 case CSSPropertyFont: return 5; | 53 case CSSPropertyFont: return 5; |
| 56 case CSSPropertyFontFamily: return 6; | 54 case CSSPropertyFontFamily: return 6; |
| 57 case CSSPropertyFontSize: return 7; | 55 case CSSPropertyFontSize: return 7; |
| 58 case CSSPropertyFontStyle: return 8; | 56 case CSSPropertyFontStyle: return 8; |
| 59 case CSSPropertyFontVariant: return 9; | 57 case CSSPropertyFontVariant: return 9; |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 | 571 |
| 574 case CSSPropertyInvalid: | 572 case CSSPropertyInvalid: |
| 575 ASSERT_NOT_REACHED(); | 573 ASSERT_NOT_REACHED(); |
| 576 return 0; | 574 return 0; |
| 577 } | 575 } |
| 578 | 576 |
| 579 ASSERT_NOT_REACHED(); | 577 ASSERT_NOT_REACHED(); |
| 580 return 0; | 578 return 0; |
| 581 } | 579 } |
| 582 | 580 |
| 583 | |
| 584 static int maximumCSSSampleId() { return 535; } | 581 static int maximumCSSSampleId() { return 535; } |
| 585 | 582 |
| 586 static EnumerationHistogram& featureObserverHistogram() | 583 static EnumerationHistogram& useCounterHistogram() |
| 587 { | 584 { |
| 588 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserv er", UseCounter::NumberOfFeatures)); | 585 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.UseCounter", UseCounter::NumberOfFeatures)); |
| 589 return histogram; | 586 return histogram; |
| 590 } | 587 } |
| 591 | 588 |
| 589 static EnumerationHistogram& CSSUseCounterHistogram() | |
| 590 { | |
| 591 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.UseCounter.CS SProperties", maximumCSSSampleId())); | |
| 592 return histogram; | |
| 593 } | |
| 594 | |
| 592 void UseCounter::muteForInspector() | 595 void UseCounter::muteForInspector() |
| 593 { | 596 { |
| 594 UseCounter::m_muteCount++; | 597 UseCounter::m_muteCount++; |
| 595 } | 598 } |
| 596 | 599 |
| 597 void UseCounter::unmuteForInspector() | 600 void UseCounter::unmuteForInspector() |
| 598 { | 601 { |
| 599 UseCounter::m_muteCount--; | 602 UseCounter::m_muteCount--; |
| 600 } | 603 } |
| 601 | 604 |
| 602 UseCounter::UseCounter() | |
| 603 { | |
| 604 m_CSSFeatureBits.ensureSize(lastUnresolvedCSSProperty + 1); | |
| 605 m_CSSFeatureBits.clearAll(); | |
| 606 } | |
| 607 | |
| 608 UseCounter::~UseCounter() | |
| 609 { | |
| 610 // We always log PageDestruction so that we have a scale for the rest of the features. | |
| 611 featureObserverHistogram().count(PageDestruction); | |
| 612 | |
| 613 updateMeasurements(); | |
| 614 } | |
| 615 | |
| 616 void UseCounter::CountBits::updateMeasurements() | |
| 617 { | |
| 618 EnumerationHistogram& featureHistogram = featureObserverHistogram(); | |
| 619 for (unsigned i = 0; i < NumberOfFeatures; ++i) { | |
| 620 if (m_bits.quickGet(i)) | |
| 621 featureHistogram.count(i); | |
| 622 } | |
| 623 // Clearing count bits is timing sensitive. | |
| 624 m_bits.clearAll(); | |
| 625 } | |
| 626 | |
| 627 void UseCounter::updateMeasurements() | |
| 628 { | |
| 629 featureObserverHistogram().count(PageVisits); | |
| 630 m_countBits.updateMeasurements(); | |
| 631 | |
| 632 // FIXME: Sometimes this function is called more than once per page. The fol lowing | |
| 633 // bool guards against incrementing the page count when there are no CSS | |
| 634 // bits set. https://crbug.com/236262. | |
| 635 DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore. FeatureObserver.CSSProperties", maximumCSSSampleId())); | |
| 636 bool needsPagesMeasuredUpdate = false; | |
| 637 for (int i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) { | |
| 638 if (m_CSSFeatureBits.quickGet(i)) { | |
| 639 int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(i); | |
| 640 cssPropertiesHistogram.count(cssSampleId); | |
| 641 needsPagesMeasuredUpdate = true; | |
| 642 } | |
| 643 } | |
| 644 | |
| 645 if (needsPagesMeasuredUpdate) | |
| 646 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | |
| 647 | |
| 648 m_CSSFeatureBits.clearAll(); | |
| 649 } | |
| 650 | |
| 651 void UseCounter::didCommitLoad() | |
| 652 { | |
| 653 updateMeasurements(); | |
| 654 } | |
| 655 | |
| 656 void UseCounter::count(const Frame* frame, Feature feature) | 605 void UseCounter::count(const Frame* frame, Feature feature) |
| 657 { | 606 { |
| 658 if (!frame) | 607 if (!frame) |
| 659 return; | 608 return; |
| 660 FrameHost* host = frame->host(); | 609 FrameHost* host = frame->host(); |
| 661 if (!host) | 610 if (!host) |
| 662 return; | 611 return; |
| 663 | 612 |
| 664 ASSERT(Deprecation::deprecationMessage(feature).isEmpty()); | 613 ASSERT(Deprecation::deprecationMessage(feature).isEmpty()); |
| 665 host->useCounter().recordMeasurement(feature); | 614 host->useCounter().recordMeasurement(feature); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 676 if (!frame) | 625 if (!frame) |
| 677 return false; | 626 return false; |
| 678 FrameHost* host = frame->host(); | 627 FrameHost* host = frame->host(); |
| 679 if (!host) | 628 if (!host) |
| 680 return false; | 629 return false; |
| 681 return host->useCounter().hasRecordedMeasurement(feature); | 630 return host->useCounter().hasRecordedMeasurement(feature); |
| 682 } | 631 } |
| 683 | 632 |
| 684 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) | 633 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) |
| 685 { | 634 { |
| 686 return m_CSSFeatureBits.quickGet(unresolvedProperty); | 635 return m_CSSFeaturesReported.quickGet(unresolvedProperty); |
| 687 } | 636 } |
| 688 | 637 |
| 638 void UseCounter::didCommitLoad() | |
| 639 { | |
| 640 m_featuresReported.clearAll(); | |
| 641 useCounterHistogram().count(PageVisits); | |
|
dtapuska
2016/05/31 01:10:51
Are you explicitly counting here even though muted
| |
| 642 | |
| 643 m_CSSFeaturesReported.clearAll(); | |
| 644 CSSUseCounterHistogram().count(totalPagesMeasuredCSSSampleId()); | |
| 645 } | |
| 646 | |
| 647 void UseCounter::recordMeasurement(Feature feature) | |
| 648 { | |
| 649 if (UseCounter::m_muteCount) | |
| 650 return; | |
| 651 | |
| 652 if (!m_featuresReported.quickGet(feature)) { | |
| 653 m_featuresReported.quickSet(feature); | |
| 654 useCounterHistogram().count(feature); | |
| 655 } | |
| 656 m_legacyCounter.recordMeasurement(feature); | |
| 657 } | |
| 689 | 658 |
| 690 bool UseCounter::isCounted(Document& document, const String& string) | 659 bool UseCounter::isCounted(Document& document, const String& string) |
| 691 { | 660 { |
| 692 Frame* frame = document.frame(); | 661 Frame* frame = document.frame(); |
| 693 if (!frame) | 662 if (!frame) |
| 694 return false; | 663 return false; |
| 695 FrameHost* host = frame->host(); | 664 FrameHost* host = frame->host(); |
| 696 if (!host) | 665 if (!host) |
| 697 return false; | 666 return false; |
| 698 | 667 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 } | 712 } |
| 744 | 713 |
| 745 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID feature) | 714 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID feature) |
| 746 { | 715 { |
| 747 ASSERT(feature >= firstCSSProperty); | 716 ASSERT(feature >= firstCSSProperty); |
| 748 ASSERT(feature <= lastUnresolvedCSSProperty); | 717 ASSERT(feature <= lastUnresolvedCSSProperty); |
| 749 | 718 |
| 750 if (!isUseCounterEnabledForMode(cssParserMode)) | 719 if (!isUseCounterEnabledForMode(cssParserMode)) |
| 751 return; | 720 return; |
| 752 | 721 |
| 753 m_CSSFeatureBits.quickSet(feature); | 722 if (!m_CSSFeaturesReported.quickGet(feature)) { |
| 723 m_CSSFeaturesReported.quickSet(feature); | |
| 724 CSSUseCounterHistogram().count(mapCSSPropertyIdToCSSSampleIdForHistogram (feature)); | |
| 725 } | |
| 726 m_legacyCounter.countCSS(feature); | |
| 754 } | 727 } |
| 755 | 728 |
| 756 void UseCounter::count(Feature feature) | 729 void UseCounter::count(Feature feature) |
| 757 { | 730 { |
| 758 ASSERT(Deprecation::deprecationMessage(feature).isEmpty()); | 731 ASSERT(Deprecation::deprecationMessage(feature).isEmpty()); |
| 759 recordMeasurement(feature); | 732 recordMeasurement(feature); |
| 760 } | 733 } |
| 761 | 734 |
| 762 UseCounter* UseCounter::getFrom(const Document* document) | 735 UseCounter* UseCounter::getFrom(const Document* document) |
| 763 { | 736 { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 775 | 748 |
| 776 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) | 749 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) |
| 777 { | 750 { |
| 778 // FIXME: We may want to handle stylesheets that have multiple owners | 751 // FIXME: We may want to handle stylesheets that have multiple owners |
| 779 // https://crbug.com/242125 | 752 // https://crbug.com/242125 |
| 780 if (sheetContents && sheetContents->hasSingleOwnerNode()) | 753 if (sheetContents && sheetContents->hasSingleOwnerNode()) |
| 781 return getFrom(sheetContents->singleOwnerDocument()); | 754 return getFrom(sheetContents->singleOwnerDocument()); |
| 782 return 0; | 755 return 0; |
| 783 } | 756 } |
| 784 | 757 |
| 758 /* | |
| 759 * | |
| 760 * LEGACY metrics support - WebCore.FeatureObserver is to be superceded by WebCo re.UseCounter | |
| 761 * | |
| 762 */ | |
| 763 | |
| 764 static EnumerationHistogram& featureObserverHistogram() | |
| 765 { | |
| 766 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("WebCore.FeatureObserv er", UseCounter::NumberOfFeatures)); | |
| 767 return histogram; | |
| 768 } | |
| 769 | |
| 770 UseCounter::LegacyCounter::LegacyCounter() | |
| 771 : m_countBits(NumberOfFeatures) | |
| 772 , m_CSSFeatureBits(lastUnresolvedCSSProperty + 1) | |
| 773 { | |
| 774 } | |
| 775 | |
| 776 UseCounter::LegacyCounter::~LegacyCounter() | |
| 777 { | |
| 778 // We always log PageDestruction so that we have a scale for the rest of the features. | |
| 779 featureObserverHistogram().count(PageDestruction); | |
| 780 updateMeasurements(); | |
| 781 } | |
| 782 | |
| 783 void UseCounter::LegacyCounter::recordMeasurement(Feature feature) | |
| 784 { | |
| 785 DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scal ing factor. | |
| 786 DCHECK(feature < NumberOfFeatures); | |
| 787 | |
| 788 m_countBits.quickSet(feature); | |
| 789 } | |
| 790 | |
| 791 void UseCounter::LegacyCounter::updateMeasurements() | |
| 792 { | |
| 793 EnumerationHistogram& featureHistogram = featureObserverHistogram(); | |
| 794 featureHistogram.count(PageVisits); | |
| 795 for (unsigned i = 0; i < NumberOfFeatures; ++i) { | |
| 796 if (m_countBits.quickGet(i)) | |
| 797 featureHistogram.count(i); | |
| 798 } | |
| 799 // Clearing count bits is timing sensitive. | |
| 800 m_countBits.clearAll(); | |
| 801 | |
| 802 // FIXME: Sometimes this function is called more than once per page. The fol lowing | |
| 803 // bool guards against incrementing the page count when there are no CSS | |
| 804 // bits set. https://crbug.com/236262. | |
| 805 DEFINE_STATIC_LOCAL(EnumerationHistogram, cssPropertiesHistogram, ("WebCore. FeatureObserver.CSSProperties", maximumCSSSampleId())); | |
| 806 bool needsPagesMeasuredUpdate = false; | |
| 807 for (int i = firstCSSProperty; i <= lastUnresolvedCSSProperty; ++i) { | |
| 808 if (m_CSSFeatureBits.quickGet(i)) { | |
| 809 int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(static_c ast<CSSPropertyID>(i)); | |
| 810 cssPropertiesHistogram.count(cssSampleId); | |
| 811 needsPagesMeasuredUpdate = true; | |
| 812 } | |
| 813 } | |
| 814 | |
| 815 if (needsPagesMeasuredUpdate) | |
| 816 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | |
| 817 | |
| 818 m_CSSFeatureBits.clearAll(); | |
| 819 } | |
| 820 | |
| 821 bool UseCounter::LegacyCounter::hasRecordedMeasurement(Feature feature) const | |
| 822 { | |
| 823 if (UseCounter::m_muteCount) | |
| 824 return false; | |
| 825 DCHECK(feature != PageDestruction); // PageDestruction is reserved as a scal ing factor. | |
| 826 DCHECK(feature < NumberOfFeatures); | |
| 827 | |
| 828 return m_countBits.quickGet(feature); | |
| 829 } | |
| 830 | |
| 831 void UseCounter::LegacyCounter::countCSS(CSSPropertyID feature) | |
| 832 { | |
| 833 m_CSSFeatureBits.quickSet(feature); | |
| 834 } | |
| 835 | |
| 836 | |
| 785 } // namespace blink | 837 } // namespace blink |
| OLD | NEW |