Use the payload size as the base to calculate download overhead
The download_overhead_percentage was calculated based on the bytes
downloaded during the current update attempt. This may leads to large
number when the update is interrupted; and the resumed update attempt
only downloads a small portion of the payload. For example, for a 10M
payload; if we download 9M, interrupt, and resume to download the
remaining 1M; the current code will report the overhead as (10-1)/1*100%
as 900. We should switch to use the payload size as it was the intention
of the metrics.
Test: run update engine, interrupt and check the metrics
Change-Id: Ic3e1c0a0a4671ee6e7751d53fc40fd2dc8072d63
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index 97c53ec..08f6c20 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -750,11 +750,15 @@
total_bytes_downloaded;
int download_overhead_percentage = 0;
- if (current_bytes_downloaded > 0) {
+ if (total_bytes_downloaded >= payload_size) {
+ CHECK_GT(payload_size, 0);
download_overhead_percentage =
- (total_bytes_downloaded - current_bytes_downloaded) * 100ull /
- current_bytes_downloaded;
+ (total_bytes_downloaded - payload_size) * 100ull / payload_size;
+ } else {
+ LOG(WARNING) << "Downloaded bytes " << total_bytes_downloaded
+ << " is smaller than the payload size " << payload_size;
}
+
metrics_reporter_->ReportSuccessfulUpdateMetrics(
static_cast<int>(attempt_number),
0, // update abandoned count