I am working on a tracing tool for multi-threaded applications, especially about memory allocation.
I would like to highlight the flow distribution. I know that when a thread executes malloc, the memory used is a global heap. I would like to track which thread allocated how much memory.
I wrapped on malloc, incrementing the values every time there is malloc as:
void *mymalloc(size_t size) {
mem_used[thread_id] += size;
return malloc(size);
}
It works well. The problem is a method freethat does not return the amount of freed memory.
Do not take my decision into account, it is just to show what I tried.
EDIT:
As mentioned above, saving my table is too hard.
source
share