Hey Zig members, I am looking for some direction to get the runtime heap size usage and overall thread count under the hood being executed of a running app, something similar to the Go runtime pkg.
I can extract the number of threads from Monitor app, but I wanted to get this information through code.
If the spawning of threads is your code, you can track that yourself. Otherwise you can read /proc/[PID]/stat which will have near the end: thread [num]
alternatively, you can count the number of files in /proc/[PID]/tasks/
You can get the current PID with std.os.linux.getpid, there is not a cross-platform API for this.
DebugAllocator when config .enable_memor_limit = true, you can access total_requested_bytes, the default limit is the maximum addressable memory which you will not hit, unless you override the limit.
But that allocator is slow, so you might want a custom allocator that just wraps another allocator and counts the requested memory.
If you cant provide the allocator for some allocations, eg a c library, or want the mapped memory instead of the used memory. /proc/[PID]/statm which has a bunch of numbers seperated by space which are, in order: