Skip to content

Commit

Permalink
[XRay] fix 99th percentile lookups by sorting the array correctly
Browse files Browse the repository at this point in the history
Summary:
It was a copy-paste typo, sorting only to the 90th percentile twice.
Now, it only sorts the array prefix once, and extracts what we need.

Reviewers: dberris, kpw, eizan

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D42690

llvm-svn: 323800
  • Loading branch information
Martin Pelikan committed Jan 30, 2018
1 parent 39a9842 commit cb6422d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions llvm/tools/llvm-xray/xray-account.cc
Expand Up @@ -237,16 +237,19 @@ ResultRow getStats(std::vector<uint64_t> &Timings) {
auto MinMax = std::minmax_element(Timings.begin(), Timings.end());
R.Min = *MinMax.first;
R.Max = *MinMax.second;
R.Count = Timings.size();

auto MedianOff = Timings.size() / 2;
std::nth_element(Timings.begin(), Timings.begin() + MedianOff, Timings.end());
R.Median = Timings[MedianOff];

auto Pct90Off = std::floor(Timings.size() * 0.9);
std::nth_element(Timings.begin(), Timings.begin() + Pct90Off, Timings.end());
R.Pct90 = Timings[Pct90Off];

auto Pct99Off = std::floor(Timings.size() * 0.99);
std::nth_element(Timings.begin(), Timings.begin() + Pct90Off, Timings.end());
std::nth_element(Timings.begin(), Timings.begin() + Pct99Off, Timings.end());
R.Pct99 = Timings[Pct99Off];
R.Count = Timings.size();
return R;
}

Expand Down

0 comments on commit cb6422d

Please sign in to comment.