aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/profile_analyzer
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-05-06 14:42:46 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-05-06 14:42:46 -0700
commit975efdc915fb165b0cfa650a9e718d9382193b31 (patch)
tree749f5410a8d06ae23bc1a24e0baddffb58cf4da6 /tools/profile_analyzer
parent776075a80a5d44bca39ee1bf1a5848939c6cd8c4 (diff)
Avoid repeated sortings in percentile() calls.
Have the function expect sorted input.
Diffstat (limited to 'tools/profile_analyzer')
-rwxr-xr-xtools/profile_analyzer/profile_analyzer.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/profile_analyzer/profile_analyzer.py b/tools/profile_analyzer/profile_analyzer.py
index b540052697..632aeffd3c 100755
--- a/tools/profile_analyzer/profile_analyzer.py
+++ b/tools/profile_analyzer/profile_analyzer.py
@@ -90,6 +90,7 @@ def print_grouped_imark_statistics(group_key, imarks_group):
print '{:>40s}: {:>15s} {:>15s} {:>15s} {:>15s}'.format(
'Relative mark', '50th p.', '90th p.', '95th p.', '99th p.')
for key, time_values in values.iteritems():
+ time_values = sorted(time_values)
print '{:>40s}: {:>15.3f} {:>15.3f} {:>15.3f} {:>15.3f}'.format(
key, percentile(time_values, 50), percentile(time_values, 90),
percentile(time_values, 95), percentile(time_values, 99))
@@ -132,10 +133,9 @@ for entry in entries():
imark.append_post_entry(entry)
def percentile(vals, percent):
- """ Calculates the interpolated percentile given a (possibly unsorted sequence)
- and a percent (in the usual 0-100 range)."""
+ """ Calculates the interpolated percentile given a sorted sequence and a
+ percent (in the usual 0-100 range)."""
assert vals, "Empty input sequence."
- vals = sorted(vals)
percent /= 100.0
k = (len(vals)-1) * percent
f = math.floor(k)
@@ -149,7 +149,7 @@ def percentile(vals, percent):
print 'tag 50%/90%/95%/99% us'
for tag in sorted(times.keys()):
- vals = times[tag]
+ vals = sorted(times[tag])
print '%d %.2f/%.2f/%.2f/%.2f' % (tag,
percentile(vals, 50),
percentile(vals, 90),