Function Call Tracing

Instrument C/C++ with -finstrument-functions for execution tracing and Perfetto visualization

25 stars

Best use case

Function Call Tracing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Instrument C/C++ with -finstrument-functions for execution tracing and Perfetto visualization

Teams using Function Call Tracing should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/function-tracing/SKILL.md --create-dirs "https://raw.githubusercontent.com/ComeOnOliver/skillshub/main/skills/gadievron/raptor/function-tracing/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/function-tracing/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How Function Call Tracing Compares

Feature / AgentFunction Call TracingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Instrument C/C++ with -finstrument-functions for execution tracing and Perfetto visualization

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 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:**
```bash
gcc -c -fPIC trace_instrument.c -o trace_instrument.o
gcc -shared trace_instrument.o -o libtrace.so -ldl -lpthread
```

### 2. Perfetto Converter (trace_to_perfetto.cpp)
Converts logs to Chrome JSON for Perfetto UI.

**Build:**
```bash
g++ -O3 -std=c++17 trace_to_perfetto.cpp -o trace_to_perfetto
```

## Usage

### Step 1: Add to Build
```makefile
CFLAGS += -finstrument-functions -g
LDFLAGS += -L. -ltrace -ldl -lpthread
```

### Step 2: Build Target
```bash
make
```

### Step 3: Run
```bash
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
./program
# Creates trace_<tid>.log files
```

### Step 4: Convert to Perfetto
```bash
./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
1. Copy `trace_instrument.c` and `trace_to_perfetto.cpp` to project
2. Build instrumentation library
3. Add `-finstrument-functions` to CFLAGS
4. Add `-L. -ltrace -ldl -lpthread` to LDFLAGS
5. Build project
6. Set `LD_LIBRARY_PATH` and run
7. Convert logs: `./trace_to_perfetto trace_*.log -o trace.json`
8. Provide link to ui.perfetto.dev

### Build System Detection
**Makefile:** Add flags conditionally
```makefile
ENABLE_TRACE ?= 0
ifeq ($(ENABLE_TRACE),1)
    CFLAGS += -finstrument-functions -g
    LDFLAGS += -L. -ltrace -ldl -lpthread
endif
```

**CMake:** Add option
```cmake
option(ENABLE_TRACE "Enable tracing" OFF)
if(ENABLE_TRACE)
    add_compile_options(-finstrument-functions -g)
    link_libraries(trace dl pthread)
endif()
```

## Output
- **trace_<tid>.log**: Per-thread text logs
- **trace.json**: Perfetto Chrome JSON format
- View at https://ui.perfetto.dev

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

Related Skills

window-function-generator

25
from ComeOnOliver/skillshub

Window Function Generator - Auto-activating skill for Data Analytics. Triggers on: window function generator, window function generator Part of the Data Analytics skill category.

step-functions-workflow

25
from ComeOnOliver/skillshub

Step Functions Workflow - Auto-activating skill for AWS Skills. Triggers on: step functions workflow, step functions workflow Part of the AWS Skills skill category.

setting-up-distributed-tracing

25
from ComeOnOliver/skillshub

Execute this skill automates the setup of distributed tracing for microservices. it helps developers implement end-to-end request visibility by configuring context propagation, span creation, trace collection, and analysis. use this skill when the user re... Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

oauth-callback-handler

25
from ComeOnOliver/skillshub

Oauth Callback Handler - Auto-activating skill for API Integration. Triggers on: oauth callback handler, oauth callback handler Part of the API Integration skill category.

lambda-function-generator

25
from ComeOnOliver/skillshub

Lambda Function Generator - Auto-activating skill for AWS Skills. Triggers on: lambda function generator, lambda function generator Part of the AWS Skills skill category.

early-stopping-callback

25
from ComeOnOliver/skillshub

Early Stopping Callback - Auto-activating skill for ML Training. Triggers on: early stopping callback, early stopping callback Part of the ML Training skill category.

cloud-function-generator

25
from ComeOnOliver/skillshub

Cloud Function Generator - Auto-activating skill for GCP Skills. Triggers on: cloud function generator, cloud function generator Part of the GCP Skills skill category.

async-api-caller

25
from ComeOnOliver/skillshub

Async Api Caller - Auto-activating skill for API Integration. Triggers on: async api caller, async api caller Part of the API Integration skill category.

Voice Call

25
from ComeOnOliver/skillshub

Use the voice-call plugin to start or inspect calls (Twilio, Telnyx, Plivo, or mock).

go-functions

25
from ComeOnOliver/skillshub

Use when organizing functions within a Go file, formatting function signatures, designing return values, or following Printf-style naming conventions. Also use when a user is adding or refactoring any Go function, even if they don't mention function design or signature formatting. Does not cover functional options constructors (see go-functional-options).

go-functional-options

25
from ComeOnOliver/skillshub

Use when designing a Go constructor or factory function with optional configuration — especially with 3+ optional parameters or extensible APIs. Also use when building a New* function that takes many settings, even if they don't mention "functional options" by name. Does not cover general function design (see go-functions).

../../../c-level-advisor/executive-mentor/skills/hard-call/SKILL.md

25
from ComeOnOliver/skillshub

No description provided.