namhyung/uftrace logo

namhyung/uftrace

Free

Function graph tracer for C/C++/Rust/Python

FreeFree tier
Type
Open Source

About namhyung/uftrace

uftrace is a function call graph tracer for C, C++, Rust, and Python programs that hooks into function entry and exit points to record timestamps, arguments, and return values. It supports tracing both user and kernel functions, library functions, system events, and provides an integrated execution flow. uftrace can trace without recompilation by dynamically patching function prologues, or via compiler instrumentation (-pg, -finstrument-functions, -fpatchable-function-entry). It offers filters to reduce trace data and provides visualization via Chrome trace viewer, flame graphs, graphviz, and mermaid. Users can write custom scripts using Python or LuaJIT APIs. The tool is heavily inspired by Linux kernel's ftrace and its name combines 'user' and 'ftrace'.

Key Features

Hooks function entry and exit to record timestamps, arguments, and return values
Supports dynamic patching (no recompilation needed) and compiler-based instrumentation
Traces user space C/C++/Rust functions, library functions (PLT hooking), Python functions, kernel functions, and system events
Users can write and run Python/LuaJIT scripts for custom tracing tools
Offers filters to minimize trace data during record and replay
Visualization via Chrome trace viewer, flame graph, graphviz, and mermaid diagrams
Records metadata, symbol tables, memory maps, and task relationship trees
Supports filtering by function call duration for performance analysis

Pros & Cons

Pros
  • Supports multiple languages (C, C++, Rust, Python) and kernel tracing
  • Can trace without recompilation using dynamic patching
  • Rich visualization output (Chrome trace, flame graph, graphviz, mermaid)
  • Scriptable with Python and LuaJIT for custom analysis
  • Open source and free to use
Cons
  • Kernel tracing feature is limited to Linux systems
  • Learning curve for advanced features like scripting and dynamic patching
  • Requires specific compiler flags or runtime support for full functionality

Best For

Performance analysis and profiling of C/C++/Rust/Python programsDebugging complex execution flows across user and kernel boundariesUnderstanding program behavior without source modificationsCreating custom diagnostic tools using scripting APIsVisualizing program execution with flame graphs or call graphs

FAQ

Does uftrace require recompilation of the target program?
No, uftrace can trace without recompilation by dynamically patching function prologues. Alternatively, it can use compiler instrumentation via -pg, -finstrument-functions, or -fpatchable-function-entry.
What programming languages are supported?
uftrace supports C, C++, Rust, and Python programs.
Can uftrace trace kernel functions?
Yes, uftrace can trace kernel functions using the Linux kernel's ftrace framework and kernel trace events via the event tracing framework.
What kind of visualization does uftrace provide?
uftrace can generate visualizations using Chrome trace viewer, flame graphs, and call-graph diagrams for graphviz and mermaid.
Is uftrace free and open source?
Yes, uftrace is open source and free to use, hosted on GitHub under an open source license.