views:

45

answers:

0

I want to see is fragmentation the reason of increasing memory usage of my twisted server. I have posted a question here: How to find the source of increasing memory usage of a twisted server?

Now, what I am going to do is to visualize the heap. I found an article: Memory fragmentation. The figure of heap in that article is something just like what I want. It is not difficult for me to draw such a figure with matplotlib or other tools. The most difficult job is: how to record the memory allocation and deallocation?

I know that I can modify the source code of CPython, add some logging code into omalloc.c and recompile the Python, and use the modified CPython to run my server. But however, I don't want to waste time with that. Then I am looking for some available tools. I know there is a tool valgrind can be used to detect memory leak, but I don't know how to record allocation and deallocation. I see its memcheck can detect something like:

  • Invalid read
  • Uninitialised
  • Invalid free

But that's not what I want, all I need is:

  • Record every allocations and deallocations of memory with time, address and size

My questions are:

  1. How can I do that with valgrind?
  2. If I can't, should I write a module for that?
  3. Or is there any better tools can achieve this?

Thanks.