summaryrefslogtreecommitdiff
path: root/scripts/update_payload/histogram.py
diff options
context:
space:
mode:
authorGilad Arnold <garnold@chromium.org>2013-10-04 18:18:45 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-07 18:31:12 +0000
commit6a3a3878daddc2536a2ac9033189274cfc5ef52d (patch)
treea969f9169908b5ea4c73c1608238f3d5244575eb /scripts/update_payload/histogram.py
parentcb638915dbc2e0898b0562c98019c077d7fc1e8a (diff)
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 <dgarrett@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
Diffstat (limited to 'scripts/update_payload/histogram.py')
-rw-r--r--scripts/update_payload/histogram.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/scripts/update_payload/histogram.py b/scripts/update_payload/histogram.py
index a5ddac4b..99163298 100644
--- a/scripts/update_payload/histogram.py
+++ b/scripts/update_payload/histogram.py
@@ -101,11 +101,13 @@ class Histogram(object):
bar_len = count * self.scale / self.total
hist_bar = '|%s|' % ('#' * bar_len).ljust(self.scale)
- line = '%s %s %s (%s)' % (
+ line = '%s %s %s' % (
str(key).ljust(self.max_key_len),
hist_bar,
- self.formatter(count),
- format_utils.NumToPercent(count, self.total))
+ self.formatter(count))
+ percent_str = format_utils.NumToPercent(count, self.total)
+ if percent_str:
+ line += ' (%s)' % percent_str
hist_lines.append(line)
return '\n'.join(hist_lines)