Hi Bob,
complicated answer: yes, but.
So, we do have the performance counters that can be enabled at compile time in GNU Radio,
and which can be queried through ctrlport. Ctrlport has been hard to or impossible to use
for quite a while, so it's pretty possible this is not a viable option to you. However, if
it is: the gr-perf-monitorx program connects to a running flowgraph's ctrlport server and
displays statistics like average and per-item runtime. These performance counters do come
with performance overhead, so use at your own risk.
A lot easier would be to attach a "Probe Rate" block to the filter's output (unless you
inherently know the rate already), and use `perf top -ag` to check how much time your CPU
cores spend in which function (pretty much randomly sampled); this won't give you an exact
"time per call", but it would give you a "CPU usage percentage per call" and inherently
"usage percentage per sample", if you will. That might be what you need, but it might also
*not* be what you need.
In case you really want to get the time in seconds per call, and relate that to the number
of items produces: see the attached bpftrace script. This uses modern Linux and bpftrace
capabilities to hook user functions. It still does have some, but usually, much more
benign, overhead.
Best regards,
Marcus
On 13.02.24 16:47, Bob Gnu wrote:
I'm using the 'Lowpass Filter Block'. Is there a way to get the average execution time
for that block? Per sample or per 1000 samples, for example? The sample rate is 2 MHz.
thanks
#!/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<float, float, float>::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<float,
float, float>::work"
{
@start_work[tid] = nsecs;
}
uretprobe:/path/to/my/libgnuradio-filter.so:cpp:"gr::filter::fir_filter_blk_impl<float,
float, float>::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]);
}