Merge pull request #14795 from jtattermusch/reimplement_percentile

Reimplement percentile function in profile_analyzer.py
pull/14733/head
Jan Tattermusch 7 years ago committed by GitHub
commit 6fbc1fbce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      tools/profiling/latency_profile/profile_analyzer.py

@ -184,24 +184,23 @@ 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
float_idx = (len(N) - 1) * percent
idx = int(float_idx)
result = key(N[idx])
if idx < len(N) - 1:
# interpolate with the next element's value
result += (float_idx - idx) * (key(N[idx + 1]) - key(N[idx]))
return result
def tidy_tag(tag):

Loading…
Cancel
Save