Skip to content

Pull Request: eBPF-based CPU Cycle Sampling Module#23

Open
dierpg wants to merge 3 commits intomasterfrom
feature/ebpf_modules
Open

Pull Request: eBPF-based CPU Cycle Sampling Module#23
dierpg wants to merge 3 commits intomasterfrom
feature/ebpf_modules

Conversation

@dierpg
Copy link
Copy Markdown
Collaborator

@dierpg dierpg commented Apr 30, 2026

Summary
This PR introduces eBPF-based CPU cycle sampling support to efimon via a new SamplingByPIDObserver class and its underlying Sampling_by_PID subproject. It replaces the need for ptrace-based instruction sampling with a lower-overhead eBPF approach that attaches to a target process by PID.

Changes
New: SamplingByPIDObserver
Implements the Observer interface using an eBPF perf-event program to sample CPU cycles from a running process by PID.
Collects instruction pointers and decodes them via the AsmClassifier, producing InstructionReadings.
Supports configurable sampling frequency (Hz) and polling interval; the frequency is automatically capped to the kernel's perf_event_max_sample_rate.
Runs a background thread to periodically drain eBPF ring/perf buffers.

New: Sampling_by_PID subproject
Self-contained eBPF subproject providing the BPF program (prog.bpf.c) and the userspace sampler library (sampler_lib.cpp/.hpp).
Integrated into the efimon build via Meson.
New example: sampling-by-pid-testing
Demonstrates attaching SamplingByPIDObserver to a process, querying samples, and printing instruction mix results.

Build system updates
Added optional eBPF module build paths and linked the new subproject.
Updated include install targets for ebpf-modules/sampling-by-pid and ebpf-modules/moduloio-disk headers.

Housekeeping
Added vmlinux.h to .gitignore.
Cleaned stale files from existing eBPF module directories.
Minor fixes in proc observers, process manager, and tool sources.

Testing
A new example binary sampling-by-pid-testing is provided. Run it against any target PID to verify eBPF attach, sample collection, and instruction classification output.

Notes
Requires kernel support for perf_event_open and eBPF (CONFIG_BPF_SYSCALL, CONFIG_PERF_EVENTS). The observer will fail gracefully if the kernel caps or denies the requested sampling rate.
ObserverScope::SYSTEM is not supported; only ObserverScope::PROCESS is valid for this observer

dierpg added 3 commits April 14, 2026 05:54
added vmlinux.h to .gitignore
cleaned unnecesary files from ebpf modules and started work on observers
This commit adds headers and definitions for ebpf sampling
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