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

Side by Side Diff: net/http/http_cache_transaction.cc

Issue 2350183002: [HttpCache] Add cache metrics for audio/video behavior (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" // For OS_POSIX 7 #include "build/build_config.h" // For OS_POSIX
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 enum ExternallyConditionalizedType { 76 enum ExternallyConditionalizedType {
77 EXTERNALLY_CONDITIONALIZED_CACHE_REQUIRES_VALIDATION, 77 EXTERNALLY_CONDITIONALIZED_CACHE_REQUIRES_VALIDATION,
78 EXTERNALLY_CONDITIONALIZED_CACHE_USABLE, 78 EXTERNALLY_CONDITIONALIZED_CACHE_USABLE,
79 EXTERNALLY_CONDITIONALIZED_MISMATCHED_VALIDATORS, 79 EXTERNALLY_CONDITIONALIZED_MISMATCHED_VALIDATORS,
80 EXTERNALLY_CONDITIONALIZED_MAX 80 EXTERNALLY_CONDITIONALIZED_MAX
81 }; 81 };
82 82
83 } // namespace 83 } // namespace
84 84
85 #define CACHE_STATUS_HISTOGRAMS(type) \
86 do { \
87 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern" type, cache_entry_status_, \
88 CacheEntryStatus::ENTRY_MAX); \
89 if (validation_request) { \
90 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause" type, \
91 validation_cause_, VALIDATION_CAUSE_MAX); \
92 } \
93 if (stale_request) { \
94 UMA_HISTOGRAM_COUNTS( \
95 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed" type, \
96 freshness_periods_since_last_used); \
97 } \
98 } while (0)
99
85 struct HeaderNameAndValue { 100 struct HeaderNameAndValue {
86 const char* name; 101 const char* name;
87 const char* value; 102 const char* value;
88 }; 103 };
89 104
90 // If the request includes one of these request headers, then avoid caching 105 // If the request includes one of these request headers, then avoid caching
91 // to avoid getting confused. 106 // to avoid getting confused.
92 static const HeaderNameAndValue kPassThroughHeaders[] = { 107 static const HeaderNameAndValue kPassThroughHeaders[] = {
93 { "if-unmodified-since", NULL }, // causes unexpected 412s 108 { "if-unmodified-since", NULL }, // causes unexpected 412s
94 { "if-match", NULL }, // causes unexpected 412s 109 { "if-match", NULL }, // causes unexpected 412s
(...skipping 2695 matching lines...) Expand 10 before | Expand all | Expand 10 after
2790 2805
2791 if (stale_request) { 2806 if (stale_request) {
2792 // For stale entries, record how many freshness periods have elapsed since 2807 // For stale entries, record how many freshness periods have elapsed since
2793 // the entry was last used. 2808 // the entry was last used.
2794 DCHECK(!open_entry_last_used_.is_null()); 2809 DCHECK(!open_entry_last_used_.is_null());
2795 DCHECK(!stale_entry_freshness_.is_zero()); 2810 DCHECK(!stale_entry_freshness_.is_zero());
2796 base::TimeDelta time_since_use = base::Time::Now() - open_entry_last_used_; 2811 base::TimeDelta time_since_use = base::Time::Now() - open_entry_last_used_;
2797 freshness_periods_since_last_used = 2812 freshness_periods_since_last_used =
2798 (time_since_use * 1000) / stale_entry_freshness_; 2813 (time_since_use * 1000) / stale_entry_freshness_;
2799 2814
2800 UMA_HISTOGRAM_COUNTS("HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed",
2801 freshness_periods_since_last_used);
2802
2803 if (validation_request) { 2815 if (validation_request) {
2804 int64_t age_in_freshness_periods = 2816 int64_t age_in_freshness_periods =
2805 (stale_entry_age_ * 100) / stale_entry_freshness_; 2817 (stale_entry_age_ * 100) / stale_entry_freshness_;
2806 if (cache_entry_status_ == CacheEntryStatus::ENTRY_VALIDATED) { 2818 if (cache_entry_status_ == CacheEntryStatus::ENTRY_VALIDATED) {
2807 UMA_HISTOGRAM_COUNTS("HttpCache.StaleEntry.Validated.Age", 2819 UMA_HISTOGRAM_COUNTS("HttpCache.StaleEntry.Validated.Age",
2808 stale_entry_age_.InSeconds()); 2820 stale_entry_age_.InSeconds());
2809 UMA_HISTOGRAM_COUNTS( 2821 UMA_HISTOGRAM_COUNTS(
2810 "HttpCache.StaleEntry.Validated.AgeInFreshnessPeriods", 2822 "HttpCache.StaleEntry.Validated.AgeInFreshnessPeriods",
2811 age_in_freshness_periods); 2823 age_in_freshness_periods);
2812 2824
2813 } else { 2825 } else {
2814 UMA_HISTOGRAM_COUNTS("HttpCache.StaleEntry.Updated.Age", 2826 UMA_HISTOGRAM_COUNTS("HttpCache.StaleEntry.Updated.Age",
2815 stale_entry_age_.InSeconds()); 2827 stale_entry_age_.InSeconds());
2816 UMA_HISTOGRAM_COUNTS( 2828 UMA_HISTOGRAM_COUNTS(
2817 "HttpCache.StaleEntry.Updated.AgeInFreshnessPeriods", 2829 "HttpCache.StaleEntry.Updated.AgeInFreshnessPeriods",
2818 age_in_freshness_periods); 2830 age_in_freshness_periods);
2819 } 2831 }
2820 } 2832 }
2821 } 2833 }
2822 2834
2823 std::string mime_type; 2835 std::string mime_type;
2824 HttpResponseHeaders* response_headers = GetResponseInfo()->headers.get(); 2836 HttpResponseHeaders* response_headers = GetResponseInfo()->headers.get();
2825 if (response_headers && response_headers->GetMimeType(&mime_type)) { 2837 if (response_headers && response_headers->GetMimeType(&mime_type)) {
2826 // Record the cache pattern by resource type. The type is inferred by 2838 // Record the cache pattern by resource type. The type is inferred by
2827 // response header mime type, which could be incorrect, so this is just an 2839 // response header mime type, which could be incorrect, so this is just an
2828 // estimate. 2840 // estimate.
2829 if (mime_type == "text/html" && 2841 if (mime_type == "text/html" &&
2830 (request_->load_flags & LOAD_MAIN_FRAME_DEPRECATED)) { 2842 (request_->load_flags & LOAD_MAIN_FRAME_DEPRECATED)) {
2831 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.MainFrameHTML", 2843 CACHE_STATUS_HISTOGRAMS(".MainFrameHTML");
2832 cache_entry_status_,
2833 CacheEntryStatus::ENTRY_MAX);
2834 if (validation_request) {
2835 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.MainFrameHTML",
2836 validation_cause_, VALIDATION_CAUSE_MAX);
2837 }
2838 if (stale_request) {
2839 UMA_HISTOGRAM_COUNTS(
2840 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed.MainFrameHTML",
2841 freshness_periods_since_last_used);
2842 }
2843 } else if (mime_type == "text/html") { 2844 } else if (mime_type == "text/html") {
2844 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.NonMainFrameHTML", 2845 CACHE_STATUS_HISTOGRAMS(".NonMainFrameHTML");
2845 cache_entry_status_,
2846 CacheEntryStatus::ENTRY_MAX);
2847 if (validation_request) {
2848 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.NonMainFrameHTML",
2849 validation_cause_, VALIDATION_CAUSE_MAX);
2850 }
2851 if (stale_request) {
2852 UMA_HISTOGRAM_COUNTS(
2853 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed."
2854 "NonMainFrameHTML",
2855 freshness_periods_since_last_used);
2856 }
2857 } else if (mime_type == "text/css") { 2846 } else if (mime_type == "text/css") {
2858 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.CSS", cache_entry_status_, 2847 CACHE_STATUS_HISTOGRAMS(".CSS");
2859 CacheEntryStatus::ENTRY_MAX);
2860 if (validation_request) {
2861 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.CSS",
2862 validation_cause_, VALIDATION_CAUSE_MAX);
2863 }
2864 if (stale_request) {
2865 UMA_HISTOGRAM_COUNTS(
2866 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed.CSS",
2867 freshness_periods_since_last_used);
2868 }
2869 } else if (base::StartsWith(mime_type, "image/", 2848 } else if (base::StartsWith(mime_type, "image/",
2870 base::CompareCase::SENSITIVE)) { 2849 base::CompareCase::SENSITIVE)) {
2871 int64_t content_length = response_headers->GetContentLength(); 2850 int64_t content_length = response_headers->GetContentLength();
2872 if (content_length >= 0 && content_length < 100) { 2851 if (content_length >= 0 && content_length < 100) {
2873 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.TinyImage", 2852 CACHE_STATUS_HISTOGRAMS(".TinyImage");
2874 cache_entry_status_,
2875 CacheEntryStatus::ENTRY_MAX);
2876 if (validation_request) {
2877 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.TinyImage",
2878 validation_cause_, VALIDATION_CAUSE_MAX);
2879 }
2880 if (stale_request) {
2881 UMA_HISTOGRAM_COUNTS(
2882 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed.TinyImage",
2883 freshness_periods_since_last_used);
2884 }
2885 } else if (content_length >= 100) { 2853 } else if (content_length >= 100) {
2886 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.NonTinyImage", 2854 CACHE_STATUS_HISTOGRAMS(".NonTinyImage");
2887 cache_entry_status_,
2888 CacheEntryStatus::ENTRY_MAX);
2889 if (validation_request) {
2890 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.NonTinyImage",
2891 validation_cause_, VALIDATION_CAUSE_MAX);
2892 }
2893 if (stale_request) {
2894 UMA_HISTOGRAM_COUNTS(
2895 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed.NonTinyImage",
2896 freshness_periods_since_last_used);
2897 }
2898 } 2855 }
2899 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.Image", cache_entry_status_, 2856 CACHE_STATUS_HISTOGRAMS(".Image");
2900 CacheEntryStatus::ENTRY_MAX);
2901 if (validation_request) {
2902 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.Image",
2903 validation_cause_, VALIDATION_CAUSE_MAX);
2904 }
2905 if (stale_request) {
2906 UMA_HISTOGRAM_COUNTS(
2907 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed.Image",
2908 freshness_periods_since_last_used);
2909 }
2910 } else if (base::EndsWith(mime_type, "javascript", 2857 } else if (base::EndsWith(mime_type, "javascript",
2911 base::CompareCase::SENSITIVE) || 2858 base::CompareCase::SENSITIVE) ||
2912 base::EndsWith(mime_type, "ecmascript", 2859 base::EndsWith(mime_type, "ecmascript",
2913 base::CompareCase::SENSITIVE)) { 2860 base::CompareCase::SENSITIVE)) {
2914 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.JavaScript", 2861 CACHE_STATUS_HISTOGRAMS(".JavaScript");
2915 cache_entry_status_,
2916 CacheEntryStatus::ENTRY_MAX);
2917 if (validation_request) {
2918 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.JavaScript",
2919 validation_cause_, VALIDATION_CAUSE_MAX);
2920 }
2921 if (stale_request) {
2922 UMA_HISTOGRAM_COUNTS(
2923 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed.JavaScript",
2924 freshness_periods_since_last_used);
2925 }
2926 } else if (mime_type.find("font") != std::string::npos) { 2862 } else if (mime_type.find("font") != std::string::npos) {
2927 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.Font", cache_entry_status_, 2863 CACHE_STATUS_HISTOGRAMS(".Font");
2928 CacheEntryStatus::ENTRY_MAX); 2864 } else if (base::StartsWith(mime_type, "audio/",
2929 if (validation_request) { 2865 base::CompareCase::SENSITIVE)) {
2930 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.Font", 2866 CACHE_STATUS_HISTOGRAMS(".Audio");
2931 validation_cause_, VALIDATION_CAUSE_MAX); 2867 } else if (base::StartsWith(mime_type, "video/",
2932 } 2868 base::CompareCase::SENSITIVE)) {
2933 if (stale_request) { 2869 CACHE_STATUS_HISTOGRAMS(".Video");
2934 UMA_HISTOGRAM_COUNTS(
2935 "HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed.Font",
2936 freshness_periods_since_last_used);
2937 }
2938 } 2870 }
2939 } 2871 }
2940 2872
2941 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern", cache_entry_status_, 2873 CACHE_STATUS_HISTOGRAMS("");
gavinp 2016/09/23 15:41:49 Does this have to be "", or would () work too? I b
jkarlin 2016/09/23 15:53:02 () works. WIll commit with that.
jkarlin 2016/09/23 17:05:22 Nope, Windows doesn't like it. Reverting.
2942 CacheEntryStatus::ENTRY_MAX);
2943
2944 if (validation_request) {
2945 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause", validation_cause_,
2946 VALIDATION_CAUSE_MAX);
2947 }
2948 2874
2949 if (cache_entry_status_ == CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE) { 2875 if (cache_entry_status_ == CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE) {
2950 UMA_HISTOGRAM_ENUMERATION("HttpCache.CantConditionalizeCause", 2876 UMA_HISTOGRAM_ENUMERATION("HttpCache.CantConditionalizeCause",
2951 validation_cause_, VALIDATION_CAUSE_MAX); 2877 validation_cause_, VALIDATION_CAUSE_MAX);
2952 } 2878 }
2953 2879
2954 if (cache_entry_status_ == CacheEntryStatus::ENTRY_OTHER) 2880 if (cache_entry_status_ == CacheEntryStatus::ENTRY_OTHER)
2955 return; 2881 return;
2956 DCHECK(!range_requested_); 2882 DCHECK(!range_requested_);
2957 DCHECK(!first_cache_access_since_.is_null()); 2883 DCHECK(!first_cache_access_since_.is_null());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 default: 2946 default:
3021 NOTREACHED(); 2947 NOTREACHED();
3022 } 2948 }
3023 } 2949 }
3024 2950
3025 void HttpCache::Transaction::OnIOComplete(int result) { 2951 void HttpCache::Transaction::OnIOComplete(int result) {
3026 DoLoop(result); 2952 DoLoop(result);
3027 } 2953 }
3028 2954
3029 } // namespace net 2955 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698