[PATCH] D42690: [XRay] fix 99th percentile lookups by sorting the array correctly

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 09:06:44 PST 2018


dberris requested changes to this revision.
dberris added a comment.
This revision now requires changes to proceed.

Good catch! See other comment though.



================
Comment at: tools/llvm-xray/xray-account.cc:243-245
+  std::nth_element(Timings.begin(), Timings.begin() + Pct99Off, Timings.end());
+  R.Median = Timings[MedianOff];
+  R.Pct90 = Timings[Pct90Off];
----------------
I don't think this does the same thing as the original code did (or what it was intended to do).

std::nth_element doesn't actually sort the elements before the `n`'th element. It just guarantees that the element that would have been at the `n`'th position is there.

We still need the two other calls to std::nth_element that would find the correct median, 90pct, and 99pct.


Repository:
  rL LLVM

https://reviews.llvm.org/D42690





More information about the llvm-commits mailing list