| 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_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "content/browser/download/download_resource_handler.h" | 12 #include "content/browser/download/download_resource_handler.h" |
| 12 #include "content/public/browser/download_interrupt_reasons.h" | 13 #include "content/public/browser/download_interrupt_reasons.h" |
| 13 #include "net/http/http_content_disposition.h" | 14 #include "net/http/http_content_disposition.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 340 |
| 340 // Maps extensions to their matching UMA histogram int value. | 341 // Maps extensions to their matching UMA histogram int value. |
| 341 int GetDangerousFileType(const base::FilePath& file_path) { | 342 int GetDangerousFileType(const base::FilePath& file_path) { |
| 342 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { | 343 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { |
| 343 if (file_path.MatchesExtension(kDangerousFileTypes[i])) | 344 if (file_path.MatchesExtension(kDangerousFileTypes[i])) |
| 344 return i + 1; | 345 return i + 1; |
| 345 } | 346 } |
| 346 return 0; // Unknown extension. | 347 return 0; // Unknown extension. |
| 347 } | 348 } |
| 348 | 349 |
| 350 // Helper method to calculate the bandwidth given the data length and time. |
| 351 int CalculateBandwidthBytesPerSecond(size_t length, |
| 352 base::TimeDelta elapsed_time) { |
| 353 size_t elapsed_time_ms = elapsed_time.InMilliseconds(); |
| 354 if (0u == elapsed_time_ms) |
| 355 elapsed_time_ms = 1; |
| 356 |
| 357 return 1000 * length / elapsed_time_ms; |
| 358 } |
| 359 |
| 360 // Helper method to record the bandwidth for a given metric. |
| 361 void RecordBandwidthMetric(const std::string& metric, int bandwidth) { |
| 362 base::UmaHistogramCustomCounts(metric, bandwidth, 1, 50 * 1000 * 1000, 50); |
| 363 } |
| 364 |
| 349 } // namespace | 365 } // namespace |
| 350 | 366 |
| 351 void RecordDownloadCount(DownloadCountTypes type) { | 367 void RecordDownloadCount(DownloadCountTypes type) { |
| 352 UMA_HISTOGRAM_ENUMERATION( | 368 UMA_HISTOGRAM_ENUMERATION( |
| 353 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY); | 369 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY); |
| 354 } | 370 } |
| 355 | 371 |
| 356 void RecordDownloadSource(DownloadSource source) { | 372 void RecordDownloadSource(DownloadSource source) { |
| 357 UMA_HISTOGRAM_ENUMERATION( | 373 UMA_HISTOGRAM_ENUMERATION( |
| 358 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY); | 374 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 resource_handler_blocked_time * 100 / resource_handler_lifetime; | 712 resource_handler_blocked_time * 100 / resource_handler_lifetime; |
| 697 } | 713 } |
| 698 | 714 |
| 699 UMA_HISTOGRAM_COUNTS_100("Download.ResourceHandlerBlockedPercentage", | 715 UMA_HISTOGRAM_COUNTS_100("Download.ResourceHandlerBlockedPercentage", |
| 700 percentage); | 716 percentage); |
| 701 } | 717 } |
| 702 | 718 |
| 703 void RecordFileBandwidth(size_t length, | 719 void RecordFileBandwidth(size_t length, |
| 704 base::TimeDelta disk_write_time, | 720 base::TimeDelta disk_write_time, |
| 705 base::TimeDelta elapsed_time) { | 721 base::TimeDelta elapsed_time) { |
| 706 size_t elapsed_time_ms = elapsed_time.InMilliseconds(); | 722 RecordBandwidthMetric("Download.BandwidthOverallBytesPerSecond", |
| 707 if (0u == elapsed_time_ms) | 723 CalculateBandwidthBytesPerSecond(length, elapsed_time)); |
| 708 elapsed_time_ms = 1; | 724 RecordBandwidthMetric( |
| 709 size_t disk_write_time_ms = disk_write_time.InMilliseconds(); | 725 "Download.BandwidthDiskBytesPerSecond", |
| 710 if (0u == disk_write_time_ms) | 726 CalculateBandwidthBytesPerSecond(length, disk_write_time)); |
| 711 disk_write_time_ms = 1; | 727 } |
| 712 | 728 |
| 713 UMA_HISTOGRAM_CUSTOM_COUNTS( | 729 void RecordParallelDownloadStats( |
| 714 "Download.BandwidthOverallBytesPerSecond", | 730 size_t bytes_downloaded_with_parallel_streams, |
| 715 (1000 * length / elapsed_time_ms), 1, 50000000, 50); | 731 base::TimeDelta time_with_parallel_streams, |
| 716 UMA_HISTOGRAM_CUSTOM_COUNTS( | 732 size_t bytes_downloaded_without_parallel_streams, |
| 717 "Download.BandwidthDiskBytesPerSecond", | 733 base::TimeDelta time_without_parallel_streams) { |
| 718 (1000 * length / disk_write_time_ms), 1, 50000000, 50); | 734 int bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond( |
| 735 bytes_downloaded_without_parallel_streams, time_without_parallel_streams); |
| 736 RecordBandwidthMetric( |
| 737 "Download.BandwidthWithoutParallelStreamsBytesPerSecond", |
| 738 bandwidth_without_parallel_streams); |
| 739 RecordBandwidthMetric( |
| 740 "Download.BandwidthWithParallelStreamsBytesPerSecond", |
| 741 CalculateBandwidthBytesPerSecond(bytes_downloaded_with_parallel_streams, |
| 742 time_with_parallel_streams)); |
| 743 |
| 744 base::TimeDelta time_saved; |
| 745 if (bandwidth_without_parallel_streams > 0) { |
| 746 time_saved = base::TimeDelta::FromMilliseconds( |
| 747 1000.0 * bytes_downloaded_with_parallel_streams / |
| 748 bandwidth_without_parallel_streams) - |
| 749 time_with_parallel_streams; |
| 750 } |
| 751 int kMillisecondsPerHour = |
| 752 base::checked_cast<int>(base::Time::kMillisecondsPerSecond * 60 * 60); |
| 753 if (time_saved >= base::TimeDelta()) { |
| 754 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 755 "Download.EstimatedTimeSavedWithParallelDownload", |
| 756 time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); |
| 757 } else { |
| 758 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 759 "Download.EstimatedTimeWastedWithParallelDownload", |
| 760 -time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); |
| 761 } |
| 719 } | 762 } |
| 720 | 763 |
| 721 void RecordDownloadFileRenameResultAfterRetry( | 764 void RecordDownloadFileRenameResultAfterRetry( |
| 722 base::TimeDelta time_since_first_failure, | 765 base::TimeDelta time_since_first_failure, |
| 723 DownloadInterruptReason interrupt_reason) { | 766 DownloadInterruptReason interrupt_reason) { |
| 724 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { | 767 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 725 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", | 768 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", |
| 726 time_since_first_failure); | 769 time_since_first_failure); |
| 727 } else { | 770 } else { |
| 728 UMA_HISTOGRAM_TIMES("Download.TimeToRenameFailureAfterInitialFailure", | 771 UMA_HISTOGRAM_TIMES("Download.TimeToRenameFailureAfterInitialFailure", |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 if (!page_transition) | 838 if (!page_transition) |
| 796 return; | 839 return; |
| 797 | 840 |
| 798 UMA_HISTOGRAM_ENUMERATION( | 841 UMA_HISTOGRAM_ENUMERATION( |
| 799 "Download.PageTransition", | 842 "Download.PageTransition", |
| 800 ui::PageTransitionStripQualifier(page_transition.value()), | 843 ui::PageTransitionStripQualifier(page_transition.value()), |
| 801 ui::PAGE_TRANSITION_LAST_CORE + 1); | 844 ui::PAGE_TRANSITION_LAST_CORE + 1); |
| 802 } | 845 } |
| 803 | 846 |
| 804 } // namespace content | 847 } // namespace content |
| OLD | NEW |