Skip to content

libbpf-tools/functrace: Add uprobe-based function tracer - #5537

Draft
ekyooo wants to merge 3 commits into
iovisor:masterfrom
ekyooo:functrace
Draft

libbpf-tools/functrace: Add uprobe-based function tracer#5537
ekyooo wants to merge 3 commits into
iovisor:masterfrom
ekyooo:functrace

Conversation

@ekyooo

@ekyooo ekyooo commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Add functrace, a BPF CO-RE tool that traces userspace function calls
via uprobes/uretprobes and reconstructs call trees with per-function
latency measurement.

Features:

  • uprobe/uretprobe-based function entry/exit tracing
  • per-thread shadow stack for call tree reconstruction
  • --root-func for trace boundary detection (transaction grouping)
  • configurable max call depth (--max-depth)
  • configurable ring buffer size (--ringbuf-size)
  • top-down text diagram output to stdout or file
  • PID filtering support
  • duration-based tracing

Why this approach

Why this approach

Many production issues — especially on embedded/edge devices or with immutable binaries — require
reconstructing a single process execution after the fact. Rebuilding the binary, adding SDK
instrumentation, or shipping a compiler toolchain to the target is frequently not possible.

functrace therefore attaches to running binaries from the outside with zero source access and
zero recompilation, reconstructs the call tree in-kernel to minimize userspace event overhead, and
keeps export format decisions (e.g., OpenTelemetry) out of the BPF tool itself so it stays usable
standalone.

This design prioritizes deployability and post-hoc observability over the richer but invasive
guarantees of compile-time instrumentation.


Checklist

  • [/] Commit prefix matches changed area (e.g., tools/toolname:, libbpf-tools/toolname:, src/cc:, docs:, build:, tests/python:)
  • Commit body explains why this change is needed

For new tools only

  • Explains why this tool is needed and what existing tools cannot cover this use case
  • Includes at least one real production use case
  • Man page (man/man8/) with an OVERHEAD section
  • Example output file (*_example.txt)
  • README.md entry added
  • Smoke test added to tests/python/test_tools_smoke.py

ekyooo added 3 commits August 7, 2026 20:25
Add functrace, a BPF CO-RE tool that traces userspace function calls
via uprobes/uretprobes and reconstructs call trees with per-function
latency measurement.

Features:
- uprobe/uretprobe-based function entry/exit tracing
- per-thread shadow stack for call tree reconstruction
- --root-func for trace boundary detection (transaction grouping)
- configurable max call depth (--max-depth)
- configurable ring buffer size (--ringbuf-size)
- top-down text diagram output to stdout or file
- PID filtering support
- duration-based tracing

Signed-off-by: Eunseon Lee <es.lee@lge.com>
Add shared helpers for emitting OTLP-compatible span records:

- struct span / enum span_kind / enum span_status:
  Userspace representation of an OTLP-compatible span record
  with 128-bit traceId, 64-bit spanId/parentSpanId, timing,
  and status fields.

- print_span():
  Emit a span record as OTLP-compatible JSONL (one JSON object
  per line), suitable for piping to an OTLP collector.

- struct time_sync / sync_time() / convert_to_realtime_ns():
  Convert BPF ktime (CLOCK_MONOTONIC) to Unix epoch nanoseconds
  for OTLP timestamp fields.

These utilities enable BPF tools to produce trace output that can
be ingested by OTLP backends such as Grafana Tempo, Jaeger, or
any OpenTelemetry-compatible collector.

Signed-off-by: Eunseon Lee <es.lee@lge.com>
Integrate trace_helpers OTLP utilities into functrace, enabling
OTLP-compatible span output for distributed tracing backends.

New option:
  -F otel    Output OTLP-compatible JSONL (one span per line)

The OTLP output includes:
- 128-bit traceId (pre-injected from userspace for consistency)
- 64-bit spanId and parentSpanId for call tree reconstruction
- Unix epoch nanosecond timestamps (converted from BPF ktime)
- Function name, pid/tid, and status fields

Example pipeline:
  functrace -b ./app -f func1 -f func2 -F otel | otlp-forwarder

Signed-off-by: Eunseon Lee <es.lee@lge.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant