function call tracing

Function Call Tracing

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "function call tracing" with this command: npx skills add gadievron/raptor/gadievron-raptor-function-call-tracing

Function Call Tracing

Purpose

Trace all function calls in C/C++ programs with per-thread logs and Perfetto visualization.

Components

  1. Instrumentation Library (trace_instrument.c)

Captures function entry/exit, writes per-thread logs.

Build:

gcc -c -fPIC trace_instrument.c -o trace_instrument.o gcc -shared trace_instrument.o -o libtrace.so -ldl -lpthread

  1. Perfetto Converter (trace_to_perfetto.cpp)

Converts logs to Chrome JSON for Perfetto UI.

Build:

g++ -O3 -std=c++17 trace_to_perfetto.cpp -o trace_to_perfetto

Usage

Step 1: Add to Build

CFLAGS += -finstrument-functions -g LDFLAGS += -L. -ltrace -ldl -lpthread

Step 2: Build Target

make

Step 3: Run

export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./program

Creates trace_<tid>.log files

Step 4: Convert to Perfetto

./trace_to_perfetto trace_*.log -o trace.json

Open trace.json in ui.perfetto.dev

Log Format

[seq] [timestamp] [dots] [ENTRY|EXIT!] function_name [0] [1.000000000] [ENTRY] main [1] [1.000050000] . [ENTRY] helper [2] [1.000100000] . [EXIT!] helper [3] [1.000150000] [EXIT!] main

  • Dots indicate call depth

  • Timestamp in seconds.nanoseconds

  • One log file per thread

When User Requests Tracing

Steps

  • Copy trace_instrument.c and trace_to_perfetto.cpp to project

  • Build instrumentation library

  • Add -finstrument-functions to CFLAGS

  • Add -L. -ltrace -ldl -lpthread to LDFLAGS

  • Build project

  • Set LD_LIBRARY_PATH and run

  • Convert logs: ./trace_to_perfetto trace_*.log -o trace.json

  • Provide link to ui.perfetto.dev

Build System Detection

Makefile: Add flags conditionally

ENABLE_TRACE ?= 0 ifeq ($(ENABLE_TRACE),1) CFLAGS += -finstrument-functions -g LDFLAGS += -L. -ltrace -ldl -lpthread endif

CMake: Add option

option(ENABLE_TRACE "Enable tracing" OFF) if(ENABLE_TRACE) add_compile_options(-finstrument-functions -g) link_libraries(trace dl pthread) endif()

Output

Perfetto JSON Format

Function ENTRY → "B" (begin) event Function EXIT! → "E" (end) event All threads aligned by timestamp in single file.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

rr-debugger

No summary provided by upstream source.

Repository SourceNeeds Review
General

line execution checker

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

github-wayback-recovery

No summary provided by upstream source.

Repository SourceNeeds Review