OLD | NEW |
---|---|
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 "content/browser/download/download_stats.h" | 5 #include "content/browser/download/download_stats.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/metrics/histogram_functions.h" | 8 #include "base/metrics/histogram_functions.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 FILE_PATH_LITERAL(".img"), | 332 FILE_PATH_LITERAL(".img"), |
333 FILE_PATH_LITERAL(".imgpart"), | 333 FILE_PATH_LITERAL(".imgpart"), |
334 FILE_PATH_LITERAL(".ndif"), | 334 FILE_PATH_LITERAL(".ndif"), |
335 FILE_PATH_LITERAL(".smi"), | 335 FILE_PATH_LITERAL(".smi"), |
336 FILE_PATH_LITERAL(".sparsebundle"), | 336 FILE_PATH_LITERAL(".sparsebundle"), |
337 FILE_PATH_LITERAL(".sparseimage"), | 337 FILE_PATH_LITERAL(".sparseimage"), |
338 FILE_PATH_LITERAL(".toast"), | 338 FILE_PATH_LITERAL(".toast"), |
339 FILE_PATH_LITERAL(".udif"), | 339 FILE_PATH_LITERAL(".udif"), |
340 }; | 340 }; |
341 | 341 |
342 // The maximum size of the file that every bucket should hold. | |
343 const int64_t kParallelizableBucketKb[] = {512, 1024, 3072, 10240, 51200}; | |
344 | |
345 // Suffixes for parallelizable downloads bucketed by file size. Each suffix will | |
346 // generate a new histogram. | |
347 const char* kParallelizableBucketName[] = {"0.5MB", "1MB", "3MB", | |
348 "10MB", "50MB", "GT50MB"}; | |
349 | |
342 // Maps extensions to their matching UMA histogram int value. | 350 // Maps extensions to their matching UMA histogram int value. |
343 int GetDangerousFileType(const base::FilePath& file_path) { | 351 int GetDangerousFileType(const base::FilePath& file_path) { |
344 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { | 352 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { |
345 if (file_path.MatchesExtension(kDangerousFileTypes[i])) | 353 if (file_path.MatchesExtension(kDangerousFileTypes[i])) |
346 return i + 1; | 354 return i + 1; |
347 } | 355 } |
348 return 0; // Unknown extension. | 356 return 0; // Unknown extension. |
349 } | 357 } |
350 | 358 |
351 // Helper method to calculate the bandwidth given the data length and time. | 359 // Helper method to calculate the bandwidth given the data length and time. |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 void RecordParallelDownloadAddStreamSuccess(bool success) { | 797 void RecordParallelDownloadAddStreamSuccess(bool success) { |
790 UMA_HISTOGRAM_BOOLEAN("Download.ParallelDownloadAddStreamSuccess", success); | 798 UMA_HISTOGRAM_BOOLEAN("Download.ParallelDownloadAddStreamSuccess", success); |
791 } | 799 } |
792 | 800 |
793 void RecordParallelizableDownloadStats( | 801 void RecordParallelizableDownloadStats( |
794 size_t bytes_downloaded_with_parallel_streams, | 802 size_t bytes_downloaded_with_parallel_streams, |
795 base::TimeDelta time_with_parallel_streams, | 803 base::TimeDelta time_with_parallel_streams, |
796 size_t bytes_downloaded_without_parallel_streams, | 804 size_t bytes_downloaded_without_parallel_streams, |
797 base::TimeDelta time_without_parallel_streams, | 805 base::TimeDelta time_without_parallel_streams, |
798 bool uses_parallel_requests) { | 806 bool uses_parallel_requests) { |
807 RecordParallelizableDownloadAverageStats( | |
808 bytes_downloaded_with_parallel_streams + | |
809 bytes_downloaded_without_parallel_streams, | |
810 time_with_parallel_streams + time_without_parallel_streams); | |
811 | |
799 int64_t bandwidth_without_parallel_streams = 0; | 812 int64_t bandwidth_without_parallel_streams = 0; |
800 if (bytes_downloaded_without_parallel_streams > 0) { | 813 if (bytes_downloaded_without_parallel_streams > 0) { |
801 bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond( | 814 bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond( |
802 bytes_downloaded_without_parallel_streams, | 815 bytes_downloaded_without_parallel_streams, |
803 time_without_parallel_streams); | 816 time_without_parallel_streams); |
804 if (uses_parallel_requests) { | 817 if (uses_parallel_requests) { |
805 RecordBandwidthMetric( | 818 RecordBandwidthMetric( |
806 "Download.ParallelizableDownloadBandwidth." | 819 "Download.ParallelizableDownloadBandwidth." |
807 "WithParallelRequestsSingleStream", | 820 "WithParallelRequestsSingleStream", |
808 bandwidth_without_parallel_streams); | 821 bandwidth_without_parallel_streams); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
856 UMA_HISTOGRAM_CUSTOM_COUNTS( | 869 UMA_HISTOGRAM_CUSTOM_COUNTS( |
857 "Download.EstimatedTimeSavedWithParallelDownload", | 870 "Download.EstimatedTimeSavedWithParallelDownload", |
858 time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); | 871 time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); |
859 } else { | 872 } else { |
860 UMA_HISTOGRAM_CUSTOM_COUNTS( | 873 UMA_HISTOGRAM_CUSTOM_COUNTS( |
861 "Download.EstimatedTimeWastedWithParallelDownload", | 874 "Download.EstimatedTimeWastedWithParallelDownload", |
862 -time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); | 875 -time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); |
863 } | 876 } |
864 } | 877 } |
865 | 878 |
879 void RecordParallelizableDownloadAverageStats( | |
880 int64_t bytes_downloaded, | |
881 const base::TimeDelta& time_span) { | |
882 if (time_span.is_zero() || bytes_downloaded <= 0) | |
883 return; | |
884 | |
885 int64_t average_bandwidth = | |
886 CalculateBandwidthBytesPerSecond(bytes_downloaded, time_span); | |
887 int64_t file_size_kb = bytes_downloaded / 1024; | |
888 RecordBandwidthMetric("Download.ParallelizableDownloadBandwidth", | |
889 average_bandwidth); | |
890 UMA_HISTOGRAM_LONG_TIMES("Download.Parallelizable.DownloadTime", time_span); | |
891 int64_t max = 1024 * 1024 * 1024; | |
892 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.Parallelizable.FileSize", file_size_kb, | |
893 1, max, /* 1 TB as maximum. */ | |
894 256); | |
895 | |
896 // Download size suffix for average bandwidth and download time metrics. | |
897 size_t i = 0; | |
898 for (size_t n = arraysize(kParallelizableBucketKb); i < n; ++i) { | |
David Trainor- moved to gerrit
2017/05/17 17:23:53
do we need n or can we just do ; i < arraysize(...
xingliu
2017/05/17 18:04:11
Trying to avoid evaluate array size on every itera
| |
899 if (file_size_kb <= kParallelizableBucketKb[i]) | |
900 break; | |
901 } | |
902 std::string suffix = kParallelizableBucketName[i]; | |
903 RecordBandwidthMetric("Download.ParallelizableDownloadBandwidth." + suffix, | |
904 average_bandwidth); | |
905 base::UmaHistogramLongTimes("Download.Parallelizable.DownloadTime." + suffix, | |
906 time_span); | |
907 } | |
908 | |
866 void RecordParallelDownloadCreationEvent(ParallelDownloadCreationEvent event) { | 909 void RecordParallelDownloadCreationEvent(ParallelDownloadCreationEvent event) { |
867 UMA_HISTOGRAM_ENUMERATION("Download.ParallelDownload.CreationEvent", event, | 910 UMA_HISTOGRAM_ENUMERATION("Download.ParallelDownload.CreationEvent", event, |
868 ParallelDownloadCreationEvent::COUNT); | 911 ParallelDownloadCreationEvent::COUNT); |
869 } | 912 } |
870 | 913 |
871 void RecordDownloadFileRenameResultAfterRetry( | 914 void RecordDownloadFileRenameResultAfterRetry( |
872 base::TimeDelta time_since_first_failure, | 915 base::TimeDelta time_since_first_failure, |
873 DownloadInterruptReason interrupt_reason) { | 916 DownloadInterruptReason interrupt_reason) { |
874 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { | 917 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { |
875 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", | 918 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 } | 995 } |
953 | 996 |
954 void RecordDownloadHttpResponseCode(int response_code) { | 997 void RecordDownloadHttpResponseCode(int response_code) { |
955 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 998 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
956 "Download.HttpResponseCode", | 999 "Download.HttpResponseCode", |
957 net::HttpUtil::MapStatusCodeForHistogram(response_code), | 1000 net::HttpUtil::MapStatusCodeForHistogram(response_code), |
958 net::HttpUtil::GetStatusCodesForHistogram()); | 1001 net::HttpUtil::GetStatusCodesForHistogram()); |
959 } | 1002 } |
960 | 1003 |
961 } // namespace content | 1004 } // namespace content |
OLD | NEW |