From 22873e2f8cd1ce128c2a9022fae7616be20a08e5 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 18 Oct 2018 22:40:38 +0200 Subject: Use stable_sort instead of sort in PerfUnwind::flushEventBuffer This is required to keep the order of events with the same time. Most notably, this happens when we analyze data from a runtime-attached perf record, i.e. `perf record -p ...`. There, the data file will contain lots of mmap events with time 0. The order is important though, so keep that via stable_sort. Change-Id: Ibaa3a816b4921e404105f3d01f500f9ffb8ddd59 Reviewed-by: Ulf Hermann --- app/perfunwind.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/perfunwind.cpp b/app/perfunwind.cpp index ddb6774..90d3f8c 100644 --- a/app/perfunwind.cpp +++ b/app/perfunwind.cpp @@ -833,8 +833,11 @@ void PerfUnwind::flushEventBuffer(uint desiredBufferSize) auto sortByTime = [](const PerfRecord &lhs, const PerfRecord &rhs) { return lhs.time() < rhs.time(); }; - std::sort(m_mmapBuffer.begin(), m_mmapBuffer.end(), sortByTime); - std::sort(m_sampleBuffer.begin(), m_sampleBuffer.end(), sortByTime); + // stable sort here to keep order of events with the same time + // esp. when we runtime-attach, we will get lots of mmap events with time 0 + // which we must not shuffle + std::stable_sort(m_mmapBuffer.begin(), m_mmapBuffer.end(), sortByTime); + std::stable_sort(m_sampleBuffer.begin(), m_sampleBuffer.end(), sortByTime); if (m_stats.enabled) { for (const auto &sample : m_sampleBuffer) { -- cgit v1.2.3