FuncGraph

Turns Linux ftrace function_graph output into one self-contained HTML report: a text view with resolved source, and a timeline that shows where the time went, error paths, critical sections and scheduling delays. Import uftrace to follow calls from user space into the kernel.

把 Linux ftrace 的 function_graph 输出转换成一个自包含的 HTML 报告: 带源码的文本视图,以及能看出时间花在哪里、错误从哪里来、关中断/关抢占区间和调度延迟的时间轴。导入 uftrace 后还能从用户态一路追到内核。

User → kernel: follow a UDP send

从用户态到内核态:追踪一次 UDP 发送

FuncGraph Timeline with a user-to-kernel divider in the sendto call stack

Follow main → run_round → exchange_loopback → send_frame → dispatch_datagram → sendto → __x64_sys_sendto in a real QEMU capture. Select dispatch_datagram for its recorded address, arguments and return value. The thin line marks the linked kernel call; Text underlines its K tag.

在真实的 QEMU 记录中,沿 main → run_round → exchange_loopback → send_frame → dispatch_datagram → sendto → __x64_sys_sendto 下探。 选中 dispatch_datagram 可看记录的地址、参数和返回值。细线标在内核调用顶边,Text 中对应入口的 K 带下划线。

Kernel-only: source and error paths

纯内核态:源码与错误路径

FuncGraph Timeline of the kernel-only sample

The sample: one process reads and writes 4 KB and sends a UDP datagram to itself (QEMU x86_64, Linux 7.4-rc2; 485 recorded calls). Selected: process_backlog, 24.21 us in the loopback softirq receive path; source links are pinned to the matching upstream tag.

示例:一个进程读写 4 KB 文件,再通过 loopback 给自己发一个 UDP 包(QEMU x86_64,Linux 7.4-rc2;485 次记录调用)。 选中的是 loopback 软中断接收路径中的 process_backlog,耗时 24.21 us;源码链接固定到匹配的上游标签。

What it shows

能看到什么

Text filters

Choose a CPU, task or recorded event type from the report's menus, and combine those selections with text search.

Timeline

Per-task flame chart over time, CPU tracks, off-CPU periods, wakeup arrows and wait chains.

Where the time went

Each call split into own code, traced callees, interrupts and blocked/preempted time, with an overhead estimate.

Error paths

Errnos from funcgraph-retval followed from their origin to user space, checked against BTF return types.

Critical sections

irqs-off, preempt-off and BH-off regions, scheduling latency windows, sleeping in atomic context.

Source

Call sites resolved to file:line with their inline chain and highlighted source.

Compare and export

Per-function differences between two traces; JSON/CSV export for scripts and CI.

Text 筛选

从报告的菜单中选择 CPU、任务或已记录的事件类型,还可以叠加文本搜索。

时间轴

按任务的时序火焰图、CPU 轨道、off-CPU 时段、唤醒箭头和等待链。

时间花在哪里

每次调用拆分为自身代码、被跟踪的子调用、中断、阻塞/被抢占时间,并估算跟踪开销。

错误路径

根据 funcgraph-retval 从错误源头一路追到用户态,并用 BTF 返回类型校验。

临界区

关中断、关抢占、关软中断的区间,调度延迟窗口,在原子上下文里睡眠。

源码

调用点解析到文件和行号,附内联链和语法高亮的源码。

对比和导出

两份 trace 按函数对比;JSON/CSV 导出,便于脚本和 CI 使用。

Try it

快速上手

# on the target, as root: capture one command with the timeline options# 在目标机上(root):采集一条命令,打开时间轴需要的选项
fgcapture.sh --sched --calibrate -o trace.txt -- cat /etc/hostname

# on the host# 在主机上
python3 funcgraph.py --timeline --enable-fold --filter --fast \
    --vmlinux vmlinux --kernel-src linux --output report.html trace.txt