Skip to content

bpftrace Basics

Data Types and Variables

bpftrace supports basic data types and variables for storing and manipulating data:
- Integers: int, long, etc.
- Strings: Enclosed in quotes (e.g., "Hello, world!").
- Pointers: Use ptr type for memory addresses.
- Structs: Define custom structures for complex data.

Variables are declared and assigned inline:

bpftrace -e 'kprobe:sys_open { $count = $count + 1; printf("Opens: %d", $count); }'
This script manually increments a counter variable $count for each sys_open call and prints it dynamically.

Note: count() is an action that increments a counter, not a function that returns a value. Use $count = $count + 1 for manual incrementing.