Bug 499194

Summary: Recording empty
Product: [Applications] Heaptrack Reporter: Peter Majchrak <petoknm>
Component: generalAssignee: Milian Wolff <mail>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: NOR    
Version First Reported In: 1.5.0   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Peter Majchrak 2025-01-27 13:31:16 UTC
SUMMARY
I want to record a heap profile of my webserver. This is a long running process that I start under heaptrack, but I have to stop it using Ctrl+C. When I do that, I get an empty heaptrack.*.zst file. If my program exits on its own the recording is fine.

Seems like some sort of stream/pipe buffering issue to me (pipe going to zstd?). 

STEPS TO REPRODUCE
1. `heaptrack ./target/debug/website`
2. `ls -alh heaptrack.*`

OBSERVED RESULT
```
$ heaptrack ./target/debug/website
heaptrack output will be written to "/home/peter/Programming/website/heaptrack.website.40763.zst"
starting application, this might take some time...
NOTE: heaptrack detected DEBUGINFOD_URLS but will disable it to prevent 
unintended network delays during recording
If you really want to use DEBUGINFOD, export HEAPTRACK_ENABLE_DEBUGINFOD=1
^CHeaptrack finished! Now run the following to investigate the data:

  heaptrack --analyze "/home/peter/Programming/website/heaptrack.website.40763.zst"

heaptrack_gui detected, automatically opening the file...
heaptrack stats:
        allocations:            478
        leaked allocations:     379
        temporary allocations:  17
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
$ ls -alh heaptrack.*
-rw-r--r-- 1 peter peter   0 Jan 27 14:29 heaptrack.website.40763.zst
```
EXPECTED RESULT

File not empty, GUI that opens to not be empty...
Comment 1 Milian Wolff 2025-01-27 14:52:49 UTC
can you attach an example project that allows me to reproduce the issue? or can you reproduce it with any normal linux utility that is commonly available?
Comment 2 Peter Majchrak 2025-01-27 16:10:43 UTC
yes, I can reproduce the same behaviour using `cat` and entering a few lines of text in order to hopefully trigger some allocs:

```
$ heaptrack cat
heaptrack output will be written to "/home/peter/temp/heaptrack.cat.3380.zst"
starting application, this might take some time...
NOTE: heaptrack detected DEBUGINFOD_URLS but will disable it to prevent 
unintended network delays during recording
If you really want to use DEBUGINFOD, export HEAPTRACK_ENABLE_DEBUGINFOD=1
hello
hello
whatup
whatup
^Cheaptrack stats:
	allocations:          	32
	leaked allocations:   	31
	temporary allocations:	1
Heaptrack finished! Now run the following to investigate the data:

  heaptrack --analyze "/home/peter/temp/heaptrack.cat.3380.zst"

heaptrack_gui detected, automatically opening the file...
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

$ ls -alh heaptrack.cat.3380.zst 
-rw-r--r-- 1 peter peter 0 Jan 27 17:08 heaptrack.cat.3380.zst
```
Comment 3 Peter Majchrak 2025-01-28 09:38:36 UTC
Changing back to "ASSIGNED"
Comment 4 Milian Wolff 2025-01-28 11:17:52 UTC
my `cat` rejects being called without args:

```
cat: -: input file is output file
```

if I instead use, say, `head` it works:

```
$ heaptrack head
heaptrack output will be written to "/home/milian/projects/src/heaptrack/heaptrack.head.44324.zst"
starting application, this might take some time...
NOTE: heaptrack detected DEBUGINFOD_URLS but will disable it to prevent 
unintended network delays during recording
If you really want to use DEBUGINFOD, export HEAPTRACK_ENABLE_DEBUGINFOD=1
a
a
a
a
a
a
^Cheaptrack stats:
        allocations:            56
        leaked allocations:     50
        temporary allocations:  4
Heaptrack finished! Now run the following to investigate the data:

  heaptrack --analyze "/home/milian/projects/src/heaptrack/heaptrack.head.44324.zst"
$ .rw-r--r-- milian milian 1.3 KB Tue Jan 28 12:13:29 2025 /home/milian/projects/src/heaptrack/heaptrack.head.44324.zst
```

the file contains info on the 56 allocations as expected. there are no changes to `heaptrack.sh.cmake` in master since, 1.5.0 was released so I don't really know what is happening here? Can you reproduce it with `head` too?
Comment 5 Peter Majchrak 2025-01-28 11:35:59 UTC
It is possible to reproduce in a container:

```
$ docker run -it --rm manjarolinux/base bash
# pacman -Sy heaptrack
# heaptrack cat
# ls -al
-rw-r--r--   1 root    root         0 Jan 28 11:32 heaptrack.cat.663.zst
```

Currently, I'm not on the same machine, so I can only verify in the docker container, but I observe the same behaviour with `head`, i.e. the recording is empty.
Comment 6 Milian Wolff 2025-01-28 15:00:32 UTC
This seems to be a difference in how `Ctrl+C` is handled / transmitted on these shells. I can reproduce it there but quite frankly I have zero intention to try to figure it out - it seems to work just fine on my archlinux system and on an ubuntu 22.04 system too - if you feel strongly about this, please investigate what makes manjaro so special here. similarly, I'm more than willing to review patches that improve this situation, but I won't spend time myself in trying to figure such a distro specific bug out I'm afraid
Comment 7 Peter Majchrak 2025-01-28 15:22:50 UTC
I see the same issue in the archlinux:base container.
Let me try on ubuntu 20.04 lts as well, which is what I'm currently on.
Comment 8 Peter Majchrak 2025-01-28 15:28:41 UTC
Ok, ubuntu 20.04 is too old... elfutils more specifically...

I also found the same issue mentioned in the forum: https://discuss.kde.org/t/heaptrack-generating-empty-heap-dump/3156
Cannot say for sure what distro the OP used.
Comment 9 Milian Wolff 2025-01-29 08:07:18 UTC
how do you reproduce it on archlinux exactly? I run arch, with bash as my shell, and I cannot reproduce it with `head` and `cat` does not work there as I wrote earlier.
Comment 10 Bug Janitor Service 2025-02-13 03:46:38 UTC
๐Ÿ›๐Ÿงน โš ๏ธ This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information, then set the bug status to REPORTED. If there is no change for at least 30 days, it will be automatically closed as RESOLVED WORKSFORME.

For more information about our bug triaging procedures, please read https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging.

Thank you for helping us make KDE software even better for everyone!
Comment 11 Bug Janitor Service 2025-02-28 03:46:47 UTC
๐Ÿ›๐Ÿงน This bug has been in NEEDSINFO status with no change for at least 30 days. Closing as RESOLVED WORKSFORME.