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

Side by Side Diff: content/browser/download/download_stats.cc

Issue 2750713003: Add UMA for estimating disk bandwidth and the time saved with parallel download (Closed)
Patch Set: Created 3 years, 9 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
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 "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_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 339
340 // Maps extensions to their matching UMA histogram int value. 340 // Maps extensions to their matching UMA histogram int value.
341 int GetDangerousFileType(const base::FilePath& file_path) { 341 int GetDangerousFileType(const base::FilePath& file_path) {
342 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { 342 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) {
343 if (file_path.MatchesExtension(kDangerousFileTypes[i])) 343 if (file_path.MatchesExtension(kDangerousFileTypes[i]))
344 return i + 1; 344 return i + 1;
345 } 345 }
346 return 0; // Unknown extension. 346 return 0; // Unknown extension.
347 } 347 }
348 348
349 // Helper method to calculate the bandwidth given the data length and time.
350 int CalculateBandwidthBytesPerSecond(size_t length,
351 base::TimeDelta elapsed_time) {
352 size_t elapsed_time_ms = elapsed_time.InMilliseconds();
353 if (0u == elapsed_time_ms)
354 elapsed_time_ms = 1;
355
356 return 1000 * length / elapsed_time_ms;
357 }
358
349 } // namespace 359 } // namespace
350 360
351 void RecordDownloadCount(DownloadCountTypes type) { 361 void RecordDownloadCount(DownloadCountTypes type) {
352 UMA_HISTOGRAM_ENUMERATION( 362 UMA_HISTOGRAM_ENUMERATION(
353 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 363 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
354 } 364 }
355 365
356 void RecordDownloadSource(DownloadSource source) { 366 void RecordDownloadSource(DownloadSource source) {
357 UMA_HISTOGRAM_ENUMERATION( 367 UMA_HISTOGRAM_ENUMERATION(
358 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY); 368 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY);
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 resource_handler_blocked_time * 100 / resource_handler_lifetime; 706 resource_handler_blocked_time * 100 / resource_handler_lifetime;
697 } 707 }
698 708
699 UMA_HISTOGRAM_COUNTS_100("Download.ResourceHandlerBlockedPercentage", 709 UMA_HISTOGRAM_COUNTS_100("Download.ResourceHandlerBlockedPercentage",
700 percentage); 710 percentage);
701 } 711 }
702 712
703 void RecordFileBandwidth(size_t length, 713 void RecordFileBandwidth(size_t length,
704 base::TimeDelta disk_write_time, 714 base::TimeDelta disk_write_time,
705 base::TimeDelta elapsed_time) { 715 base::TimeDelta elapsed_time) {
706 size_t elapsed_time_ms = elapsed_time.InMilliseconds();
707 if (0u == elapsed_time_ms)
708 elapsed_time_ms = 1;
709 size_t disk_write_time_ms = disk_write_time.InMilliseconds();
710 if (0u == disk_write_time_ms)
711 disk_write_time_ms = 1;
712
713 UMA_HISTOGRAM_CUSTOM_COUNTS( 716 UMA_HISTOGRAM_CUSTOM_COUNTS(
714 "Download.BandwidthOverallBytesPerSecond", 717 "Download.BandwidthOverallBytesPerSecond",
715 (1000 * length / elapsed_time_ms), 1, 50000000, 50); 718 CalculateBandwidthBytesPerSecond(length, elapsed_time), 1, 50000000, 50);
716 UMA_HISTOGRAM_CUSTOM_COUNTS( 719 UMA_HISTOGRAM_CUSTOM_COUNTS(
717 "Download.BandwidthDiskBytesPerSecond", 720 "Download.BandwidthDiskBytesPerSecond",
718 (1000 * length / disk_write_time_ms), 1, 50000000, 50); 721 CalculateBandwidthBytesPerSecond(length, disk_write_time), 1, 50000000,
722 50);
723 }
724
725 void RecordParallelDownloadStats(
726 size_t bytes_downloaded_with_parallel_streams,
727 base::TimeDelta time_with_parallel_streams,
728 size_t bytes_downloaded_without_parallel_streams,
729 base::TimeDelta time_without_parallel_streams) {
730 int bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond(
731 bytes_downloaded_without_parallel_streams, time_without_parallel_streams);
732 UMA_HISTOGRAM_CUSTOM_COUNTS(
David Trainor- moved to gerrit 2017/03/14 15:28:38 Might be cleaner to have a helper that logs the hi
qinmin 2017/03/15 00:17:19 Done.
733 "Download.BandwidthWithParallelStreamsBytesPerSecond",
734 CalculateBandwidthBytesPerSecond(bytes_downloaded_with_parallel_streams,
735 time_with_parallel_streams),
736 1, 50000000, 50);
737 UMA_HISTOGRAM_CUSTOM_COUNTS(
738 "Download.BandwidthWithoutParallelStreamsBytesPerSecond",
739 bandwidth_without_parallel_streams, 1, 50000000, 50);
740
741 base::TimeDelta time_saved =
742 time_without_parallel_streams -
xingliu 2017/03/14 00:10:55 Substraction between unsigned and signed integer i
qinmin 2017/03/15 00:17:19 TimeDelta uses a int64, which is signed, so I am n
xingliu 2017/03/15 01:07:22 Sorry, I probably mistake the parameters here. Mea
qinmin 2017/03/15 16:29:09 That's correct. Thanks, fixed
743 base::TimeDelta::FromMilliseconds(1000.0 *
744 bytes_downloaded_with_parallel_streams /
745 bandwidth_without_parallel_streams);
746 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.TimeSavedWithParallelDownload",
747 time_saved.InMilliseconds(), 0, 3600 * 1000, 50);
David Trainor- moved to gerrit 2017/03/14 15:28:38 It looks like we're setting the min at 0. Can thi
qinmin 2017/03/15 00:17:19 Good catch, fixed
719 } 748 }
720 749
721 void RecordDownloadFileRenameResultAfterRetry( 750 void RecordDownloadFileRenameResultAfterRetry(
722 base::TimeDelta time_since_first_failure, 751 base::TimeDelta time_since_first_failure,
723 DownloadInterruptReason interrupt_reason) { 752 DownloadInterruptReason interrupt_reason) {
724 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { 753 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) {
725 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", 754 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure",
726 time_since_first_failure); 755 time_since_first_failure);
727 } else { 756 } else {
728 UMA_HISTOGRAM_TIMES("Download.TimeToRenameFailureAfterInitialFailure", 757 UMA_HISTOGRAM_TIMES("Download.TimeToRenameFailureAfterInitialFailure",
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 if (!page_transition) 824 if (!page_transition)
796 return; 825 return;
797 826
798 UMA_HISTOGRAM_ENUMERATION( 827 UMA_HISTOGRAM_ENUMERATION(
799 "Download.PageTransition", 828 "Download.PageTransition",
800 ui::PageTransitionStripQualifier(page_transition.value()), 829 ui::PageTransitionStripQualifier(page_transition.value()),
801 ui::PAGE_TRANSITION_LAST_CORE + 1); 830 ui::PAGE_TRANSITION_LAST_CORE + 1);
802 } 831 }
803 832
804 } // namespace content 833 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698