How to profile memory usage of a C program

前端 未结 4 399
鱼传尺愫
鱼传尺愫 2021-01-02 17:13

I need to figure out which part of a linux program that I am running, is taking how much (either percentage, or absolute) memory. I need to create a profile of multiple such

相关标签:
4条回答
  • 2021-01-02 17:43

    Beside Valgrind, there exists a lot of other memory debugger/profiler. All the following seems to support MIPS (but I've not tried them on that architecture) :

    jemalloc, CCMALLOC, mpatrol, NJAMD, Dmalloc, and even Google's own google-perftools.

    0 讨论(0)
  • 2021-01-02 17:47

    You can use Google's perftools for memory profiling. The project provides a very fast, multi-threaded malloc implementation, a Heap profiler, a Heap checker and a CPU profiler.

    0 讨论(0)
  • 2021-01-02 17:48

    Memory consumption should not be massively affected by the underlying processor architecture so you might be able to do the memory profiling on x86 Linux. Yes, the absolute amounts of memory probably are a affected but as you're looking more for relative than absolute numbers, this should work.

    That said, this solution is unlikely to be an option if a Linux x86 build is more than a recompile away.

    0 讨论(0)
  • 2021-01-02 17:54

    You could wrap all your calls to free and malloc with your own functions in which you also supply for instance in which file and at what line number each allocation is done. From this information it's easy to see what memory is being used where.

    0 讨论(0)
提交回复
热议问题