aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/profiling
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2018-03-22 13:43:41 +0100
committerGravatar Jan Tattermusch <jtattermusch@google.com>2018-03-22 13:43:41 +0100
commit577e6379200f629c0bab3c954221dd22b9520f41 (patch)
tree19b01177d58287e343e909932f6eeb9167449121 /tools/profiling
parentb4a5727149201bac53a33c53c2cf93fed5414540 (diff)
reimplement percentile function
Diffstat (limited to 'tools/profiling')
-rwxr-xr-xtools/profiling/latency_profile/profile_analyzer.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/tools/profiling/latency_profile/profile_analyzer.py b/tools/profiling/latency_profile/profile_analyzer.py
index d4d14ef8c7..ad453a9eb0 100755
--- a/tools/profiling/latency_profile/profile_analyzer.py
+++ b/tools/profiling/latency_profile/profile_analyzer.py
@@ -184,24 +184,24 @@ for cs in call_stacks:
def percentile(N, percent, key=lambda x: x):
"""
- Find the percentile of a list of values.
+ Find the percentile of an already sorted list of values.
- @parameter N - is a list of values. Note N MUST BE already sorted.
- @parameter percent - a float value from 0.0 to 1.0.
+ @parameter N - is a list of values. MUST be already sorted.
+ @parameter percent - a float value from [0.0,1.0].
@parameter key - optional key function to compute value from each element of N.
@return - the percentile of the values
"""
if not N:
return None
- k = (len(N) - 1) * percent
- f = math.floor(k)
- c = math.ceil(k)
- if f == c:
- return key(N[int(k)])
- d0 = key(N[int(f)]) * (c - k)
- d1 = key(N[int(c)]) * (k - f)
- return d0 + d1
+ idx = (len(N) - 1) * percent
+ idx_floor = math.floor(idx)
+ idx_ceil = math.ceil(idx)
+ if idx_floor != idx_ceil:
+ # interpolate the nearest element values
+ return (key(N[int(idx_floor)]) * (idx_ceil - idx) +
+ key(N[int(idx_ceil)]) * (idx - idx_floor))
+ return key(N[int(idx)])
def tidy_tag(tag):