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..2e4d6f887c8506c937491b5807957112c78063df 100644 |
| --- a/content/browser/download/download_stats.cc |
| +++ b/content/browser/download/download_stats.cc |
| @@ -346,6 +346,22 @@ int GetDangerousFileType(const base::FilePath& file_path) { |
| return 0; // Unknown extension. |
| } |
| +// Helper method to calculate and record the bandwidth for a given metric by |
| +// dividing the |data_length| by |elapsed_time|. |
| +int LogBandwidthBytesPerSecond( |
| + const std::string& metric, |
| + size_t data_length, |
| + 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.
|
| + size_t elapsed_time_ms = elapsed_time.InMilliseconds(); |
| + if (0u == elapsed_time_ms) |
| + elapsed_time_ms = 1; |
| + |
| + int bandwidth = 1000 * data_length / elapsed_time_ms; |
| + 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.
|
| + 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
|
| + return bandwidth; |
| +} |
| + |
| } // namespace |
| void RecordDownloadCount(DownloadCountTypes type) { |
| @@ -703,19 +719,36 @@ 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; |
| + LogBandwidthBytesPerSecond( |
| + "Download.BandwidthOverallBytesPerSecond", length, elapsed_time); |
| + LogBandwidthBytesPerSecond( |
| + "Download.BandwidthDiskBytesPerSecond", length, disk_write_time); |
| +} |
| +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 = LogBandwidthBytesPerSecond( |
| + "Download.BandwidthWithoutParallelStreamsBytesPerSecond", |
| + bytes_downloaded_without_parallel_streams, time_without_parallel_streams); |
| + LogBandwidthBytesPerSecond( |
| + "Download.BandwidthWithParallelStreamsBytesPerSecond", |
| + bytes_downloaded_with_parallel_streams, time_with_parallel_streams); |
| + |
| + base::TimeDelta time_saved = |
| + base::TimeDelta::FromMilliseconds(1000.0 * |
| + bytes_downloaded_with_parallel_streams / |
| + bandwidth_without_parallel_streams) - |
| + time_with_parallel_streams; |
| + |
| + 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.
|
| + static_cast<int>(base::Time::kMicrosecondsPerHour); |
| UMA_HISTOGRAM_CUSTOM_COUNTS( |
| - "Download.BandwidthOverallBytesPerSecond", |
| - (1000 * length / elapsed_time_ms), 1, 50000000, 50); |
| - UMA_HISTOGRAM_CUSTOM_COUNTS( |
| - "Download.BandwidthDiskBytesPerSecond", |
| - (1000 * length / disk_write_time_ms), 1, 50000000, 50); |
| + "Download.TimeSavedWithParallelDownload", |
| + 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.
|
| + microseconds_per_hour, 50); |
| } |
| void RecordDownloadFileRenameResultAfterRetry( |