Chromium Code Reviews| Index: content/browser/download/download_stats.cc |
| diff --git a/content/browser/download/download_stats.cc b/content/browser/download/download_stats.cc |
| index 87fbe199defcee2e36592a7e527d14245328ec72..6c108ed758393fd006b6446db10edc3b2ceae46a 100644 |
| --- a/content/browser/download/download_stats.cc |
| +++ b/content/browser/download/download_stats.cc |
| @@ -346,6 +346,16 @@ int GetDangerousFileType(const base::FilePath& file_path) { |
| return 0; // Unknown extension. |
| } |
| +// Helper method to calculate the bandwidth given the data length and time. |
| +int CalculateBandwidthBytesPerSecond(size_t length, |
| + base::TimeDelta elapsed_time) { |
| + size_t elapsed_time_ms = elapsed_time.InMilliseconds(); |
| + if (0u == elapsed_time_ms) |
| + elapsed_time_ms = 1; |
| + |
| + return 1000 * length / elapsed_time_ms; |
| +} |
| + |
| } // namespace |
| void RecordDownloadCount(DownloadCountTypes type) { |
| @@ -703,19 +713,38 @@ void RecordNetworkBlockage(base::TimeDelta resource_handler_lifetime, |
| void RecordFileBandwidth(size_t length, |
| base::TimeDelta disk_write_time, |
| base::TimeDelta elapsed_time) { |
| - size_t elapsed_time_ms = elapsed_time.InMilliseconds(); |
| - if (0u == elapsed_time_ms) |
| - elapsed_time_ms = 1; |
| - size_t disk_write_time_ms = disk_write_time.InMilliseconds(); |
| - if (0u == disk_write_time_ms) |
| - disk_write_time_ms = 1; |
| - |
| UMA_HISTOGRAM_CUSTOM_COUNTS( |
| "Download.BandwidthOverallBytesPerSecond", |
| - (1000 * length / elapsed_time_ms), 1, 50000000, 50); |
| + CalculateBandwidthBytesPerSecond(length, elapsed_time), 1, 50000000, 50); |
| UMA_HISTOGRAM_CUSTOM_COUNTS( |
| "Download.BandwidthDiskBytesPerSecond", |
| - (1000 * length / disk_write_time_ms), 1, 50000000, 50); |
| + CalculateBandwidthBytesPerSecond(length, disk_write_time), 1, 50000000, |
| + 50); |
| +} |
| + |
| +void RecordParallelDownloadStats( |
| + size_t bytes_downloaded_with_parallel_streams, |
| + base::TimeDelta time_with_parallel_streams, |
| + size_t bytes_downloaded_without_parallel_streams, |
| + base::TimeDelta time_without_parallel_streams) { |
| + int bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond( |
| + bytes_downloaded_without_parallel_streams, time_without_parallel_streams); |
| + 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.
|
| + "Download.BandwidthWithParallelStreamsBytesPerSecond", |
| + CalculateBandwidthBytesPerSecond(bytes_downloaded_with_parallel_streams, |
| + time_with_parallel_streams), |
| + 1, 50000000, 50); |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + "Download.BandwidthWithoutParallelStreamsBytesPerSecond", |
| + bandwidth_without_parallel_streams, 1, 50000000, 50); |
| + |
| + base::TimeDelta time_saved = |
| + 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
|
| + base::TimeDelta::FromMilliseconds(1000.0 * |
| + bytes_downloaded_with_parallel_streams / |
| + bandwidth_without_parallel_streams); |
| + UMA_HISTOGRAM_CUSTOM_COUNTS("Download.TimeSavedWithParallelDownload", |
| + 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
|
| } |
| void RecordDownloadFileRenameResultAfterRetry( |