diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2018-10-18 22:40:38 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2018-10-22 09:58:48 +0000 |
commit | 22873e2f8cd1ce128c2a9022fae7616be20a08e5 (patch) | |
tree | 54d5272be36742cc1a95676eb43ac8a50b51e366 | |
parent | f80412d60233e5cdc40434abba9c311ba07ecdf5 (diff) |
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 <ulf.hermann@qt.io>
-rw-r--r-- | app/perfunwind.cpp | 7 |
1 files 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) { |