C++ cache-profiler library and CLI built on eBPF.
Current scope:
- L1 read accesses and misses
- L2 read accesses and misses
- LLC read accesses and misses
meson setup build
meson compile -C buildsudo ./build/cache_profiler [options] <pid> <interval_ms> [duration_ms]- Options must come before positional arguments.
--terminal-log: enables terminal output.--csv-log: enables CSV output mode.--csv-path <dir>: CSV output directory (default: current directory).--csv-filename <name>: CSV file name.- Default when omitted:
YYYYMMDDTHHMMSS_PID.csv.
- Default when omitted:
--csv-flush-samples <count>: number of samples buffered before file flush (default:10).--terminal-logand CSV options can be used together to log to terminal and CSV simultaneously.interval_ms: sampling period between emitted cumulative snapshots.duration_ms(optional): total profiler runtime. If omitted, profiling continues until the profiler is stopped or the target PID exits.- Optional log level control: set
CACHE_PROFILER_LOG_LEVELtodebug,info,warning, orerror(default:info). - Current sample semantics: each metric is cumulative since profiling initialization (not interval delta).
Public headers:
include/CacheProfilerApp.hinclude/CacheSampleLoggerConfig.hinclude/ProfilingConfig.hinclude/ICacheProfiler.hinclude/EBpfCacheProfiler.hinclude/CacheSample.hinclude/ICacheSampleLogger.hinclude/TerminalCacheSampleLogger.hinclude/CsvCacheSampleLogger.h
Runtime split:
CacheProfilerAppis the library entry point that runs periodic sampling.ICacheProfilerimplementations only produce samples.ICacheSampleLoggerimplementations decide how samples are emitted (terminal now, CSV later).- The CLI client (
src/client/Main.cpp) only parses CLI arguments and invokes the library API.
L2 and LLC events are currently opened as raw PMU events (model-specific encodings such as L2_RQSTS and longest_lat_cache.*), so kernel/CPU support is required.
Note on map compatibility:
- BPF maps are declared using legacy
bpf_map_deffor compatibility with this machine's kernel/libbpf map-create behavior. - Profiling still runs in-kernel via eBPF (
tracepoint+bpf_perf_event_read). - Tradeoff: reduced BTF-based map metadata/introspection compared to modern BTF-style map declarations.
Reusable experiment harness lives in playground/.