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

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: fix UMA calculation 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 and record the bandwidth for a given metric by
350 // dividing the |data_length| by |elapsed_time|.
351 int LogBandwidthBytesPerSecond(
352 const std::string& metric,
353 size_t data_length,
354 base::TimeDelta elapsed_time) {
Ilya Sherman 2017/03/15 20:54:43 Optional nit: I find this function a bit hard to t
qinmin 2017/03/15 23:20:11 Done.
355 size_t elapsed_time_ms = elapsed_time.InMilliseconds();
356 if (0u == elapsed_time_ms)
357 elapsed_time_ms = 1;
358
359 int bandwidth = 1000 * data_length / elapsed_time_ms;
360 UMA_HISTOGRAM_CUSTOM_COUNTS(
Ilya Sherman 2017/03/15 20:54:43 The UMA_HISTOGRAM macros (other than the SPARSE ma
qinmin 2017/03/15 23:20:11 Done.
361 metric, bandwidth, 1, 50000000, 50);
Ilya Sherman 2017/03/15 20:54:43 nit: Could you please write this as "50 * 1000 * 1
qinmin 2017/03/15 23:20:11 Done. still keeping 1000 as the existing UMAs are
362 return bandwidth;
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
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 LogBandwidthBytesPerSecond(
707 if (0u == elapsed_time_ms) 723 "Download.BandwidthOverallBytesPerSecond", length, elapsed_time);
708 elapsed_time_ms = 1; 724 LogBandwidthBytesPerSecond(
709 size_t disk_write_time_ms = disk_write_time.InMilliseconds(); 725 "Download.BandwidthDiskBytesPerSecond", length, disk_write_time);
710 if (0u == disk_write_time_ms) 726 }
711 disk_write_time_ms = 1;
712 727
728 void RecordParallelDownloadStats(
729 size_t bytes_downloaded_with_parallel_streams,
730 base::TimeDelta time_with_parallel_streams,
731 size_t bytes_downloaded_without_parallel_streams,
732 base::TimeDelta time_without_parallel_streams) {
733 int bandwidth_without_parallel_streams = LogBandwidthBytesPerSecond(
734 "Download.BandwidthWithoutParallelStreamsBytesPerSecond",
735 bytes_downloaded_without_parallel_streams, time_without_parallel_streams);
736 LogBandwidthBytesPerSecond(
737 "Download.BandwidthWithParallelStreamsBytesPerSecond",
738 bytes_downloaded_with_parallel_streams, time_with_parallel_streams);
739
740 base::TimeDelta time_saved =
741 base::TimeDelta::FromMilliseconds(1000.0 *
742 bytes_downloaded_with_parallel_streams /
743 bandwidth_without_parallel_streams) -
744 time_with_parallel_streams;
745
746 int microseconds_per_hour =
Ilya Sherman 2017/03/15 20:54:43 nit: I'd name this kMicrosecondsPerHour, and use b
qinmin 2017/03/15 23:20:11 Done.
747 static_cast<int>(base::Time::kMicrosecondsPerHour);
713 UMA_HISTOGRAM_CUSTOM_COUNTS( 748 UMA_HISTOGRAM_CUSTOM_COUNTS(
714 "Download.BandwidthOverallBytesPerSecond", 749 "Download.TimeSavedWithParallelDownload",
715 (1000 * length / elapsed_time_ms), 1, 50000000, 50); 750 time_saved.InMilliseconds(), -microseconds_per_hour,
Ilya Sherman 2017/03/15 20:54:43 UMA histograms do not support negative buckets (ag
qinmin 2017/03/15 23:20:11 Use 2 separate histogram instead.
716 UMA_HISTOGRAM_CUSTOM_COUNTS( 751 microseconds_per_hour, 50);
717 "Download.BandwidthDiskBytesPerSecond",
718 (1000 * length / disk_write_time_ms), 1, 50000000, 50);
719 } 752 }
720 753
721 void RecordDownloadFileRenameResultAfterRetry( 754 void RecordDownloadFileRenameResultAfterRetry(
722 base::TimeDelta time_since_first_failure, 755 base::TimeDelta time_since_first_failure,
723 DownloadInterruptReason interrupt_reason) { 756 DownloadInterruptReason interrupt_reason) {
724 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { 757 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) {
725 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", 758 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure",
726 time_since_first_failure); 759 time_since_first_failure);
727 } else { 760 } else {
728 UMA_HISTOGRAM_TIMES("Download.TimeToRenameFailureAfterInitialFailure", 761 UMA_HISTOGRAM_TIMES("Download.TimeToRenameFailureAfterInitialFailure",
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 if (!page_transition) 828 if (!page_transition)
796 return; 829 return;
797 830
798 UMA_HISTOGRAM_ENUMERATION( 831 UMA_HISTOGRAM_ENUMERATION(
799 "Download.PageTransition", 832 "Download.PageTransition",
800 ui::PageTransitionStripQualifier(page_transition.value()), 833 ui::PageTransitionStripQualifier(page_transition.value()),
801 ui::PAGE_TRANSITION_LAST_CORE + 1); 834 ui::PAGE_TRANSITION_LAST_CORE + 1);
802 } 835 }
803 836
804 } // namespace content 837 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698