1

I am using jemalloc for memory profiling in Python code. I'm having difficulty tracing back to my Python function calls.

When analyzing the heap profile generated by jemalloc, it only shows C API calls related to the Python interpreter but does not show my actual Python function that is responsible for memory allocation.

this is my dummy program to test the jemalloc profiling for Python:

import time

def leak_mem():
    list = []
    while True:
        # string is 1MB in size.
        list.append(' ' * 1000 * 1000)

        time.sleep(0.1)

if __name__ == "__main__":
    leak_mem()

execution steps:

  • download jemalloc.5.3.0 source code,cd into the folder
  • ./configure --enable-prof && make && sudo make insatll
  • Set Environment Variable: export MALLOC_CONF="prof:true,prof_prefix:test.out,lg_prof_interval:25"
  • Run python script with jemalloc preload: LD_PRELOAD=/home/jemalloc-5.3.0/lib/libjemalloc.so python3 leak.py
  • Analyze heap profile using jeprof: jeprof /usr/bin/python3 test*

enter image description here

I would like to know if there is any way around this to achieve the Python function that is responsible for memory allocation.

0 Answers0