[fpc-pascal] Is such memory statistics possible?

Marco van de Voort marcov at stack.nl
Mon Aug 15 11:03:45 CEST 2011


In our previous episode, Max Vlasov said:
> about collecting some statistics.
> 
> The idea is similar to some disk utilities that collects and sort the sizes
> of directories. You know when every folder on the computer is scanned and
> all the resulting paths are sorted by the summed size. Such utilities
> usually help to find space on the hard drive to free.
> 
> With memory for every memory allocation we can call the path the addresses
> of procedures in stack. So when a function funci() is called from the
> function parentfunc() and getmem is called inside func() then we should add
> this size to the corresponding entries both for func() and parentfunc().
> Sure for every freemem we should decrease from every entry related to the
> previous getmem (that might be a challenge since freemem not necessary
> follows the same calling pattern). Anyway, if this system is implemented, in
> any moment during the program run, the developer can query N most memory
> hungry procedures to the moment. And this will include non only the
> procedures that call getmem,new  etc, but also higher level ones giving
> better hints for further optimization.
> 
> Do tools(units) like this already exist? If not, is developing such unit
> technically possible/hard with the currently available debug information?

This is basically what valgrind (or fulldebugmode of fastmm) does. But they
do this by parsing the stack on each call to the memory manager, and then
keep track of it.

Note that all these techniques can be very, very slowing. E.g. I tried to debug
the CHM support with valgrind, and I terminated the valgrind process after 5
hours because it was not even half way to where the bug was.

Without valgrind the program reached the point in 1-2 minutes.....




More information about the fpc-pascal mailing list