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

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

Issue 2798723002: Fix the UMA stats calculation because of overflow (Closed)
Patch Set: Created 3 years, 8 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 | no next file » | 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 "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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Maps extensions to their matching UMA histogram int value. 341 // Maps extensions to their matching UMA histogram int value.
342 int GetDangerousFileType(const base::FilePath& file_path) { 342 int GetDangerousFileType(const base::FilePath& file_path) {
343 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { 343 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) {
344 if (file_path.MatchesExtension(kDangerousFileTypes[i])) 344 if (file_path.MatchesExtension(kDangerousFileTypes[i]))
345 return i + 1; 345 return i + 1;
346 } 346 }
347 return 0; // Unknown extension. 347 return 0; // Unknown extension.
348 } 348 }
349 349
350 // Helper method to calculate the bandwidth given the data length and time. 350 // Helper method to calculate the bandwidth given the data length and time.
351 int CalculateBandwidthBytesPerSecond(size_t length, 351 int64_t CalculateBandwidthBytesPerSecond(size_t length,
352 base::TimeDelta elapsed_time) { 352 base::TimeDelta elapsed_time) {
353 size_t elapsed_time_ms = elapsed_time.InMilliseconds(); 353 int64_t elapsed_time_ms = elapsed_time.InMilliseconds();
354 if (0u == elapsed_time_ms) 354 if (0 == elapsed_time_ms)
355 elapsed_time_ms = 1; 355 elapsed_time_ms = 1;
356 356 return 1000 * static_cast<int64_t>(length) / elapsed_time_ms;
357 return 1000 * length / elapsed_time_ms;
358 } 357 }
359 358
360 // Helper method to record the bandwidth for a given metric. 359 // Helper method to record the bandwidth for a given metric.
361 void RecordBandwidthMetric(const std::string& metric, int bandwidth) { 360 void RecordBandwidthMetric(const std::string& metric, int bandwidth) {
362 base::UmaHistogramCustomCounts(metric, bandwidth, 1, 50 * 1000 * 1000, 50); 361 base::UmaHistogramCustomCounts(metric, bandwidth, 1, 50 * 1000 * 1000, 50);
363 } 362 }
364 363
365 } // namespace 364 } // namespace
366 365
367 void RecordDownloadCount(DownloadCountTypes type) { 366 void RecordDownloadCount(DownloadCountTypes type) {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 "Download.BandwidthDiskBytesPerSecond", 766 "Download.BandwidthDiskBytesPerSecond",
768 CalculateBandwidthBytesPerSecond(length, disk_write_time)); 767 CalculateBandwidthBytesPerSecond(length, disk_write_time));
769 } 768 }
770 769
771 void RecordParallelDownloadCount(DownloadCountTypes type) { 770 void RecordParallelDownloadCount(DownloadCountTypes type) {
772 UMA_HISTOGRAM_ENUMERATION("Download.Counts.ParallelDownload", type, 771 UMA_HISTOGRAM_ENUMERATION("Download.Counts.ParallelDownload", type,
773 DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 772 DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
774 } 773 }
775 774
776 void RecordParallelDownloadStats( 775 void RecordParallelDownloadStats(
777 size_t bytes_downloaded_with_parallel_streams, 776 size_t bytes_downloaded_with_parallel_streams,
xingliu 2017/04/05 00:29:10 nit%: Not in this patch, but does it make sense to
qinmin 2017/04/05 05:33:55 normally anything non-negative and has file system
xingliu 2017/04/05 17:56:38 sgtm, but does cpu architecture limit the size of
778 base::TimeDelta time_with_parallel_streams, 777 base::TimeDelta time_with_parallel_streams,
779 size_t bytes_downloaded_without_parallel_streams, 778 size_t bytes_downloaded_without_parallel_streams,
780 base::TimeDelta time_without_parallel_streams) { 779 base::TimeDelta time_without_parallel_streams) {
781 int bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond( 780 int64_t bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond(
782 bytes_downloaded_without_parallel_streams, time_without_parallel_streams); 781 bytes_downloaded_without_parallel_streams, time_without_parallel_streams);
783 RecordBandwidthMetric( 782 RecordBandwidthMetric(
784 "Download.BandwidthWithoutParallelStreamsBytesPerSecond", 783 "Download.BandwidthWithoutParallelStreamsBytesPerSecond",
785 bandwidth_without_parallel_streams); 784 bandwidth_without_parallel_streams);
786 RecordBandwidthMetric( 785 RecordBandwidthMetric(
787 "Download.BandwidthWithParallelStreamsBytesPerSecond", 786 "Download.BandwidthWithParallelStreamsBytesPerSecond",
788 CalculateBandwidthBytesPerSecond(bytes_downloaded_with_parallel_streams, 787 CalculateBandwidthBytesPerSecond(bytes_downloaded_with_parallel_streams,
789 time_with_parallel_streams)); 788 time_with_parallel_streams));
790 789
791 base::TimeDelta time_saved; 790 base::TimeDelta time_saved;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 if (!page_transition) 884 if (!page_transition)
886 return; 885 return;
887 886
888 UMA_HISTOGRAM_ENUMERATION( 887 UMA_HISTOGRAM_ENUMERATION(
889 "Download.PageTransition", 888 "Download.PageTransition",
890 ui::PageTransitionStripQualifier(page_transition.value()), 889 ui::PageTransitionStripQualifier(page_transition.value()),
891 ui::PAGE_TRANSITION_LAST_CORE + 1); 890 ui::PAGE_TRANSITION_LAST_CORE + 1);
892 } 891 }
893 892
894 } // namespace content 893 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698