From 6a3a3878daddc2536a2ac9033189274cfc5ef52d Mon Sep 17 00:00:00 2001 From: Gilad Arnold Date: Fri, 4 Oct 2013 18:18:45 -0700 Subject: paycheck: fix errors around percentage / formatting of zero sizes This fixes two problems, both having to do with histogram generation: * When the total number of elements is zero, paycheck would crash due to a division by zero; further, even if the crash is fixed (returning, say, None) the histogram will contain a meaningless value in parenthesis, which we might as well drop. Both are fixed here. * When some size (say, bytes) is zero, its formatter (bytes-to-human-readable) returns None, which shows up as is in the final report. This should be checked and avoided. BUG=None TEST=Crash fixed; None percentage/formatted value omitted. Change-Id: I8bb5fbc47e1cde9dcbee7f7b96bcb63ef3a0935e Reviewed-on: https://chromium-review.googlesource.com/172046 Reviewed-by: Don Garrett Commit-Queue: Gilad Arnold Tested-by: Gilad Arnold --- scripts/update_payload/format_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'scripts/update_payload/format_utils.py') diff --git a/scripts/update_payload/format_utils.py b/scripts/update_payload/format_utils.py index 2c82f32f..2c3775c4 100644 --- a/scripts/update_payload/format_utils.py +++ b/scripts/update_payload/format_utils.py @@ -27,9 +27,13 @@ def NumToPercent(num, total, min_precision=1, max_precision=5): min_precision: minimum precision for fractional percentage max_precision: maximum precision for fractional percentage Returns: - Percentage string. + Percentage string, or None if percent cannot be computed (i.e. total is + zero). """ + if total == 0: + return None + percent = 0 precision = min(min_precision, max_precision) factor = 10 ** precision -- cgit v1.2.3