|
From: Nicholas N. <nj...@cs...> - 2008-05-28 22:36:06
|
On Wed, 28 May 2008, Andrei Soare wrote: > I suspected that. However, I have no idea how and what I must modify and I > would really appreciate some hints. Look at the code: massif/ms_main.c. Massif is fairly well commented, and the most complicated parts are dealing with snapshots and the XTree structure, all of which you could probably rip out. In particular, look at the "Heap management" and "malloc() et al replacement wrappers" for the code that intercepts malloc/free/etc and does stuff in response. Also, 'ms_instrument' and related functions, as well as 'get_time' are responsible for keeping track of time (either instructions executed, bytes allocated/deallocated, or real time). Then, think what you want your tool to do. I'd start by recording in a table the allocation site, deallocation site, and lifetime of every block allocated, and then at the end present them in order from shortest to longest. Massif already records all live allocated blocks in the 'malloc_list' structure, you could just change the content of the nodes and change it to not remove freed ones. The 'VG_(ssort)' sorting function (include/pub_tool_libcbase.h) might be useful for sorting the results at the end. Once you get that working, I expect you'll find the output is very repetitive. You'll probably want to aggregate results somehow, eg. 100 blocks were allocated at point X that all had a lifetime of N instructions. I expect the appropriate aggregation approach will become clearer once you see what the basic output looks like, and what kinds of patterns occur. Nick |