#!/usr/bin/bpftrace /* * Trace Runtime of a GNU Radio block * For Linux, uses bpftrace and eBPF. * * Usage: * * 0. Install GNU Radio and bpftrace * 1. change the path to the library you want to probe * (in this example, that was /path/to/my/libgnuradio-filter.so). * If the library is installed in a system-default location, the * name alone should suffice. * 2. change the C++ name of the work function you want to probe * (in this example, * gr::filter::fir_filter_blk_impl::work) * 3. run this script as root: * `sudo bpftrace thisscript.bt | tee statistics.txt` * 4. Start your GNU Radio flow graph * 5. Marvel at the numbers you're getting! * * Copyright (c) 2021 Tao Xu (as sslsnoop.bt) * Copyright (c) 2024 Marcus Müller * Licensed under the Apache License, Version 2.0 (the "License") * * 15-Dec-2021 Tao Xu created this. * 14-Feb-2024 Marcus Müller adopted to GR */ BEGIN { printf("Tracing work call runtimes... Hit Ctrl-C to end.\n"); printf("NOTE: this assumes that the block never manually calls produce(), but returns the items produced in each call!\n"); printf("%8s %7s %5s\n", "TID", "Δt [ns]", "Ret (s/S)"); } uprobe:/path/to/my/libgnuradio-filter.so:cpp:"gr::filter::fir_filter_blk_impl::work" { @start_work[tid] = nsecs; } uretprobe:/path/to/my/libgnuradio-filter.so:cpp:"gr::filter::fir_filter_blk_impl::work" /@start_work[tid] != 0/ { printf("%-8d %7u %5d\n", tid, (nsecs - @start_work[tid]), 1e9 * retval / (nsecs - @start_work[tid])); delete(@start_work[tid]); }