Warning: This application is highly unstable, and its output cannot be fully trusted. Use this application at your own risk.
This is a real-time, remote memory allocation monitoring tool. It is designed to trace memory operations (e.g. malloc, free, calloc, realloc) in a target application running on a resource-constrained like embedded systems and visualize the data on a local machine.
This project was born out of curiosity and the desire to be able to visualize in real time the allocations that occur in a binary, in order to help software developers identify potential leaks/fragmentation more quickly during debugging.
This is an ongoing project that will undergo many changes over time as I learn to understand how this low-level realm works. If you need production-ready solutions, you should use tools like: heaptrack and valgrind.
- Real-time Memory Tracing: Intercepts memory allocation calls on a remote target.
- TCP Data Transfer: Streams allocation data to a local machine for visualization.
- Memory Usage Heatmap: Provides a high-level, logarithmic visualization of memory fragmentation.
- Allocation Statistics Tree: Hierarchically breaks down memory usage by call stack.
- DWARF Symbol Resolution: Resolves function names from debug symbols for clear analysis.
The project consists of two main components:
- C Tracer (
mem_tracer.c): A shared library that usesLD_PRELOADto hook into the target application's memory functions. It captures allocation data, timestamps, and backtraces, and sends this information over a TCP socket to the local GUI. - Python GUI (
gui.py): A local desktop application built with Python's Tkinter. It receives data from the tracer, resolves function names from DWARF debug symbols, and presents the information to the user.*
* it may change in future.
- C Compiler: for building the C components. The build scripts requires a specific path.
- Python 3: For running the GUI application.
- Tracer Library (
mem_tracer.so):
python build.py -c /your/compiler/path
This compiles mem_tracer.c into a shared library (mem_tracer.so).
- Local Machine:
- Run the GUI application:
python gui.py
- The application will prompt you to select the debug-enabled executable corresponding to the application running on the remote target. This is necessary for symbol resolution.
- Remote Target:
- Copy the compiled
mem_tracer.soand your target application to the remote system. - Run your application with
LD_PRELOAD:
LD_PRELOAD=/path/of/mem_tracer.so ./your_application
mem_tracer.c: The C source for the memory tracer library.gui.py: The Python source for the GUI visualization tool.local_server.py: The Python TCP server that receives data from the tracer.build.py: Python script to build themem_tracer.solibrary.
Currently is only possible to see the allocation where they happens in the given binary up to the function which invokes the allocation
- implement the overload for dlopen / dlclose
- allow user to specify a sysroot in order to allow automatic resolution for shared objects debug symbols
- allow to locally save sessions
- add a "record" mode in order allow replay of processed sections
- map symbols from .debug sections too
- include test pipelines to ensure output data can be trusted
- better connection handling
- proper session cleanup between runs
