Bug 427970

Summary: Heaptrack GUI crash when opening a zst file
Product: [Applications] Heaptrack Reporter: Andrea Cavalli <andrea>
Component: generalAssignee: Milian Wolff <mail>
Status: RESOLVED FIXED    
Severity: crash    
Priority: NOR    
Version First Reported In: 1.2.0   
Target Milestone: ---   
Platform: Appimage   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Andrea Cavalli 2020-10-19 10:53:15 UTC
SUMMARY
When opening a specific .zst file heaptrack crashes.


STEPS TO REPRODUCE
1. Open heaptrack gui
2. Open the attached .zst file
3. The program will crash

OBSERVED RESULT
The app closes itself and prints this error in the console:
heaptrack_gui: /workspace/build/src/analyze/accumulatedtracedata.cpp:689: AllocationIndex AccumulatedTraceData::mapToAllocationIndex(TraceIndex): Assertion `allocations.back().traceIndex == traceIndex' failed.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma:
KDE Plasma Version: 5.20.0
KDE Frameworks Version: 5.75.0
Qt Version: 5.15.0

ADDITIONAL INFORMATION
The .zst file download link:
https://mega.nz/file/hZsWgJiC#q0kewRdTJEEdMoW_j5PX6kzBtvrE8X3XsU5YqX90Lrg
Comment 1 Milian Wolff 2020-10-19 15:47:36 UTC
A 500MB zst compressed file? 1329658135 lines! Woha :) Try to reduce the time you are profiling if at all possible. I doubt you'll gain much by looking at _that much_ data!

I wonder if that's maybe overflowing the allocation index then, leading to this assertion. Anyhow, I'll try to investigate and reproduce.

Cheers
Comment 2 Milian Wolff 2020-10-19 16:21:57 UTC
reproduced in a debug build, happens quickly on start - seems unrelated to the real big size of the file:

: 1
i: 6598
v: 1
R: 8242528
+: 657714438
-: 654883794
a: 268508
c: 8242528
I: 1
#: 2
X: 1
s: 2400
t: 297335
Comment 3 Milian Wolff 2020-10-20 07:07:54 UTC
Git commit d525eee12ee379849ba005a658ec6161c77bff0a by Milian Wolff.
Committed on 20/10/2020 at 07:00.
Pushed by mwolff into branch 'master'.

Fix assertion in AccumulatedTraceData::mapToAllocationIndex

When we encounter trace indices in the order A, B, A, where
the index A is the current maximum but B is less than that,
we incorrectly mapped the second occurrence of A to B.

Fix this by explicitly remembering the allocation index of the
maximum index. This allows us to keep the fast-path code and
at the same time prevents the improperly attribution.

M  +3    -2    src/analyze/accumulatedtracedata.cpp
M  +1    -0    src/analyze/accumulatedtracedata.h

https://invent.kde.org/sdk/heaptrack/commit/d525eee12ee379849ba005a658ec6161c77bff0a
Comment 4 Milian Wolff 2020-10-20 07:09:10 UTC
OK, fixed the issue. And looking at the heaptrack file, you should seriously consider using sqlite3_prepare and then reuse the queries instead of sqlite3_exec'ing all the time - I'm assuming that this would remove millions of temporary allocations from your code base ;-)

cheers